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
3 changes: 2 additions & 1 deletion .eslintrc.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,8 @@
"commonjs": false,
"es2022": true,
"amd": true,
"jest": true
"jest": true,
"cypress": true
},
"extends": [
"standard",
Expand Down
12 changes: 10 additions & 2 deletions cypress.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,15 @@ module.exports = defineConfig({
baseUrl: 'http://localhost:9001/',
screenshotOnRunFailure: false,
video: false,
supportFile: false,
specPattern: '**/test/e2e/**/*.cy.{js,jsx}'
supportFile: '**/test/e2e/commands.js',
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,10 +82,10 @@ async function waitForGruntServer() {

async function cypressRun() {
if (argumentValues.testfiles) {
return asyncSpawn('node', './node_modules/cypress/bin/cypress', 'run', '--spec', `${argumentValues.testfiles}`);
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');
return asyncSpawn('node', './node_modules/cypress/bin/cypress', 'run', '--config', `{"fixturesFolder": "${argumentValues.outputdir}"}`);
};

async function jestRun() {
Expand Down
82 changes: 82 additions & 0 deletions test/e2e/commands.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,82 @@
function getData() {
try {
// Setup data array
const data = [];
// Expose this.data in cypress
cy.wrap(data).as('data');
// Allow adapt-style shorthand properties:
// this.data.config, this.data.course, this.data.articles, etc
Object.defineProperties(data, {
config: {
get() {
return data.find(item => item._type === 'config');
},
enumerable: false
},
course: {
get() {
return data.find(item => item._type === 'course');
},
enumerable: false
},
contentObjects: {
get() {
return data.filter(item => ['menu','page'].includes(item._type));
},
enumerable: false
},
articles: {
get() {
return data.filter(item => item._type === 'article');
},
enumerable: false
},
blocks: {
get() {
return data.filter(item => item._type === 'block');
},
enumerable: false
},
components: {
get() {
return data.filter(item => item._type === 'component');
},
enumerable: false
}
});
const coursedir = 'course';
// Load the config.json
cy.fixture(`${coursedir}/config.json`).then(configData => {
// Assign _type = 'config' to the config object
configData._type = 'config';
data.push(configData);
// Fetch the default language
const defaultLanguage = configData._defaultLanguage;
// Load the language_data_manifest.js for the default language
cy.fixture(`${coursedir}/${defaultLanguage}/language_data_manifest.js`).then(languageDataManifest => {
// Load each of the files specified in the manifest
languageDataManifest.forEach(localFilePath => {
const filePath = `${coursedir}/${defaultLanguage}/${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
if (Array.isArray(fileData)) {
fileData.forEach((item, index) => {
item.__index__ = index;
item.__path__ = filePath;
data.push(item);
});
return data.push(...fileData);
}
fileData.__path__ = filePath;
data.push(fileData);
});
});
})
});
} catch {
cy.task('log', 'fail');
}
}

Cypress.Commands.add('getData', getData);
9 changes: 6 additions & 3 deletions test/e2e/menuPage.cy.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,11 @@
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 () {
cahirodoherty-learningpool marked this conversation as resolved.
Show resolved Hide resolved
cy.visit('/');
cy.get('.menu__title-inner').should('contain', pageTitle);
cy.get('.menu__title-inner').should('contain', this.data.course.displayTitle);
});
});