Created
July 18, 2017 21:39
-
-
Save joeeames/c43761f25086bfbbd390911e5fef76bc to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
here's the folder structure: | |
root | |
karma.conf.js | |
karma-test-shim.js | |
public | |
systemjs.config.js | |
systemjs-angular-loader.js | |
main.ts | |
app | |
all Angular (not angularJS) files | |
spec files |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// /*global jasmine, __karma__, window*/ | |
Error.stackTraceLimit = 0; // "No stacktrace"" is usually best for app testing. | |
// Uncomment to get full stacktrace output. Sometimes helpful, usually not. | |
// Error.stackTraceLimit = Infinity; // | |
jasmine.DEFAULT_TIMEOUT_INTERVAL = 1000; | |
var builtPath = '/base/public/app/'; | |
__karma__.loaded = function () { }; | |
function isJsFile(path) { | |
return path.slice(-3) == '.js'; | |
} | |
function isSpecFile(path) { | |
return /\.spec\.(.*\.)?js$/.test(path); | |
} | |
function isBuiltFile(path) { | |
return isJsFile(path) && (path.substr(0, builtPath.length) == builtPath); | |
} | |
var allSpecFiles = Object.keys(window.__karma__.files) | |
.filter(isSpecFile) | |
.filter(isBuiltFile); | |
System.config({ | |
baseURL: '/base', | |
// Extend usual application package list with test folder | |
packages: { 'testing': { main: 'index.js', defaultExtension: 'js' } }, | |
// Assume npm: is set in `paths` in systemjs.config | |
// Map the angular testing umd bundles | |
map: { | |
'@angular/core/testing': 'npm:@angular/core/bundles/core-testing.umd.js', | |
'@angular/common/testing': 'npm:@angular/common/bundles/common-testing.umd.js', | |
'@angular/compiler/testing': 'npm:@angular/compiler/bundles/compiler-testing.umd.js', | |
'@angular/platform-browser/testing': 'npm:@angular/platform-browser/bundles/platform-browser-testing.umd.js', | |
'@angular/platform-browser-dynamic/testing': 'npm:@angular/platform-browser-dynamic/bundles/platform-browser-dynamic-testing.umd.js', | |
'@angular/http/testing': 'npm:@angular/http/bundles/http-testing.umd.js', | |
'@angular/router/testing': 'npm:@angular/router/bundles/router-testing.umd.js', | |
'@angular/forms/testing': 'npm:@angular/forms/bundles/forms-testing.umd.js', | |
}, | |
}); | |
System.import('public/systemjs.config.js') | |
.then(importSystemJsExtras) | |
.then(initTestBed) | |
.then(initTesting); | |
/** Optional SystemJS configuration extras. Keep going w/o it */ | |
function importSystemJsExtras(){ | |
return System.import('systemjs.config.extras.js') | |
.catch(function(reason) { | |
console.log( | |
'Warning: System.import could not load the optional "systemjs.config.extras.js". Did you omit it by accident? Continuing without it.' | |
); | |
console.log(reason); | |
}); | |
} | |
function initTestBed(){ | |
return Promise.all([ | |
System.import('@angular/core/testing'), | |
System.import('@angular/platform-browser-dynamic/testing') | |
]) | |
.then(function (providers) { | |
var coreTesting = providers[0]; | |
var browserTesting = providers[1]; | |
coreTesting.TestBed.initTestEnvironment( | |
browserTesting.BrowserDynamicTestingModule, | |
browserTesting.platformBrowserDynamicTesting()); | |
}) | |
} | |
// Import all spec files and start karma | |
function initTesting () { | |
return Promise.all( | |
allSpecFiles.map(function (moduleName) { | |
return System.import(moduleName); | |
}) | |
) | |
.then(__karma__.start, __karma__.error); | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Karma configuration | |
// Generated on Sat Apr 16 2016 16:47:26 GMT-0600 (Mountain Daylight 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'], | |
plugins: [ | |
require('karma-jasmine'), | |
require('karma-chrome-launcher'), | |
require('karma-jasmine-html-reporter') | |
], | |
// list of files / patterns to load in the browser | |
files: [ | |
'node_modules/systemjs/dist/system.src.js', | |
'node_modules/core-js/client/shim.js', | |
'node_modules/zone.js/dist/zone.js', | |
'node_modules/zone.js/dist/long-stack-trace-zone.js', | |
'node_modules/zone.js/dist/proxy.js', | |
'node_modules/zone.js/dist/sync-test.js', | |
'node_modules/zone.js/dist/jasmine-patch.js', | |
'node_modules/zone.js/dist/async-test.js', | |
'node_modules/zone.js/dist/fake-async-test.js', | |
// RxJs. | |
{ pattern: 'node_modules/rxjs/**/*.js', included: false, watched: false }, | |
{ pattern: 'node_modules/rxjs/**/*.js.map', included: false, watched: false }, | |
// Angular itself and the testing library | |
{pattern: 'node_modules/@angular/**/*.js', included: false, watched: false}, | |
{pattern: 'node_modules/@angular/**/*.js.map', included: false, watched: false}, | |
{pattern: 'public/systemjs.config.js', included: false, watched: false}, | |
{pattern: 'systemjs.config.extras.js', included: false, watched: false}, | |
'karma-test-shim.js', | |
// transpiled application & spec code paths loaded via module imports | |
{ pattern: 'public/app/**/*.js', included: false, watched: true }, | |
{ pattern: 'public/app/**/*.html', included: false, watched: true }, | |
], | |
proxies: { | |
"/app/": "/base/public/app/" | |
}, | |
// list of files to exclude | |
exclude: [ | |
// 'public/vendor/1.4.9/**/*.js' | |
], | |
reporters: ['progress'], | |
// 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_INFO, | |
// 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 simultaneous | |
concurrency: Infinity | |
}) | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* System configuration for Angular samples | |
* Adjust as necessary for your application needs. | |
*/ | |
(function (global) { | |
System.config({ | |
paths: { | |
// paths serve as alias | |
'npm:': 'node_modules/' | |
}, | |
// map tells the System loader where to look for things | |
map: { | |
// our app is within the app folder | |
app: './', | |
// angular bundles | |
'@angular/core': 'npm:@angular/core/bundles/core.umd.js', | |
'@angular/common': 'npm:@angular/common/bundles/common.umd.js', | |
'@angular/compiler': 'npm:@angular/compiler/bundles/compiler.umd.js', | |
'@angular/platform-browser': 'npm:@angular/platform-browser/bundles/platform-browser.umd.js', | |
'@angular/platform-browser-dynamic': 'npm:@angular/platform-browser-dynamic/bundles/platform-browser-dynamic.umd.js', | |
'@angular/http': 'npm:@angular/http/bundles/http.umd.js', | |
'@angular/router': 'npm:@angular/router/bundles/router.umd.js', | |
'@angular/forms': 'npm:@angular/forms/bundles/forms.umd.js', | |
'@angular/upgrade': 'npm:@angular/upgrade/bundles/upgrade.umd.js', | |
'@angular/upgrade/static': 'npm:@angular/upgrade/bundles/upgrade-static.umd.js', | |
// other libraries | |
'rxjs': 'npm:rxjs' | |
}, | |
// packages tells the System loader how to load when no filename and/or no extension | |
packages: { | |
app: { | |
main: 'main.js', | |
defaultExtension: 'js', | |
meta: { | |
'./app/*.js': { | |
loader: 'systemjs-angular-loader.js' | |
} | |
} | |
}, | |
rxjs: { | |
defaultExtension: 'js' | |
} | |
} | |
}); | |
})(this); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment