Skip to content

Commit

Permalink
fix: split paths out into its own file (#431)
Browse files Browse the repository at this point in the history
  • Loading branch information
dlockhart committed Jul 9, 2024
1 parent 52e1b43 commit 8a331bb
Show file tree
Hide file tree
Showing 7 changed files with 22 additions and 15 deletions.
2 changes: 1 addition & 1 deletion src/server/cli/vdiff/migrate.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import { appendFile, mkdir, readFile, rename, rm } from 'node:fs/promises';
import { join, normalize, parse } from 'node:path';
import commandLineArgs from 'command-line-args';
import { glob } from 'glob';
import { PATHS } from '../../visual-diff-plugin.js';
import { PATHS } from '../../paths.js';
import { stdout } from 'node:process';

async function start(argv = [], local = false) {
Expand Down
2 changes: 1 addition & 1 deletion src/server/cli/vdiff/report.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
#!/usr/bin/env node
import { PATHS } from '../../visual-diff-plugin.js';
import { PATHS } from '../../paths.js';
import { startDevServer } from '@web/dev-server';

export const report = {
Expand Down
15 changes: 15 additions & 0 deletions src/server/paths.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
import { env } from 'node:process';
import { join } from 'node:path';

const isCI = !!env['CI'];
const METADATA_NAME = '.vdiff.json';
const ROOT_NAME = '.vdiff';

export const PATHS = {
FAIL: 'fail',
GOLDEN: 'golden',
PASS: 'pass',
METADATA: isCI ? METADATA_NAME : join(ROOT_NAME, METADATA_NAME),
REPORT_ROOT: '.report',
VDIFF_ROOT: ROOT_NAME
};
2 changes: 1 addition & 1 deletion src/server/rollup.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import { cwd } from 'node:process';
import { rollupPluginHTML as html } from '@web/rollup-plugin-html';
import { join } from 'path';
import { nodeResolve } from '@rollup/plugin-node-resolve';
import { PATHS } from './visual-diff-plugin.js';
import { PATHS } from './paths.js';

export default {
input: join(cwd(), PATHS.VDIFF_ROOT, PATHS.REPORT_ROOT, './temp/index.html'),
Expand Down
11 changes: 1 addition & 10 deletions src/server/visual-diff-plugin.js
Original file line number Diff line number Diff line change
@@ -1,21 +1,12 @@
import { access, constants, mkdir, readdir, readFile, rename, rm, stat, writeFile } from 'node:fs/promises';
import { basename, dirname, join } from 'node:path';
import { env } from 'node:process';
import { PATHS } from './paths.js';
import pixelmatch from 'pixelmatch';
import { PNG } from 'pngjs';

const isCI = !!env['CI'];
const DEFAULT_TOLERANCE = 0; // TODO: Support tolerance override?
const METADATA_NAME = '.vdiff.json';
const ROOT_NAME = '.vdiff';
export const PATHS = {
FAIL: 'fail',
GOLDEN: 'golden',
PASS: 'pass',
METADATA: isCI ? METADATA_NAME : join(ROOT_NAME, METADATA_NAME),
REPORT_ROOT: '.report',
VDIFF_ROOT: ROOT_NAME
};

async function checkFileExists(fileName) {
try {
Expand Down
3 changes: 2 additions & 1 deletion src/server/visual-diff-reporter.js
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
import { cpSync, existsSync, mkdirSync, readFileSync, rmSync, writeFileSync } from 'node:fs';
import { dirname, join } from 'node:path';
import { getTestInfo, PATHS } from './visual-diff-plugin.js';
import { env } from 'node:process';
import { execSync } from 'node:child_process';
import { fileURLToPath } from 'node:url';
import { getTestInfo } from './visual-diff-plugin.js';
import { PATHS } from './paths.js';

const __dirname = dirname(fileURLToPath(import.meta.url));
const isCI = !!env['CI'];
Expand Down
2 changes: 1 addition & 1 deletion test/browser/vdiff.config.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { argv, env } from 'node:process';
import { dirname, join } from 'node:path';
import { readFile, writeFile } from 'node:fs/promises';
import { PATHS } from '../../src/server/visual-diff-plugin.js';
import { PATHS } from '../../src/server/paths.js';
import { PNG } from 'pngjs';

const isCI = !!env['CI'];
Expand Down

0 comments on commit 8a331bb

Please sign in to comment.