Skip to content
Merged
Show file tree
Hide file tree
Changes from 5 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
29 changes: 27 additions & 2 deletions addon/ng2/blueprints/ng2/files/config/karma.conf.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,8 @@ module.exports = function (config) {
require('karma-jasmine'),
require('karma-chrome-launcher'),
require('karma-coverage'),
require('angular-cli/plugins/karma')
require('angular-cli/plugins/karma'),
require('karma-remap-istanbul')
],
customLaunchers: {
// chrome setup for travis CI using chromium
Expand All @@ -22,10 +23,34 @@ module.exports = function (config) {
{ pattern: './src/test.ts', watched: false }
],
preprocessors: {
'./src/**/**/*.ts': ['angular-cli-coverage'],
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Would you be willing to explain this?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I added a new preprocessor in the karma plugin. While there is a single entry point for the tests in order to get the remap plugin to generate the mapped coverage report it needs to run over the test files themselves.

'./src/test.ts': ['angular-cli']
},
coverageReporter: {
dir: 'coverage',
reporters: [
{
type: 'text-summary'
},
{
type: 'json',
subdir: '.',
file: 'coverage-final.json'
}
]
},

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is there a reason to keep using karma-coverage? karma-remap-istanbul produces the coverage report and no longer needs the intermediate file and instrumenting is done by sourcemap-istanbul-instrumenter-loader.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

you are correct. I misunderstood the docs for the karma plugin


remapIstanbulReporter: {
src: 'coverage/coverage-final.json',
reports: {
lcovonly: 'coverage/lcov.info',
html: 'coverage/report'
},
timeoutNotCreated: 5000,
timeoutNoMoreFiles: 1000
},
angularCliConfig: './angular-cli.json',
reporters: ['coverage', 'progress'],
reporters: ['coverage', 'progress', 'karma-remap-istanbul'],
port: 9876,
colors: true,
logLevel: config.LOG_INFO,
Expand Down
1 change: 1 addition & 0 deletions addon/ng2/blueprints/ng2/files/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@
"karma-chrome-launcher": "0.2.3",
"karma-coverage": "^1.0.0",
"karma-jasmine": "0.3.8",
"karma-remap-istanbul": "^0.1.1",
"protractor": "3.3.0",
"ts-node": "1.2.1",
"tslint": "3.13.0",
Expand Down
3 changes: 3 additions & 0 deletions addon/ng2/models/webpack-build-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,9 @@ const getWebpackTestConfig = function(projectRoot, sourceDir) {
tsconfig: path.resolve(projectRoot, `./${sourceDir}/tsconfig.json`),
module: 'commonjs',
target: 'es5',
mapRoot: false,
sourceMap: false,
inlineSourceMap: true,
useForkChecker: true,
removeComments: true
}
Expand Down
13 changes: 10 additions & 3 deletions plugins/karma.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,11 +22,17 @@ const init = (config) => {
}
};

// replace the angular-cli preprocessor with webpack+sourcemap
// replace the angular-cli preprocessor with webpack
Object.keys(config.preprocessors)
.filter((file) => config.preprocessors[file].indexOf('angular-cli') !== -1)
.map((file) => config.preprocessors[file])
.map((arr) => arr.splice(arr.indexOf('angular-cli'), 1, 'webpack', 'sourcemap'));
.map((arr) => arr.splice(arr.indexOf('angular-cli'), 1, 'webpack'));

// replace the angular-cli preprocessor with webpack + sourcemap + coverage
Object.keys(config.preprocessors)
.filter((file) => config.preprocessors[file].indexOf('angular-cli-coverage') !== -1)
.map((file) => config.preprocessors[file])
.map((arr) => arr.splice(arr.indexOf('angular-cli-coverage'), 1, 'webpack', 'sourcemap', 'coverage'));
}

init.$inject = ['config']
Expand All @@ -38,5 +44,6 @@ preprocessor.$inject = []
// also export karma-webpack and karma-sourcemap-loader
module.exports = Object.assign({
'framework:angular-cli': ['factory', init],
'preprocessor:angular-cli': ['factory', preprocessor]
'preprocessor:angular-cli': ['factory', preprocessor],
'preprocessor:angular-cli-coverage': ['factory', preprocessor]
}, require('karma-webpack'), require('karma-sourcemap-loader'));