()
| 17 | } |
| 18 | |
| 19 | async function main() { |
| 20 | const events = await collectEvents(); |
| 21 | |
| 22 | // 1. Every per-test event should have a numeric testId. |
| 23 | const perTestTypes = new Set([ |
| 24 | 'test:start', 'test:complete', 'test:fail', |
| 25 | 'test:pass', 'test:enqueue', 'test:dequeue', |
| 26 | ]); |
| 27 | for (const event of events) { |
| 28 | if (perTestTypes.has(event.type)) { |
| 29 | assert.strictEqual(typeof event.data.testId, 'number', |
| 30 | `${event.type} for "${event.data.name}" should have numeric testId`); |
| 31 | } |
| 32 | } |
| 33 | |
| 34 | // 2. test:start and test:fail for the same instance should share testId. |
| 35 | const failEvent = events.find( |
| 36 | (e) => e.type === 'test:fail' && e.data.name === 'e2e', |
| 37 | ); |
| 38 | assert.ok(failEvent, 'should have a test:fail for "e2e"'); |
| 39 | |
| 40 | const startEvent = events.find( |
| 41 | (e) => e.type === 'test:start' && |
| 42 | e.data.testId === failEvent.data.testId, |
| 43 | ); |
| 44 | assert.ok(startEvent, 'should have a test:start with matching testId'); |
| 45 | assert.strictEqual(startEvent.data.name, 'e2e'); |
| 46 | |
| 47 | // 3. Concurrent instances at the same source location get distinct testIds. |
| 48 | const e2eStarts = events.filter( |
| 49 | (e) => e.type === 'test:start' && e.data.name === 'e2e', |
| 50 | ); |
| 51 | assert.strictEqual(e2eStarts.length, 4); |
| 52 | |
| 53 | const testIds = e2eStarts.map((e) => e.data.testId); |
| 54 | const uniqueIds = new Set(testIds); |
| 55 | assert.strictEqual(uniqueIds.size, 4, |
| 56 | `all 4 "e2e" instances should have distinct testIds, got: ${testIds}`); |
| 57 | |
| 58 | // 4. test:complete for the same instance shares testId with test:start. |
| 59 | const completeEvents = events.filter( |
| 60 | (e) => e.type === 'test:complete' && e.data.name === 'e2e', |
| 61 | ); |
| 62 | for (const complete of completeEvents) { |
| 63 | const matchingStart = e2eStarts.find( |
| 64 | (s) => s.data.testId === complete.data.testId, |
| 65 | ); |
| 66 | assert.ok(matchingStart, |
| 67 | `test:complete (testId=${complete.data.testId}) should match a test:start`); |
| 68 | } |
| 69 | |
| 70 | console.log('All testId assertions passed'); |
| 71 | } |
| 72 | |
| 73 | main().catch((err) => { |
| 74 | console.error(err); |
no test coverage detected