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

test: parallelizing cypress tests to speed up pipeline #2155

Merged
merged 19 commits into from
Oct 20, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
19 commits
Select commit Hold shift + click to select a range
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 6 additions & 4 deletions .github/workflows/cypress-tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,19 +9,21 @@ on:
jobs:
cypress-run:
runs-on: ubuntu-latest

strategy:
fail-fast: false
matrix:
containers: [0, 1, 2, 3, 4, 5, 6, 7]
steps:
- name: Checkout code
uses: actions/checkout@v3

- name: Use Node.js 16.x
uses: actions/setup-node@v3
with:
node-version: 16.x


- name: Install dependencies
run: npm install

- name: Cypress Tests are running
run : node ./scripts/index.js && npm run test
run: node ./scripts/index.js && npx cypress run --component --spec $(node cypress-parallel.js ${{ matrix.containers }} 8)
31 changes: 31 additions & 0 deletions cypress-parallel.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
const fs = require('fs');
const path = require('path');

const NODE_INDEX = Number(process.argv[2] || 1);
const NODE_TOTAL = Number(process.argv[3] || 1);

const TEST_FOLDER = './cypress/test';

console.log(getSpecFiles().join(','))

function getSpecFiles() {
const allSpecFiles = traverse(TEST_FOLDER);
const node_index= NODE_INDEX +1;
return allSpecFiles.sort()
.filter((_, index) => (index % NODE_TOTAL) === (node_index - 1));

}

function traverse(dir) {
let files = fs.readdirSync(dir);
files = files.map(file => {
const filePath = path.join(dir, file);
const stats = fs.statSync(filePath);
if (stats.isDirectory()) return traverse(filePath);
else if (stats.isFile())return filePath;
});

return files
.reduce((all, folderContents) => all.concat(folderContents), []);

}
3 changes: 3 additions & 0 deletions cypress.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,4 +9,7 @@ module.exports = defineConfig({
video : false,
screenshotOnRunFailure : false
},
retries: {
runMode: 3
}
});
2 changes: 1 addition & 1 deletion cypress/support/commands.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,4 +22,4 @@
//
//
// -- This will overwrite an existing command --
// Cypress.Commands.overwrite('visit', (originalFn, url, options) => { ... })
// Cypress.Commands.overwrite('visit', (originalFn, url, options) => { ... })
2 changes: 1 addition & 1 deletion cypress/support/component.js
Original file line number Diff line number Diff line change
Expand Up @@ -25,4 +25,4 @@ import '../../styles/globals.css'
Cypress.Commands.add('mount', mount)

// Example use:
// cy.mount(<MyComponent />)
// cy.mount(<MyComponent />)
Loading