Skip to content
This repository was archived by the owner on Feb 26, 2024. It is now read-only.

Commit c18870f

Browse files
committed
chore: extend with testing support (preliminary)
1 parent c17b1fb commit c18870f

7 files changed

Lines changed: 529 additions & 7 deletions

File tree

.editorconfig

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
# http://editorconfig.org
2+
root = true
3+
4+
[*]
5+
charset = utf-8
6+
indent_style = space
7+
indent_size = 2
8+
end_of_line = lf
9+
insert_final_newline = true
10+
trim_trailing_whitespace = true
11+
12+
13+
[*.md]
14+
max_line_length = 0
15+
trim_trailing_whitespace = false
16+
17+
# Indentation override
18+
#[lib/**.js]
19+
#[{package.json,.travis.yml}]
20+
#[**/**.js]

CHANGELOG.md

Lines changed: 27 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,31 @@
1+
<a name="0.1.15"></a>
2+
# 0.1.15 (2016-04-13)
3+
* Add testing support
4+
* npm scripts
5+
* karma/jasmine
6+
* protractor
7+
8+
* update packages
9+
* Angular 2 beta 15
10+
* lite-server 2.2.0
11+
* typings 0.7.12
12+
13+
* add run packages
14+
* a2-in-memory-web-api
15+
16+
* add testing dev-dependency packages
17+
* http-server: ^0.9.0,
18+
* jasmine-core: ~2.4.1,
19+
* karma: ^0.13.22,
20+
* karma-chrome-launcher: ^0.2.3,
21+
* karma-cli: ^0.1.2,
22+
* karma-htmlfile-reporter: ^0.2.2,
23+
* karma-jasmine: ^0.3.8,
24+
* protractor: ^3.2.2,
25+
* rimraf: ^2.5.2
26+
127
<a name="0.1.14"></a>
2-
# 0.1.13 (2016-04-07)
28+
# 0.1.14 (2016-04-07)
329
* update packages
430
* Angular 2 beta 14
531
* lite-server 2.2.0

karma-test-shim.js

Lines changed: 91 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,91 @@
1+
/*global jasmine, __karma__, window*/
2+
(function () {
3+
4+
// Error.stackTraceLimit = Infinity;
5+
6+
jasmine.DEFAULT_TIMEOUT_INTERVAL = 1000;
7+
8+
// Cancel Karma's synchronous start,
9+
// we call `__karma__.start()` later, once all the specs are loaded.
10+
__karma__.loaded = function () { };
11+
12+
// SET THE RUNTIME APPLICATION ROOT HERE
13+
var appRoot ='app'; // no trailing slash!
14+
15+
// RegExp for client application base path within karma (which always starts 'base\')
16+
var karmaBase = '^\/base\/'; // RegEx string for base of karma folders
17+
var appPackage = 'base/' + appRoot; //e.g., base/app
18+
var appRootRe = new RegExp(karmaBase + appRoot + '\/');
19+
var onlyAppFilesRe = new RegExp(karmaBase + appRoot + '\/(?!.*\.spec\.js$)([a-z0-9-_\.\/]+)\.js$');
20+
21+
var moduleNames = [];
22+
23+
// Configure systemjs packages to use the .js extension for imports from the app folder
24+
var packages = {};
25+
packages[appPackage] = {
26+
defaultExtension: false,
27+
format: 'register',
28+
map: Object.keys(window.__karma__.files)
29+
.filter(onlyAppFiles)
30+
// Create local module name mapping to karma file path for app files
31+
// with karma's fingerprint in query string, e.g.:
32+
// './hero.service': '/base/app/hero.service.js?f4523daf879cfb7310ef6242682ccf10b2041b3e'
33+
.reduce(function (pathsMapping, appPath) {
34+
var moduleName = appPath.replace(appRootRe, './').replace(/\.js$/, '');
35+
pathsMapping[moduleName] = appPath + '?' + window.__karma__.files[appPath];
36+
return pathsMapping;
37+
}, {})
38+
}
39+
40+
System.config({ packages: packages });
41+
42+
// Configure Angular for the browser and
43+
// with test versions of the platform providers
44+
System.import('angular2/testing')
45+
.then(function (testing) {
46+
return System.import('angular2/platform/testing/browser')
47+
.then(function (providers) {
48+
testing.setBaseTestProviders(
49+
providers.TEST_BROWSER_PLATFORM_PROVIDERS,
50+
providers.TEST_BROWSER_APPLICATION_PROVIDERS
51+
);
52+
});
53+
})
54+
55+
// Load all spec files
56+
// (e.g. 'base/app/hero.service.spec.js')
57+
.then(function () {
58+
return Promise.all(
59+
Object.keys(window.__karma__.files)
60+
.filter(onlySpecFiles)
61+
.map(function (moduleName) {
62+
moduleNames.push(moduleName);
63+
return System.import(moduleName);
64+
}));
65+
})
66+
67+
.then(success, fail);
68+
69+
////// Helpers //////
70+
71+
function onlyAppFiles(filePath) {
72+
return onlyAppFilesRe.test(filePath);
73+
}
74+
75+
function onlySpecFiles(filePath) {
76+
return /\.spec\.js$/.test(filePath);
77+
}
78+
79+
function success () {
80+
console.log(
81+
'Spec files loaded:\n ' +
82+
moduleNames.join('\n ') +
83+
'\nStarting Jasmine testrunner');
84+
__karma__.start();
85+
}
86+
87+
function fail(error) {
88+
__karma__.error(error.stack || error);
89+
}
90+
91+
})();

karma.conf.js

Lines changed: 82 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,82 @@
1+
module.exports = function(config) {
2+
3+
var appBase = 'app/'; // transpiled app JS files
4+
var appAssets ='base/app/'; // component assets fetched by Angular's compiler
5+
6+
config.set({
7+
basePath: '',
8+
frameworks: ['jasmine'],
9+
plugins: [
10+
require('karma-jasmine'),
11+
require('karma-chrome-launcher'),
12+
require('karma-htmlfile-reporter')
13+
],
14+
15+
customLaunchers: {
16+
// From the CLI. Not used here but interesting
17+
// chrome setup for travis CI using chromium
18+
Chrome_travis_ci: {
19+
base: 'Chrome',
20+
flags: ['--no-sandbox']
21+
}
22+
},
23+
24+
files: [
25+
// Angular and shim libraries loaded by Karma
26+
{ pattern: 'node_modules/systemjs/dist/system-polyfills.js', included: true, watched: true },
27+
{ pattern: 'node_modules/systemjs/dist/system.src.js', included: true, watched: true },
28+
{ pattern: 'node_modules/es6-shim/es6-shim.js', included: true, watched: true },
29+
{ pattern: 'node_modules/angular2/bundles/angular2-polyfills.js', included: true, watched: true },
30+
{ pattern: 'node_modules/rxjs/bundles/Rx.js', included: true, watched: true },
31+
{ pattern: 'node_modules/angular2/bundles/angular2.js', included: true, watched: true },
32+
{ pattern: 'node_modules/angular2/bundles/testing.dev.js', included: true, watched: true },
33+
34+
// External libraries loaded by Karma
35+
{ pattern: 'node_modules/angular2/bundles/http.dev.js', included: true, watched: true },
36+
{ pattern: 'node_modules/angular2/bundles/router.dev.js', included: true, watched: true },
37+
{ pattern: 'node_modules/a2-in-memory-web-api/web-api.js', included: true, watched: true },
38+
39+
// Configures module loader w/ app and specs, then launch karma
40+
{ pattern: 'karma-test-shim.js', included: true, watched: true },
41+
42+
// transpiled application & spec code paths loaded via module imports
43+
{pattern: appBase + '**/*.js', included: false, watched: true},
44+
45+
// asset (HTML & CSS) paths loaded via Angular's component compiler
46+
// (these paths need to be rewritten, see proxies section)
47+
{pattern: appBase + '**/*.html', included: false, watched: true},
48+
{pattern: appBase + '**/*.css', included: false, watched: true},
49+
50+
// paths for debugging with source maps in dev tools
51+
{pattern: appBase + '**/*.ts', included: false, watched: false},
52+
{pattern: appBase + '**/*.js.map', included: false, watched: false}
53+
],
54+
55+
// proxied base paths for loading assets
56+
proxies: {
57+
// required for component assets fetched by Angular's compiler
58+
"/app/": appAssets
59+
},
60+
61+
exclude: [],
62+
preprocessors: {},
63+
reporters: ['progress', 'html'],
64+
65+
// HtmlReporter configuration
66+
htmlReporter: {
67+
// Open this file to see results in browser
68+
outputFile: '_test-output/tests.html',
69+
70+
// Optional
71+
pageTitle: 'Unit Tests',
72+
subPageTitle: __dirname
73+
},
74+
75+
port: 9876,
76+
colors: true,
77+
logLevel: config.LOG_INFO,
78+
autoWatch: true,
79+
browsers: ['Chrome'],
80+
singleRun: false
81+
})
82+
}

package.json

Lines changed: 20 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2,28 +2,42 @@
22
"name": "angular2-quickstart",
33
"version": "1.0.0",
44
"scripts": {
5-
"start": "tsc && concurrently \"npm run tsc:w\" \"npm run lite\" ",
5+
"start": "tsc && concurrently \"tsc -w\" \"lite-server\" ",
6+
"build-and-test": "npm run tsc && npm run test",
7+
"docker-build": "docker build -t ng2-quickstart .",
8+
"docker": "npm run docker-build && docker run -it --rm -p 3000:3000 -p 3001:3001 ng2-quickstart",
9+
"e2e": "tsc && http-server && protractor protractor.config.js",
610
"tsc": "tsc",
711
"tsc:w": "tsc -w",
812
"lite": "lite-server",
13+
"test": "tsc && concurrently \"tsc -w\" \"karma start karma.conf.js\"",
914
"typings": "typings",
10-
"docker-build": "docker build -t ng2-quickstart .",
11-
"docker": "npm run docker-build && docker run -it --rm -p 3000:3000 -p 3001:3001 ng2-quickstart",
1215
"postinstall": "typings install"
1316
},
1417
"license": "ISC",
1518
"dependencies": {
16-
"angular2": "2.0.0-beta.14",
19+
"angular2": "2.0.0-beta.15",
20+
"a2-in-memory-web-api": "^0.1.14",
21+
1722
"systemjs": "0.19.25",
1823
"es6-shim": "^0.35.0",
1924
"reflect-metadata": "0.1.2",
2025
"rxjs": "5.0.0-beta.2",
21-
"zone.js": "0.6.6"
26+
"zone.js": "0.6.10"
2227
},
2328
"devDependencies": {
2429
"concurrently": "^2.0.0",
30+
"http-server": "^0.9.0",
31+
"jasmine-core": "~2.4.1",
32+
"karma": "^0.13.22",
33+
"karma-chrome-launcher": "^0.2.3",
34+
"karma-cli": "^0.1.2",
35+
"karma-htmlfile-reporter": "^0.2.2",
36+
"karma-jasmine": "^0.3.8",
2537
"lite-server": "^2.2.0",
26-
"typescript": "^1.8.9",
38+
"protractor": "^3.2.2",
39+
"rimraf": "^2.5.2",
40+
"typescript": "^1.8.10",
2741
"typings":"^0.7.12"
2842
}
2943
}

0 commit comments

Comments
 (0)