Skip to content

Commit

Permalink
treat metadata file differently locally from CI
Browse files Browse the repository at this point in the history
  • Loading branch information
dlockhart committed Jul 26, 2023
1 parent d88d6d9 commit dca2404
Show file tree
Hide file tree
Showing 4 changed files with 18 additions and 28 deletions.
16 changes: 0 additions & 16 deletions .vdiff.json

This file was deleted.

6 changes: 4 additions & 2 deletions src/server/visual-diff-plugin.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,15 @@ import { PNG } from 'pngjs';
const isCI = !!env['CI'];
const DEFAULT_MARGIN = 10;
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: '.vdiff.json',
METADATA: isCI ? METADATA_NAME : join(ROOT_NAME, METADATA_NAME),
REPORT_ROOT: '.report',
VDIFF_ROOT: '.vdiff'
VDIFF_ROOT: ROOT_NAME
};

async function checkFileExists(fileName) {
Expand Down
22 changes: 13 additions & 9 deletions src/server/visual-diff-reporter.js
Original file line number Diff line number Diff line change
@@ -1,12 +1,14 @@
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';

const __dirname = dirname(fileURLToPath(import.meta.url));
const isCI = !!env['CI'];

function createData(rootDir, sessions) {
function createData(rootDir, updateGoldens, sessions) {

let metadata = {};
const metadataPath = join(rootDir, PATHS.METADATA);
Expand Down Expand Up @@ -51,10 +53,12 @@ function createData(rootDir, sessions) {
});
});

metadata.browsers = Array.from(browsers.values()).map(b => {
return { name: b.name, version: b.version };
});
writeFileSync(metadataPath, JSON.stringify(metadata, undefined, '\t'));
if (isCI || updateGoldens) {
metadata.browsers = Array.from(browsers.values()).map(b => {
return { name: b.name, version: b.version };
});
writeFileSync(metadataPath, JSON.stringify(metadata, undefined, '\t'));
}

return { browsers, files, numFailed, numTests };

Expand Down Expand Up @@ -99,7 +103,7 @@ function flattenResults(session, browserData, fileData) {

}

export function visualDiffReporter({ reportResults = true } = {}) {
export function visualDiffReporter({ updateGoldens } = {}) {
let rootDir;
return {
start({ config }) {
Expand All @@ -108,14 +112,14 @@ export function visualDiffReporter({ reportResults = true } = {}) {
},
stop({ sessions }) {

if (!reportResults) return;

const data = createData(rootDir, sessions);
const data = createData(rootDir, updateGoldens, sessions);
const json = JSON.stringify(data, (_key, val) => {
if (val instanceof Map) return [...val.values()].sort((a, b) => a.name.localeCompare(b.name));
return val;
}, '\t');

if (updateGoldens) return;

const inputDir = join(__dirname, 'report');
const reportDir = join(rootDir, PATHS.VDIFF_ROOT, PATHS.REPORT_ROOT);
const tempDir = join(reportDir, 'temp');
Expand Down
2 changes: 1 addition & 1 deletion src/server/wtr-config.js
Original file line number Diff line number Diff line change
Expand Up @@ -175,7 +175,7 @@ export class WTRConfig {
});
} else if (group === 'vdiff') {
config.reporters ??= [ defaultReporter() ];
config.reporters.push(visualDiffReporter({ reportResults: !golden }));
config.reporters.push(visualDiffReporter({ updateGoldens: golden }));

config.plugins ??= [];
config.plugins.push(visualDiff({ updateGoldens: golden, runSubset: !!(filter || grep) }));
Expand Down

0 comments on commit dca2404

Please sign in to comment.