diff --git a/bin/d2l-test-runner.js b/bin/d2l-test-runner.js index ddd0e0f7..6ac43891 100755 --- a/bin/d2l-test-runner.js +++ b/bin/d2l-test-runner.js @@ -4,7 +4,6 @@ import process from 'node:process'; import { runner } from '../src/server/cli/test-runner.js'; const { argv, stdout } = process; - const cli = commandLineArgs({ name: 'subcommand', defaultOption: true }, { stopAtFirstUnknown: true, argv }); if (cli.subcommand === 'vdiff') { @@ -17,15 +16,15 @@ if (cli.subcommand === 'vdiff') { stdout.write('\nGenerating vdiff goldens...\n'); runTests(); } else if (vdiff.subcommand === 'report') { - await import('../src/server/cli/vdiff/report.js'); - } else if (vdiff.subcommand === 'migrate') { + const { report } = await import('../src/server/cli/vdiff/report.js'); + await report.start(); + } else if (vdiff.subcommand === 'migrate') { const { migrate } = await import('../src/server/cli/vdiff/migrate.js'); await migrate.start(vdiff._unknown); } else { stdout.write(`\nfatal: unknown subcomamnd: ${vdiff.subcommand}\n`); } -} -else { +} else { runTests(); } diff --git a/src/server/bail.js b/src/server/bail.js deleted file mode 100644 index 32d6f0c5..00000000 --- a/src/server/bail.js +++ /dev/null @@ -1,7 +0,0 @@ -const bail = new Set(); -const bailOn = key => bail.delete(key); - -export { - bail, - bailOn -}; diff --git a/src/server/cli/vdiff/report.js b/src/server/cli/vdiff/report.js index 798fdcb9..79d468b7 100644 --- a/src/server/cli/vdiff/report.js +++ b/src/server/cli/vdiff/report.js @@ -1,18 +1,19 @@ #!/usr/bin/env node -import { bailOn } from '../../bail.js'; import { PATHS } from '../../visual-diff-plugin.js'; import { startDevServer } from '@web/dev-server'; -bailOn('report') || - -await startDevServer({ - config: { - nodeResolve: false, - open: `./${PATHS.REPORT_ROOT}/`, - rootDir: `${PATHS.VDIFF_ROOT}`, - preserveSymlinks: false, - watch: true - }, - readCliArgs: false, - readFileConfig: false -}); +export const report = { + start() { + return startDevServer({ + config: { + nodeResolve: false, + open: `./${PATHS.REPORT_ROOT}/`, + rootDir: `${PATHS.VDIFF_ROOT}`, + preserveSymlinks: false, + watch: true + }, + readCliArgs: false, + readFileConfig: false + }); + } +}; diff --git a/test/bin/d2l-test-runner.test.js b/test/bin/d2l-test-runner.test.js index 75403516..ce7d3e42 100644 --- a/test/bin/d2l-test-runner.test.js +++ b/test/bin/d2l-test-runner.test.js @@ -1,8 +1,8 @@ import { assert, restore, stub } from 'sinon'; -import { bail } from '../../src/server/bail.js'; import { expect } from 'chai'; import { migrate } from '../../src/server/cli/vdiff/migrate.js'; import process from 'node:process'; +import { report } from '../../src/server/cli/vdiff/report.js'; import { runner } from '../../src/server/cli/test-runner.js'; const { argv, stdout } = process; @@ -13,8 +13,8 @@ const run = async() => { describe('d2l-test-runner', () => { - beforeEach(() => { - bail.clear(); + afterEach(() => { + restore(); }); it('starts test runner with options', async() => { @@ -29,20 +29,17 @@ describe('d2l-test-runner', () => { restore(); }); - it('runs report.js', async() => { + it('starts report server', async() => { + const reportStub = stub(report, 'start'); const optionsStub = stub(runner, 'getOptions'); const startStub = stub(runner, 'start'); - bail.add('report'); argv.splice(0, argv.length, 'fake-node', 'fake-test-runner', 'vdiff', 'report'); await run(); - expect(bail).to.not.include('report'); - + assert.calledOnce(reportStub); assert.notCalled(optionsStub); assert.notCalled(startStub); - - restore(); }); it('generates goldens', async() => { @@ -57,11 +54,9 @@ describe('d2l-test-runner', () => { assert.calledOnceWithExactly(optionsStub, argv); assert.calledOnce(startStub); assert.calledOnceWithExactly(stdoutStub, '\nGenerating vdiff goldens...\n'); - - restore(); }); - it('calls migrate()', async() => { + it('starts migration', async() => { const migrateStub = stub(migrate, 'start'); const optionsStub = stub(runner, 'getOptions'); const startStub = stub(runner, 'start'); @@ -72,8 +67,6 @@ describe('d2l-test-runner', () => { assert.calledOnceWithExactly(migrateStub, ['./test/**/dir']); assert.notCalled(optionsStub); assert.notCalled(startStub); - - restore(); }); });