Skip to content

Commit

Permalink
fix(ci): e2e coverage (#2142)
Browse files Browse the repository at this point in the history
* tests(e2e): coverage for separate shard runs

* test(e2e): cache test-build
  • Loading branch information
SgtPooki committed Jul 25, 2023
1 parent 670ba7c commit 83353e0
Show file tree
Hide file tree
Showing 2 changed files with 93 additions and 0 deletions.
92 changes: 92 additions & 0 deletions .github/workflows/test-e2e.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,48 @@ on:
workflow_call:

jobs:
test-build:
name: 'test:build'
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3.5.3

- name: Setup node
uses: actions/setup-node@v3.6.0
with:
node-version: 18.14.0

- name: Cache bigger downloads
uses: actions/cache@v3.3.1
id: cache
with:
path: ${{ github.workspace }}/.cache
key: ${{ runner.os }}-${{ hashFiles('package.json', 'package-lock.json') }}
restore-keys: |
${{ runner.os }}-${{ hashFiles('package.json', 'package-lock.json') }}
${{ runner.os }}-
- name: Install dependencies
run: npm ci --prefer-offline --no-audit --progress=false --cache ${{ github.workspace }}/.cache/npm

- name: Cache test-build output
uses: actions/cache@v3.3.1
id: test-build-cache
with:
path: build
key: test-build-${{ runner.os }}-${{ github.sha }}
restore-keys: |
test-build-${{ runner.os }}-${{ github.sha }}
# This is required to ensure that our code is instrumented with coverage details
- name: Run test build
if: steps.test-build-cache.outputs.cache-hit != 'true'
run: npm run test:build

test-e2e:
name: 'test:e2e'
runs-on: ubuntu-latest
needs: [test-build]
strategy:
fail-fast: false
matrix:
Expand Down Expand Up @@ -35,10 +73,29 @@ jobs:
- name: Install playwright browsers
run: npx playwright install --with-deps

- name: Cache test-build output
uses: actions/cache@v3.3.1
id: test-build-cache
with:
path: build
key: test-build-${{ runner.os }}-${{ github.sha }}
restore-keys: |
test-build-${{ runner.os }}-${{ github.sha }}
# This is required to ensure that our code is instrumented with coverage details
- name: Run test build
if: steps.test-build-cache.outputs.cache-hit != 'true'
run: npm run test:build

- name: Cache nyc_output dir
uses: actions/cache@v3.3.1
id: nyc_output-cache
with:
path: ./.nyc_output
key: nyc_output-${{ runner.os }}-${{ github.sha }}
restore-keys: |
nyc_output-${{ runner.os }}-${{ github.sha }}
- name: Run repeated-E2E against Kubo
if: github.ref != 'refs/heads/main' # only run duplicated e2e tests on PRs
run: npm run test:e2e -- --repeat-each 10 --shard=${{ matrix.shardIndex }}/${{ matrix.shardTotal }} # run each test 10 times to ensure no flakiness
Expand All @@ -47,6 +104,41 @@ jobs:
if: github.ref == 'refs/heads/main' # run non-duplicated tests on non-PRs
run: npm run test:e2e -- --shard=${{ matrix.shardIndex }}/${{ matrix.shardTotal }}

e2e-coverage: # since we run coverage in shards and some files may not contain coverage, we cache the .nyc_output directory
name: 'e2e-coverage'
runs-on: ubuntu-latest
needs: [test-e2e]
steps:
- uses: actions/checkout@v3.5.3

- name: Setup node
uses: actions/setup-node@v3.6.0
with:
node-version: 18.14.0

- name: Cache bigger downloads
uses: actions/cache@v3.3.1
id: cache
with:
path: ${{ github.workspace }}/.cache
key: ${{ runner.os }}-${{ hashFiles('package.json', 'package-lock.json') }}
restore-keys: |
${{ runner.os }}-${{ hashFiles('package.json', 'package-lock.json') }}
${{ runner.os }}-
- name: Install dependencies
run: npm ci --prefer-offline --no-audit --progress=false --cache ${{ github.workspace }}/.cache/npm

- name: Cache nyc_output dir
uses: actions/cache@v3.3.1
id: nyc_output-cache
with:
path: ./.nyc_output
key: nyc_output-${{ runner.os }}-${{ github.sha }}
restore-keys: |
nyc_output-${{ runner.os }}-${{ github.sha }}
- name: Generate nyc coverage report
id: coverage
run: npx nyc report --reporter=lcov
Expand Down
1 change: 1 addition & 0 deletions config-overrides.js
Original file line number Diff line number Diff line change
Expand Up @@ -110,6 +110,7 @@ function webpackOverride (config) {
const REACT_APP_ENV = process.env.REACT_APP_ENV ?? process.env.NODE_ENV ?? 'development'
if (REACT_APP_ENV === 'test') {
config.module.rules = modifyBabelLoaderRuleForTest(config.module.rules)
config.devtool = 'inline-source-map'
} else if (REACT_APP_ENV === 'development') {
config.optimization = {
...config.optimization,
Expand Down

0 comments on commit 83353e0

Please sign in to comment.