Skip to content

Commit 7b59307

Browse files
committed
Run browser tests to collect code coverage data
Obviously it's not yet possible to just migrate `gulp browsertest` to GitHub Actions, however it's already possible to at least run the browser tests there which allows collection of more code coverage data. This should thus give us more realistic coverage numbers, since currently there's many `src/` files that have very low code coverage. By taking advantage of the fact that the GitHub Actions runners provide multiple cores, these tests are also fairly fast: - The ubuntu-latest/firefox job complete in ~9 minutes. - The windows-latest/firefox job complete in ~11 minutes.
1 parent 241dbab commit 7b59307

2 files changed

Lines changed: 107 additions & 0 deletions

File tree

Lines changed: 103 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,103 @@
1+
name: Coverage (Browser tests)
2+
on:
3+
push:
4+
paths:
5+
- 'gulpfile.mjs'
6+
- 'external/builder/**'
7+
- 'src/**'
8+
- 'test/images/**'
9+
- 'test/pdfs/**'
10+
- 'test/resources/**'
11+
- 'test/*.css'
12+
- 'test/driver.js'
13+
- 'test/test.mjs'
14+
- 'test/test_manifest.json'
15+
- 'test/test_slave.html'
16+
- 'web/**'
17+
- '.github/workflows/browser_tests.yml'
18+
branches:
19+
- master
20+
pull_request:
21+
paths:
22+
- 'gulpfile.mjs'
23+
- 'external/builder/**'
24+
- 'src/**'
25+
- 'test/images/**'
26+
- 'test/pdfs/**'
27+
- 'test/resources/**'
28+
- 'test/*.css'
29+
- 'test/driver.js'
30+
- 'test/test.mjs'
31+
- 'test/test_manifest.json'
32+
- 'test/test_slave.html'
33+
- 'web/**'
34+
- '.github/workflows/browser_tests.yml'
35+
branches:
36+
- master
37+
workflow_dispatch:
38+
permissions:
39+
contents: read
40+
41+
jobs:
42+
test:
43+
name: ${{ matrix.os }} / ${{ matrix.browser }}
44+
45+
strategy:
46+
fail-fast: false
47+
matrix:
48+
node-version: [lts/*]
49+
os: [windows-latest, ubuntu-latest]
50+
browser: [firefox]
51+
include:
52+
- browser: firefox
53+
skip: --noChrome
54+
55+
runs-on: ${{ matrix.os }}
56+
environment: code-coverage
57+
58+
steps:
59+
- name: Checkout repository
60+
uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6.0.2
61+
with:
62+
fetch-depth: 0
63+
persist-credentials: false
64+
65+
- name: Use Node.js ${{ matrix.node-version }}
66+
uses: actions/setup-node@48b55a011bda9f5d6aeb4c2d9c7362e8dae4041e # v6.4.0
67+
with:
68+
node-version: ${{ matrix.node-version }}
69+
cache: 'npm'
70+
71+
- name: Install dependencies
72+
run: npm ci
73+
74+
- name: Restore cached PDF files
75+
uses: actions/cache/restore@27d5ce7f107fe9357f9df03efb73ab90386fccae # v5.0.5
76+
with:
77+
path: test/pdfs/*.pdf
78+
key: cached-pdf-files-${{ hashFiles('test/pdfs/*.pdf') }}
79+
restore-keys: |
80+
cached-pdf-files-
81+
enableCrossOsArchive: true
82+
83+
- name: Run browser tests with code coverage
84+
run: npx gulp browsertest --bot --headless -j4 --coverage --coverage-output build/coverage/browser ${{ matrix.skip }}
85+
86+
- name: Save cached PDF files
87+
uses: actions/cache/save@27d5ce7f107fe9357f9df03efb73ab90386fccae # v5.0.5
88+
with:
89+
path: test/pdfs/*.pdf
90+
key: cached-pdf-files-${{ hashFiles('test/pdfs/*.pdf') }}
91+
enableCrossOsArchive: true
92+
93+
- name: Upload results to Codecov
94+
uses: codecov/codecov-action@e79a6962e0d4c0c17b229090214935d2e33f8354 # v6.0.1
95+
with:
96+
token: ${{ secrets.CODECOV_TOKEN }}
97+
fail_ci_if_error: true
98+
files: ./build/coverage/integration/lcov.info
99+
flags: integrationtest
100+
name: codecov-umbrella
101+
disable_search: true
102+
disable_telem: true
103+
verbose: true

gulpfile.mjs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -723,6 +723,8 @@ function runTests(testsName, { bot = false } = {}) {
723723
return new Promise((resolve, reject) => {
724724
console.log("\n### Running " + testsName + " tests");
725725

726+
bot ??= process.argv.includes("--bot");
727+
726728
const PDF_TEST = process.env.PDF_TEST || "test_manifest.json";
727729
let forceNoChrome = false;
728730
const args = ["test.mjs"];
@@ -887,6 +889,8 @@ function collectArgs(options, args) {
887889
function makeRef(done, bot) {
888890
console.log("\n### Creating reference images");
889891

892+
bot ??= process.argv.includes("--bot");
893+
890894
let forceNoChrome = false;
891895
const args = ["test.mjs", "--masterMode"];
892896
if (bot) {

0 commit comments

Comments
 (0)