1- // const filePatterns = ['tests/test-main.ts','tests/**/*.ts', '**/*.spec.ts'];
2- const filePatterns = [ 'tests/test-main.ts' , 'tests/**/*.ts' ] ;
31module . exports = function ( config ) {
42 const options = {
53 // base path that will be used to resolve all patterns (eg. files, exclude)
@@ -9,8 +7,8 @@ module.exports = function (config) {
97 // available frameworks: https://npmjs.org/browse/keyword/karma-adapter
108 frameworks : [ 'jasmine' , 'sinon' ] ,
119
12- // list of files / patterns to load in the browser
13- files : filePatterns ,
10+ // list of files / patterns to load in the browser. Leave empty for webpack projects
11+ // files: [] ,
1412
1513 // list of files to exclude
1614 exclude : [ ] ,
@@ -24,6 +22,13 @@ module.exports = function (config) {
2422 // available reporters: https://npmjs.org/browse/keyword/karma-reporter
2523 reporters : [ 'mocha' ] ,
2624
25+ // configure optional coverage, enable via --env.codeCoverage
26+ coverageReporter : {
27+ dir : require ( 'path' ) . join ( __dirname , './coverage' ) ,
28+ subdir : '.' ,
29+ reporters : [ { type : 'html' } , { type : 'text-summary' } ] ,
30+ } ,
31+
2732 // web server port
2833 port : 9876 ,
2934
@@ -62,41 +67,9 @@ module.exports = function (config) {
6267 singleRun : false ,
6368 } ;
6469
65- setWebpackPreprocessor ( config , options ) ;
66- setWebpack ( config , options ) ;
70+ if ( config . _NS && config . _NS . env && config . _NS . env . codeCoverage ) {
71+ options . reporters = ( options . reporters || [ ] ) . concat ( [ 'coverage' ] ) ;
72+ }
6773
6874 config . set ( options ) ;
6975} ;
70- module . exports . filePatterns = filePatterns ;
71- // You can also use RegEx if you'd like:
72- // module.exports.filesRegex = /\.\/tests\/.*\.ts$/;
73-
74- function setWebpackPreprocessor ( config , options ) {
75- if ( config && config . bundle ) {
76- if ( ! options . preprocessors ) {
77- options . preprocessors = { } ;
78- }
79-
80- options . files . forEach ( ( file ) => {
81- if ( ! options . preprocessors [ file ] ) {
82- options . preprocessors [ file ] = [ ] ;
83- }
84- options . preprocessors [ file ] . push ( 'webpack' ) ;
85- } ) ;
86- }
87- }
88-
89- function setWebpack ( config , options ) {
90- if ( config && config . bundle ) {
91- const env = { } ;
92- env [ config . platform ] = true ;
93- env . sourceMap = config . debugBrk ;
94- env . appPath = config . appPath ;
95- env . karmaWebpack = true ;
96- options . webpack = require ( './webpack.config' ) ( env ) ;
97- delete options . webpack . entry ;
98- delete options . webpack . output . libraryTarget ;
99- const invalidPluginsForUnitTesting = [ 'GenerateBundleStarterPlugin' , 'GenerateNativeScriptEntryPointsPlugin' ] ;
100- options . webpack . plugins = options . webpack . plugins . filter ( ( p ) => ! invalidPluginsForUnitTesting . includes ( p . constructor . name ) ) ;
101- }
102- }
0 commit comments