Skip to content

Commit

Permalink
Merge pull request mgechev#1232 from mgechev/testing
Browse files Browse the repository at this point in the history
feat(build): improve testing
  • Loading branch information
ludohenin authored Aug 21, 2016
2 parents 048f376 + 81186f6 commit dcc894e
Show file tree
Hide file tree
Showing 10 changed files with 57 additions and 36 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
5 changes: 3 additions & 2 deletions gulpfile.ts
Original file line number Diff line number Diff line change
Expand Up @@ -68,9 +68,10 @@ gulp.task('build.test', (done: any) =>

// --------------
// Build test watch.
gulp.task('build.test.watch', (done: any) =>
gulp.task('test.watch', (done: any) =>
runSequence('build.test',
'watch.test',
'karma.watch',
done));

// --------------
Expand Down Expand Up @@ -116,7 +117,7 @@ gulp.task('serve.prod', (done: any) =>
// Test.
gulp.task('test', (done: any) =>
runSequence('build.test',
'karma.start',
'karma.run',
done));

// --------------
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
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
"build.e2e": "gulp build.e2e --color",
"build.prod": "gulp build.prod --color --config-env prod",
"build.test": "gulp build.test --color",
"build.test.watch": "gulp build.test.watch --color",
"test.watch": "gulp test.watch --color",
"generate.manifest": "gulp generate.manifest --color",
"e2e": "protractor",
"e2e.live": "protractor --elementExplorer",
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));
};

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

This file was deleted.

9 changes: 9 additions & 0 deletions tools/tasks/seed/karma.watch.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
import { startKarma } from '../../utils/seed/karma.start';
/**
* Executes the build process, running all unit tests using `karma`.
*/
export = (done: any) => {
return startKarma(done, {
singleRun: false
});
};
10 changes: 10 additions & 0 deletions tools/utils/seed/karma.start.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
import * as karma from 'karma';
import { join } from 'path';

export const startKarma = (done: any, config: any = {}) => {
return new (<any>karma).Server(Object.assign({
configFile: join(process.cwd(), 'karma.conf.js'),
singleRun: true
}, config)).start(done);
};

0 comments on commit dcc894e

Please sign in to comment.