You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: guide/lifecycle.md
+13-13Lines changed: 13 additions & 13 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -11,13 +11,13 @@ Understanding the test run lifecycle is essential for writing effective tests, d
11
11
12
12
A typical Vitest test run goes through these main phases:
13
13
14
-
1.**Initialization** - Configuration loading and project setup
15
-
2.**Global Setup** - One-time setup before any tests run
16
-
3.**Worker Creation** - Test workers are spawned based on the [pool](/config/pool) configuration
17
-
4.**Test File Collection** - Test files are discovered and organized
18
-
5.**Test Execution** - Tests run with their hooks and assertions
19
-
6.**Reporting** - Results are collected and reported
20
-
7.**Global Teardown** - Final cleanup after all tests complete
14
+
1.**Initialization:** Configuration loading and project setup
15
+
2.**Global Setup:** One-time setup before any tests run
16
+
3.**Worker Creation:** Test workers are spawned based on the [pool](/config/pool) configuration
17
+
4.**Test File Collection:** Test files are discovered and organized
18
+
5.**Test Execution:** Tests run with their hooks and assertions
19
+
6.**Reporting:** Results are collected and reported
20
+
7.**Global Teardown:** Final cleanup after all tests complete
21
21
22
22
Phases 4–6 run once for each test file, so across your test suite they will execute multiple times and may also run in parallel across different files when you use more than [1 worker](/config/maxworkers).
23
23
@@ -124,10 +124,10 @@ Test files are executed based on your configuration:
124
124
125
125
The execution follows this order:
126
126
127
-
1.**File-level code** - All code outside `describe` blocks runs immediately
128
-
2.**Test collection** -`describe` blocks are processed, and tests are registered as side effects of importing the test file
129
-
3.**[`aroundAll`](/api/hooks#aroundall) hooks** - Wrap around all tests in the suite (must call `runSuite()`)
130
-
4.**[`beforeAll`](/api/hooks#beforeall) hooks** - Run once before any tests in the suite
127
+
1.**File-level code:** All code outside `describe` blocks runs immediately
128
+
2.**Test collection:**`describe` blocks are processed, and tests are registered as side effects of importing the test file
129
+
3.**[`aroundAll`](/api/hooks#aroundall) hooks:** Wrap around all tests in the suite (must call `runSuite()`)
130
+
4.**[`beforeAll`](/api/hooks#beforeall) hooks:** Run once before any tests in the suite
131
131
5.**For each test:**
132
132
-[`aroundEach`](/api/hooks#aroundeach) hooks wrap around the test (must call `runTest()`)
133
133
-`beforeEach` hooks execute (in order defined, or based on [`sequence.hooks`](/config/sequence#sequence-hooks))
@@ -136,7 +136,7 @@ The execution follows this order:
136
136
-[`onTestFinished`](/api/hooks#ontestfinished) callbacks run (always in reverse order)
137
137
- If test failed: [`onTestFailed`](/api/hooks#ontestfailed) callbacks run
138
138
- Note: if `repeats` or `retry` are set, all of these steps are executed again
139
-
6.**[`afterAll`](/api/hooks#afterall) hooks** - Run once after all tests in the suite complete
139
+
6.**[`afterAll`](/api/hooks#afterall) hooks:** Run once after all tests in the suite complete
140
140
141
141
**Example execution flow:**
142
142
@@ -347,7 +347,7 @@ Understanding where code executes is crucial for avoiding common pitfalls:
347
347
348
348
In watch mode, the lifecycle repeats with some differences:
349
349
350
-
1.**Initial run** - Full lifecycle as described above
350
+
1.**Initial run:** Full lifecycle as described above
351
351
2.**On file change:**
352
352
- New [test run](/api/advanced/reporters#ontestrunstart) starts
0 commit comments