Skip to content

Commit

Permalink
State change -> event
Browse files Browse the repository at this point in the history
  • Loading branch information
codetheweb committed Oct 28, 2023
1 parent e15de69 commit f10831b
Show file tree
Hide file tree
Showing 4 changed files with 11 additions and 50 deletions.
22 changes: 2 additions & 20 deletions entrypoints/internal.d.mts
Original file line number Diff line number Diff line change
@@ -1,25 +1,7 @@
import type {StateChangeEvent} from '../types/state-change-events.d.cts';

export type RunEvent = {
type: 'stateChange';
stateChange: StateChangeEvent;
} | {
type: 'run';
plan: {
bailWithoutReporting: boolean;
debug: boolean;
failFastEnabled: boolean;
filePathPrefix: string;
files: string[];
matching: boolean;
previousFailures: number;
runOnlyExclusive: boolean;
firstRun: boolean;
};
};

export type {StateChangeEvent} from '../types/state-change-events.d.cts';
export type Event = StateChangeEvent;

export type ObservedRun = {
events: AsyncIterableIterator<RunEvent>;
events: AsyncIterableIterator<Event>;
};
13 changes: 1 addition & 12 deletions lib/api-event-iterator.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,20 +2,9 @@ import {on} from 'node:events';

export async function * asyncEventIteratorFromApi(api) {
for await (const [plan] of on(api, 'run')) {

Check failure on line 4 in lib/api-event-iterator.js

View workflow job for this annotation

GitHub Actions / Lint source files

Block must not be padded by blank lines.
yield {
type: 'run',
plan,
};

for await (const [stateChange] of on(plan.status, 'stateChange')) {
yield {
type: 'stateChange',
stateChange,
};

if (stateChange.type === 'end') {
break;
}
yield stateChange;
}
}

Check warning on line 9 in lib/api-event-iterator.js

View check run for this annotation

Codecov / codecov/patch

lib/api-event-iterator.js#L9

Added line #L9 was not covered by tests
}
2 changes: 1 addition & 1 deletion test/internal-events/fixtures/ava.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ export default {
for await (const event of run.events) {
internalEvents.push(event);

if (event.type === 'stateChange' && event.stateChange.type === 'end') {
if (event.type === 'end') {
await fs.writeFile('internal-events.json', JSON.stringify(internalEvents));
}
}
Expand Down
24 changes: 7 additions & 17 deletions test/internal-events/test.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,28 +11,18 @@ test('internal events are emitted', async t => {
const result = JSON.parse(await fs.readFile(fileURLToPath(new URL('fixtures/internal-events.json', import.meta.url))));

t.like(result[0], {
type: 'run',
plan: {
files: [
fileURLToPath(new URL('fixtures/test.js', import.meta.url)),
],
},
type: 'starting',
testFile: fileURLToPath(new URL('fixtures/test.js', import.meta.url)),
});

const testPassedEvent = result.find(event => event.type === 'stateChange' && event.stateChange.type === 'test-passed');
const testPassedEvent = result.find(event => event.type === 'test-passed');
t.like(testPassedEvent, {
type: 'stateChange',
stateChange: {
type: 'test-passed',
title: 'placeholder',
testFile: fileURLToPath(new URL('fixtures/test.js', import.meta.url)),
},
type: 'test-passed',
title: 'placeholder',
testFile: fileURLToPath(new URL('fixtures/test.js', import.meta.url)),
});

t.like(result[result.length - 1], {
type: 'stateChange',
stateChange: {
type: 'end',
},
type: 'end',
});
});

0 comments on commit f10831b

Please sign in to comment.