forked from angular/quickstart
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
chore: extend with testing support (preliminary)
- Loading branch information
Showing
7 changed files
with
529 additions
and
7 deletions.
There are no files selected for viewing
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
# http://editorconfig.org | ||
root = true | ||
|
||
[*] | ||
charset = utf-8 | ||
indent_style = space | ||
indent_size = 2 | ||
end_of_line = lf | ||
insert_final_newline = true | ||
trim_trailing_whitespace = true | ||
|
||
|
||
[*.md] | ||
max_line_length = 0 | ||
trim_trailing_whitespace = false | ||
|
||
# Indentation override | ||
#[lib/**.js] | ||
#[{package.json,.travis.yml}] | ||
#[**/**.js] |
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,91 @@ | ||
/*global jasmine, __karma__, window*/ | ||
(function () { | ||
|
||
// Error.stackTraceLimit = Infinity; | ||
|
||
jasmine.DEFAULT_TIMEOUT_INTERVAL = 1000; | ||
|
||
// Cancel Karma's synchronous start, | ||
// we call `__karma__.start()` later, once all the specs are loaded. | ||
__karma__.loaded = function () { }; | ||
|
||
// SET THE RUNTIME APPLICATION ROOT HERE | ||
var appRoot ='app'; // no trailing slash! | ||
|
||
// RegExp for client application base path within karma (which always starts 'base\') | ||
var karmaBase = '^\/base\/'; // RegEx string for base of karma folders | ||
var appPackage = 'base/' + appRoot; //e.g., base/app | ||
var appRootRe = new RegExp(karmaBase + appRoot + '\/'); | ||
var onlyAppFilesRe = new RegExp(karmaBase + appRoot + '\/(?!.*\.spec\.js$)([a-z0-9-_\.\/]+)\.js$'); | ||
|
||
var moduleNames = []; | ||
|
||
// Configure systemjs packages to use the .js extension for imports from the app folder | ||
var packages = {}; | ||
packages[appPackage] = { | ||
defaultExtension: false, | ||
format: 'register', | ||
map: Object.keys(window.__karma__.files) | ||
.filter(onlyAppFiles) | ||
// Create local module name mapping to karma file path for app files | ||
// with karma's fingerprint in query string, e.g.: | ||
// './hero.service': '/base/app/hero.service.js?f4523daf879cfb7310ef6242682ccf10b2041b3e' | ||
.reduce(function (pathsMapping, appPath) { | ||
var moduleName = appPath.replace(appRootRe, './').replace(/\.js$/, ''); | ||
pathsMapping[moduleName] = appPath + '?' + window.__karma__.files[appPath]; | ||
return pathsMapping; | ||
}, {}) | ||
} | ||
|
||
System.config({ packages: packages }); | ||
|
||
// Configure Angular for the browser and | ||
// with test versions of the platform providers | ||
System.import('angular2/testing') | ||
.then(function (testing) { | ||
return System.import('angular2/platform/testing/browser') | ||
.then(function (providers) { | ||
testing.setBaseTestProviders( | ||
providers.TEST_BROWSER_PLATFORM_PROVIDERS, | ||
providers.TEST_BROWSER_APPLICATION_PROVIDERS | ||
); | ||
}); | ||
}) | ||
|
||
// Load all spec files | ||
// (e.g. 'base/app/hero.service.spec.js') | ||
.then(function () { | ||
return Promise.all( | ||
Object.keys(window.__karma__.files) | ||
.filter(onlySpecFiles) | ||
.map(function (moduleName) { | ||
moduleNames.push(moduleName); | ||
return System.import(moduleName); | ||
})); | ||
}) | ||
|
||
.then(success, fail); | ||
|
||
////// Helpers ////// | ||
|
||
function onlyAppFiles(filePath) { | ||
return onlyAppFilesRe.test(filePath); | ||
} | ||
|
||
function onlySpecFiles(filePath) { | ||
return /\.spec\.js$/.test(filePath); | ||
} | ||
|
||
function success () { | ||
console.log( | ||
'Spec files loaded:\n ' + | ||
moduleNames.join('\n ') + | ||
'\nStarting Jasmine testrunner'); | ||
__karma__.start(); | ||
} | ||
|
||
function fail(error) { | ||
__karma__.error(error.stack || 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,82 @@ | ||
module.exports = function(config) { | ||
|
||
var appBase = 'app/'; // transpiled app JS files | ||
var appAssets ='base/app/'; // component assets fetched by Angular's compiler | ||
|
||
config.set({ | ||
basePath: '', | ||
frameworks: ['jasmine'], | ||
plugins: [ | ||
require('karma-jasmine'), | ||
require('karma-chrome-launcher'), | ||
require('karma-htmlfile-reporter') | ||
], | ||
|
||
customLaunchers: { | ||
// From the CLI. Not used here but interesting | ||
// chrome setup for travis CI using chromium | ||
Chrome_travis_ci: { | ||
base: 'Chrome', | ||
flags: ['--no-sandbox'] | ||
} | ||
}, | ||
|
||
files: [ | ||
// Angular and shim libraries loaded by Karma | ||
{ pattern: 'node_modules/systemjs/dist/system-polyfills.js', included: true, watched: true }, | ||
{ pattern: 'node_modules/systemjs/dist/system.src.js', included: true, watched: true }, | ||
{ pattern: 'node_modules/es6-shim/es6-shim.js', included: true, watched: true }, | ||
{ pattern: 'node_modules/angular2/bundles/angular2-polyfills.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.dev.js', included: true, watched: true }, | ||
|
||
// External libraries loaded by Karma | ||
{ pattern: 'node_modules/angular2/bundles/http.dev.js', included: true, watched: true }, | ||
{ pattern: 'node_modules/angular2/bundles/router.dev.js', included: true, watched: true }, | ||
{ pattern: 'node_modules/a2-in-memory-web-api/web-api.js', included: true, watched: true }, | ||
|
||
// Configures module loader w/ app and specs, then launch karma | ||
{ pattern: 'karma-test-shim.js', included: true, watched: true }, | ||
|
||
// transpiled application & spec code paths loaded via module imports | ||
{pattern: appBase + '**/*.js', included: false, watched: true}, | ||
|
||
// asset (HTML & CSS) paths loaded via Angular's component compiler | ||
// (these paths need to be rewritten, see proxies section) | ||
{pattern: appBase + '**/*.html', included: false, watched: true}, | ||
{pattern: appBase + '**/*.css', included: false, watched: true}, | ||
|
||
// paths for debugging with source maps in dev tools | ||
{pattern: appBase + '**/*.ts', included: false, watched: false}, | ||
{pattern: appBase + '**/*.js.map', included: false, watched: false} | ||
], | ||
|
||
// proxied base paths for loading assets | ||
proxies: { | ||
// required for component assets fetched by Angular's compiler | ||
"/app/": appAssets | ||
}, | ||
|
||
exclude: [], | ||
preprocessors: {}, | ||
reporters: ['progress', 'html'], | ||
|
||
// HtmlReporter configuration | ||
htmlReporter: { | ||
// Open this file to see results in browser | ||
outputFile: '_test-output/tests.html', | ||
|
||
// Optional | ||
pageTitle: 'Unit Tests', | ||
subPageTitle: __dirname | ||
}, | ||
|
||
port: 9876, | ||
colors: true, | ||
logLevel: config.LOG_INFO, | ||
autoWatch: true, | ||
browsers: ['Chrome'], | ||
singleRun: false | ||
}) | ||
} |
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
Oops, something went wrong.