Skip to content

Commit 34e2f69

Browse files
committed
Update for 2020: Headless Firefox, Semistandard, NYC report, Coveralls
== Update to Karma 5 == * Introducing Headless Firefox. Use Headless Firefox by default instead of Headless Chrome. This tends to be more stable, especially in development environments that use Docker where Chrome has root/sandboxing requirements that allow non-trivial "last mile" configuration, causing things like karma, grunt and puppeteer to always fail by default and thus create a barrier to entry. Ref puppeteer/puppeteer#5505. * karma-cli no longer needed. == Update ESLint and use Semistandard == * Introducing Semistandard Remove custom ESLint configuration and use Semistandard wrapper. Less configuration to fiddle with. It just works. Set any overrides local to the individual JS files. No more opinionated or indirect per-repo or per-directory overrides. Follow the standard™! * Switch excludes from package.json to .eslintignore file. * Switch .eslintrc from YAML to JSON, and add a `.json` file extension. * Update test files to use modern ES6 syntax. == Combined code coverage reports! == * Introducing NYC. Use NYC to generate code coverage from the Node.js test run. And, more importantly, use NYC to generate a combined code coverage report from both the Node.js and web browser test runs. This is possible by configuring karma-coverage in karma.conf.js to save the internal JSON file, without a 'subdir'. (This matches what the `nyc` command does for Node.js) These two are then combined by the `nyc report` command. * Introducing Coveralls. Switch from Codecov to Coveralls <https://coveralls.io/>.
1 parent 52b53e9 commit 34e2f69

14 files changed

+186
-187
lines changed

Diff for: .editorconfig

+9
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
root = true
2+
3+
[*]
4+
indent_style = space
5+
indent_size = 2
6+
end_of_line = lf
7+
charset = utf-8
8+
trim_trailing_whitespace = true
9+
insert_final_newline = true

Diff for: .eslintignore

+2
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
/.nyc_output
2+
/coverage

Diff for: .eslintrc.json

+4
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
{
2+
"root": true,
3+
"extends": "semistandard"
4+
}

Diff for: .eslintrc.yml

-6
This file was deleted.

Diff for: .gitignore

+1
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
/.nyc_output
12
/coverage
23
/node_modules
34
/npm-debug.log

Diff for: .travis.yml

+13-16
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,15 @@
1-
sudo: false
2-
dist: trusty
31
language: node_js
4-
5-
node_js:
6-
- "8"
7-
82
addons:
9-
chrome: stable
10-
11-
after_success:
12-
- npm install -g [email protected]
13-
- codecov
14-
15-
# notifications:
16-
# irc:
17-
# channels:
18-
# - "chat.freenode.net#example"
3+
firefox: latest
4+
node_js:
5+
- "14"
6+
- "12"
7+
- "10"
8+
script: npm test
9+
10+
jobs:
11+
include:
12+
- name: Coverage
13+
os: linux
14+
node_js: "14"
15+
script: npm run coveralls

Diff for: README.md

+10-26
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,15 @@
1-
[![Build Status](https://travis-ci.org/Krinkle/travis-ci-node-and-browser-qunit.svg?branch=master)](https://travis-ci.org/Krinkle/travis-ci-node-and-browser-qunit) [![Code coverage](https://img.shields.io/codecov/c/github/Krinkle/travis-ci-node-and-browser-qunit.svg)](https://codecov.io/gh/Krinkle/travis-ci-node-and-browser-qunit)
1+
[![Build Status](https://travis-ci.com/Krinkle/travis-ci-node-and-browser-qunit.svg?branch=master)](https://travis-ci.com/github/Krinkle/travis-ci-node-and-browser-qunit) [![Coverage Status](https://coveralls.io/repos/github/Krinkle/travis-ci-node-and-browser-qunit/badge.svg?branch=master)](https://coveralls.io/github/Krinkle/travis-ci-node-and-browser-qunit?branch=master)
22

3-
# Run QUnit in Node.js and Chrome! (using Travis CI)
3+
# Run QUnit on the web and in Node.js!
44

5-
This project is an example of how to approach continuous integration
6-
by running QUnit tests inside a headless browser (Chrome) and/or inside Node.js.
5+
This is an example project showing an approach running QUnit in continuous integration
6+
with the same application and test suite run both in a web browser (Headless Firefox) and
7+
on Node.js, plus (combined) code coverage reports.
78

89
## Get started
910

1011
Clone or fork this repository and be sure to run the following two commands to
11-
install the dependencies and start the first test run:
12+
install the development dependencies and kick off your first test run:
1213

1314
<pre lang="bash">
1415
npm install
@@ -17,29 +18,12 @@ npm test
1718

1819
## Tell me more
1920

20-
[Travis CI](https://travis-ci.org/) provides cloud-based [Continuous integration](https://en.wikipedia.org/wiki/Continuous_integration) for open source projects on GitHub. After you enable it, Travis CI will automatically run the tests and report back whenever you `git push`,
21-
or submit a pull-request.
21+
[Travis CI](https://travis-ci.com/) provides cloud-based [Continuous integration](https://en.wikipedia.org/wiki/Continuous_integration) for open source projects on GitHub. After you enable it, Travis automatically runs the tests and reports back whenever you `git push`, or submit a pull-request.
2222

23-
This boilerplate repository has Travis enabled ([view build history](https://travis-ci.org/Krinkle/travis-ci-node-and-browser-qunit)).
23+
This boilerplate repository has Travis enabled ([view build history](https://travis-ci.com/github/Krinkle/travis-ci-node-and-browser-qunit)).
2424

25-
Just get into it, have a look at it all, you'll get the hang of it, it's easy!
26-
If you've got any problems, feel free to ask on Twitter or [file an issue](https://github.com/Krinkle/travis-ci-node-and-browser-qunit/issues).
25+
Take a look around, you'll get the hang of it, it's easy!
26+
If you've got any questions or problems, feel free to [file an issue](https://github.com/Krinkle/travis-ci-node-and-browser-qunit/issues).
2727

2828
* [@Krinkle](https://github.com/Krinkle) ([Twitter](https://twitter.com/TimoTijhof))
2929
* [@keithamus](https://github.com/keithamus) ([Twitter](https://twitter.com/keithamus))
30-
31-
By default, Travis-CI will execute the `npm test` command, which in this example
32-
repository runs `grunt test` and `node test/node-index.js`. The Gruntfile takes care
33-
of running ESLint and running the QUnit tests in Headless Chrome.
34-
The second script runs the unit tests in Node.js (without a browser environment).
35-
36-
Depending on the kind of project you have you may want to keep only one of these.
37-
38-
If your application only runs in a browser:
39-
* Remove `test/node-test.js`
40-
* Remove the `qunit test/node-index.js` command from `scripts.test` in `package.json`
41-
42-
If your app is written specifically for Node.js only, then:
43-
* Remove `karma.conf.js`
44-
* Remove the `karma-debug` run script from `package.json`
45-
* Remove `karma` and `karma-*` from the `devDependencies` in `package.json`

Diff for: karma.conf.js

+25-28
Original file line numberDiff line numberDiff line change
@@ -1,31 +1,28 @@
11
/* eslint-env node */
2+
23
module.exports = function (config) {
3-
config.set({
4-
// To debug, run `npm run karma-debug` and press the "Debug" button in the browser window
5-
browsers: [ 'ChromeHeadless' ],
6-
frameworks: [ 'qunit' ],
7-
files: [
8-
'src/MyLib.js',
9-
'test/MyLib.test.js'
10-
],
11-
autoWatch: false,
12-
singleRun: true,
13-
preprocessors: {
14-
'src/*.js': [ 'coverage' ]
15-
},
16-
reporters: [ 'dots', 'coverage' ],
17-
coverageReporter: {
18-
reporters: [
19-
{ type: 'text-summary' },
20-
{ type: 'html', dir:'coverage/' },
21-
{ type: 'lcovonly', dir: 'coverage/' },
22-
],
23-
check: { global: {
24-
functions: 90,
25-
statements: 50,
26-
branches: 50,
27-
lines: 50
28-
} }
29-
}
30-
});
4+
config.set({
5+
browsers: ['FirefoxHeadless'],
6+
frameworks: ['qunit'],
7+
files: [
8+
'src/MyLib.js',
9+
'test/*.test.js'
10+
],
11+
autoWatch: false,
12+
singleRun: true,
13+
preprocessors: {
14+
'src/*.js': ['coverage']
15+
},
16+
reporters: ['dots', 'coverage'],
17+
coverageReporter: {
18+
reporters: [
19+
{ type: 'lcov', dir: '.nyc_output/' },
20+
// Karma uses subdirs by default to account for multiple browsers.
21+
// For the JSON file, it's important we disable 'subdir' so that
22+
// the 'nyc report' command can pick this up when combining code
23+
// coverage with the Node.js test run.
24+
{ type: 'json', dir: '.nyc_output/', subdir: '.' }
25+
]
26+
}
27+
});
3128
};

Diff for: package.json

+23-12
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,31 @@
11
{
22
"private": true,
33
"scripts": {
4-
"test": "eslint . && qunit test/node-index.js && karma start",
5-
"karma-debug": "karma start --no-single-run --browsers Chrome --logLevel DEBUG"
4+
"lint": "semistandard",
5+
"test-node": "qunit --require ./test/setup test/",
6+
"test-node-cover": "nyc qunit --require ./test/setup test/",
7+
"test-node-watch": "qunit --watch --require ./test/setup test/",
8+
"test-browser": "karma start",
9+
"test-browser-watch": "karma start --auto-watch --no-single-mode",
10+
"test": "npm run lint && npm run test-node && npm run test-browser",
11+
"cover": "npm run test-node-cover && npm run test-browser && nyc report",
12+
"coveralls": "npm run cover && cat coverage/lcov.info | coveralls"
613
},
7-
"eslintIgnore": [
8-
"/coverage"
9-
],
1014
"dependencies": {},
1115
"devDependencies": {
12-
"eslint": "4.3.0",
13-
"karma": "1.7.0",
14-
"karma-chrome-launcher": "2.2.0",
15-
"karma-cli": "^1.0.1",
16-
"karma-coverage": "1.1.1",
17-
"karma-qunit": "1.2.1",
18-
"qunitjs": "2.4.0"
16+
"coveralls": "^3.1.0",
17+
"karma": "^5.2.3",
18+
"karma-chrome-launcher": "^3.1.0",
19+
"karma-coverage": "^2.0.3",
20+
"karma-firefox-launcher": "^2.1.0",
21+
"karma-qunit": "^4.1.1",
22+
"nyc": "^15.1.0",
23+
"qunit": "^2.12.0",
24+
"semistandard": "^14.0.0"
25+
},
26+
"nyc": {
27+
"temp-dir": ".nyc_output/",
28+
"report-dir": "coverage/",
29+
"reporter": ["text", "lcov"]
1930
}
2031
}

Diff for: src/MyLib.js

+32-45
Original file line numberDiff line numberDiff line change
@@ -1,47 +1,34 @@
11
(function (global) {
2-
var originalMyLib = global.MyLib;
3-
4-
function MyLib(a, b) {
5-
this.a = a;
6-
this.b = b;
7-
}
8-
9-
/* Static members */
10-
11-
/**
12-
* We love everything that isn't undefined.
13-
* If it is defined, it is cool in our book.
14-
*
15-
* @param {mixed} o
16-
* @return {boolean}
17-
*/
18-
MyLib.isAwesome = function isAwesome(o) {
19-
return o !== undefined;
20-
};
21-
22-
/* Instance members */
23-
24-
MyLib.prototype.a = 'a';
25-
26-
MyLib.prototype.b = 'b';
27-
28-
if (typeof module !== 'undefined' && module.exports) {
29-
module.exports = MyLib;
30-
} else {
31-
global.MyLib = MyLib;
32-
33-
/**
34-
* For browsers, also implement a noConflict that restores
35-
* the orignal value of the used global (if any).
36-
* @example
37-
* <code>
38-
* var someLib = MyLib.noConflict();
39-
* </code>
40-
*/
41-
MyLib.noConflict = function () {
42-
global.MyLib = originalMyLib;
43-
return MyLib;
44-
};
45-
}
46-
2+
/**
3+
* @class
4+
* @constructor
5+
* @param {string} a
6+
* @param {string} b
7+
*/
8+
function MyLib (a, b) {
9+
this.a = a;
10+
this.b = b;
11+
}
12+
13+
/**
14+
* @static
15+
* @param {Mixed} o
16+
* @return {boolean}
17+
*/
18+
MyLib.isAwesome = function (value) {
19+
return value !== undefined;
20+
};
21+
22+
/**
23+
* @return {string}
24+
*/
25+
MyLib.prototype.getAye = function () {
26+
return this.a;
27+
};
28+
29+
if (typeof module !== 'undefined' && module.exports) {
30+
module.exports = MyLib;
31+
} else {
32+
global.MyLib = MyLib;
33+
}
4734
}(this));

Diff for: test/General.test.js

+26
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
/* global QUnit */
2+
3+
QUnit.module('General');
4+
5+
QUnit.test('foo', assert => {
6+
assert.equal('Foo', 'Foo', 'similar strings');
7+
assert.equal(true, 1, 'true and one');
8+
assert.strictEqual(true, true, 'just true');
9+
});
10+
11+
QUnit.test('bar', assert => {
12+
const x = { one: 1, two: 2 };
13+
const y = x;
14+
15+
assert.strictEqual(
16+
x,
17+
y,
18+
'same object by reference'
19+
);
20+
21+
assert.deepEqual(
22+
{ one: 1, two: 2 },
23+
{ one: 1, two: 2 },
24+
'distinct objects with similar keys and values'
25+
);
26+
});

0 commit comments

Comments
 (0)