From 7a41ee68ac81ba427ee6b3dbcd1fff6ff8e8152d Mon Sep 17 00:00:00 2001 From: cahirodoherty-learningpool Date: Fri, 6 Sep 2024 16:58:44 +0100 Subject: [PATCH 01/10] Update: Function to populate cypress test spec if no argument value passed --- test.js | 20 +++++++++++++++----- test/e2e/commands.js | 8 ++++---- test/e2e/helpers.js | 14 +++++++------- test/e2e/trackingIds.cy.js | 2 +- 4 files changed, 27 insertions(+), 17 deletions(-) diff --git a/test.js b/test.js index fa33ce57d..292ed8a80 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,12 +81,21 @@ 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 = fs.readFileSync('./src/course/config.json', { + encoding: null + }); + + argumentValues.testfiles = config?.build?.includes?.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() { 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'); }); - }) + }); }); }); From 4fefd2e42127c50cf8e98bd02a58fef2366951aa Mon Sep 17 00:00:00 2001 From: cahirodoherty-learningpool Date: Fri, 6 Sep 2024 17:01:11 +0100 Subject: [PATCH 02/10] Tidy up --- test.js | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/test.js b/test.js index 292ed8a80..adceb8422 100644 --- a/test.js +++ b/test.js @@ -86,11 +86,12 @@ async function populateTestFiles() { if (argumentValues.testfiles) return; // otherwise, only include test files for plugins present in the course config - const config = fs.readFileSync('./src/course/config.json', { - encoding: null - }); + const config = fs.readFileSync('./src/course/config.json'); + const plugins = config?.build?.includes || []; - argumentValues.testfiles = config?.build?.includes?.join(',') || []; + argumentValues.testfiles = plugins.map(plugin => { + return `**/${plugin}/*`; + }); } async function cypressRun() { From 3cbf056ffab537bc87d2fb9b3a2fab6f868898de Mon Sep 17 00:00:00 2001 From: cahirodoherty-learningpool Date: Mon, 9 Sep 2024 14:49:28 +0100 Subject: [PATCH 03/10] Fix: Corrected json reading and passing param --- test.js | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/test.js b/test.js index adceb8422..313fc2b0c 100644 --- a/test.js +++ b/test.js @@ -86,17 +86,17 @@ async function populateTestFiles() { if (argumentValues.testfiles) return; // otherwise, only include test files for plugins present in the course config - const config = fs.readFileSync('./src/course/config.json'); + const config = JSON.parse(fs.readFileSync('./build/course/config.json')); const plugins = config?.build?.includes || []; argumentValues.testfiles = plugins.map(plugin => { - return `**/${plugin}/*`; + return `**/${plugin}/**/*.cy.js`; }); } async function cypressRun() { await populateTestFiles(); - return asyncSpawn('node', './node_modules/cypress/bin/cypress', 'run', '--spec', `${argumentValues.testfiles}`, '--config', `{"fixturesFolder": "${argumentValues.outputdir}"}`); + return asyncSpawn('node', './node_modules/cypress/bin/cypress', 'run', '--spec', `${argumentValues.testfiles.join(',')}`, '--config', `{"fixturesFolder": "${argumentValues.outputdir}"}`); }; async function jestRun() { From ef4440b0df1e4cdf53bb828bc31f44a6dc8c75c4 Mon Sep 17 00:00:00 2001 From: cahirodoherty-learningpool Date: Mon, 9 Sep 2024 14:58:43 +0100 Subject: [PATCH 04/10] Shifting the join command to allow spec passing --- test.js | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/test.js b/test.js index 313fc2b0c..ad0f0f4e5 100644 --- a/test.js +++ b/test.js @@ -89,14 +89,16 @@ async function populateTestFiles() { const config = JSON.parse(fs.readFileSync('./build/course/config.json')); const plugins = config?.build?.includes || []; - argumentValues.testfiles = plugins.map(plugin => { + const testFiles = plugins.map(plugin => { return `**/${plugin}/**/*.cy.js`; }); + + argumentValues.testfiles = testFiles.join(','); } async function cypressRun() { await populateTestFiles(); - return asyncSpawn('node', './node_modules/cypress/bin/cypress', 'run', '--spec', `${argumentValues.testfiles.join(',')}`, '--config', `{"fixturesFolder": "${argumentValues.outputdir}"}`); + return asyncSpawn('node', './node_modules/cypress/bin/cypress', 'run', '--spec', `${argumentValues.testfiles}`, '--config', `{"fixturesFolder": "${argumentValues.outputdir}"}`); }; async function jestRun() { From e28012a50b7fe79f17a5f8ab8a07ca7d89c336ed Mon Sep 17 00:00:00 2001 From: cahirodoherty-learningpool Date: Mon, 9 Sep 2024 15:17:42 +0100 Subject: [PATCH 05/10] Fix: Process should exit non-zero when tests fail --- test.js | 1 + 1 file changed, 1 insertion(+) diff --git a/test.js b/test.js index ad0f0f4e5..83606b3b4 100644 --- a/test.js +++ b/test.js @@ -189,6 +189,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(); From 8d8f2869377dd6576e7e9755594f0c97468b6268 Mon Sep 17 00:00:00 2001 From: cahirodoherty-learningpool Date: Fri, 27 Sep 2024 09:14:26 +0100 Subject: [PATCH 06/10] Account for passed output directory param --- test.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test.js b/test.js index 83606b3b4..c6526498c 100644 --- a/test.js +++ b/test.js @@ -86,7 +86,7 @@ async function populateTestFiles() { if (argumentValues.testfiles) return; // otherwise, only include test files for plugins present in the course config - const config = JSON.parse(fs.readFileSync('./build/course/config.json')); + const config = JSON.parse(fs.readFileSync(path.join(argumentValues.outputdir, 'course', 'config.json'))); const plugins = config?.build?.includes || []; const testFiles = plugins.map(plugin => { From 010195e067dd8535422ef78fb4eeeefcb5e218ab Mon Sep 17 00:00:00 2001 From: cahirodoherty-learningpool Date: Mon, 30 Sep 2024 09:23:30 +0100 Subject: [PATCH 07/10] Applying tesfiles populator to jest runs also --- test.js | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/test.js b/test.js index c6526498c..b72fda765 100644 --- a/test.js +++ b/test.js @@ -104,10 +104,8 @@ async function cypressRun() { async function jestRun() { config.testEnvironmentOptions.outputDir = argumentValues.outputdir; - // Limit the tests if a certain set are passed in - if (argumentValues.testfiles) { - config.testMatch = argumentValues.testfiles.split(','); - } + await populateTestFiles(); + config.testMatch = argumentValues.testfiles.split(','); return jest.runCLI(config, [process.cwd().replace(/\\/g, '/')]); }; From ccf0691699851719b0bba988f0b71ee42d78c708 Mon Sep 17 00:00:00 2001 From: cahirodoherty-learningpool Date: Mon, 30 Sep 2024 09:27:11 +0100 Subject: [PATCH 08/10] Debugging --- test.js | 2 ++ 1 file changed, 2 insertions(+) diff --git a/test.js b/test.js index b72fda765..7a17d9cf7 100644 --- a/test.js +++ b/test.js @@ -94,6 +94,8 @@ async function populateTestFiles() { }); argumentValues.testfiles = testFiles.join(','); + console.log('CAHIR'); + console.log(argumentValues.testfiles); } async function cypressRun() { From 1fae1bd8158eb27af0d9bb8e5d2d6d01ba71f5af Mon Sep 17 00:00:00 2001 From: cahirodoherty-learningpool Date: Mon, 30 Sep 2024 09:31:09 +0100 Subject: [PATCH 09/10] Debugging --- test.js | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/test.js b/test.js index 7a17d9cf7..e6c0651fe 100644 --- a/test.js +++ b/test.js @@ -88,14 +88,18 @@ async function populateTestFiles() { // 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 || []; + console.log('CAHIRA'); + console.log(JSON.stringify(config)); + console.log('CAHIRB'); const testFiles = plugins.map(plugin => { return `**/${plugin}/**/*.cy.js`; }); argumentValues.testfiles = testFiles.join(','); - console.log('CAHIR'); + console.log('CAHIR1'); console.log(argumentValues.testfiles); + console.log('CAHIR2'); } async function cypressRun() { From 0345df720b1461b57f1db48b81512f3cb84408e2 Mon Sep 17 00:00:00 2001 From: cahirodoherty-learningpool Date: Mon, 30 Sep 2024 09:33:59 +0100 Subject: [PATCH 10/10] Empty string check --- test.js | 11 ++++------- 1 file changed, 4 insertions(+), 7 deletions(-) diff --git a/test.js b/test.js index e6c0651fe..68bdb20c9 100644 --- a/test.js +++ b/test.js @@ -88,18 +88,12 @@ async function populateTestFiles() { // 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 || []; - console.log('CAHIRA'); - console.log(JSON.stringify(config)); - console.log('CAHIRB'); const testFiles = plugins.map(plugin => { return `**/${plugin}/**/*.cy.js`; }); argumentValues.testfiles = testFiles.join(','); - console.log('CAHIR1'); - console.log(argumentValues.testfiles); - console.log('CAHIR2'); } async function cypressRun() { @@ -111,7 +105,10 @@ async function jestRun() { config.testEnvironmentOptions.outputDir = argumentValues.outputdir; await populateTestFiles(); - config.testMatch = argumentValues.testfiles.split(','); + + if (argumentValues.testfiles) { + config.testMatch = argumentValues.testfiles.split(','); + } return jest.runCLI(config, [process.cwd().replace(/\\/g, '/')]); };