Skip to content

Commit a70d2a7

Browse files
committed
Add karma / protractor / codelyzer
Closes TrilonIO#6 Closes TrilonIO#7 More detailed unit tests to come.
1 parent 8902c84 commit a70d2a7

File tree

12 files changed

+822
-31
lines changed

12 files changed

+822
-31
lines changed

Client/app/app.component.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,4 +21,4 @@ export class AppComponent {
2121

2222
}
2323

24-
}
24+
}

Client/app/app.e2e.ts

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
describe('App', () => {
2+
3+
beforeEach(() => {
4+
//browser.get('/');
5+
});
6+
7+
it('e2e test should run', () => {
8+
let subject = true;
9+
let result = true;
10+
expect(subject).toEqual(result);
11+
});
12+
13+
});

README.md

Lines changed: 14 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,24 @@
11
# ASP.NET Core & Angular2 Universal starter
22

3-
## - Fully functioning (some additional features coming soon!)
4-
5-
### What does this starter include?
3+
### What does this repo include?
64

75
- Angular2
86
- Featuring Server-side rendering (Angular Universal)
97
- Faster paints, better SEO, deep-linking, etc
108
- Baked in best-practices (follows Angular style guide)
11-
- Bootstrap (with ng2-bootstrap)
9+
- Bootstrap4 (with ng2-bootstrap) - can be rendered on the server
1210

1311
- Webpack build system
1412
- HMR : Hot Module Reloading/Replacement
1513
- Production builds
1614

17-
- asp.NET Core
15+
- Testing frameworks
16+
- Unit testing with Karma/Jasmine
17+
- Codelyzer (for real-time static code analysis) `npm run lint`
18+
- *Note, only VSCode & Atom can provide real-time code analysis at this moment*
19+
20+
- asp.NET Core 1.0.1
21+
- RestAPI integration
1822
- Integration with NodeJS to provide pre-rendering, as well as any other Node module asset you want to use.
1923

2024
### Getting Started?
@@ -31,8 +35,8 @@ Make sure to be aware of [Universal's (isomorphic javascripts) **"Gotchas"**](ht
3135

3236
### UPCOMING Features:
3337

34-
- NgRx (reactive Redux application state management) TODO
35-
- Unit testing with Karma/Jasmine TODO
36-
- HMR State management
37-
- Angular 2.1.1+ fixes (for Universal)
38-
- Websockets example
38+
- [ ] NgRx (reactive Redux application state management) TODO
39+
- [ ] Unit testing with Karma/Jasmine TODO
40+
- [ ] HMR State management
41+
- [ ] Angular 2.1.1+ fixes (for Universal)
42+
- [ ] Websockets example

helpers.js

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
/**
2+
* @author: @AngularClass
3+
*/
4+
5+
var path = require('path');
6+
7+
// Helper functions
8+
// var ROOT = path.resolve(__dirname, '..');
9+
var ROOT = path.resolve(__dirname);
10+
11+
console.log('root directory:', root() + '\n');
12+
13+
function hasProcessFlag(flag) {
14+
return process.argv.join('').indexOf(flag) > -1;
15+
}
16+
17+
function root(args) {
18+
args = Array.prototype.slice.call(arguments, 0);
19+
return path.join.apply(path, [ROOT].concat(args));
20+
}
21+
22+
23+
exports.hasProcessFlag = hasProcessFlag;
24+
exports.root = root;

karma.config.js

Lines changed: 107 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,107 @@
1+
/**
2+
* @author: @AngularClass
3+
*/
4+
5+
module.exports = function (config) {
6+
var testWebpackConfig = require('./webpack.test.js')({ env: 'test' });
7+
8+
var configuration = {
9+
10+
// base path that will be used to resolve all patterns (e.g. files, exclude)
11+
basePath: '',
12+
13+
/*
14+
* Frameworks to use
15+
*
16+
* available frameworks: https://npmjs.org/browse/keyword/karma-adapter
17+
*/
18+
frameworks: ['jasmine'],
19+
20+
// list of files to exclude
21+
exclude: [],
22+
23+
/*
24+
* list of files / patterns to load in the browser
25+
*
26+
* we are building the test environment in ./spec-bundle.js
27+
*/
28+
files: [{ pattern: './config/spec-bundle.js', watched: false }],
29+
30+
/*
31+
* preprocess matching files before serving them to the browser
32+
* available preprocessors: https://npmjs.org/browse/keyword/karma-preprocessor
33+
*/
34+
preprocessors: { './config/spec-bundle.js': ['coverage', 'webpack', 'sourcemap'] },
35+
36+
// Webpack Config at ./webpack.test.js
37+
webpack: testWebpackConfig,
38+
39+
coverageReporter: {
40+
type: 'in-memory'
41+
},
42+
43+
remapCoverageReporter: {
44+
'text-summary': null,
45+
json: './coverage/coverage.json',
46+
html: './coverage/html'
47+
},
48+
49+
// Webpack please don't spam the console when running in karma!
50+
webpackMiddleware: { stats: 'errors-only' },
51+
52+
/*
53+
* test results reporter to use
54+
*
55+
* possible values: 'dots', 'progress'
56+
* available reporters: https://npmjs.org/browse/keyword/karma-reporter
57+
*/
58+
reporters: ['mocha', 'coverage'],
59+
60+
// web server port
61+
port: 9876,
62+
63+
// enable / disable colors in the output (reporters and logs)
64+
colors: true,
65+
66+
/*
67+
* level of logging
68+
* possible values: config.LOG_DISABLE || config.LOG_ERROR || config.LOG_WARN || config.LOG_INFO || config.LOG_DEBUG
69+
*/
70+
logLevel: config.LOG_INFO,
71+
72+
// enable / disable watching file and executing tests whenever any file changes
73+
autoWatch: false,
74+
75+
/*
76+
* start these browsers
77+
* available browser launchers: https://npmjs.org/browse/keyword/karma-launcher
78+
*/
79+
browsers: [
80+
// 'Chrome',
81+
'PhantomJS'
82+
83+
],
84+
85+
customLaunchers: {
86+
ChromeTravisCi: {
87+
base: 'Chrome',
88+
flags: ['--no-sandbox']
89+
}
90+
},
91+
92+
/*
93+
* Continuous Integration mode
94+
* if true, Karma captures browsers, runs the tests and exits
95+
*/
96+
singleRun: true
97+
};
98+
99+
if (process.env.TRAVIS) {
100+
configuration.browsers = [
101+
'ChromeTravisCi',
102+
'PhantomJS'
103+
];
104+
}
105+
106+
config.set(configuration);
107+
};

package.json

Lines changed: 44 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,15 @@
11
{
22
"name": "aspnetcore-angular2-universal-starter",
3-
"version": "0.5.0",
4-
"repository": {
5-
"type": "git",
6-
"url": "git+https://github.com/MarkPieszak/aspnetcore-angular2-starter.git"
7-
},
3+
"version": "0.6.0",
84
"author": {
95
"name": "Mark Pieszak",
106
"email": "[email protected]",
117
"url": "http://www.github.com/MarkPieszak"
128
},
9+
"repository": {
10+
"type": "git",
11+
"url": "git+https://github.com/MarkPieszak/aspnetcore-angular2-starter.git"
12+
},
1313
"dependencies": {
1414
"@angular/common": "2.1.0",
1515
"@angular/compiler": "2.1.0",
@@ -20,15 +20,29 @@
2020
"@angular/platform-browser-dynamic": "2.1.0",
2121
"@angular/platform-server": "2.1.0",
2222
"@angular/router": "3.1.0",
23-
"@types/node": "^6.0.46",
2423
"angular2-platform-node": "~2.1.0-rc.1",
25-
"angular2-template-loader": "0.5.0",
2624
"angular2-universal": "~2.1.0-rc.1",
2725
"angular2-universal-polyfills": "~2.1.0-rc.1",
2826
"aspnet-prerendering": "^1.0.7",
29-
"aspnet-webpack": "^1.0.21",
27+
"aspnet-webpack": "^1.0.24",
28+
"bootstrap": "4.0.0-alpha.5",
29+
"ng2-bootstrap": "^1.1.16",
30+
"preboot": "^4.5.2",
31+
"rxjs": "5.0.0-rc.2",
32+
"zone.js": "^0.6.26"
33+
},
34+
"devDependencies": {
35+
"@types/hammerjs": "2.0.33",
36+
"@types/jasmine": "2.5.35",
37+
"@types/node": "^6.0.46",
38+
"@types/protractor": "1.5.20",
39+
"@types/source-map": "0.1.28",
40+
"@types/uglify-js": "2.6.28",
41+
"@types/webpack": "1.12.35",
42+
"@types/sinon": "1.16.31",
43+
"angular2-template-loader": "0.6.0",
3044
"awesome-typescript-loader": "2.2.4",
31-
"bootstrap": "^3.3.7",
45+
"codelyzer": "1.0.0-beta.3",
3246
"css": "^2.2.1",
3347
"css-loader": "^0.25.0",
3448
"es6-shim": "^0.35.1",
@@ -37,17 +51,30 @@
3751
"file-loader": "^0.9.0",
3852
"html-loader": "^0.4.3",
3953
"isomorphic-fetch": "^2.2.1",
40-
"jquery": "^2.2.1",
4154
"js.clone": "0.0.3",
4255
"json-loader": "^0.5.4",
43-
"ng2-bootstrap": "^1.1.16",
44-
"preboot": "^4.5.2",
56+
"karma": "1.3.0",
57+
"karma-chrome-launcher": "2.0.0",
58+
"karma-coverage": "1.1.1",
59+
"karma-jasmine": "1.0.2",
60+
"karma-mocha-reporter": "2.2.0",
61+
"karma-remap-coverage": "0.1.2",
62+
"karma-phantomjs-launcher": "1.0.2",
63+
"karma-source-map-support": "1.2.0",
64+
"karma-sourcemap-loader": "0.3.7",
65+
"karma-webpack": "1.8.0",
66+
"phantomjs-polyfill": "0.0.2",
67+
"phantomjs-prebuilt": "2.1.13",
68+
"protractor": "4.0.9",
4569
"raw-loader": "^0.5.1",
4670
"reflect-metadata": "^0.1.8",
47-
"rxjs": "5.0.0-beta.12",
4871
"source-map-loader": "0.1.5",
49-
"style-loader": "^0.13.0",
50-
"ts-loader": "^0.9.4",
72+
"style-loader": "^0.13.1",
73+
"ts-loader": "^1.0.0",
74+
"ts-node": "^1.6.1",
75+
"tslint": "3.15.1",
76+
"tslint-loader": "2.1.5",
77+
"typedoc": "0.5.1",
5178
"typescript": "^2.0.3",
5279
"url-loader": "^0.5.7",
5380
"webpack": "^2.1.0-beta.25",
@@ -56,8 +83,7 @@
5683
"webpack-externals-plugin": "^1.0.0",
5784
"webpack-hot-middleware": "^2.12.2",
5885
"webpack-merge": "^0.14.1",
59-
"webpack-node-externals": "^1.4.3",
60-
"zone.js": "^0.6.21"
86+
"webpack-node-externals": "^1.4.3"
6187
},
6288
"keywords": [
6389
"aspnetcore",
@@ -85,6 +111,7 @@
85111
"pretest": "npm run lint",
86112
"preversion": "npm test",
87113
"protractor": "protractor",
114+
"pree2e": "npm run webdriver:update -- --standalone",
88115
"rimraf": "rimraf",
89116
"test": "karma start",
90117
"tslint": "tslint",

protractor.conf.js

Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
/**
2+
* @author: @AngularClass
3+
*/
4+
5+
require('ts-node/register');
6+
var helpers = require('./helpers');
7+
8+
exports.config = {
9+
baseUrl: 'http://localhost:5000/',
10+
11+
// use `npm run e2e`
12+
specs: [
13+
helpers.root('Client/**/**.e2e.ts'),
14+
helpers.root('Client/**/*.e2e.ts')
15+
],
16+
exclude: [],
17+
18+
framework: 'jasmine2',
19+
20+
allScriptsTimeout: 110000,
21+
22+
jasmineNodeOpts: {
23+
showTiming: true,
24+
showColors: true,
25+
isVerbose: false,
26+
includeStackTrace: false,
27+
defaultTimeoutInterval: 400000
28+
},
29+
directConnect: true,
30+
31+
capabilities: {
32+
'browserName': 'chrome',
33+
'chromeOptions': {
34+
'args': ['show-fps-counter=true']
35+
}
36+
},
37+
38+
onPrepare: function () {
39+
browser.ignoreSynchronization = true;
40+
},
41+
42+
/**
43+
* Angular 2 configuration
44+
*
45+
* useAllAngular2AppRoots: tells Protractor to wait for any angular2 apps on the page instead of just the one matching
46+
* `rootEl`
47+
*/
48+
useAllAngular2AppRoots: true
49+
};

0 commit comments

Comments
 (0)