Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add migrate-local subcommand #144

Merged
merged 6 commits into from
Aug 24, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 14 additions & 1 deletion bin/d2l-test-runner.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
#!/usr/bin/env node
import commandLineArgs from 'command-line-args';
import { execSync } from 'node:child_process';
import process from 'node:process';
import { runner } from '../src/server/cli/test-runner.js';

Expand All @@ -21,8 +22,20 @@ if (cli.subcommand === 'vdiff') {
} else if (vdiff.subcommand === 'migrate') {
const { migrate } = await import('../src/server/cli/vdiff/migrate.js');
await migrate.start(vdiff._unknown);
} else if (vdiff.subcommand === 'migrate-local') {

const { pattern = './**' } = commandLineArgs({ name: 'pattern', type: String, defaultOption: true }, { partial: true, argv: vdiff._unknown || [] });

stdout.write('\nInstalling @brightspace-ui/visual-diff\n');
execSync('npm install @brightspace-ui/visual-diff@14 --no-save');
stdout.write(`\nRunning existing tests for pattern '${pattern}/*.visual-diff.js'\n`);
execSync(`npx mocha '${pattern}/*.visual-diff.js' -t 10000 --golden`);
stdout.write('\nTest run complete.\n');

const { migrate } = await import('../src/server/cli/vdiff/migrate.js');
await migrate.start(vdiff._unknown, true);
} else {
stdout.write(`\nfatal: unknown subcomamnd: ${vdiff.subcommand}\n`);
stdout.write(`\nfatal: unknown subcommand: ${vdiff.subcommand}\n`);
}
} else {
runTests();
Expand Down
4 changes: 4 additions & 0 deletions src/server/cli/test-runner.js
Original file line number Diff line number Diff line change
Expand Up @@ -163,6 +163,10 @@ async function getTestRunnerOptions(argv = []) {
{
example: 'vdiff migrate [directory]',
desc: 'Migrate from @brightspace-ui/visual-diff. Restrict which goldens are migrated with a directory glob.'
},
{
example: 'vdiff migrate-local [directory]',
desc: 'Generate goldens with @brightspace-ui/visual-diff for local comparison while migrating tests. Restrict which goldens are generated with a directory glob.'
}]
}
]);
Expand Down
15 changes: 11 additions & 4 deletions src/server/cli/vdiff/migrate.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,11 @@ import { glob } from 'glob';
import { PATHS } from '../../visual-diff-plugin.js';
import { stdout } from 'node:process';

async function start(argv = []) {
async function start(argv = [], local = false) {
const { pattern = './**' } = commandLineArgs({ name: 'pattern', type: String, defaultOption: true }, { partial: true, argv });
const oldSuffix = 'screenshots/ci/golden';
const oldSuffix = local ? 'screenshots/golden' : 'screenshots/ci/golden';

stdout.write(`\nMigrating goldens for pattern '${pattern}/${oldSuffix}'\n`);
const dirs = await glob(`${pattern}/${oldSuffix}`, { ignore: 'node_modules/**', posix: true });
let fileCount = 0;

Expand All @@ -30,12 +32,17 @@ async function start(argv = []) {
.replace(/^d2l-/, '')
.replace(new RegExp(`^${dirName}-`), '');

const newDir = dir.replace(`${oldSuffix}/${dirName}`, `${PATHS.GOLDEN}/${dirName}/chromium`);
const newDir = local ?
`${PATHS.VDIFF_ROOT}/${dir.replace(`${oldSuffix}/${dirName}`, `${dirName}/${PATHS.GOLDEN}/chromium`)}` :
dir.replace(`${oldSuffix}/${dirName}`, `${PATHS.GOLDEN}/${dirName}/chromium`);

await mkdir(newDir, { recursive: true });
return rename(file, join(newDir, newName));
svanherk marked this conversation as resolved.
Show resolved Hide resolved
}));
return rm(normalize(join(dir, '..', '..')), { recursive: true });

if (!local) {
return rm(normalize(join(dir, '..', '..')), { recursive: true });
}
}));

stdout.write(`\nMigrated ${fileCount} ${fileCount === 1 ? 'golden' : 'goldens'} found in ${dirs.length} test ${dirs.length === 1 ? 'directory' : 'directories'}\n`);
Expand Down