Skip to content

Instantly share code, notes, and snippets.

@sasxa
Last active July 14, 2016 11:28
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save sasxa/0939f5bb00285e82af21 to your computer and use it in GitHub Desktop.
Save sasxa/0939f5bb00285e82af21 to your computer and use it in GitHub Desktop.
Setup for karma testing
// Karma configuration
// Generated on Thu Dec 24 2015 20:24:55 GMT+0100 (Central Europe Standard Time)
module.exports = function(config) {
config.set({
// base path that will be used to resolve all patterns (eg. files, exclude)
basePath: '',
// frameworks to use
// available frameworks: https://npmjs.org/browse/keyword/karma-adapter
frameworks: ['jasmine'],
// list of files / patterns to load in the browser
files: [
// {pattern: 'node_modules/traceur/bin/traceur.js', included: true, watched: false},
// {pattern: 'node_modules/systemjs/dist/system-polyfills.js', included: true, watched: false},
{pattern: 'node_modules/angular2/bundles/angular2-polyfills.js', included: true, watched: false},
{pattern: 'node_modules/systemjs/dist/system.js', included: true, watched: false},
{pattern: 'node_modules/rxjs/bundles/Rx.js', included: true, watched: false},
{pattern: 'node_modules/angular2/bundles/angular2.dev.js', included: true, watched: false},
{pattern: 'node_modules/angular2/bundles/http.dev.js', included: true, watched: false},
{pattern: 'node_modules/angular2/bundles/router.dev.js', included: true, watched: false},
{pattern: 'node_modules/angular2/bundles/testing.dev.js', included: true, watched: false},
{pattern: 'node_modules/**/*.map', included: false, watched: false},
// SystemJS config
{pattern: 'karma.shim.js', included: true, watched: false},
// paths loaded via module imports
{pattern: 'dist/**/*.js', included: false, watched: false},
{pattern: 'node_modules/rxjs/**/*.js', included: false, watched: false},
// paths loaded via Angular's component compiler
// (these paths need to be rewritten, see proxies section)
{pattern: 'dist/**/*.html', included: false, watched: false},
{pattern: 'dist/**/*.css', included: false, watched: false},
// paths to support debugging with source maps in dev tools
{pattern: 'src/scripts/**/*.ts', included: false, watched: false},
{pattern: 'dist/**/*.js.map', included: false, watched: false}
],
// list of files to exclude
exclude: [
'dist/**/system.conf.js',
],
// urlRoot: '__karma__',
proxies: {
// required for component assests fetched by Angular's compiler
"/scripts/app/": "/base/dist/scripts/app/",
"/scripts/core/": "/base/dist/scripts/core/",
"/scripts/lab/": "/base/dist/scripts/lab/",
},
// preprocess matching files before serving them to the browser
// available preprocessors: https://npmjs.org/browse/keyword/karma-preprocessor
preprocessors: {
// 'dist/scripts/**/*.js': ['coverage']
},
// test results reporter to use
// possible values: 'dots', 'progress'
// available reporters: https://npmjs.org/browse/keyword/karma-reporter
reporters: ['progress', 'html', 'coverage'],
// web server port
port: 9876,
// enable / disable colors in the output (reporters and logs)
colors: true,
// level of logging
// possible values: config.LOG_DISABLE || config.LOG_ERROR || config.LOG_WARN || config.LOG_INFO || config.LOG_DEBUG
logLevel: config.LOG_DISABLE,
// enable / disable watching file and executing tests whenever any file changes
autoWatch: true,
// start these browsers
// available browser launchers: https://npmjs.org/browse/keyword/karma-launcher
browsers: ['Chrome'],
// Continuous Integration mode
// if true, Karma captures browsers, runs the tests and exits
singleRun: false,
// Concurrency level
// how many browser should be started simultanous
concurrency: Infinity,
// Plugins
plugins: [
'karma-coverage',
'karma-jasmine',
'karma-jasmine-html-reporter',
'karma-chrome-launcher',
'karma-phantomjs-launcher',
]
})
}
/**
* Turn on full stack traces in errors to help debugging
* */
Error.stackTraceLimit = Infinity;
jasmine.DEFAULT_TIMEOUT_INTERVAL = 1000;
// Cancel Karma's synchronous start
__karma__.loaded = function () { };
var pathsMapping = function (path) {
var pathFilter = new RegExp(path.replace('/', '\\/') + '.*\/.*\.js$');
var pathReplace = new RegExp('^' + path.replace('/', '\\/'));
// console.log(pathFilter.source, pathReplace.source);
return Object.keys(window.__karma__.files)
.filter(function (path) { return pathFilter.test(path); })
// .filter(function (path) { console.log(path); return true; })
.reduce(function (systemjsPaths, karmaPath) {
/**
* Creates local module name mapping to global path with karma's fingerprint in path, e.g.:
* './hero.service': '/base/dist/scripts/hero.service.js?f4523daf879cfb7310ef6242682ccf10b2041b3e'
*
* and, when using GoogleAppEngine:
* './hero.service': '/base/dist/static/scripts/hero.service.js?f4523daf879cfb7310ef6242682ccf10b2041b3e'
*/
var systemjsPath = karmaPath.replace(pathReplace, './').replace(/\.js$/, '');
systemjsPaths[systemjsPath] = karmaPath + '?' + window.__karma__.files[karmaPath];
return systemjsPaths;
}, {});
};
/**
* Setup SystemJS to correctly
* locate user modules served by Karma.
*/
System.config({
packages: {
'/base/dist/scripts/': {
defaultExtension: false,
format: 'register',
map: pathsMapping('/base/dist/scripts/')
},
'/base/dist/static/scripts/': {
defaultExtension: false,
format: 'register',
map: pathsMapping('/base/dist/static/scripts/')
},
}
});
var specFiles =
Object.keys(window.__karma__.files)
.filter(function (path) { return /\.spec\.js$/.test(path); })
// .filter(function (path) { console.log(path); return true; })
.map(function (moduleName) { return System.import(moduleName); })
System
.import('angular2/platform/browser').then(function (b) { b.BrowserDomAdapter.makeCurrent(); })
.then(function () { return Promise.all(specFiles); })
.then(function () { __karma__.start(); }, function (error) { __karma__.error(error.stack || error); });
System.import('app/bootstrap');
@shafqatalix
Copy link

do you have any update for @angular.rc.1?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment