()
| 1286 | } |
| 1287 | |
| 1288 | async run() { |
| 1289 | if (this.parent !== null) { |
| 1290 | this.parent.activeSubtests++; |
| 1291 | this.computeInheritedHooks(); |
| 1292 | } |
| 1293 | this.startTime ??= hrtime(); |
| 1294 | |
| 1295 | // Channel context object shared across all lifecycle events for this test run. |
| 1296 | // Only tests emit events; hooks do not. This way, the test's span encompasses |
| 1297 | // its before/beforeEach hooks, the test body, and its afterEach/after hooks. |
| 1298 | const channelContext = this.hookType === undefined ? { |
| 1299 | __proto__: null, |
| 1300 | name: this.name, |
| 1301 | nesting: this.nesting, |
| 1302 | file: this.entryFile, |
| 1303 | type: this.reportedType, |
| 1304 | } : null; |
| 1305 | |
| 1306 | if (this[kShouldAbort]()) { |
| 1307 | this.postRun(); |
| 1308 | return; |
| 1309 | } |
| 1310 | |
| 1311 | const hookArgs = this.getRunArgs(); |
| 1312 | const { args, ctx } = hookArgs; |
| 1313 | |
| 1314 | if (this.plan === null && this.expectedAssertions) { |
| 1315 | ctx.plan(this.expectedAssertions); |
| 1316 | } |
| 1317 | |
| 1318 | const wasSkippedBeforeRun = this.skipped; |
| 1319 | |
| 1320 | const after = async () => { |
| 1321 | if (this.hooks.after.length > 0) { |
| 1322 | await this.runHook('after', hookArgs); |
| 1323 | } |
| 1324 | }; |
| 1325 | const afterEach = runOnce(async () => { |
| 1326 | if (this.parent?.hooks.afterEach.length > 0 && !wasSkippedBeforeRun) { |
| 1327 | await this.parent.runHook('afterEach', hookArgs); |
| 1328 | } |
| 1329 | }, kRunOnceOptions); |
| 1330 | |
| 1331 | let stopPromise; |
| 1332 | |
| 1333 | let publishEnd = () => testChannel.end.publish(channelContext); |
| 1334 | let publishError = (err) => testChannel.error.publish({ __proto__: null, ...channelContext, error: err }); |
| 1335 | |
| 1336 | try { |
| 1337 | if (this.parent?.hooks.before.length > 0) { |
| 1338 | // This hook usually runs immediately, we need to wait for it to finish |
| 1339 | await this.parent.runHook('before', this.parent.getRunArgs()); |
| 1340 | } |
| 1341 | if (this.parent?.hooks.beforeEach.length > 0 && !this.skipped) { |
| 1342 | await this.parent.runHook('beforeEach', hookArgs); |
| 1343 | } |
| 1344 | stopPromise = stopTest(this.timeout, this.signal); |
| 1345 | const runArgs = ArrayPrototypeSlice(args); |
no test coverage detected