/// <reference types="cypress" />
// In cypress/plugins/index.js add this task to check folder and file existence
module.exports = (on, config) => {
const fs = require('fs');
const path = require('path');
on('task', {
checkExists({ pathToCheck }) {
return fs.existsSync(pathToCheck);
}
});
};
// Test file: cypress/integration/folder_structure_spec.js
describe('Cypress folder structure verification', () => {
const projectRoot = Cypress.config('projectRoot');
const cypressFolder = `${projectRoot}/cypress`;
it('should have cypress folder', () => {
cy.task('checkExists', { pathToCheck: cypressFolder }).then(exists => {
expect(exists).to.be.true;
});
});
['fixtures', 'integration', 'plugins', 'support'].forEach(subfolder => {
it(`should have ${subfolder} folder inside cypress`, () => {
cy.task('checkExists', { pathToCheck: `${cypressFolder}/${subfolder}` }).then(exists => {
expect(exists).to.be.true;
});
});
});
it('should have cypress.json file in project root', () => {
cy.task('checkExists', { pathToCheck: `${projectRoot}/cypress.json` }).then(exists => {
expect(exists).to.be.true;
});
});
});This test uses Cypress tasks to access the Node.js file system because Cypress commands run in the browser context and cannot directly check files or folders on disk.
In cypress/plugins/index.js, we define a task checkExists that returns true if a given path exists.
The test file folder_structure_spec.js uses this task to verify the presence of the cypress folder, its subfolders fixtures, integration, plugins, and support, and the cypress.json configuration file in the project root.
Each check uses cy.task and asserts the result is true, ensuring the folder structure is as expected.