Skip to content

Commit

Permalink
No need for class
Browse files Browse the repository at this point in the history
  • Loading branch information
codetheweb committed Sep 25, 2023
1 parent 4d55422 commit 9296944
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 27 deletions.
17 changes: 17 additions & 0 deletions lib/api-event-iterator.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
import {on} from 'node:events';

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

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

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

View check run for this annotation

Codecov / codecov/patch

lib/api-event-iterator.js#L16

Added line #L16 was not covered by tests
}
8 changes: 6 additions & 2 deletions lib/cli.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import figures from 'figures';
import yargs from 'yargs';
import {hideBin} from 'yargs/helpers'; // eslint-disable-line n/file-extension-in-import

import {asyncEventIteratorFromApi} from './api-event-iterator.js';
import Api from './api.js';
import {chalk} from './chalk.js';
import validateEnvironmentVariables from './environment-variables.js';
Expand All @@ -19,7 +20,6 @@ import {loadConfig} from './load-config.js';
import normalizeModuleTypes from './module-types.js';
import normalizeNodeArguments from './node-arguments.js';
import pkg from './pkg.cjs';
import { ExternalRunObserver } from './external-run-observer.js';

function exit(message) {
console.error(`\n ${chalk.red(figures.cross)} ${message}`);
Expand Down Expand Up @@ -472,7 +472,11 @@ export default async function loadCli() { // eslint-disable-line complexity
});
}

const externalRunObserver = combined.observeRun ? new ExternalRunObserver(api, combined.observeRun) : null;
if (combined.observeRun) {
combined.observeRun({
events: asyncEventIteratorFromApi(api),
});
}

api.on('run', async plan => {
reporter.startRun(plan);
Expand Down
25 changes: 0 additions & 25 deletions lib/external-run-observer.js

This file was deleted.

0 comments on commit 9296944

Please sign in to comment.