Skip to content

Commit f489940

Browse files
davidsekarMarkPieszak
authored andcommitted
(Unit Testing) Run unit testcases using PhantomJS in Continuous Integration environments (TrilonIO#403)
* Modified .csproject to emit the wwwroot/dist folder, if the folder is not created yet * Remove Jest and added Karma test runner for executing unit test cases * Added PhantomJS for running test in CI environments. Removed deprecated tslint rules and amended existing rules.
1 parent 2f11294 commit f489940

File tree

6 files changed

+39
-29
lines changed

6 files changed

+39
-29
lines changed

ClientApp/test/boot-tests.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
Error.stackTraceLimit = Infinity;
22
// Load required polyfills and testing libraries
3-
require('reflect-metadata');
3+
require('core-js'); // Added for Phantomjs
44
require('zone.js');
55
require('zone.js/dist/long-stack-trace-zone');
66
require('zone.js/dist/proxy.js');

ClientApp/test/karma.conf.js

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ module.exports = function (config) {
77
frameworks: ['jasmine'],
88
exclude: [],
99
files: [
10+
'../../wwwroot/dist/vendor.js',
1011
'./boot-tests.js'
1112
],
1213
preprocessors: {
@@ -41,6 +42,24 @@ module.exports = function (config) {
4142
stats: {
4243
chunks: false
4344
}
45+
},
46+
// you can define custom flags
47+
customLaunchers: {
48+
'PhantomJS_custom': {
49+
base: 'PhantomJS',
50+
options: {
51+
windowName: 'test-window',
52+
settings: {
53+
webSecurityEnabled: false
54+
}
55+
},
56+
flags: ['--load-images=true'],
57+
// debug: true
58+
}
59+
},
60+
phantomjsLauncher: {
61+
// Have phantomjs exit if a ResourceError is encountered (useful if karma exits without killing phantom)
62+
exitOnResourceError: true
4463
}
4564
});
4665
};

ClientApp/test/webpack.config.test.js

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
const ContextReplacementPlugin = require('webpack/lib/ContextReplacementPlugin');
22
const LoaderOptionsPlugin = require('webpack/lib/LoaderOptionsPlugin');
33

4+
const webpack = require('webpack');
45
var path = require('path');
56
var rootPath = path.join.bind(path, path.resolve(__dirname, '../../'));
67

@@ -67,6 +68,10 @@ module.exports = function (options) {
6768
]
6869
},
6970
plugins: [
71+
new webpack.DllReferencePlugin({
72+
context: __dirname,
73+
manifest: require(rootPath('wwwroot', 'dist', 'vendor-manifest.json'))
74+
}),
7075
new ContextReplacementPlugin(
7176
/**
7277
* The (\\|\/) piece accounts for path separators in *nix and Windows

package.json

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,11 @@
22
"name": "angular4-aspnetcore-universal",
33
"version": "1.0.0-rc3",
44
"scripts": {
5-
"test": "karma start ClientApp/test/karma.conf.js",
5+
"lint": "tslint -p tsconfig.json",
6+
"test": "npm run build:vendor && karma start ClientApp/test/karma.conf.js",
67
"test:watch": "npm run test -- --auto-watch --no-single-run",
7-
"test:ci": "npm run test -- --runInBand",
8+
"test:ci": "npm run test -- --browsers PhantomJS_custom",
9+
"test:ci:watch": "npm run test:ci -- --auto-watch --no-single-run",
810
"test:coverage": "npm run test -- --coverage",
911
"build:dev": "npm run build:vendor && npm run build:webpack",
1012
"build:webpack": "webpack --progress --color",
@@ -78,6 +80,7 @@
7880
"karma-coverage": "^1.1.1",
7981
"karma-jasmine": "^1.1.0",
8082
"karma-mocha-reporter": "^2.2.4",
83+
"karma-phantomjs-launcher": "^1.0.4",
8184
"karma-remap-coverage": "^0.1.4",
8285
"karma-sourcemap-loader": "^0.3.7",
8386
"karma-webpack": "^2.0.3",

tsconfig.json

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,12 +3,14 @@
33
"moduleResolution": "node",
44
"module": "es2015",
55
"target": "es5",
6+
"alwaysStrict": true,
67
"noImplicitAny": false,
78
"sourceMap": true,
89
"experimentalDecorators": true,
910
"emitDecoratorMetadata": true,
1011
"skipDefaultLibCheck": true,
1112
"skipLibCheck": true,
13+
"allowUnreachableCode": false,
1214
"lib": [
1315
"es2016",
1416
"dom"

tslint.json

Lines changed: 7 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -8,32 +8,20 @@
88
"check-space"
99
],
1010
"component-class-suffix": true,
11-
"component-selector-name": [
11+
"component-selector": [
1212
true,
13+
"element",
14+
"app",
1315
"kebab-case"
1416
],
15-
"component-selector-prefix": [
16-
true,
17-
"app"
18-
],
19-
"component-selector-type": [
20-
true,
21-
"element"
22-
],
2317
"curly": false,
2418
"directive-class-suffix": true,
25-
"directive-selector-name": [
19+
"directive-selector": [
2620
true,
21+
"attribute",
22+
"app",
2723
"camelCase"
2824
],
29-
"directive-selector-prefix": [
30-
true,
31-
"app"
32-
],
33-
"directive-selector-type": [
34-
true,
35-
"attribute"
36-
],
3725
"eofline": true,
3826
"forin": true,
3927
"import-destructuring-spacing": true,
@@ -44,7 +32,6 @@
4432
"interface-name": false,
4533
"jsdoc-format": true,
4634
"label-position": true,
47-
"label-undefined": true,
4835
"max-line-length": [
4936
true,
5037
200
@@ -73,7 +60,6 @@
7360
"no-construct": true,
7461
"no-constructor-vars": false,
7562
"no-debugger": true,
76-
"no-duplicate-key": true,
7763
"no-duplicate-variable": true,
7864
"no-empty": false,
7965
"no-eval": true,
@@ -88,7 +74,6 @@
8874
"no-string-literal": false,
8975
"no-switch-case-fall-through": true,
9076
"no-trailing-whitespace": false,
91-
"no-unreachable": true,
9277
"no-unused-expression": true,
9378
"no-unused-variable": false,
9479
"no-use-before-declare": true,
@@ -153,10 +138,6 @@
153138
"use-life-cycle-interface": true,
154139
"use-output-property-decorator": true,
155140
"use-pipe-transform-interface": true,
156-
"use-strict": [
157-
true,
158-
"check-module"
159-
],
160141
"variable-name": [
161142
true,
162143
"check-format",
@@ -175,4 +156,4 @@
175156
"rulesDirectory": [
176157
"node_modules/codelyzer"
177158
]
178-
}
159+
}

0 commit comments

Comments
 (0)