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.
This commit is contained in:
Pierre Ossman 2018-07-13 15:06:34 +02:00
parent 800abf1277
commit 7bcdbbc65b
3 changed files with 38 additions and 28 deletions

View File

@ -4,7 +4,6 @@ module.exports = (config) => {
const customLaunchers = {};
let browsers = [];
let useSauce = false;
let transpileToES5 = ['internet explorer'].includes(process.env.TEST_BROWSER_NAME);
// use Sauce when running on Travis
if (process.env.TRAVIS_JOB_NUMBER) {
@ -53,7 +52,7 @@ module.exports = (config) => {
// frameworks to use
// available frameworks: https://npmjs.org/browse/keyword/karma-adapter
frameworks: ['requirejs', 'mocha', 'sinon-chai'],
frameworks: ['mocha', 'sinon-chai'],
// list of files / patterns to load in the browser (loaded in order)
files: [
@ -61,9 +60,11 @@ module.exports = (config) => {
{ pattern: 'app/webutil.js', included: false },
{ pattern: 'core/**/*.js', included: false },
{ pattern: 'vendor/pako/**/*.js', included: false },
{ pattern: 'vendor/browser-es-module-loader/dist/*.js*', included: false },
{ pattern: 'tests/test.*.js', included: false },
{ pattern: 'tests/fake.*.js', included: false },
{ pattern: 'tests/assertions.js', included: false },
'vendor/promise.js',
'tests/karma-test-main.js',
],
@ -85,26 +86,6 @@ module.exports = (config) => {
// available browser launchers: https://npmjs.org/browse/keyword/karma-launcher
browsers: browsers,
// preprocess matching files before serving them to the browser
// available preprocessors: https://npmjs.org/browse/keyword/karma-preprocessor
preprocessors: {
'app/localization.js': ['babel'],
'app/webutil.js': ['babel'],
'core/**/*.js': ['babel'],
'tests/test.*.js': ['babel'],
'tests/fake.*.js': ['babel'],
'tests/assertions.js': ['babel'],
'vendor/pako/**/*.js': ['babel'],
},
babelPreprocessor: {
options: {
presets: transpileToES5 ? ['es2015'] : [],
plugins: ['transform-es2015-modules-amd', 'syntax-dynamic-import'],
sourceMap: 'inline',
},
},
// test results reporter to use
// possible values: 'dots', 'progress'
// available reporters: https://npmjs.org/browse/keyword/karma-reporter

View File

@ -46,10 +46,8 @@
"fs-extra": "^1.0.0",
"jsdom": "*",
"karma": "^1.3.0",
"karma-babel-preprocessor": "^6.0.1",
"karma-mocha": "^1.3.0",
"karma-mocha-reporter": "^2.2.0",
"karma-requirejs": "^1.1.0",
"karma-sauce-launcher": "^1.0.0",
"karma-sinon-chai": "^2.0.0",
"mocha": "^3.1.2",

View File

@ -9,8 +9,39 @@ Object.keys(window.__karma__.files).forEach(function (file) {
}
});
require.config({
baseUrl: '/base',
deps: allTestFiles.concat(extraFiles),
callback: window.__karma__.start,
// Stub out mocha's start function so we can run it once we're done loading
mocha.origRun = mocha.run;
mocha.run = function () {};
let script;
// Script to import all our tests
script = document.createElement("script");
script.type = "module";
script.text = "";
let allModules = allTestFiles.concat(extraFiles);
allModules.forEach(function (file) {
script.text += "import \"" + file + "\";\n";
});
script.text += "\nmocha.origRun();\n";
document.body.appendChild(script);
// Fallback code for browsers that don't support modules (IE)
script = document.createElement("script");
script.type = "module";
script.text = "window._noVNC_has_module_support = true;\n";
document.body.appendChild(script);
function fallback() {
if (!window._noVNC_has_module_support) {
/* eslint-disable no-console */
if (console)
console.log("No module support detected. Loading fallback...");
/* eslint-enable no-console */
let loader = document.createElement("script");
loader.src = "base/vendor/browser-es-module-loader/dist/browser-es-module-loader.js";
document.body.appendChild(loader);
}
}
setTimeout(fallback, 500);