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

Unit-test: the Last Reporter #2900

Closed
wants to merge 12 commits into from
Closed
Show file tree
Hide file tree
Changes from 8 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
3 changes: 2 additions & 1 deletion .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,12 +11,13 @@ env:
# phantomjs hosts binaries @ bitbucket, which has fairly restrictive
# rate-limiting. pull it from this sketchy site in China instead.
- PHANTOMJS_CDNURL='https://cnpmjs.org/downloads'
COVERAGE=true

matrix:
fast_finish: true
include:
- node_js: '8'
env: TARGET=test-node COVERAGE=true
env: TARGET=test-node
- node_js: '7'
env: TARGET=test-node
- node_js: '6'
Expand Down
35 changes: 26 additions & 9 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -7,25 +7,42 @@ ifdef COVERAGE
define test_node
$(NYC) --report-dir coverage/reports/$(1) $(MOCHA)
endef
instrument_browser := -t ./instrumentBrowserEntry
else
test_node := $(MOCHA)
endif

TM_BUNDLE = JavaScript\ mocha.tmbundle
SRC = $(shell find lib -name "*.js" -type f | LC_ALL=C sort)
TESTS = $(shell find test -name "*.js" -type f | sort)

all: mocha.js

mocha.js BUILDTMP/mocha.js: $(SRC) browser-entry.js
@printf "==> [Browser :: build]\n"
mkdir -p ${@D}
define bundle_command
$(BROWSERIFY) ./browser-entry \
$(1) \
--plugin ./scripts/dedefine \
--ignore 'fs' \
--ignore 'glob' \
--ignore 'path' \
--ignore 'supports-color' > $@
endef

TM_BUNDLE = JavaScript\ mocha.tmbundle
SRC = $(shell find lib -name "*.js" -type f | LC_ALL=C sort)
TESTS = $(shell find test -name "*.js" -type f | sort)

all: mocha.js

mocha.js: $(SRC) browser-entry.js
@printf "==> [Browser :: Build]\n"
$(call bundle_command)

BUILDTMP/mocha.js: $(SRC) browser-entry.js BUILDTMP BUILDTMP/mocha.css
@printf "==> [Browser :: Build :: Test :: Bundle]\n"
$(call bundle_command,$(instrument_browser))

BUILDTMP/mocha.css: BUILDTMP
@printf "==> [Browser :: Build :: Test :: CSS]\n"
cp mocha.css $@

BUILDTMP:
@printf "==> [Browser :: Build :: Test :: Temporary Directory]\n"
mkdir -p $@

clean:
@printf "==> [Clean]\n"
Expand Down
11 changes: 11 additions & 0 deletions instrumentBrowserEntry.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
'use strict';

var browserifyIstanbul = require('browserify-istanbul');

var nyc = require('./nycInstrumenter');

var overrideOptions = { ignore: ['**/lib/**', '**/node_modules/**', '**/test/**'], instrumenter: nyc };

module.exports = function (file, options) {
return browserifyIstanbul(file, Object.assign({}, options, overrideOptions));
};
36 changes: 31 additions & 5 deletions karma.conf.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,16 @@ var path = require('path');
var mkdirp = require('mkdirp');
var baseBundleDirpath = path.join(__dirname, '.karma');
var osName = require('os-name');
var workaroundMultiplePreprocessorIncompatibility = require('browserify-istanbul');
var nyc = require('./nycInstrumenter');

module.exports = function (config) {
var bundleDirpath;
var filesBase = [
// make browserify bundle these properly (if nothing else, this is necessary for coverage transform; unclear whether it makes a difference as to how browserify gets them otherwise, as it doesn't print any debug logs about them without it)
{ pattern: 'browser-entry.js', included: false, served: false },
{ pattern: 'lib/**/*.js', included: false, served: false }
];
var cfg = {
frameworks: [
'browserify',
Expand All @@ -23,12 +30,14 @@ module.exports = function (config) {
'karma-spec-reporter',
require('@coderbyheart/karma-sauce-launcher')
],
files: [
files: filesBase.concat([
// we use the BDD interface for all of the tests that
// aren't interface-specific.
'test/browser-fixtures/bdd.fixture.js',
'test/unit/*.spec.js'
],
'test/unit/*.spec.js',
'test/browser-unit/*.spec.js',
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Planning on filling test/browser-unit with tests for lib/browser/*.js, especially any that don't just end up covered by extension of being used in other tested stuff.

'test/browser-reporters/*.spec.js'
]),
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We could put the HTML reporter test in the browser unit folder (it's not like we're planning on adding multiple browser reporters in core), but this is more obvious by parallel of test/reporters.

preprocessors: {
'test/**/*.js': ['browserify']
},
Expand Down Expand Up @@ -128,14 +137,31 @@ module.exports = function (config) {
if (cfg.sauceLabs) {
cfg.sauceLabs.testName = 'Interface "' + ui + '" integration tests';
}
cfg.files = [
cfg.files = filesBase.concat([
'test/browser-fixtures/' + ui + '.fixture.js',
'test/interfaces/' + ui + '.spec.js'
];
]);
} else if (cfg.sauceLabs) {
cfg.sauceLabs.testName = 'Unit Tests';
}

if (env.COVERAGE) {
cfg.plugins.push('karma-coverage');
filesBase.forEach(function (file) {
cfg.preprocessors[file.pattern] = ['browserify'];
});
cfg.reporters.push('coverage');
cfg.coverageReporter = {
instrumenters: { istanbul: nyc },
reporters: [ { type: 'json' }, { type: 'text-summary' } ],
dir: 'coverage/reports/browser' + (ui ? '-' + ui : ''),
subdir: '.',
includeAllSources: true
};
cfg.browserify.transform = [ workaroundMultiplePreprocessorIncompatibility({ ignore: ['**/node_modules/**', '**/test/**'], instrumenter: nyc }) ];
console.error('Reporting coverage to ' + cfg.coverageReporter.dir);
}

config.set(cfg);
};

Expand Down
16 changes: 16 additions & 0 deletions nycInstrumenter.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
'use strict';

var defaultOptions = {
autoWrap: true,
embedSource: true,
produceSourceMap: true,
noCompact: false
};

var istanbulLib;
try {
istanbulLib = require('nyc/node_modules/istanbul-lib-instrument');
} catch (ignore) {
istanbulLib = require('istanbul-lib-instrument');
}
module.exports = { Instrumenter: function (options) { return istanbulLib.createInstrumenter(Object.assign({}, defaultOptions, options)); } };
2 changes: 2 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -323,6 +323,7 @@
"@coderbyheart/karma-sauce-launcher": "coderbyheart/karma-sauce-launcher#5259942cd6d40090eaa13ceeef5b0b8738c7710f",
"assert": "^1.4.1",
"browserify": "^13.0.0",
"browserify-istanbul": "^2.0.0",
"coffee-script": "^1.10.0",
"coveralls": "^2.11.15",
"eslint": "^3.11.1",
Expand All @@ -335,6 +336,7 @@
"karma": "1.3.0",
"karma-browserify": "^5.0.5",
"karma-chrome-launcher": "^2.0.0",
"karma-coverage": "^1.1.1",
"karma-expect": "^1.1.2",
"karma-mocha": "^1.3.0",
"karma-phantomjs-launcher": "0.2.3",
Expand Down
2 changes: 1 addition & 1 deletion test/browser-fixtures/bdd.fixture.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,5 +4,5 @@

process.stdout = require('browser-stdout')();

window.mocha.timeout(200)
window.mocha.timeout(500)
.ui('bdd');
2 changes: 1 addition & 1 deletion test/browser-fixtures/exports.fixture.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,5 +4,5 @@

process.stdout = require('browser-stdout')();

window.mocha.timeout(200)
window.mocha.timeout(500)
.ui('exports');
2 changes: 1 addition & 1 deletion test/browser-fixtures/qunit.fixture.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,5 +4,5 @@

process.stdout = require('browser-stdout')();

window.mocha.timeout(200)
window.mocha.timeout(500)
.ui('qunit');
2 changes: 1 addition & 1 deletion test/browser-fixtures/tdd.fixture.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,5 +4,5 @@

process.stdout = require('browser-stdout')();

window.mocha.timeout(200)
window.mocha.timeout(500)
.ui('tdd');