From 9769a16fb887428ef88184526ff1bec0e9c16158 Mon Sep 17 00:00:00 2001 From: Danny Gleckler Date: Wed, 23 Aug 2023 15:21:19 -0400 Subject: [PATCH 1/6] Add migrate-local subcommand --- bin/d2l-test-runner.js | 8 ++++++++ src/server/cli/vdiff/migrate.js | 4 ++-- 2 files changed, 10 insertions(+), 2 deletions(-) diff --git a/bin/d2l-test-runner.js b/bin/d2l-test-runner.js index 61a77b11..18b54e75 100755 --- a/bin/d2l-test-runner.js +++ b/bin/d2l-test-runner.js @@ -2,6 +2,7 @@ import commandLineArgs from 'command-line-args'; import process from 'node:process'; import { runner } from '../src/server/cli/test-runner.js'; +import { execSync } from 'node:child_process'; const { argv, stdout } = process; const cli = commandLineArgs({ name: 'subcommand', defaultOption: true }, { stopAtFirstUnknown: true, argv }); @@ -21,6 +22,13 @@ 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.subcomamnd === 'migrate-local') { + + execSync('npm install @brightspace-ui/visual-diff@14 --no-save'); + execSync('npx mocha \'./**/*.visual-diff.js\' -t 10000 --golden'); + + 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`); } diff --git a/src/server/cli/vdiff/migrate.js b/src/server/cli/vdiff/migrate.js index 430af78c..d4d06381 100755 --- a/src/server/cli/vdiff/migrate.js +++ b/src/server/cli/vdiff/migrate.js @@ -6,9 +6,9 @@ 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'; const dirs = await glob(`${pattern}/${oldSuffix}`, { ignore: 'node_modules/**', posix: true }); let fileCount = 0; From 416f5bf5e7e1ce4f56d6cf34ff2145c475832180 Mon Sep 17 00:00:00 2001 From: Danny Gleckler Date: Wed, 23 Aug 2023 15:59:28 -0400 Subject: [PATCH 2/6] Fix output path for migrating local goldens --- src/server/cli/vdiff/migrate.js | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/src/server/cli/vdiff/migrate.js b/src/server/cli/vdiff/migrate.js index d4d06381..c7fae890 100755 --- a/src/server/cli/vdiff/migrate.js +++ b/src/server/cli/vdiff/migrate.js @@ -30,7 +30,9 @@ async function start(argv = [], local = false) { .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)); From 784cb1e8da739be1239725a25d7fca050444361f Mon Sep 17 00:00:00 2001 From: Danny Gleckler Date: Wed, 23 Aug 2023 16:41:17 -0400 Subject: [PATCH 3/6] I can spell --- bin/d2l-test-runner.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/bin/d2l-test-runner.js b/bin/d2l-test-runner.js index 18b54e75..310a585a 100755 --- a/bin/d2l-test-runner.js +++ b/bin/d2l-test-runner.js @@ -22,7 +22,7 @@ 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.subcomamnd === 'migrate-local') { + } else if (vdiff.subcommand === 'migrate-local') { execSync('npm install @brightspace-ui/visual-diff@14 --no-save'); execSync('npx mocha \'./**/*.visual-diff.js\' -t 10000 --golden'); @@ -30,7 +30,7 @@ if (cli.subcommand === 'vdiff') { 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(); From fb2e9e5be5706c39a5b3b2f4674b7c4da2a7db21 Mon Sep 17 00:00:00 2001 From: Danny Gleckler Date: Thu, 24 Aug 2023 11:16:03 -0400 Subject: [PATCH 4/6] Use existing pattern when running old visual-diff tests --- bin/d2l-test-runner.js | 6 ++++-- src/server/cli/vdiff/migrate.js | 5 ++++- 2 files changed, 8 insertions(+), 3 deletions(-) diff --git a/bin/d2l-test-runner.js b/bin/d2l-test-runner.js index 310a585a..99feeda5 100755 --- a/bin/d2l-test-runner.js +++ b/bin/d2l-test-runner.js @@ -1,8 +1,8 @@ #!/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'; -import { execSync } from 'node:child_process'; const { argv, stdout } = process; const cli = commandLineArgs({ name: 'subcommand', defaultOption: true }, { stopAtFirstUnknown: true, argv }); @@ -24,8 +24,10 @@ if (cli.subcommand === 'vdiff') { 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 || [] }); + execSync('npm install @brightspace-ui/visual-diff@14 --no-save'); - execSync('npx mocha \'./**/*.visual-diff.js\' -t 10000 --golden'); + execSync(`npx mocha '${pattern}/*.visual-diff.js' -t 10000 --golden`); const { migrate } = await import('../src/server/cli/vdiff/migrate.js'); await migrate.start(vdiff._unknown, true); diff --git a/src/server/cli/vdiff/migrate.js b/src/server/cli/vdiff/migrate.js index c7fae890..863a261c 100755 --- a/src/server/cli/vdiff/migrate.js +++ b/src/server/cli/vdiff/migrate.js @@ -37,7 +37,10 @@ async function start(argv = [], local = false) { await mkdir(newDir, { recursive: true }); return rename(file, join(newDir, newName)); })); - 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`); From 3dd2706f2242a6ffecf7df5140556a34e976c220 Mon Sep 17 00:00:00 2001 From: Stacey Van Herk <13419300+svanherk@users.noreply.github.com> Date: Thu, 24 Aug 2023 15:18:45 -0400 Subject: [PATCH 5/6] Add some output (#148) --- bin/d2l-test-runner.js | 3 +++ src/server/cli/vdiff/migrate.js | 2 ++ 2 files changed, 5 insertions(+) diff --git a/bin/d2l-test-runner.js b/bin/d2l-test-runner.js index 99feeda5..36b97234 100755 --- a/bin/d2l-test-runner.js +++ b/bin/d2l-test-runner.js @@ -26,8 +26,11 @@ if (cli.subcommand === 'vdiff') { 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); diff --git a/src/server/cli/vdiff/migrate.js b/src/server/cli/vdiff/migrate.js index 863a261c..0e44cbce 100755 --- a/src/server/cli/vdiff/migrate.js +++ b/src/server/cli/vdiff/migrate.js @@ -9,6 +9,8 @@ import { stdout } from 'node:process'; async function start(argv = [], local = false) { const { pattern = './**' } = commandLineArgs({ name: 'pattern', type: String, defaultOption: true }, { partial: true, argv }); 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; From e750c2f8f119c7b32acda9866f9c37f3eade0a82 Mon Sep 17 00:00:00 2001 From: Danny Gleckler Date: Thu, 24 Aug 2023 15:37:31 -0400 Subject: [PATCH 6/6] Add migrate-local to --help --- src/server/cli/test-runner.js | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/src/server/cli/test-runner.js b/src/server/cli/test-runner.js index cc8f0876..1c807f7d 100755 --- a/src/server/cli/test-runner.js +++ b/src/server/cli/test-runner.js @@ -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.' }] } ]);