diff --git a/test.js b/test.js index fa33ce57d..68bdb20c9 100644 --- a/test.js +++ b/test.js @@ -1,4 +1,5 @@ const os = require('os'); +const fs = require('fs-extra'); const { spawn, exec } = require('child_process'); const jest = require('jest'); const config = require('./jest.config'); @@ -80,18 +81,31 @@ async function waitForGruntServer() { return waitForExec('node', './node_modules/wait-on/bin/wait-on', 'http://127.0.0.1:9001'); }; -async function cypressRun() { - if (argumentValues.testfiles) { - return asyncSpawn('node', './node_modules/cypress/bin/cypress', 'run', '--spec', `${argumentValues.testfiles}`, '--config', `{"fixturesFolder": "${argumentValues.outputdir}"}`); - } +async function populateTestFiles() { + // accept the user-specified file(s) + if (argumentValues.testfiles) return; + + // 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 testFiles = plugins.map(plugin => { + return `**/${plugin}/**/*.cy.js`; + }); + + argumentValues.testfiles = testFiles.join(','); +} - return asyncSpawn('node', './node_modules/cypress/bin/cypress', 'run', '--config', `{"fixturesFolder": "${argumentValues.outputdir}"}`); +async function cypressRun() { + await populateTestFiles(); + return asyncSpawn('node', './node_modules/cypress/bin/cypress', 'run', '--spec', `${argumentValues.testfiles}`, '--config', `{"fixturesFolder": "${argumentValues.outputdir}"}`); }; async function jestRun() { config.testEnvironmentOptions.outputDir = argumentValues.outputdir; - // Limit the tests if a certain set are passed in + await populateTestFiles(); + if (argumentValues.testfiles) { config.testMatch = argumentValues.testfiles.split(','); } @@ -176,6 +190,7 @@ ${Object.values(commands).map(({ name, description }) => ` ${name.padEnd(21, } catch (cypressErr) { console.log('Cypress tests failure'); console.log(cypressErr); + process.exit(1); } gruntServerRun.kill(); diff --git a/test/e2e/commands.js b/test/e2e/commands.js index f7e69ff1d..7fb49cef0 100644 --- a/test/e2e/commands.js +++ b/test/e2e/commands.js @@ -1,8 +1,8 @@ -import './helpers' +import './helpers'; function getBuild() { try { - return cy.fixture(`adapt/js/build.min.js`).then(build => { + return cy.fixture('adapt/js/build.min.js').then(build => { // Return for cy.getBuild().then(build => {}); // Expose this.build in cypress return cy.wrap(build).as('build'); @@ -40,7 +40,7 @@ function getData(languageCode = null) { }, contentObjects: { get() { - return data.filter(item => ['menu','page'].includes(item._type)); + return data.filter(item => ['menu', 'page'].includes(item._type)); }, enumerable: false }, @@ -80,7 +80,7 @@ function getData(languageCode = null) { cy.fixture(`${coursedir}/${languageCode}/language_data_manifest.js`).then(languageDataManifest => { // Load each of the files specified in the manifest languageDataManifest.forEach(localFilePath => { - const filePath = `${coursedir}/${languageCode}/${localFilePath}` + const filePath = `${coursedir}/${languageCode}/${localFilePath}`; cy.fixture(filePath).then(fileData => { // Add __index__ and __path__ attributes to each object as in adapt // so that each object's origin can be identified later if necessary diff --git a/test/e2e/helpers.js b/test/e2e/helpers.js index 281c5dc43..72b518b78 100644 --- a/test/e2e/helpers.js +++ b/test/e2e/helpers.js @@ -1,8 +1,8 @@ cy.helpers = { - stripHtml(text) { - let tmp = document.createElement("DIV"); - tmp.innerHTML = text; - const textWithoutHtml = tmp.textContent || tmp.innerText || ""; - return textWithoutHtml - } - } \ No newline at end of file + stripHtml(text) { + const tmp = document.createElement('DIV'); + tmp.innerHTML = text; + const textWithoutHtml = tmp.textContent || tmp.innerText || ''; + return textWithoutHtml; + } +}; diff --git a/test/e2e/trackingIds.cy.js b/test/e2e/trackingIds.cy.js index f43f82326..e07416d99 100644 --- a/test/e2e/trackingIds.cy.js +++ b/test/e2e/trackingIds.cy.js @@ -15,7 +15,7 @@ describe('Tracking Ids', function () { trackingIdItems.forEach(item => { expect(item).to.have.ownProperty('_trackingId'); }); - }) + }); }); });