Skip to content

Commit

Permalink
feat(tests): auto run tests with a single command
Browse files Browse the repository at this point in the history
Auto run tests with `npm run test.watch` and provides source maps for both spec and app files.

Fix mgechev#1180
Fix mgechev#1193
  • Loading branch information
mgechev committed Aug 21, 2016
1 parent 754d3e5 commit 81186f6
Show file tree
Hide file tree
Showing 5 changed files with 28 additions and 22 deletions.
6 changes: 3 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -117,9 +117,9 @@ Visit the [Wiki page](https://github.com/mgechev/angular2-seed/wiki) of the proj
```bash
npm test

# Debug - In two different shell windows
npm run build.test.watch # 1st window
npm run karma.start # 2nd window
# Development. Your app will be watched by karma
# on each change all your specs will be executed.
npm run test.watch

# code coverage (istanbul)
# auto-generated at the end of `npm test`
Expand Down
13 changes: 2 additions & 11 deletions karma.conf.js
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ module.exports = function(config) {
// RxJs.
{ pattern: 'node_modules/rxjs/**/*.js', included: false, watched: false },
{ pattern: 'node_modules/rxjs/**/*.js.map', included: false, watched: false },
{ pattern: 'node_modules/@angular/**/*.js.map', included: false, watched: false },

// paths loaded via module imports
// Angular itself
Expand Down Expand Up @@ -62,14 +63,11 @@ module.exports = function(config) {

// preprocess matching files before serving them to the browser
// available preprocessors: https://npmjs.org/browse/keyword/karma-preprocessor
preprocessors: {
'dist/**/!(*spec).js': ['coverage']
},

// test results reporter to use
// possible values: 'dots', 'progress'
// available reporters: https://npmjs.org/browse/keyword/karma-reporter
reporters: ['mocha', 'coverage'],
reporters: ['mocha'],


// web server port
Expand Down Expand Up @@ -103,13 +101,6 @@ module.exports = function(config) {
}
},

coverageReporter: {
dir: 'coverage/',
reporters: [
{ type: 'json', subdir: '.', file: 'coverage-final.json' }
]
},

// Continuous Integration mode
// if true, Karma captures browsers, runs the tests and exits
singleRun: false,
Expand Down
17 changes: 10 additions & 7 deletions tools/tasks/seed/build.js.dev.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,9 @@ import * as gulp from 'gulp';
import * as gulpLoadPlugins from 'gulp-load-plugins';
import * as merge from 'merge-stream';
import * as util from 'gulp-util';
import { join, sep, relative } from 'path';
import { join/*, sep, relative*/ } from 'path';

import { APP_DEST, APP_SRC, PROJECT_ROOT, TOOLS_DIR, TYPED_COMPILE_INTERVAL } from '../../config';
import { APP_DEST, APP_SRC, /*PROJECT_ROOT, */TOOLS_DIR, TYPED_COMPILE_INTERVAL } from '../../config';
import { makeTsProject, templateLocals } from '../../utils';

const plugins = <any>gulpLoadPlugins();
Expand Down Expand Up @@ -57,11 +57,14 @@ export = () => {
}

return result.js
.pipe(plugins.sourcemaps.write('.', {
includeContent: false,
sourceRoot: (file: any) =>
relative(file.path, PROJECT_ROOT + '/' + APP_SRC).replace(sep, '/') + '/' + APP_SRC
}))
.pipe(plugins.sourcemaps.write())
// Use for debugging with Webstorm/IntelliJ
// https://github.com/mgechev/angular2-seed/issues/1220
// .pipe(plugins.sourcemaps.write('.', {
// includeContent: false,
// sourceRoot: (file: any) =>
// relative(file.path, PROJECT_ROOT + '/' + APP_SRC).replace(sep, '/') + '/' + APP_SRC
// }))
.pipe(plugins.template(templateLocals()))
.pipe(gulp.dest(APP_DEST));
};
1 change: 1 addition & 0 deletions tools/tasks/seed/build.js.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -32,3 +32,4 @@ export = () => {
.pipe(plugins.sourcemaps.write())
.pipe(gulp.dest(APP_DEST));
};

13 changes: 12 additions & 1 deletion tools/tasks/seed/karma.run.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,5 +3,16 @@ import { startKarma } from '../../utils/seed/karma.start';
* Executes the build process, running all unit tests using `karma`.
*/
export = (done: any) => {
return startKarma(done);
return startKarma(done, {
preprocessors: {
'dist/**/!(*spec).js': ['coverage']
},
reporters: ['mocha', 'coverage'],
coverageReporter: {
dir: 'coverage/',
reporters: [
{ type: 'json', subdir: '.', file: 'coverage-final.json' }
]
},
});
};

0 comments on commit 81186f6

Please sign in to comment.