Skip to content

Commit dc12bd5

Browse files
boneskullBamieh
authored andcommitted
test setup for ESM support
1 parent 95d2fe7 commit dc12bd5

File tree

5 files changed

+9915
-3425
lines changed

5 files changed

+9915
-3425
lines changed

Makefile

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -5,10 +5,10 @@ NYC := "node_modules/.bin/nyc"
55

66
ifdef COVERAGE
77
define test_node
8-
$(NYC) --no-clean --report-dir coverage/reports/$(1) $(MOCHA)
8+
$(NYC) --no-clean --report-dir coverage/reports/$(1) $(MOCHA)
99
endef
1010
else
11-
test_node := $(MOCHA)
11+
test_node := $(MOCHA)
1212
endif
1313

1414
TM_BUNDLE = JavaScript\ mocha.tmbundle
@@ -37,7 +37,7 @@ lint:
3737

3838
test-node: test-bdd test-tdd test-qunit test-exports test-unit test-integration test-jsapi test-compilers test-requires test-reporters test-only test-global-only
3939

40-
test-browser: clean mocha.js test-browser-unit test-browser-bdd test-browser-qunit test-browser-tdd test-browser-exports
40+
test-browser: clean mocha.js test-browser-unit test-browser-bdd test-browser-qunit test-browser-tdd test-browser-esm
4141

4242
test: lint test-node test-browser
4343

@@ -47,15 +47,19 @@ test-browser-unit:
4747

4848
test-browser-bdd:
4949
@printf "==> [Test :: Browser :: BDD]\n"
50-
MOCHA_UI=bdd $(MAKE) test-browser-unit
50+
MOCHA_TEST=bdd $(MAKE) test-browser-unit
5151

5252
test-browser-qunit:
5353
@printf "==> [Test :: Browser :: QUnit]\n"
54-
MOCHA_UI=qunit $(MAKE) test-browser-unit
54+
MOCHA_TEST=qunit $(MAKE) test-browser-unit
5555

5656
test-browser-tdd:
5757
@printf "==> [Test :: Browser :: TDD]\n"
58-
MOCHA_UI=tdd $(MAKE) test-browser-unit
58+
MOCHA_TEST=tdd $(MAKE) test-browser-unit
59+
60+
test-browser-esm:
61+
@printf "==> [Test :: Browser :: ESM]\n"
62+
MOCHA_TEST=esm $(MAKE) test-browser-unit
5963

6064
test-jsapi:
6165
@printf "==> [Test :: JS API]\n"

karma.conf.js

Lines changed: 51 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -38,10 +38,13 @@ module.exports = config => {
3838
.ignore('path')
3939
.ignore('supports-color')
4040
.on('bundled', (err, content) => {
41-
if (!err && bundleDirpath) {
41+
if (err) {
42+
throw err;
43+
}
44+
if (bundleDirpath) {
4245
// write bundle to directory for debugging
4346
fs.writeFileSync(path.join(bundleDirpath,
44-
`bundle.${Date.now()}.js`), content);
47+
`mocha.${Date.now()}.js`), content);
4548
}
4649
});
4750
}
@@ -60,18 +63,8 @@ module.exports = config => {
6063
}
6164
};
6265

63-
// see https://github.com/saucelabs/karma-sauce-example
64-
65-
// We define the browser to run on the Saucelabs Infrastructure
66-
// via the environment variables BROWSER and PLATFORM.
67-
// PLATFORM is e.g. "Windows"
68-
// BROWSER is expected to be in the format "<name>@<version>",
69-
// e.g. "MicrosoftEdge@latest"
70-
// See https://wiki.saucelabs.com/display/DOCS/Platform+Configurator#/
71-
// for available browsers.
72-
73-
// TO RUN LOCALLY, execute:
74-
// `CI=1 SAUCE_USERNAME=<user> SAUCE_ACCESS_KEY=<key> BROWSER=<browser> PLATFORM=<platform> make test-browser`
66+
// TO RUN AGAINST SAUCELABS LOCALLY, execute:
67+
// `CI=1 SAUCE_USERNAME=<user> SAUCE_ACCESS_KEY=<key> make test-browser`
7568
const env = process.env;
7669
let sauceConfig;
7770

@@ -92,8 +85,7 @@ module.exports = config => {
9285
console.error('No SauceLabs credentials present');
9386
}
9487
} else if (env.APPVEYOR) {
95-
console.error('AppVeyor detected');
96-
bundleDirpath = path.join(baseBundleDirpath, process.env.APPVEYOR_BUILD_ID);
88+
throw new Error('no browser tests should run on AppVeyor!');
9789
} else {
9890
console.error('Local/unknown environment detected');
9991
bundleDirpath = path.join(baseBundleDirpath, 'local');
@@ -120,21 +112,48 @@ module.exports = config => {
120112
addSauceTests(cfg);
121113
}
122114

123-
// the MOCHA_UI env var will determine if we're running interface-specific
124-
// tests. since you can only load one at a time, each must be run separately.
125-
// each has its own set of acceptance tests and a fixture.
126-
// the "bdd" fixture is used by default.
127-
const ui = env.MOCHA_UI;
128-
if (ui) {
129-
if (cfg.sauceLabs) {
130-
cfg.sauceLabs.testName = `Interface "${ui}" integration tests`;
131-
}
132-
cfg.files = [
133-
`test/browser-fixtures/${ui}.fixture.js`,
134-
`test/interfaces/${ui}.spec.js`
135-
];
136-
} else if (cfg.sauceLabs) {
137-
cfg.sauceLabs.testName = 'Unit Tests';
115+
/* the MOCHA_TEST env var will be set for "special" cases of tests.
116+
* these may require different interfaces or other setup which make
117+
* them unable to be batched w/ the rest.
118+
*/
119+
const MOCHA_TEST = env.MOCHA_TEST;
120+
switch (MOCHA_TEST) {
121+
case 'bdd':
122+
case 'tdd':
123+
case 'qunit':
124+
if (cfg.sauceLabs) {
125+
cfg.sauceLabs.testName = `Interface "${MOCHA_TEST}" Integration Tests`;
126+
}
127+
cfg.files = [
128+
`test/browser-fixtures/${MOCHA_TEST}.fixture.js`,
129+
`test/interfaces/${MOCHA_TEST}.spec.js`
130+
];
131+
break;
132+
133+
case 'esm':
134+
// for now we will only run against Chrome to test this.
135+
if (cfg.sauceLabs) {
136+
cfg.sauceLabs.testName = 'ESM Integration Tests';
137+
cfg.browsers = ['chrome@latest'];
138+
cfg.customLaunchers = {
139+
'chrome@latest': cfg.customLaunchers['chrome@latest']
140+
};
141+
} else if (!env.TRAVIS) {
142+
cfg.browsers = ['Chrome'];
143+
} else {
144+
console.error(
145+
'skipping ESM tests & exiting; no SauceLabs nor local run detected');
146+
process.exit(0);
147+
}
148+
cfg.files = [
149+
'test/browser-fixtures/esm.fixture.html',
150+
'test/browser-specific/esm.spec.js'
151+
];
152+
break;
153+
default:
154+
if (cfg.sauceLabs) {
155+
cfg.sauceLabs.testName = 'Unit Tests';
156+
}
138157
}
139158

140159
config.set(cfg);
@@ -146,9 +165,7 @@ function addSauceTests (cfg) {
146165
cfg.browsers = cfg.browsers.concat(browsers);
147166
cfg.customLaunchers = browsers.reduce((acc, browser) => {
148167
const platform = browserPlatformPairs[browser];
149-
const browserParts = browser.split('@');
150-
const browserName = browserParts[0];
151-
const version = browserParts[1];
168+
const [browserName, version] = browser.split('@');
152169
acc[browser] = {
153170
base: 'SauceLabs',
154171
browserName: browserName,

0 commit comments

Comments
 (0)