Skip to content

Commit

Permalink
Merge pull request #41039 from nextcloud/fix/run-cypress-always-parallel
Browse files Browse the repository at this point in the history
feat(cypress): Always run cypress CI in parallel
  • Loading branch information
susnux authored Oct 22, 2023
2 parents 4b70f19 + 37d53d6 commit 91e02fe
Show file tree
Hide file tree
Showing 4 changed files with 756 additions and 50 deletions.
19 changes: 7 additions & 12 deletions .github/workflows/cypress.yml
Original file line number Diff line number Diff line change
Expand Up @@ -72,15 +72,11 @@ jobs:
fail-fast: false
matrix:
# Run multiple copies of the current job in parallel
# Please increase the number or runners as your tests suite grows
containers: ["component", 1, 2]
# Only use cypress cloud for PRs
use-cypress-cloud:
- ${{ !!github.head_ref }}
# Only use one container if we are not using the cypress cloud.
exclude:
- use-cypress-cloud: false
containers: 2
# Please increase the number or runners as your tests suite grows (0 based index for e2e tests)
containers: ["component", 0, 1, 2]
# Hack as strategy.job-total includes the component and GitHub does not allow math expressions
# Always aling this number with the total of e2e runners (max. index + 1)
total-containers: [3]

name: runner ${{ matrix.containers }}

Expand All @@ -103,9 +99,6 @@ jobs:
- name: Run ${{ matrix.containers == 'component' && 'component' || 'E2E' }} cypress tests
uses: cypress-io/github-action@59810ebfa5a5ac6fcfdcfdf036d1cd4d083a88f2 # v6.5.0
with:
record: ${{ !!matrix.use-cypress-cloud }}
parallel: ${{ !!matrix.use-cypress-cloud }}
# cypress run type
component: ${{ matrix.containers == 'component' }}
group: ${{ matrix.use-cypress-cloud && matrix.containers == 'component' && 'Run component' || matrix.use-cypress-cloud && 'Run E2E' || '' }}
# cypress env
Expand All @@ -120,6 +113,8 @@ jobs:
TESTING: true
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
CYPRESS_RECORD_KEY: ${{ secrets.CYPRESS_RECORD_KEY }}
SPLIT: ${{ matrix.total-containers }}
SPLIT_INDEX: ${{ matrix.containers == 'component' && 0 || matrix.containers }}

- name: Upload snapshots
uses: actions/upload-artifact@a8a3f3ad30e3422c9c7b888a15615d19a852ae32 # v3.1.3
Expand Down
25 changes: 13 additions & 12 deletions cypress.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import {
waitOnNextcloud,
} from './cypress/dockerNode'
import { defineConfig } from 'cypress'
import cypressSplit from 'cypress-split'
import webpackPreprocessor from '@cypress/webpack-preprocessor'
import type { Configuration } from 'webpack'

Expand Down Expand Up @@ -47,6 +48,8 @@ export default defineConfig({
// We've imported your old cypress plugins here.
// You may want to clean this up later by importing these.
async setupNodeEvents(on, config) {
cypressSplit(on, config)

on('file:preprocessor', webpackPreprocessor({ webpackOptions: webpackConfig as Configuration }))

// Disable spell checking to prevent rendering differences
Expand Down Expand Up @@ -76,18 +79,16 @@ export default defineConfig({

// Before the browser launches
// starting Nextcloud testing container
return startNextcloud(process.env.BRANCH)
.then((ip) => {
// Setting container's IP as base Url
config.baseUrl = `http://${ip}/index.php`
return ip
})
.then(waitOnNextcloud)
.then(configureNextcloud)
.then(applyChangesToNextcloud)
.then(() => {
return config
})
const ip = await startNextcloud(process.env.BRANCH)

// Setting container's IP as base Url
config.baseUrl = `http://${ip}/index.php`
await waitOnNextcloud(ip)
await configureNextcloud()
await applyChangesToNextcloud()

// IMPORTANT: return the config otherwise cypress-split will not work
return config
},
},

Expand Down
Loading

0 comments on commit 91e02fe

Please sign in to comment.