Skip to content

يمكن تكوين bun test باستخدام ملف bunfig.toml في جذر مشروعك.

تكوين bunfig.toml

يمكن تكوين bun test باستخدام ملف bunfig.toml في جذر مشروعك.

bunfig.toml
toml
[test]
# تكوين الاختبار

root

يحدد الدليل الجذر الذي سيتم تشغيل الاختبارات منه.

bunfig.toml
toml
[test]
root = "./tests"

preload

يحدد الملفات التي سيتم تحميلها مسبقًا قبل تشغيل الاختبارات. هذا مفيد لإعداد خطافات دورة الحياة أو المحاكاة العامة.

bunfig.toml
toml
[test]
preload = ["./test/setup.ts"]

يمكن تحديد ملفات متعددة:

bunfig.toml
toml
[test]
preload = ["./test/setup.ts", "./test/mocks.ts"]

coverage

يمكّن تقرير تغطية الكود.

bunfig.toml
toml
[test]
coverage = true

coverageSkipTestFiles

عند التمكين، يستبعد ملفات الاختبار نفسها من تقارير التغطية.

bunfig.toml
toml
[test]
coverageSkipTestFiles = true  # الافتراضي false

coverageThreshold

يحدد عتبة تغطية دنيا. إذا كانت التغطية أقل من هذه القيمة، سيفشل الاختبار.

bunfig.toml
toml
[test]
# عتبة بسيطة
coverageThreshold = 0.8

# عتبات مفصلة
coverageThreshold = { lines = 0.8, functions = 0.9, statements = 0.8 }

coverageReporter

يحدد مُبلغي التغطية لاستخدامهم.

bunfig.toml
toml
[test]
coverageReporter = ["text", "lcov"]

القيم المتاحة:

  • "text" - يطبع ملخصًا نصيًا إلى وحدة التحكم
  • "lcov" - يحفظ بتنسيق LCOV للتكامل مع أدوات CI/CD

coverageDir

يحدد دليل إخراج التغطية.

bunfig.toml
toml
[test]
coverageDir = "coverage-reports"  # الافتراضي "coverage"

coveragePathIgnorePatterns

يحدد أنماط الملفات التي سيتم استبعادها من تقارير التغطية.

bunfig.toml
toml
[test]
coveragePathIgnorePatterns = [
  "**/*.spec.ts",
  "src/utils/**",
  "*.config.js"
]

coverageIgnoreSourcemaps

عند التمكين، يتجاهل خرائط المصدر عند حساب التغطية.

bunfig.toml
toml
[test]
coverageIgnoreSourcemaps = true  # الافتراضي false

reporters

يحدد مُبلغي الاختبار لاستخدامهم.

bunfig.toml
toml
[test]
reporters = ["default", "junit"]

القيم المتاحة:

  • "default" - المبلغ الافتراضي
  • "junit" - إخراج بتنسيق JUnit XML
  • "json" - إخراج بتنسيق JSON

reporterOutfile

يحدد ملف الإخراج للمُبلغين مثل JUnit.

bunfig.toml
toml
[test]
reporterOutfile = "./test-results.xml"

timeout

يحدد مهلة الاختبار الافتراضية بالمللي ثانية.

bunfig.toml
toml
[test]
timeout = 5000  # 5 ثوانٍ

concurrent

يمكّن التنفيذ المتزامن للاختبارات.

bunfig.toml
toml
[test]
concurrent = true

maxConcurrency

يحدد الحد الأقصى لعدد الاختبارات التي تعمل بشكل متزامن.

bunfig.toml
toml
[test]
maxConcurrency = 10  # الافتراضي 20

randomize

يمكّن التشغيل العشوائي للاختبارات.

bunfig.toml
toml
[test]
randomize = true

seed

يحدد البذرة للعشوائية القابلة للتكرار.

bunfig.toml
toml
[test]
seed = 12345

bail

ينهي الاختبارات مبكرًا بعد عدد محدد من حالات الفشل.

bunfig.toml
toml
[test]
bail = 5  # الإنهاء بعد 5 فشل

rerunEach

يشغل كل اختبار عدة مرات.

bunfig.toml
toml
[test]
rerunEach = 3

testNamePattern

يصفّي الاختبارات حسب نمط الاسم.

bunfig.toml
toml
[test]
testNamePattern = "API"

only

عند التمكين، يشغل فقط الاختبارات المحددة بـ test.only.

bunfig.toml
toml
[test]
only = true

skip

عند التمكين، يتخطى جميع الاختبارات المحددة بـ test.skip.

bunfig.toml
toml
[test]
skip = true

todo

عند التمكين، يعامل الاختبارات المحددة بـ test.todo كاختبارات todo.

bunfig.toml
toml
[test]
todo = true

autoInstall

عند التمكين، يثبت التبعيات تلقائيًا عند الحاجة.

bunfig.toml
toml
[test]
autoInstall = true

ignore

يحدد الملفات أو الأدلة التي سيتم تجاهلها عند اكتشاف الاختبارات.

bunfig.toml
toml
[test]
ignore = [
  "node_modules/**",
  "dist/**",
  "build/**"
]

example

إليك مثال كامل لملف bunfig.toml:

bunfig.toml
toml
[test]
# الإعدادات الأساسية
root = "./tests"
preload = ["./tests/setup.ts"]
timeout = 10000

# التغطية
coverage = true
coverageSkipTestFiles = true
coverageThreshold = 0.8
coverageReporter = ["text", "lcov"]
coverageDir = "coverage"
coveragePathIgnorePatterns = [
  "**/*.spec.ts",
  "src/utils/**"
]

# المُبلغون
reporters = ["default", "junit"]
reporterOutfile = "./test-results.xml"

# التنفيذ
concurrent = true
maxConcurrency = 10
randomize = false
seed = 12345

# التصفية
testNamePattern = ""
ignore = ["node_modules/**", "dist/**"]

# خيارات أخرى
bail = 5
rerunEach = 1
autoInstall = true

متغيرات البيئة

يمكن أيضًا تكوين بعض الخيارات باستخدام متغيرات البيئة:

bash
# تعيين المهلة
BUN_TEST_TIMEOUT=10000 bun test

# تمكين التغطية
BUN_TEST_COVERAGE=1 bun test

# نمط اسم الاختبار
BUN_TEST_NAME_PATTERN="API" bun test

# البذرة العشوائية
BUN_TEST_SEED=12345 bun test

الأولوية

عند تحديد الخيارات في مواقع متعددة، تكون الأولوية كما يلي:

  1. خيارات سطر الأوامر (الأعلى أولوية)
  2. متغيرات البيئة
  3. bunfig.toml
  4. القيم الافتراضية (الأدنى أولوية)
bash
# يلغي هذا إعداد bunfig.toml
bun test --timeout=20000  # يتجاوز timeout = 10000 في bunfig.toml

تكوين خاص بالبيئة

يمكنك استخدام تكوينات مختلفة لبيئات مختلفة:

bunfig.toml
toml
# تكوين مشترك
[test]
timeout = 5000

# تكوين التطوير
[dev-test]
coverage = false
concurrent = false

# تكوين CI
[ci-test]
coverage = true
coverageReporter = ["lcov"]
reporters = ["junit"]

ثم في نصوص CI الخاصة بك:

bash
# للتطوير
bun test

# لـ CI
bun test --config bunfig.toml#ci-test

Bun بواسطة www.bunjs.com.cn تحرير