Skip to content

Commit

Permalink
Fix: Populating testfile globs that are specific to the current test …
Browse files Browse the repository at this point in the history
…runner (#3609)
  • Loading branch information
cahirodoherty-learningpool authored Oct 2, 2024
1 parent dba8e70 commit 5e3e7e2
Showing 1 changed file with 13 additions and 11 deletions.
24 changes: 13 additions & 11 deletions test.js
Original file line number Diff line number Diff line change
Expand Up @@ -81,34 +81,36 @@ async function waitForGruntServer() {
return waitForExec('node', './node_modules/wait-on/bin/wait-on', 'http://127.0.0.1:9001');
};

async function populateTestFiles() {
function populateTestFiles(testFormat) {
// accept the user-specified file(s)
if (argumentValues.testfiles) return;
if (argumentValues.testfiles) return argumentValues.testfiles;

// otherwise, only include test files for plugins present in the course config
const config = JSON.parse(fs.readFileSync(path.join(argumentValues.outputdir, 'course', 'config.json')));
const plugins = config?.build?.includes || [];

const globSuffix = testFormat === 'e2e' ? 'e2e/*.cy.js' : 'unit/*.js';

const testFiles = plugins.map(plugin => {
return `**/${plugin}/**/*.cy.js`;
return `**/${plugin}/test/${globSuffix}`;
});

argumentValues.testfiles = testFiles.join(',');
// Add the framework level test files
testFiles.push(`**/test/${globSuffix}`);

return testFiles.join(',');
}

async function cypressRun() {
await populateTestFiles();
return asyncSpawn('node', './node_modules/cypress/bin/cypress', 'run', '--spec', `${argumentValues.testfiles}`, '--config', `{"fixturesFolder": "${argumentValues.outputdir}"}`);
const testFiles = populateTestFiles('e2e');
return asyncSpawn('node', './node_modules/cypress/bin/cypress', 'run', '--spec', `${testFiles}`, '--config', `{"fixturesFolder": "${argumentValues.outputdir}"}`);
};

async function jestRun() {
config.testEnvironmentOptions.outputDir = argumentValues.outputdir;

await populateTestFiles();

if (argumentValues.testfiles) {
config.testMatch = argumentValues.testfiles.split(',');
}
const testFiles = populateTestFiles('unit');
config.testMatch = testFiles.split(',');

return jest.runCLI(config, [process.cwd().replace(/\\/g, '/')]);
};
Expand Down

0 comments on commit 5e3e7e2

Please sign in to comment.