diff --git a/karma-test-shim.js b/karma-test-shim.js index b11d12c8bf3..6cca7c7f829 100644 --- a/karma-test-shim.js +++ b/karma-test-shim.js @@ -4,18 +4,28 @@ jasmine.DEFAULT_TIMEOUT_INTERVAL = 1000; __karma__.loaded = function() {}; + +/** + * Gets map of module alias to location or package. + * @param dir Directory name under `src/` for create a map for. + */ +function getPathsMap(dir) { + return Object.keys(window.__karma__.files) + .filter(isComponentsFile) + .reduce(function(pathsMapping, appPath) { + var pathToReplace = new RegExp('^/base/dist/' + dir + '/'); + var moduleName = appPath.replace(pathToReplace, './').replace(/\.js$/, ''); + pathsMapping[moduleName] = appPath + '?' + window.__karma__.files[appPath]; + return pathsMapping; + }, {}); +} + System.config({ packages: { - 'base/dist/app': { + 'base/dist/components': { defaultExtension: false, format: 'register', - map: Object.keys(window.__karma__.files) - .filter(onlyAppFiles) - .reduce(function(pathsMapping, appPath) { - var moduleName = appPath.replace(/^\/base\/dist\/app\//, './').replace(/\.js$/, ''); - pathsMapping[moduleName] = appPath + '?' + window.__karma__.files[appPath] - return pathsMapping; - }, {}) + map: getPathsMap('components') } } }); @@ -36,8 +46,8 @@ System.import('angular2/platform/browser').then(function(browser_adapter) { __karma__.error(error.stack || error); }); -function onlyAppFiles(filePath) { - return /^\/base\/dist\/app\/(?!spec)([a-z0-9-_\/]+)\.js$/.test(filePath); +function isComponentsFile(filePath) { + return /^\/base\/dist\/components\/(?!spec)([a-z0-9-_\/]+)\.js$/.test(filePath); } function onlySpecFiles(path) { diff --git a/karma.conf.js b/karma.conf.js index 94e5c069580..ab45bfb235a 100644 --- a/karma.conf.js +++ b/karma.conf.js @@ -2,10 +2,16 @@ module.exports = function(config) { config.set({ basePath: '', frameworks: ['jasmine'], + plugins: [ + require('karma-jasmine'), + require('karma-chrome-launcher') + ], files: [ + {pattern: 'node_modules/angular2/bundles/angular2-polyfills.js', included: true, watched: true}, {pattern: 'node_modules/systemjs/dist/system.src.js', included: true, watched: true}, + {pattern: 'node_modules/rxjs/bundles/Rx.js', included: true, watched: true}, {pattern: 'node_modules/angular2/bundles/angular2.js', included: true, watched: true}, - {pattern: 'node_modules/angular2/bundles/testing.js', included: true, watched: true}, + {pattern: 'node_modules/angular2/bundles/testing.dev.js', included: true, watched: true}, {pattern: 'karma-test-shim.js', included: true, watched: true}, @@ -23,7 +29,8 @@ module.exports = function(config) { ], proxies: { // required for component assests fetched by Angular's compiler - "/app/": "/base/dist/demo-app/" + "/demo-app/": "/base/dist/demo-app/", + "/components/": "/base/dist/components/", }, exclude: [], preprocessors: {},