]> git.proxmox.com Git - mirror_novnc.git/blob - tests/karma-test-main.js
Stop transpiling karma tests
[mirror_novnc.git] / tests / karma-test-main.js
1 const TEST_REGEXP = /test\..*\.js/;
2 const allTestFiles = [];
3 const extraFiles = ['/base/tests/assertions.js'];
4
5 Object.keys(window.__karma__.files).forEach(function (file) {
6 if (TEST_REGEXP.test(file)) {
7 // TODO: normalize?
8 allTestFiles.push(file);
9 }
10 });
11
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";
25 });
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);