Skip to content

Commit f03a979

Browse files
author
borysn
committed
update karma and coverage for webpack 2
1 parent 168490a commit f03a979

File tree

3 files changed

+41
-76
lines changed

3 files changed

+41
-76
lines changed

frontend/config/karma.conf.js

Lines changed: 19 additions & 69 deletions
Original file line numberDiff line numberDiff line change
@@ -1,106 +1,56 @@
11
/* karma.conf.js */
2-
/**
3-
* @author: @AngularClass
4-
*/
5-
var path = require('path');
2+
const path = require('path');
3+
const testWebpackConfig = require('./webpack.test.js');
64

75
module.exports = function(config) {
8-
var testWebpackConfig = require('./webpack.test.js');
9-
106
var configuration = {
11-
12-
// base path that will be used to resolve all patterns (e.g. files, exclude)
137
basePath: '',
14-
15-
/*
16-
* Frameworks to use
17-
*
18-
* available frameworks: https://npmjs.org/browse/keyword/karma-adapter
19-
*/
208
frameworks: ['jasmine'],
21-
22-
// list of files to exclude
239
exclude: [ ],
10+
client: { captureConsole: false },
11+
files: [{pattern: './spec-bundle.js', watched: false}],
12+
preprocessors: {
13+
'./spec-bundle.js': ['coverage', 'webpack', 'sourcemap']
14+
},
2415

25-
/*
26-
* list of files / patterns to load in the browser
27-
*
28-
* we are building the test environment in ./spec-bundle.js
29-
*/
30-
files: [ { pattern: './spec-bundle.js', watched: false } ],
31-
32-
/*
33-
* preprocess matching files before serving them to the browser
34-
* available preprocessors: https://npmjs.org/browse/keyword/karma-preprocessor
35-
*/
36-
preprocessors: { './spec-bundle.js': ['coverage', 'webpack', 'sourcemap'] },
37-
38-
// Webpack Config at ./webpack.test.js
3916
webpack: testWebpackConfig,
4017

4118
coverageReporter: {
42-
dir : '../coverage/',
43-
reporters: [
44-
{ type: 'text-summary' },
45-
{ type: 'json' },
46-
{ type: 'html' }
47-
]
19+
type: 'in-memory'
4820
},
4921

50-
// Webpack please don't spam the console when running in karma!
51-
webpackServer: { noInfo: true },
22+
remapCoverageReporter: {
23+
'text-summary': null,
24+
json: './coverage/coverage.json',
25+
html: './coverage/html'
26+
},
5227

53-
/*
54-
* test results reporter to use
55-
*
56-
* possible values: 'dots', 'progress'
57-
* available reporters: https://npmjs.org/browse/keyword/karma-reporter
58-
*/
59-
reporters: [ 'mocha', 'coverage' ],
28+
webpackServer: { noInfo: true },
6029

61-
// web server port
62-
port: 9876,
30+
reporters: ['mocha', 'coverage', 'remap-coverage'],
6331

64-
// enable / disable colors in the output (reporters and logs)
6532
colors: true,
6633

67-
/*
68-
* level of logging
69-
* possible values: config.LOG_DISABLE || config.LOG_ERROR || config.LOG_WARN || config.LOG_INFO || config.LOG_DEBUG
70-
*/
71-
logLevel: config.LOG_INFO,
72-
73-
// do not fail on empty test suite
74-
//failOnEmptyTestSuite: false,
34+
logLevel: config.LOG_WARN,
7535

76-
// enable / disable watching file and executing tests whenever any file changes
7736
autoWatch: false,
7837

79-
/*
80-
* start these browsers
81-
* available browser launchers: https://npmjs.org/browse/keyword/karma-launcher
82-
*/
8338
browsers: [
84-
'Chromium'
39+
'Chrome'
8540
],
8641

8742
customLaunchers: {
8843
Chrome_travis_ci: {
89-
base: 'Chromium',
90-
chromeDataDir: path.resolve(__dirname, '.chrome'),
44+
base: 'Chrome',
9145
flags: ['--no-sandbox']
9246
}
9347
},
9448

95-
/*
96-
* Continuous Integration mode
97-
* if true, Karma captures browsers, runs the tests and exits
98-
*/
9949
singleRun: true
10050
};
10151

10252
if(process.env.TRAVIS){
103-
configuration.browsers = ['Chrome_travis_ci'];
53+
configuration.browsers = ['ChromeTravisCi'];
10454
}
10555

10656
config.set(configuration);

frontend/config/webpack.test.js

Lines changed: 21 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -32,19 +32,31 @@ module.exports = {
3232
},
3333
{
3434
test: /\.ts$/,
35-
loader: 'awesome-typescript-loader',
36-
query: {
37-
compilerOptions: {
38-
removeComments: true
39-
}
40-
},
35+
use: [
36+
{
37+
loader: 'awesome-typescript-loader',
38+
query: {
39+
sourceMap: false,
40+
inlineSourceMap: true,
41+
compilerOptions: {
42+
removeComments: true
43+
}
44+
},
45+
},
46+
'angular2-template-loader'
47+
],
4148
exclude: [/\.e2e\.ts$/]
4249
},
4350
{
4451
test: /\.json$/,
4552
loader: 'json-loader',
4653
exclude: [helpers.root('src/index.html')]
4754
},
55+
{
56+
test: /\.scss$/,
57+
use: ['raw-loader', 'sass-loader'],
58+
exclude: [helpers.root('node_modules')]
59+
},
4860
{
4961
test: /\.css$/, loaders: ['to-string-loader', 'css-loader'],
5062
exclude: [helpers.root('src/index.html')]
@@ -55,7 +67,8 @@ module.exports = {
5567
exclude: [helpers.root('src/index.html')]
5668
},
5769
{
58-
test: /\.(js|ts)$/, loader: 'istanbul-instrumenter-loader',
70+
test: /\.(js|ts)$/,
71+
loader: 'istanbul-instrumenter-loader',
5972
include: helpers.root('src'),
6073
enforce: 'post',
6174
exclude: [
@@ -79,6 +92,7 @@ module.exports = {
7992

8093
new webpack.LoaderOptionsPlugin({
8194
options: {
95+
debug: false,
8296
tslint: {
8397
emitErrors: false,
8498
failOnHint: false,

frontend/package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -86,6 +86,7 @@
8686
"karma-coverage": "^1.1.1",
8787
"karma-jasmine": "^1.1.0",
8888
"karma-mocha-reporter": "^2.2.2",
89+
"karma-remap-coverage": "^0.1.4",
8990
"karma-sourcemap-loader": "^0.3.7",
9091
"karma-webpack": "^2.0.2",
9192
"node-sass": "^4.5.0",

0 commit comments

Comments
 (0)