Skip to content

Instantly share code, notes, and snippets.

@Nijhazer
Created December 2, 2015 03:37
Show Gist options
  • Save Nijhazer/703ca3ad390401693495 to your computer and use it in GitHub Desktop.
Save Nijhazer/703ca3ad390401693495 to your computer and use it in GitHub Desktop.
Building Applications with TypeScript - Snippet 18
var baseUrl = '/base';
var config = {
baseUrl: baseUrl,
baseUILib: baseUrl + '/src/www/js/lib',
baseAPILib: baseUrl + '/node_modules',
fileInclusionTest: /spec\..+\.js$/i
};
var allTestFiles = [];
// Get a list of all the test files to include
Object.keys(window.__karma__.files).forEach(function(file) {
if (config.fileInclusionTest.test(file)) {
// Normalize paths to RequireJS module names.
// If you require sub-dependencies of test files to be loaded as-is (requiring file extension)
// then do not normalize the paths
var normalizedTestModule = file.replace(/^\/base\/|\.js$/g, '');
allTestFiles.push(normalizedTestModule);
}
});
require.config({
// Karma serves files under /base, which is the basePath from your config file
baseUrl: config.baseUrl,
// Provide the locations of any dependencies our unit tests will need,
// so that RequireJS knows where to find them
paths: {
'chai': config.baseAPILib + '/chai/chai',
'lodash': config.baseUILib + '/lodash/lodash.min',
'jquery': config.baseUILib + '/jquery/dist/jquery.min',
'promise': config.baseUILib + '/es6-promise/promise.min',
'handlebars': config.baseUILib + 'handlebars/handlebars.amd.min'
},
// dynamically load all test files
deps: allTestFiles,
// we have to kickoff jasmine, as it is asynchronous
callback: window.__karma__.start
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment