Skip to content

Commit 4cecbda

Browse files
authoredJun 23, 2021
chore: add a code coverage ci workflow (#7282)
1 parent 9cfc15c commit 4cecbda

File tree

5 files changed

+103
-14
lines changed

5 files changed

+103
-14
lines changed
 

‎.github/workflows/ci.yml

+12-5
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ on: [push, pull_request]
55
jobs:
66
should-skip:
77
continue-on-error: true
8-
runs-on: ubuntu-18.04
8+
runs-on: ubuntu-latest
99
# Map a step output to a job output
1010
outputs:
1111
should-skip-job: ${{steps.skip-check.outputs.should_skip}}
@@ -21,10 +21,12 @@ jobs:
2121
strategy:
2222
fail-fast: false
2323
matrix:
24-
os: [ubuntu-18.04]
24+
os: [ubuntu-latest]
25+
test-type: [unit, coverage]
2526
env:
2627
BROWSER_STACK_USERNAME: ${{secrets.BROWSER_STACK_USERNAME}}
2728
BROWSER_STACK_ACCESS_KEY: ${{secrets.BROWSER_STACK_ACCESS_KEY}}
29+
CI_TEST_TYPE: ${{matrix.test-type}}
2830
runs-on: ${{matrix.os}}
2931
steps:
3032
- name: checkout code
@@ -48,15 +50,12 @@ jobs:
4850

4951
- name: update apt cache on linux w/o browserstack
5052
run: sudo apt-get update
51-
if: ${{startsWith(matrix.os, 'ubuntu') && !env.BROWSER_STACK_USERNAME}}
5253

5354
- name: install ffmpeg/pulseaudio for firefox on linux w/o browserstack
5455
run: sudo apt-get install ffmpeg pulseaudio
55-
if: ${{startsWith(matrix.os, 'ubuntu') && !env.BROWSER_STACK_USERNAME}}
5656

5757
- name: start pulseaudio for firefox on linux w/o browserstack
5858
run: pulseaudio -D
59-
if: ${{startsWith(matrix.os, 'ubuntu') && !env.BROWSER_STACK_USERNAME}}
6059

6160
- name: setup node
6261
uses: actions/setup-node@v1
@@ -75,3 +74,11 @@ jobs:
7574
uses: GabrielBB/xvfb-action@v1
7675
with:
7776
run: npm run test
77+
78+
- name: coverage
79+
uses: codecov/codecov-action@v1
80+
with:
81+
token: ${{secrets.CODECOV_TOKEN}}
82+
files: './test/dist/coverage/coverage-final.json'
83+
fail_ci_if_error: true
84+
if: ${{startsWith(env.CI_TEST_TYPE, 'coverage')}}

‎package-lock.json

+60
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

‎package.json

+2
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,7 @@
5959
"lint": "vjsstandard",
6060
"lint-errors": "vjsstandard --errors",
6161
"karma-server": "karma start test/karma.conf.js --singleRun=false --auto-watch",
62+
"posttest": "[ \"$CI_TEST_TYPE\" != 'coverage' ] || shx cat test/dist/coverage/text.txt",
6263
"pretest": "npm run build-dev",
6364
"test": "npm-run-all -p test:*",
6465
"test:node-require": "node test/require/node.js",
@@ -138,6 +139,7 @@
138139
"remark-validate-links": "^8.0.2",
139140
"replace": "^1.2.1",
140141
"rollup": "^2.2.0",
142+
"rollup-plugin-istanbul": "^3.0.0",
141143
"rollup-plugin-alias": "^1.5.2",
142144
"rollup-plugin-babel": "^4.4.0",
143145
"rollup-plugin-commonjs": "^9.3.4",

‎rollup.config.js

+11
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,16 @@ import multiEntry from 'rollup-plugin-multi-entry';
1313
import stub from 'rollup-plugin-stub';
1414
import isCI from 'is-ci';
1515
import replace from '@rollup/plugin-replace';
16+
import istanbul from 'rollup-plugin-istanbul';
1617

18+
const excludeCoverage = [
19+
'test/**',
20+
'node_modules/**',
21+
'package.json',
22+
/^data-files!/
23+
];
24+
25+
const CI_TEST_TYPE = process.env.CI_TEST_TYPE || '';
1726
const compiledLicense = _.template(fs.readFileSync('./build/license-header.txt', 'utf8'));
1827
const bannerData = _.pick(pkg, ['version', 'copyright']);
1928
const banner = compiledLicense(Object.assign({includesVtt: true}, bannerData));
@@ -172,8 +181,10 @@ export default cliargs => [
172181
json(),
173182
stub(),
174183
primedCjs,
184+
CI_TEST_TYPE === 'coverage' ? istanbul({exclude: excludeCoverage}) : {},
175185
primedBabel,
176186
cliargs.progress !== false ? progress() : {}
187+
177188
],
178189
onwarn,
179190
watch

‎test/karma.conf.js

+18-9
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,28 @@
11
const generate = require('videojs-generate-karma-config');
2+
const CI_TEST_TYPE = process.env.CI_TEST_TYPE || '';
23

34
module.exports = function(config) {
4-
// const coverageFlag = process.env.npm_config_coverage;
5-
// process.env.TRAVIS || coverageFlag || false;
6-
const reportCoverage = false;
7-
85
// see https://github.com/videojs/videojs-generate-karma-config
96
// for options
107
const options = {
11-
travisLaunchers(defaults) {
12-
delete defaults.travisFirefox;
13-
return defaults;
8+
browsers(aboutToRun) {
9+
// never run on Chromium
10+
return aboutToRun.filter(function(launcherName) {
11+
return !(/^(Chromium)/).test(launcherName);
12+
});
1413
},
1514
serverBrowsers(defaults) {
1615
return [];
1716
},
18-
coverage: reportCoverage
17+
browserstackLaunchers(defaults) {
18+
// do not use browserstack for coverage testing
19+
if (CI_TEST_TYPE === 'coverage') {
20+
return {};
21+
}
22+
23+
return defaults;
24+
},
25+
coverage: CI_TEST_TYPE === 'coverage' ? true : false
1926
};
2027

2128
config = generate(config, options);
@@ -43,7 +50,9 @@ module.exports = function(config) {
4350

4451
// pin Browserstack Firefox version to 64
4552
/* eslint-disable camelcase */
46-
config.customLaunchers.bsFirefox.browser_version = '64.0';
53+
if (config.customLaunchers && config.customLaunchers.bsFirefox) {
54+
config.customLaunchers.bsFirefox.browser_version = '64.0';
55+
}
4756
/* eslint-enable camelcase */
4857

4958
// uncomment the section below to re-enable all browserstack video recording

0 commit comments

Comments
 (0)
Please sign in to comment.