Skip to content

Commit 7bcdbbc

Browse files
committed
Stop transpiling karma tests
This runs our code in the same manner as it would be used if loaded directly in the browser. Includes the same kind of fallback for older browsers.
1 parent 800abf1 commit 7bcdbbc

File tree

3 files changed

+38
-28
lines changed

3 files changed

+38
-28
lines changed

karma.conf.js

+3-22
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@ module.exports = (config) => {
44
const customLaunchers = {};
55
let browsers = [];
66
let useSauce = false;
7-
let transpileToES5 = ['internet explorer'].includes(process.env.TEST_BROWSER_NAME);
87

98
// use Sauce when running on Travis
109
if (process.env.TRAVIS_JOB_NUMBER) {
@@ -53,17 +52,19 @@ module.exports = (config) => {
5352

5453
// frameworks to use
5554
// available frameworks: https://npmjs.org/browse/keyword/karma-adapter
56-
frameworks: ['requirejs', 'mocha', 'sinon-chai'],
55+
frameworks: ['mocha', 'sinon-chai'],
5756

5857
// list of files / patterns to load in the browser (loaded in order)
5958
files: [
6059
{ pattern: 'app/localization.js', included: false },
6160
{ pattern: 'app/webutil.js', included: false },
6261
{ pattern: 'core/**/*.js', included: false },
6362
{ pattern: 'vendor/pako/**/*.js', included: false },
63+
{ pattern: 'vendor/browser-es-module-loader/dist/*.js*', included: false },
6464
{ pattern: 'tests/test.*.js', included: false },
6565
{ pattern: 'tests/fake.*.js', included: false },
6666
{ pattern: 'tests/assertions.js', included: false },
67+
'vendor/promise.js',
6768
'tests/karma-test-main.js',
6869
],
6970

@@ -85,26 +86,6 @@ module.exports = (config) => {
8586
// available browser launchers: https://npmjs.org/browse/keyword/karma-launcher
8687
browsers: browsers,
8788

88-
// preprocess matching files before serving them to the browser
89-
// available preprocessors: https://npmjs.org/browse/keyword/karma-preprocessor
90-
preprocessors: {
91-
'app/localization.js': ['babel'],
92-
'app/webutil.js': ['babel'],
93-
'core/**/*.js': ['babel'],
94-
'tests/test.*.js': ['babel'],
95-
'tests/fake.*.js': ['babel'],
96-
'tests/assertions.js': ['babel'],
97-
'vendor/pako/**/*.js': ['babel'],
98-
},
99-
100-
babelPreprocessor: {
101-
options: {
102-
presets: transpileToES5 ? ['es2015'] : [],
103-
plugins: ['transform-es2015-modules-amd', 'syntax-dynamic-import'],
104-
sourceMap: 'inline',
105-
},
106-
},
107-
10889
// test results reporter to use
10990
// possible values: 'dots', 'progress'
11091
// available reporters: https://npmjs.org/browse/keyword/karma-reporter

package.json

-2
Original file line numberDiff line numberDiff line change
@@ -46,10 +46,8 @@
4646
"fs-extra": "^1.0.0",
4747
"jsdom": "*",
4848
"karma": "^1.3.0",
49-
"karma-babel-preprocessor": "^6.0.1",
5049
"karma-mocha": "^1.3.0",
5150
"karma-mocha-reporter": "^2.2.0",
52-
"karma-requirejs": "^1.1.0",
5351
"karma-sauce-launcher": "^1.0.0",
5452
"karma-sinon-chai": "^2.0.0",
5553
"mocha": "^3.1.2",

tests/karma-test-main.js

+35-4
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,39 @@ Object.keys(window.__karma__.files).forEach(function (file) {
99
}
1010
});
1111

12-
require.config({
13-
baseUrl: '/base',
14-
deps: allTestFiles.concat(extraFiles),
15-
callback: window.__karma__.start,
12+
// Stub out mocha's start function so we can run it once we're done loading
13+
mocha.origRun = mocha.run;
14+
mocha.run = function () {};
15+
16+
let script;
17+
18+
// Script to import all our tests
19+
script = document.createElement("script");
20+
script.type = "module";
21+
script.text = "";
22+
let allModules = allTestFiles.concat(extraFiles);
23+
allModules.forEach(function (file) {
24+
script.text += "import \"" + file + "\";\n";
1625
});
26+
script.text += "\nmocha.origRun();\n";
27+
document.body.appendChild(script);
28+
29+
// Fallback code for browsers that don't support modules (IE)
30+
script = document.createElement("script");
31+
script.type = "module";
32+
script.text = "window._noVNC_has_module_support = true;\n";
33+
document.body.appendChild(script);
34+
35+
function fallback() {
36+
if (!window._noVNC_has_module_support) {
37+
/* eslint-disable no-console */
38+
if (console)
39+
console.log("No module support detected. Loading fallback...");
40+
/* eslint-enable no-console */
41+
let loader = document.createElement("script");
42+
loader.src = "base/vendor/browser-es-module-loader/dist/browser-es-module-loader.js";
43+
document.body.appendChild(loader);
44+
}
45+
}
46+
47+
setTimeout(fallback, 500);

0 commit comments

Comments
 (0)