Skip to content

Commit

Permalink
Cleanup
Browse files Browse the repository at this point in the history
  • Loading branch information
bearfriend committed Aug 4, 2023
1 parent 716cf93 commit 126be01
Show file tree
Hide file tree
Showing 4 changed files with 26 additions and 40 deletions.
9 changes: 4 additions & 5 deletions bin/d2l-test-runner.js
Original file line number Diff line number Diff line change
Expand Up @@ -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') {
Expand All @@ -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();
}

Expand Down
7 changes: 0 additions & 7 deletions src/server/bail.js

This file was deleted.

29 changes: 15 additions & 14 deletions src/server/cli/vdiff/report.js
Original file line number Diff line number Diff line change
@@ -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
});
}
};
21 changes: 7 additions & 14 deletions test/bin/d2l-test-runner.test.js
Original file line number Diff line number Diff line change
@@ -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;
Expand All @@ -13,8 +13,8 @@ const run = async() => {

describe('d2l-test-runner', () => {

beforeEach(() => {
bail.clear();
afterEach(() => {
restore();
});

it('starts test runner with options', async() => {
Expand All @@ -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() => {
Expand All @@ -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');
Expand All @@ -72,8 +67,6 @@ describe('d2l-test-runner', () => {
assert.calledOnceWithExactly(migrateStub, ['./test/**/dir']);
assert.notCalled(optionsStub);
assert.notCalled(startStub);

restore();
});

});

0 comments on commit 126be01

Please sign in to comment.