Skip to content

Commit

Permalink
reintroduce node golden generation
Browse files Browse the repository at this point in the history
@asturur this is what I meant in the comments of #8206
  • Loading branch information
ShaMan123 committed Aug 29, 2022
1 parent 80a778a commit ee3388c
Show file tree
Hide file tree
Showing 2 changed files with 43 additions and 30 deletions.
51 changes: 32 additions & 19 deletions scripts/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -320,40 +320,53 @@ async function runTestem({ suite, port, launch, dev, processOptions, context } =
* @returns {Promise<boolean | undefined>} true if some tests failed
*/
async function test(suite, tests, options = {}) {
const processOptions = {
cwd: wd,
env: {
...process.env,
TEST_FILES: (tests || []).join(','),
NODE_CMD: ['qunit', 'test/node_test_setup.js', 'test/lib'].concat(tests || `test/${suite}`).join(' '),
VERBOSE: Number(options.verbose),
QUNIT_DEBUG_VISUAL_TESTS: Number(options.debug),
QUNIT_RECREATE_VISUAL_REFS: Number(options.recreate),
QUNIT_FILTER: options.filter,
REPORT_FILE: options.out
},
shell: true,
stdio: 'inherit',
}

let failed = false;
const qunitEnv = {
QUNIT_DEBUG_VISUAL_TESTS: Number(options.debug),
QUNIT_RECREATE_VISUAL_REFS: Number(options.recreate),
QUNIT_FILTER: options.filter,
};
const env = {
...process.env,
TEST_FILES: (tests || []).join(','),
NODE_CMD: ['qunit', 'test/node_test_setup.js', 'test/lib'].concat(tests || `test/${suite}`).join(' '),
VERBOSE: Number(options.verbose),
REPORT_FILE: options.out
};
const browserContexts = options.context.filter(c => c !== 'node');

// temporary revert
// run node tests directly with qunit
if (options.context.includes('node')) {
try {
cp.execSync(processOptions.env.NODE_CMD, processOptions);
cp.execSync(env.NODE_CMD, {
cwd: wd,
env: {
...env,
// browser takes precendence in golden ref generation
...(browserContexts.length === 0 ? qunitEnv : {})
},
shell: true,
stdio: 'inherit',
});
} catch (error) {
failed = true;
}
}

const browserContexts = options.context.filter(c => c !== 'node');
if (browserContexts.length > 0) {
failed = await runTestem({
...options,
suite,
processOptions,
processOptions: {
cwd: wd,
env: {
...env,
...qunitEnv
},
shell: true,
stdio: 'inherit',
},
context: browserContexts
}) || failed;
}
Expand Down
22 changes: 11 additions & 11 deletions test/node_test_setup.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,17 +3,17 @@ var chalk = require('chalk');
var diff = require('deep-object-diff').diff;
var commander = require('commander');

// commander.program
// .option('-d, --debug', 'debug visual tests by overriding refs (golden images) in case of visual changes', false)
// .option('-r, --recreate', 'recreate visual refs (golden images)', false)
// .action(options => {
// QUnit.debug = QUnit.debugVisual = options.debug;
// QUnit.recreateVisualRefs = options.recreate;
// }).parse(process.argv);
// // for now accept an env variable because qunit doesn't allow passing unknown options
// QUnit.debugVisual = Number(process.env.QUNIT_DEBUG_VISUAL_TESTS);
// QUnit.recreateVisualRefs = Number(process.env.QUNIT_RECREATE_VISUAL_REFS);
// QUnit.config.filter = process.env.QUNIT_FILTER;
commander.program
.option('-d, --debug', 'debug visual tests by overriding refs (golden images) in case of visual changes', false)
.option('-r, --recreate', 'recreate visual refs (golden images)', false)
.action(options => {
QUnit.debug = QUnit.debugVisual = options.debug;
QUnit.recreateVisualRefs = options.recreate;
}).parse(process.argv);
// for now accept an env variable because qunit doesn't allow passing unknown options
QUnit.debugVisual = Number(process.env.QUNIT_DEBUG_VISUAL_TESTS);
QUnit.recreateVisualRefs = Number(process.env.QUNIT_RECREATE_VISUAL_REFS);
QUnit.config.filter = process.env.QUNIT_FILTER;

global.fabric = require('../dist/fabric').fabric;
global.pixelmatch = require('pixelmatch');
Expand Down

0 comments on commit ee3388c

Please sign in to comment.