Skip to content

Commit

Permalink
Merge pull request #4190 from preschian/feat-cypress-parallel
Browse files Browse the repository at this point in the history
ci: run cypress parallel
  • Loading branch information
yangwao authored Oct 28, 2022
2 parents 99d7c44 + 2d90025 commit bd976bd
Show file tree
Hide file tree
Showing 8 changed files with 179 additions and 30 deletions.
27 changes: 2 additions & 25 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,6 @@ on:
jobs:
test:
runs-on: ubuntu-latest
container:
image: cypress/included:10.6.0
options: --user 1001
env:
CYPRESS_CACHE_FOLDER: '${GITHUB_WORKSPACE}/.cypress-cache'
steps:
- uses: actions/checkout@v3

Expand All @@ -27,7 +22,7 @@ jobs:
${{ runner.os }}-
- name: Install pnpm
uses: pnpm/action-setup@v2.2.1
uses: pnpm/action-setup@v2
with:
version: latest

Expand All @@ -46,24 +41,6 @@ jobs:
- name: Run Test
run: pnpm test

- name: Cypress run
uses: cypress-io/github-action@v4
with:
project: ./tests
build: pnpm generate
start: pnpm start:static
wait-on: 'http://localhost:9090'
# wait for 2 minutes for the server to respond
wait-on-timeout: 150
command: pnpm test:e2e --browser chrome

- name: Upload Screenshots
uses: actions/upload-artifact@v2
if: failure()
with:
name: cypress-website-screenshots
path: ./tests/cypress/screenshots/

build:
strategy:
matrix:
Expand All @@ -81,7 +58,7 @@ jobs:
${{ runner.os }}-
- name: Install pnpm
uses: pnpm/action-setup@v2.2.1
uses: pnpm/action-setup@v2
with:
version: latest

Expand Down
56 changes: 56 additions & 0 deletions .github/workflows/e2e.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
name: cypress

on:
workflow_dispatch:
push:
branches: [main]
pull_request:
branches: [main]

jobs:
e2e:
runs-on: ubuntu-latest
container:
image: cypress/included:10.10.0
options: --user 1001
env:
CYPRESS_CACHE_FOLDER: '${GITHUB_WORKSPACE}/.cypress-cache'
strategy:
matrix:
index: [1, 2, 3, 4] # [1, ..., n] where n === parallelSize in e2e-run-tests.js
steps:
- uses: actions/checkout@v3

- name: Cache pnpm modules
uses: actions/cache@v3
with:
path: ~/.pnpm-store
key: ${{ runner.os }}-${{ hashFiles('**/pnpm-lock.yaml') }}
restore-keys: |
${{ runner.os }}-
- name: Install pnpm
uses: pnpm/action-setup@v2
with:
version: latest

- name: Setup Node.js
uses: actions/setup-node@v3
with:
node-version: 16
cache: 'pnpm'

- name: Install Dependencies
run: pnpm install && pnpm cypress install

- name: Build App
run: pnpm generate

- name: Cypress run
run: pnpm start:static & pnpm wait-on http://localhost:9090 && MATRIX=${{ matrix.index }} node tests/cypress/e2e-run-tests.js

- name: Upload Screenshots
uses: actions/upload-artifact@v3
if: failure()
with:
path: ./cypress/screenshots/
2 changes: 1 addition & 1 deletion .github/workflows/reviewdog.yml
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ jobs:
${{ runner.os }}-
- name: Install pnpm
uses: pnpm/action-setup@v2.2.1
uses: pnpm/action-setup@v2
with:
version: latest

Expand Down
2 changes: 1 addition & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -91,4 +91,4 @@ typings/
## service-worker.js

# cypress
/tests/cypress/screenshots/
cypress/screenshots/
4 changes: 3 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -147,6 +147,7 @@
"eslint-plugin-unicorn": "^42.0.0",
"eslint-plugin-vue": "^8.7.1",
"fake-indexeddb": "^4.0.0",
"glob": "^8.0.3",
"graphql-tag": "^2.12.6",
"husky": "^7.0.4",
"jsdom": "^19.0.0",
Expand All @@ -160,7 +161,8 @@
"vite-plugin-vue2": "^2.0.2",
"vitest": "^0.24.3",
"vue-debounce-decorator": "^1.0.1",
"vue-eslint-parser": "^9.1.0"
"vue-eslint-parser": "^9.1.0",
"wait-on": "^6.0.1"
},
"pnpm": {
"overrides": {
Expand Down
72 changes: 71 additions & 1 deletion pnpm-lock.yaml

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

42 changes: 42 additions & 0 deletions tests/cypress/e2e-run-tests.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
/* eslint-disable @typescript-eslint/no-var-requires */
const cypress = require('cypress')
const glob = require('glob')
const path = require('path')
const { chunk } = require('lodash')

const configFile = path.join(__dirname, '../cypress.config.ts')
const supportFile = path.join(__dirname, './support/e2e.ts')
const fixturesFolder = path.join(__dirname, './fixtures')

glob('./tests/cypress/e2e/**/*.cy.ts', async (err, files) => {
if (err) {
process.exit(1)
}

const parallelSize = 4 // make sure to adjust strategy.matrix.index also in e2e.yml
const size = Math.ceil(files.length / parallelSize)
const group = chunk(files, size)
const index = process.env.MATRIX || 1
const specs = group[index - 1]

try {
const results = await cypress.run({
browser: 'chrome',
configFile,
config: {
supportFile,
e2e: {
fixturesFolder,
specPattern: specs,
},
},
})

if (results.totalFailed > 0) {
process.exit(1)
}
} catch (error) {
console.log(error)
process.exit(1)
}
})
4 changes: 3 additions & 1 deletion tests/cypress/e2e/rmrk-simple-mint.cy.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
describe('simple mint in rmrk', () => {
beforeEach(() => {
cy.loginWithKeyring()
cy.visit('/rmrk')
cy.visit(
'/rmrk/gallery/10177217-0a24c7876a892acb79-RADTOADZ-RADTOADZ-0000000000000103'
)
cy.waitForNetworkIdle('POST', '*', 1000)
})

Expand Down

0 comments on commit bd976bd

Please sign in to comment.