Skip to content

Commit 5cff76e

Browse files
committed
feat(test generated projets): setup unit testing structure powered by Karma
Closes #10
1 parent d89595b commit 5cff76e

File tree

11 files changed

+641
-3
lines changed

11 files changed

+641
-3
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,73 @@
1+
module.exports = function(config) {
2+
config.set({
3+
// base path that will be used to resolve all patterns (eg. files, exclude)
4+
basePath: '',
5+
6+
// frameworks to use
7+
// available frameworks: https://npmjs.org/browse/keyword/karma-adapter
8+
frameworks: ['jasmine'],
9+
10+
// list of files / patterns to load in the browser
11+
files: [
12+
'spec.bundle.js'
13+
],
14+
15+
// list of files to exclude
16+
exclude: [
17+
],
18+
19+
// preprocess matching files before serving them to the browser
20+
// available preprocessors: https://npmjs.org/browse/keyword/karma-preprocessor
21+
preprocessors: {
22+
'spec.bundle.js': ['webpack', 'sourcemap']
23+
},
24+
25+
webpack: {
26+
resolve: {
27+
root: __dirname,
28+
extensions: ['','.ts','.js','.json']
29+
},
30+
devtool: 'inline-source-map',
31+
module: {
32+
loaders: [
33+
{ test: /\.ts$/, loader: 'typescript-simple?ignoreWarnings[]=2304', exclude: [
34+
/web_modules/,
35+
/node_modules/
36+
]
37+
},
38+
{ test: /\.json$/, loader: 'json' },
39+
{ test: /\.html$/, loader: 'raw' },
40+
{ test: /\.css$/, loader: 'raw' }
41+
]
42+
},
43+
stats: { colors: true, reasons: true },
44+
debug: false
45+
},
46+
47+
// test results reporter to use
48+
// possible values: 'dots', 'progress'
49+
// available reporters: https://npmjs.org/browse/keyword/karma-reporter
50+
reporters: ['progress'],
51+
52+
// web server port
53+
port: 9876,
54+
55+
// enable / disable colors in the output (reporters and logs)
56+
colors: true,
57+
58+
// level of logging
59+
// possible values: config.LOG_DISABLE || config.LOG_ERROR || config.LOG_WARN || config.LOG_INFO || config.LOG_DEBUG
60+
logLevel: config.LOG_INFO,
61+
62+
// enable / disable watching file and executing tests whenever any file changes
63+
autoWatch: false,
64+
65+
// start these browsers
66+
// available browser launchers: https://npmjs.org/browse/keyword/karma-launcher
67+
browsers: ['ChromeCanary'],
68+
69+
// Continuous Integration mode
70+
// if true, Karma captures browsers, runs the tests and exits
71+
singleRun: true
72+
})
73+
};

addon/ng2/blueprints/ng2/files/package.json

+20-1
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,25 @@
44
"license": "MIT",
55
"devDependencies": {
66
"angular-cli": "0.0.*",
7-
"ember-cli-inject-live-reload": "^1.3.0"
7+
"angular2": "^2.0.0-alpha.34",
8+
"ember-cli-inject-live-reload": "^1.3.0",
9+
"jasmine-core": "^2.3.4",
10+
"karma": "^0.13.9",
11+
"karma-chrome-launcher": "^0.2.0",
12+
"karma-jasmine": "^0.3.6",
13+
"karma-sourcemap-loader": "^0.3.5",
14+
"karma-webpack": "^1.7.0",
15+
"reflect-metadata": "^0.1.0",
16+
"typescript": "^1.5.3",
17+
"typescript-simple-loader": "^0.3.4",
18+
"webpack": "^1.11.0",
19+
"css-loader": "^0.16.0",
20+
"exports-loader": "^0.6.2",
21+
"expose-loader": "^0.7.0",
22+
"file-loader": "^0.8.4",
23+
"json-loader": "^0.5.2",
24+
"raw-loader": "^0.5.1",
25+
"style-loader": "^0.12.3",
26+
"url-loader": "^0.5.6"
827
}
928
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
// @AngularClass
2+
/*
3+
* When testing with webpack and ES6, we have to do some extra
4+
* things get testing to work right. Because we are gonna write test
5+
* in ES6 to, we have to compile those as well. That's handled in
6+
* karma.conf.js with the karma-webpack plugin. This is the entry
7+
* file for webpack test. Just like webpack will create a bundle.js
8+
* file for our client, when we run test, it well compile and bundle them
9+
* all here! Crazy huh. So we need to do some setup
10+
*/
11+
Error.stackTraceLimit = Infinity;
12+
require('reflect-metadata');
13+
require('angular2/test');
14+
require('angular2/mock');
15+
16+
/*
17+
Ok, this is kinda crazy. We can use the the context method on
18+
require that webpack created in order to tell webpack
19+
what files we actually want to require or import.
20+
Below, context will be an function/object with file names as keys.
21+
using that regex we are saying look in client/app and find
22+
any file that ends with spec.js and get its path. By passing in true
23+
we say do this recursively
24+
*/
25+
var appContext = require.context('./src', true, /\.spec\.ts/);
26+
27+
// get all the files, for each file, call the context function
28+
// that will require the file and load it up here. Context will
29+
// loop and require those spec files here
30+
appContext.keys().forEach(appContext);
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
<h1>Hello {{ name }}!</h1>
12
<p>
23
<%= htmlComponentName %> Works!
34
</p>
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
/// <reference path="./typings/jasmine/jasmine.d.ts"/>
2+
import {<%= jsComponentName %>App} from './<%= htmlComponentName %>';
3+
4+
describe('Component: <%= jsComponentName %>', () => {
5+
let app;
6+
7+
beforeEach(() => {
8+
app = new <%= jsComponentName %>App();
9+
});
10+
11+
it('should have a name', () => {
12+
expect(app.name).toBe('World');
13+
});
14+
});

addon/ng2/blueprints/ng2/files/src/__name__.ts

+4-2
Original file line numberDiff line numberDiff line change
@@ -8,9 +8,11 @@ import {Component, View, bootstrap} from 'angular2/angular2';
88
templateUrl: '<%= htmlComponentName %>.html',
99
directives: []
1010
})
11-
class <%= jsComponentName %>App {
12-
constructor() {
11+
export class <%= jsComponentName %>App {
12+
name: string;
1313

14+
constructor() {
15+
this.name = 'World';
1416
}
1517
}
1618
bootstrap(<%= jsComponentName %>App);

0 commit comments

Comments
 (0)