Skip to content

Instantly share code, notes, and snippets.

@zhilich
Created November 8, 2017 22:24
Show Gist options
  • Save zhilich/eecfcc202168d28f1fdcaf12a43bdad3 to your computer and use it in GitHub Desktop.
Save zhilich/eecfcc202168d28f1fdcaf12a43bdad3 to your computer and use it in GitHub Desktop.
"use strict";
//This file is used to load ES6 unit-tests transpiled into AMD modules.
var __karma__;
var tests = [];
var files = {};
for (var file in __karma__.files) {
if (__karma__.files.hasOwnProperty(file)) {
if (/spec\.js$/.test(file)) {
tests.push(file);
}
//For case-insensitive search
var key = file.toLowerCase();
files[key] = file;
}
}
//Delay loading of Karma
__karma__.loaded = function () { };
requirejs.config({
// Karma serves files from '/base'
baseUrl: '.',
paths: {},
shim: {},
// ask Require.js to load these files (all our tests)
deps: tests,
// start test run, once Require.js is done
callback: function () {
__karma__.start();
}
});
//Normalize urls because Karma server is case-sensitive
var _load = require.load;
require.load = function (context, moduleName, url) {
var normalizedUrl = files[url.toLowerCase()];
if (!normalizedUrl) {
console.error("File " + url + " is not served by Karma. Add missing files to Karma configuration in config.json. Consider mocking external module dependencies in main.ts.");
}
_load(context, moduleName, normalizedUrl);
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment