Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

New: Cypress task log added, cypress commands file added, cypress get… #3489

Merged
merged 11 commits into from
Jan 11, 2024
10 changes: 9 additions & 1 deletion cypress.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,14 @@ module.exports = defineConfig({
screenshotOnRunFailure: false,
video: false,
supportFile: false,
specPattern: '**/test/e2e/**/*.cy.{js,jsx}'
specPattern: '**/test/e2e/**/*.cy.{js,jsx}',
setupNodeEvents (on, config) {
on('task', {
log(message) {
console.log(message);
return null;
}
});
}
}
});
4 changes: 2 additions & 2 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions test.js
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ async function waitForGruntServer() {
};

async function cypressRun() {
return asyncSpawn('node', './node_modules/cypress/bin/cypress', 'run');
return asyncSpawn('node', './node_modules/cypress/bin/cypress', 'run', '--config', `{"fixturesFolder": "${outputDir}course/en"}`);
};

async function jestRun() {
Expand Down Expand Up @@ -130,7 +130,7 @@ ${Object.values(commands).map(({ name, description }) => ` ${name.padEnd(21,
description: 'Run prepare and e2e testing',
async start() {
const gruntServerRun = await gruntServer();
await waitForGruntServer();
waitForGruntServer();
const cypressCode = await cypressRun();

if (cypressCode > 0) {
Expand Down
46 changes: 46 additions & 0 deletions test/e2e/commands.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
const path = require('path');

/*
function flatten (arr) {
try {
const allData = arr.reduce((result, fileData) => {
if (Array.isArray(fileData)) {
result.push(...fileData);
} else if (fileData instanceof Object) {
result.push(fileData);
}
return result;
}, []);
cy.wrap(allData).as('allData');
} catch {
cy.task('log', 'Issue with flatten');
}
}
*/

const loadManifestFiles = () => {
try {
const manifest = 'language_data_manifest.js';
const allFileData = [];
cy.fixture(manifest).as('manifest_data').then((data) => {
data.forEach((item) => {
const name = path.parse(item).name;
cy.fixture(item).as(`${name}Data`).then((data) => {
allFileData.push(data);
});
});
}).then(() => {
// Potentially flatten data as with FW data.js
oliverfoster marked this conversation as resolved.
Show resolved Hide resolved
// flatten(allFileData);
});
} catch {
cy.task('log', 'fail');
}

};

function getData() {
cy.wrap(loadManifestFiles());
}

Cypress.Commands.add('getData', getData);
11 changes: 8 additions & 3 deletions test/e2e/menuPage.cy.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,13 @@
import {getData} from './commands'
joe-allen-89 marked this conversation as resolved.
Show resolved Hide resolved

describe('Menu Page', () => {
const pageTitle = 'Adapt Version 5';

it(`should have the title ${pageTitle}`, () => {
beforeEach(() => {
cahirodoherty-learningpool marked this conversation as resolved.
Show resolved Hide resolved
cy.getData()
})

it(`should have the correct title`, function () {
cy.visit('/');
cy.get('.menu__title-inner').should('contain', pageTitle);
cy.get('.menu__title-inner').should('contain', this.courseData.displayTitle);
});
});