@@ -1076,7 +1076,7 @@ test('aroundAll enforces teardown timeout when inner error is caught', async () |
1076 | 1076 | }) |
1077 | 1077 |
|
1078 | 1078 | function extractLogs(log: string) { |
1079 | | - const result = log.split('\n').filter(line => line.match(/^![<>]/)).join('\n') |
| 1079 | + const result = log.split('\n').filter(line => line.match(/^(?:![<>]|\d+ -> \d+)/)).join('\n') |
1080 | 1080 | return `\n${result.trim()}\n` |
1081 | 1081 | } |
1082 | 1082 |
|
@@ -1194,33 +1194,33 @@ describe.for(["a", "b"])("%s", { concurrent: true }, () => { |
1194 | 1194 | `) |
1195 | 1195 | }) |
1196 | 1196 |
|
1197 | | -// we could enforce this by adding yet another limit globally at `runTest` |
1198 | | -// (like we originally had before https://github.com/vitest-dev/vitest/pull/9653) |
1199 | | -// but there's no way to achieve the same for deep suite-level hooks anyways, |
1200 | | -// so we don't do that (yet). |
1201 | | -test('non-sibling test sequential lifecycle non-guarantee', async () => { |
| 1197 | +test('non-sibling test sequential lifecycle guarantee', async () => { |
1202 | 1198 | const result = await runInlineTests({ |
1203 | 1199 | 'basic.test.ts': ` |
1204 | 1200 | const sleep = (ms: number) => new Promise(resolve => setTimeout(resolve, ms)) |
| 1201 | +let inFlight = 0 |
| 1202 | +
|
| 1203 | +function logInFlight(change: number, ...names: string[]) { |
| 1204 | + const previous = inFlight |
| 1205 | + inFlight += change |
| 1206 | + console.log(previous, "->", inFlight, ...names) |
| 1207 | +} |
1205 | 1208 |
|
1206 | 1209 | describe.for(["a0", "a1"])("%s", { concurrent: true }, () => { |
1207 | 1210 | describe.for(["b0", "b1"])("%s", { concurrent: true }, () => { |
1208 | 1211 | beforeEach(async ({ task }) => { |
1209 | | - console.log("!> beforeEach", task.suite.suite.name, task.suite.name, task.name) |
| 1212 | + logInFlight(1, "beforeEach", task.suite.suite.name, task.suite.name, task.name) |
1210 | 1213 | await sleep(10) |
1211 | | - console.log("!< beforeEach", task.suite.suite.name, task.suite.name, task.name) |
1212 | 1214 | }) |
1213 | 1215 |
|
1214 | 1216 | afterEach(async ({ task }) => { |
1215 | | - console.log("!> afterEach", task.suite.suite.name, task.suite.name, task.name) |
1216 | 1217 | await sleep(10) |
1217 | | - console.log("!< afterEach", task.suite.suite.name, task.suite.name, task.name) |
| 1218 | + logInFlight(-1, "afterEach", task.suite.suite.name, task.suite.name, task.name) |
1218 | 1219 | }) |
1219 | 1220 |
|
1220 | 1221 | test("test", async ({ task }) => { |
1221 | | - console.log("!> test", task.suite.suite.name,task.suite.name, task.name) |
| 1222 | + logInFlight(0, "test", task.suite.suite.name, task.suite.name, task.name) |
1222 | 1223 | await sleep(10) |
1223 | | - console.log("!< test", task.suite.suite.name,task.suite.name, task.name) |
1224 | 1224 | }) |
1225 | 1225 | }) |
1226 | 1226 | }) |
@@ -1232,30 +1232,18 @@ describe.for(["a0", "a1"])("%s", { concurrent: true }, () => { |
1232 | 1232 |
|
1233 | 1233 | expect(extractLogs(result.stdout)).toMatchInlineSnapshot(` |
1234 | 1234 | " |
1235 | | - !> beforeEach a0 b0 test |
1236 | | - !> beforeEach a0 b1 test |
1237 | | - !< beforeEach a0 b0 test |
1238 | | - !> beforeEach a1 b0 test |
1239 | | - !< beforeEach a0 b1 test |
1240 | | - !> beforeEach a1 b1 test |
1241 | | - !< beforeEach a1 b0 test |
1242 | | - !> test a0 b0 test |
1243 | | - !< beforeEach a1 b1 test |
1244 | | - !> test a0 b1 test |
1245 | | - !< test a0 b0 test |
1246 | | - !> test a1 b0 test |
1247 | | - !< test a0 b1 test |
1248 | | - !> test a1 b1 test |
1249 | | - !< test a1 b0 test |
1250 | | - !> afterEach a0 b0 test |
1251 | | - !< test a1 b1 test |
1252 | | - !> afterEach a0 b1 test |
1253 | | - !< afterEach a0 b0 test |
1254 | | - !> afterEach a1 b0 test |
1255 | | - !< afterEach a0 b1 test |
1256 | | - !> afterEach a1 b1 test |
1257 | | - !< afterEach a1 b0 test |
1258 | | - !< afterEach a1 b1 test |
| 1235 | + 0 -> 1 beforeEach a0 b0 test |
| 1236 | + 1 -> 2 beforeEach a0 b1 test |
| 1237 | + 2 -> 2 test a0 b0 test |
| 1238 | + 2 -> 2 test a0 b1 test |
| 1239 | + 2 -> 1 afterEach a0 b0 test |
| 1240 | + 1 -> 2 beforeEach a1 b0 test |
| 1241 | + 2 -> 1 afterEach a0 b1 test |
| 1242 | + 1 -> 2 beforeEach a1 b1 test |
| 1243 | + 2 -> 2 test a1 b0 test |
| 1244 | + 2 -> 2 test a1 b1 test |
| 1245 | + 2 -> 1 afterEach a1 b0 test |
| 1246 | + 1 -> 0 afterEach a1 b1 test |
1259 | 1247 | " |
1260 | 1248 | `) |
1261 | 1249 |
|
@@ -1287,25 +1275,29 @@ test('non-sibling suite sequential lifecycle non-guarantee', async () => { |
1287 | 1275 | const result = await runInlineTests({ |
1288 | 1276 | 'basic.test.ts': ` |
1289 | 1277 | const sleep = (ms: number) => new Promise(resolve => setTimeout(resolve, ms)) |
| 1278 | +let inFlight = 0 |
| 1279 | +
|
| 1280 | +function logInFlight(change: number, ...names: string[]) { |
| 1281 | + const previous = inFlight |
| 1282 | + inFlight += change |
| 1283 | + console.log(previous, "->", inFlight, ...names) |
| 1284 | +} |
1290 | 1285 |
|
1291 | 1286 | describe.for(["a0", "a1"])("%s", { concurrent: true }, () => { |
1292 | 1287 | describe.for(["b0", "b1"])("%s", { concurrent: true }, () => { |
1293 | 1288 | beforeAll(async ({}, suite) => { |
1294 | | - console.log("!> beforeAll", suite.suite.name, suite.name) |
| 1289 | + logInFlight(1, "beforeAll", suite.suite.name, suite.name) |
1295 | 1290 | await sleep(10) |
1296 | | - console.log("!< beforeAll", suite.suite.name, suite.name) |
1297 | 1291 | }) |
1298 | 1292 |
|
1299 | 1293 | afterAll(async ({}, suite) => { |
1300 | | - console.log("!> afterAll", suite.suite.name, suite.name) |
1301 | 1294 | await sleep(10) |
1302 | | - console.log("!< afterAll", suite.suite.name, suite.name) |
| 1295 | + logInFlight(-1, "afterAll", suite.suite.name, suite.name) |
1303 | 1296 | }) |
1304 | 1297 |
|
1305 | 1298 | test("test", async ({ task }) => { |
1306 | | - console.log("!> test", task.suite.suite.name, task.suite.name, task.name) |
| 1299 | + logInFlight(0, "test", task.suite.suite.name, task.suite.name, task.name) |
1307 | 1300 | await sleep(10) |
1308 | | - console.log("!< test", task.suite.suite.name, task.suite.name, task.name) |
1309 | 1301 | }) |
1310 | 1302 | }) |
1311 | 1303 | }) |
@@ -1317,30 +1309,18 @@ describe.for(["a0", "a1"])("%s", { concurrent: true }, () => { |
1317 | 1309 |
|
1318 | 1310 | expect(extractLogs(result.stdout)).toMatchInlineSnapshot(` |
1319 | 1311 | " |
1320 | | - !> beforeAll a0 b0 |
1321 | | - !> beforeAll a0 b1 |
1322 | | - !< beforeAll a0 b0 |
1323 | | - !> beforeAll a1 b0 |
1324 | | - !< beforeAll a0 b1 |
1325 | | - !> beforeAll a1 b1 |
1326 | | - !< beforeAll a1 b0 |
1327 | | - !> test a0 b0 test |
1328 | | - !< beforeAll a1 b1 |
1329 | | - !> test a0 b1 test |
1330 | | - !< test a0 b0 test |
1331 | | - !> test a1 b0 test |
1332 | | - !< test a0 b1 test |
1333 | | - !> test a1 b1 test |
1334 | | - !< test a1 b0 test |
1335 | | - !> afterAll a0 b0 |
1336 | | - !< test a1 b1 test |
1337 | | - !> afterAll a0 b1 |
1338 | | - !< afterAll a0 b0 |
1339 | | - !> afterAll a1 b0 |
1340 | | - !< afterAll a0 b1 |
1341 | | - !> afterAll a1 b1 |
1342 | | - !< afterAll a1 b0 |
1343 | | - !< afterAll a1 b1 |
| 1312 | + 0 -> 1 beforeAll a0 b0 |
| 1313 | + 1 -> 2 beforeAll a0 b1 |
| 1314 | + 2 -> 3 beforeAll a1 b0 |
| 1315 | + 3 -> 4 beforeAll a1 b1 |
| 1316 | + 4 -> 4 test a0 b0 test |
| 1317 | + 4 -> 4 test a0 b1 test |
| 1318 | + 4 -> 4 test a1 b0 test |
| 1319 | + 4 -> 4 test a1 b1 test |
| 1320 | + 4 -> 3 afterAll a0 b0 |
| 1321 | + 3 -> 2 afterAll a0 b1 |
| 1322 | + 2 -> 1 afterAll a1 b0 |
| 1323 | + 1 -> 0 afterAll a1 b1 |
1344 | 1324 | " |
1345 | 1325 | `) |
1346 | 1326 |
|
|