Skip to content

Commit a46f4b3

Browse files
committed
Add minimal tests
1 parent 4a61806 commit a46f4b3

File tree

6 files changed

+138
-2
lines changed

6 files changed

+138
-2
lines changed

.eslintrc

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,8 @@
11
{
22
"globals": {
33
"expect": true,
4-
"angular": true
4+
"angular": true,
5+
"inject": true
56
},
67
"root": true,
78
"env": {

karma.conf.js

Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
// Reference: http://karma-runner.github.io/0.12/config/configuration-file.html
2+
module.exports = function (config) {
3+
config.set({
4+
frameworks: [
5+
// Reference: https://github.com/karma-runner/karma-jasmine
6+
// Set framework to jasmine
7+
'jasmine'
8+
],
9+
10+
reporters: [
11+
// Reference: https://github.com/mlex/karma-spec-reporter
12+
// Set reporter to print detailed results to console
13+
'progress',
14+
15+
// Reference: https://github.com/karma-runner/karma-coverage
16+
// Output code coverage files
17+
'coverage'
18+
],
19+
20+
files: [
21+
// Grab all files in the app folder that contain .spec.
22+
'src/tests.webpack.js'
23+
],
24+
25+
preprocessors: {
26+
// Reference: http://webpack.github.io/docs/testing.html
27+
// Reference: https://github.com/webpack/karma-webpack
28+
// Convert files with webpack and load sourcemaps
29+
'src/tests.webpack.js': ['webpack', 'sourcemap']
30+
},
31+
32+
browsers: [
33+
// Run tests using PhantomJS
34+
'PhantomJS'
35+
],
36+
37+
singleRun: true,
38+
39+
// Configure code coverage reporter
40+
coverageReporter: {
41+
dir: 'coverage/',
42+
reporters: [
43+
{type: 'text-summary'},
44+
{type: 'html'}
45+
]
46+
},
47+
48+
webpack: require('./webpack.tests.config'),
49+
50+
// Hide webpack build information from output
51+
webpackMiddleware: {
52+
noInfo: 'errors-only'
53+
}
54+
});
55+
};

package.json

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,13 +26,15 @@
2626
"scripts": {
2727
"build": "webpack --config webpack.build.config.js",
2828
"serve": "webpack-dev-server --config webpack.serve.config.js",
29-
"test": "echo \"Error: no test specified\" && exit 1"
29+
"test": "karma start",
30+
"test-watch": "karma start --auto-watch --no-single-run"
3031
},
3132
"dependencies": {
3233
"angular": ">=1.6.0",
3334
"bootstrap": ">=3.3.0"
3435
},
3536
"devDependencies": {
37+
"angular-mocks": "^1.6.4",
3638
"autoprefixer": "^7.0.1",
3739
"babel-core": "^6.24.1",
3840
"babel-eslint": "^7.2.3",
@@ -47,9 +49,21 @@
4749
"file-loader": "^0.11.1",
4850
"html-loader": "^0.4.5",
4951
"html-webpack-plugin": "^2.28.0",
52+
"istanbul-instrumenter-loader": "^2.0.0",
53+
"jasmine-core": "^2.6.2",
54+
"karma": "^1.7.0",
55+
"karma-coverage": "^1.1.1",
56+
"karma-jasmine": "^1.1.0",
57+
"karma-phantomjs-launcher": "^1.0.4",
58+
"karma-sourcemap-loader": "^0.3.7",
59+
"karma-spec-reporter": "0.0.31",
60+
"karma-webpack": "^2.0.3",
5061
"ng-annotate-loader": "^0.6.0",
5162
"node-sass": "^4.5.2",
63+
"null-loader": "^0.1.1",
64+
"phantomjs-prebuilt": "^2.1.14",
5265
"postcss-loader": "^2.0.3",
66+
"raw-loader": "^0.5.1",
5367
"sass-loader": "^6.0.3",
5468
"style-loader": "^0.17.0",
5569
"webpack": "^2.5.1",

src/input-tags.spec.js

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
describe('input-tags', () => {
2+
let element;
3+
let scope;
4+
5+
beforeEach(inject((_$rootScope_, _$compile_) => {
6+
const $compile = _$compile_;
7+
scope = _$rootScope_.$new();
8+
9+
element = angular.element('<div>test</div>');
10+
11+
$compile(element)(scope);
12+
}));
13+
14+
it('should dummy test pass', () => {
15+
const expected = 'test';
16+
scope.item = {
17+
name: expected,
18+
active: false
19+
};
20+
21+
scope.$digest();
22+
23+
expect(element.text()).toContain(expected);
24+
});
25+
});

src/tests.webpack.js

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
import 'angular';
2+
import 'angular-mocks/angular-mocks';
3+
4+
const context = require.context('.', true, /\.js$/);
5+
6+
context.keys().forEach(context);

webpack.tests.config.js

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
'use strict';
2+
3+
module.exports = {
4+
devtool: 'inline-source-map',
5+
module: {
6+
rules: [{
7+
test: /\.js$/,
8+
loader: 'babel-loader',
9+
exclude: /node_modules/
10+
}, {
11+
test: /\.(css|scss)$/,
12+
loader: 'null-loader'
13+
}, {
14+
test: /\.(png|jpg|jpeg|gif|svg|woff|woff2|ttf|eot)$/,
15+
loader: 'file-loader'
16+
}, {
17+
test: /\.html$/,
18+
loader: 'raw-loader'
19+
}, {
20+
enforce: 'pre',
21+
test: /\.js$/,
22+
exclude: [
23+
/node_modules/,
24+
/\.spec\.js$/
25+
],
26+
loader: 'istanbul-instrumenter-loader',
27+
query: {
28+
esModules: true
29+
}
30+
}]
31+
},
32+
devServer: {
33+
stats: 'minimal'
34+
}
35+
};

0 commit comments

Comments
 (0)