Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore: get test coverage working again #1094

Merged
merged 4 commits into from
Mar 12, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 12 additions & 4 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ jobs:
fail-fast: false
matrix:
os: [ubuntu-18.04]
test-type: [unit, playback, playback-min]
test-type: [unit, playback, playback-min, coverage]
env:
BROWSER_STACK_USERNAME: ${{secrets.BROWSER_STACK_USERNAME}}
BROWSER_STACK_ACCESS_KEY: ${{secrets.BROWSER_STACK_ACCESS_KEY}}
Expand Down Expand Up @@ -50,15 +50,15 @@ jobs:

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

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

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

- name: setup node
uses: actions/setup-node@v1
Expand All @@ -77,3 +77,11 @@ jobs:
uses: GabrielBB/xvfb-action@v1
with:
run: npm run test

- name: coverage
uses: codecov/codecov-action@v1
with:
token: ${{secrets.CODECOV_TOKEN}}
files: './test/dist/coverage/coverage-final.json'
fail_ci_if_error: true
if: ${{startsWith(env.CI_TEST_TYPE, 'coverage')}}
6 changes: 3 additions & 3 deletions package-lock.json

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

3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
"start": "npm-run-all -p server watch",
"server": "karma start scripts/karma.conf.js --singleRun=false --auto-watch",
"test": "npm-run-all lint build-test && karma start scripts/karma.conf.js",
"posttest": "[ \"$CI_TEST_TYPE\" != 'coverage' ] || shx cat test/dist/coverage/text.txt",
"version": "is-prerelease || npm run update-changelog && git add CHANGELOG.md",
"update-changelog": "conventional-changelog -p videojs -i CHANGELOG.md -s",
"watch": "npm-run-all -p watch:*",
Expand Down Expand Up @@ -76,7 +77,7 @@
"lodash-compat": "^3.10.0",
"nomnoml": "^0.3.0",
"rollup": "^2.36.1",
"rollup-plugin-worker-factory": "^0.5.1",
"rollup-plugin-worker-factory": "0.5.4",
"shelljs": "^0.8.4",
"sinon": "^8.1.1",
"url-toolkit": "^2.2.1",
Expand Down
8 changes: 7 additions & 1 deletion scripts/karma.conf.js
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
const generate = require('videojs-generate-karma-config');
const CI_TEST_TYPE = process.env.CI_TEST_TYPE || '';

module.exports = function(config) {

// see https://github.com/videojs/videojs-generate-karma-config
// for options
const options = {
coverage: false,
coverage: CI_TEST_TYPE === 'coverage' ? true : false,
preferHeadless: false,
browsers(aboutToRun) {
return aboutToRun.filter(function(launcherName) {
Expand All @@ -28,6 +29,11 @@ module.exports = function(config) {
delete defaults.bsSafariMojave;
delete defaults.bsSafariElCapitan;

// do not run on browserstack for coverage
if (CI_TEST_TYPE === 'coverage') {
defaults = {};
}

return defaults;
},
serverBrowsers() {
Expand Down
17 changes: 14 additions & 3 deletions scripts/rollup.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,13 @@ let syncWorker;
const options = {
input: 'src/videojs-http-streaming.js',
distName: 'videojs-http-streaming',
checkWatch: false,
excludeCoverage(defaults) {
defaults.push(/^rollup-plugin-worker-factory/);
defaults.push(/^create-test-data!/);

return defaults;
},
globals(defaults) {
defaults.browser.xmldom = 'window';
defaults.test.xmldom = 'window';
Expand All @@ -34,15 +41,19 @@ const options = {
defaults.browser.unshift('worker');
// change this to `syncWorker` for syncronous web worker
// during unit tests
defaults.test.unshift('worker');
if (CI_TEST_TYPE === 'coverage') {
defaults.test.unshift('syncWorker');
} else {
defaults.test.unshift('worker');
}
defaults.test.unshift('createTestData');

if (CI_TEST_TYPE === 'playback-min') {
defaults.test.push('uglify');
}

// istanbul is only in the list for regular builds and not watch
if (defaults.test.indexOf('istanbul') !== -1) {
if (CI_TEST_TYPE !== 'coverage' && defaults.test.indexOf('istanbul') !== -1) {
defaults.test.splice(defaults.test.indexOf('istanbul'), 1);
}
defaults.module.unshift('replace');
Expand Down Expand Up @@ -92,7 +103,7 @@ const options = {

if (CI_TEST_TYPE === 'playback' || CI_TEST_TYPE === 'playback-min') {
options.testInput = 'test/playback.test.js';
} else if (CI_TEST_TYPE === 'unit') {
} else if (CI_TEST_TYPE === 'unit' || CI_TEST_TYPE === 'coverage') {
options.testInput = {include: ['test/**/*.test.js'], exclude: ['test/playback.test.js']};
}

Expand Down
2 changes: 1 addition & 1 deletion test/loader-common.js
Original file line number Diff line number Diff line change
Expand Up @@ -192,7 +192,7 @@ export const LoaderCommonFactory = ({

if (usesAsyncAppends) {
return new Promise((resolve, reject) => {
loader.one('appending', loader.pause);
loader.one('appended', loader.pause);
loader.one('appended', resolve);
loader.one('error', reject);
});
Expand Down
13 changes: 7 additions & 6 deletions test/master-playlist-controller.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -832,9 +832,9 @@ QUnit.test('if buffered, will request second segment byte range', function(asser
};
this.clock.tick(1);
// segment
this.standardXHRResponse(this.requests[1], muxedSegment());
return new Promise((resolve, reject) => {
this.masterPlaylistController.mainSegmentLoader_.on('appending', resolve);
this.standardXHRResponse(this.requests[1], muxedSegment());
}).then(() => {
this.masterPlaylistController.mainSegmentLoader_.fetchAtBuffer_ = true;
// source buffers are mocked, so must manually trigger update ends on audio and video
Expand Down Expand Up @@ -1114,11 +1114,11 @@ QUnit.test('Segment loaders are unpaused when seeking after player has ended', f
// media
this.standardXHRResponse(this.requests.shift(), videoMedia);

// segment
this.standardXHRResponse(this.requests.shift(), muxedSegment());

return new Promise((resolve, reject) => {
this.masterPlaylistController.mainSegmentLoader_.one('appending', resolve);

// segment
this.standardXHRResponse(this.requests.shift(), muxedSegment());
}).then(() => {
assert.notOk(
this.masterPlaylistController.mainSegmentLoader_.paused(),
Expand Down Expand Up @@ -2125,11 +2125,12 @@ QUnit.test('updates the duration after switching playlists', function(assert) {
// 1ms for request duration
this.clock.tick(1);
this.masterPlaylistController.mainSegmentLoader_.mediaIndex = 0;
// segment 0
this.standardXHRResponse(this.requests[2], segment);

return new Promise((resolve, reject) => {
this.masterPlaylistController.mainSegmentLoader_.on('appending', resolve);

// segment 0
this.standardXHRResponse(this.requests[2], segment);
}).then(() => {
// source buffers are mocked, so must manually trigger update ends on audio and video
// buffers
Expand Down
Loading