File tree 3 files changed +57
-12
lines changed
3 files changed +57
-12
lines changed Original file line number Diff line number Diff line change 32
32
"name" : {
33
33
"type" : " string" ,
34
34
"description" : " Name of the app."
35
- },
35
+ },
36
36
"root" : {
37
37
"type" : " string" ,
38
38
"description" : " The root directory of the app."
270
270
}
271
271
},
272
272
"additionalProperties" : false
273
+ },
274
+ "codeCoverage" : {
275
+ "type" : " object" ,
276
+ "properties" : {
277
+ "exclude" : {
278
+ "description" : " Globs to exclude from code coverage." ,
279
+ "type" : " array" ,
280
+ "items" : {
281
+ "type" : " string"
282
+ },
283
+ "default" : []
284
+ }
285
+ },
286
+ "additionalProperties" : false
273
287
}
274
288
},
275
289
"additionalProperties" : false
435
449
"description" : " The host the application will be served on" ,
436
450
"type" : " string" ,
437
451
"default" : " localhost"
438
-
452
+
439
453
},
440
454
"ssl" : {
441
455
"description" : " Enables ssl for the application" ,
442
456
"type" : " boolean" ,
443
457
"default" : false
444
-
458
+
445
459
},
446
460
"sslKey" : {
447
461
"description" : " The ssl key used by the server" ,
448
462
"type" : " string" ,
449
463
"default" : " ssl/server.key"
450
-
464
+
451
465
},
452
466
"sslCert" : {
453
467
"description" : " The ssl certificate used by the server" ,
Original file line number Diff line number Diff line change 1
1
import * as path from 'path' ;
2
+ import * as glob from 'glob' ;
2
3
import * as webpack from 'webpack' ;
3
4
4
5
import { CliConfig } from '../config' ;
@@ -20,14 +21,27 @@ export function getTestConfig(testConfig: WebpackTestOptions) {
20
21
const appConfig = CliConfig . fromProject ( ) . config . apps [ 0 ] ;
21
22
const extraRules : any [ ] = [ ] ;
22
23
23
- if ( testConfig . codeCoverage ) {
24
+ if ( testConfig . codeCoverage && CliConfig . fromProject ( ) ) {
25
+ const codeCoverageExclude = CliConfig . fromProject ( ) . get ( 'test.codeCoverage.exclude' ) ;
26
+ let exclude : ( string | RegExp ) [ ] = [
27
+ / \. ( e 2 e | s p e c ) \. t s $ / ,
28
+ / n o d e _ m o d u l e s /
29
+ ] ;
30
+
31
+ if ( codeCoverageExclude ) {
32
+ codeCoverageExclude . forEach ( ( excludeGlob : string ) => {
33
+ const excludeFiles = glob
34
+ . sync ( path . join ( projectRoot , excludeGlob ) , { nodir : true } )
35
+ . map ( file => path . normalize ( file ) ) ;
36
+ exclude . push ( ...excludeFiles ) ;
37
+ } ) ;
38
+ }
39
+
40
+
24
41
extraRules . push ( {
25
42
test : / \. ( j s | t s ) $ / , loader : 'istanbul-instrumenter-loader' ,
26
43
enforce : 'post' ,
27
- exclude : [
28
- / \. ( e 2 e | s p e c ) \. t s $ / ,
29
- / n o d e _ m o d u l e s /
30
- ]
44
+ exclude
31
45
} ) ;
32
46
}
33
47
Original file line number Diff line number Diff line change 1
- import { expectFileToExist } from '../../utils/fs' ;
1
+ import { expectFileToExist , expectFileToMatch } from '../../utils/fs' ;
2
+ import { updateJsonFile } from '../../utils/project' ;
3
+ import { expectToFail } from '../../utils/utils' ;
2
4
import { ng } from '../../utils/process' ;
3
5
4
6
5
- export default function ( ) {
7
+ export default function ( ) {
6
8
return ng ( 'test' , '--single-run' , '--code-coverage' )
7
9
. then ( ( ) => expectFileToExist ( 'coverage/src/app' ) )
8
- . then ( ( ) => expectFileToExist ( 'coverage/lcov.info' ) ) ;
10
+ . then ( ( ) => expectFileToExist ( 'coverage/lcov.info' ) )
11
+ // Verify code coverage exclude work
12
+ . then ( ( ) => expectFileToMatch ( 'coverage/lcov.info' , 'polyfills.ts' ) )
13
+ . then ( ( ) => expectFileToMatch ( 'coverage/lcov.info' , 'test.ts' ) )
14
+ . then ( ( ) => updateJsonFile ( '.angular-cli.json' , configJson => {
15
+ const test = configJson [ 'test' ] ;
16
+ test [ 'codeCoverage' ] = {
17
+ exclude : [
18
+ 'src/polyfills.ts' ,
19
+ '**/test.ts'
20
+ ]
21
+ } ;
22
+ } ) )
23
+ . then ( ( ) => ng ( 'test' , '--single-run' , '--code-coverage' ) )
24
+ . then ( ( ) => expectToFail ( ( ) => expectFileToMatch ( 'coverage/lcov.info' , 'polyfills.ts' ) ) )
25
+ . then ( ( ) => expectToFail ( ( ) => expectFileToMatch ( 'coverage/lcov.info' , 'test.ts' ) ) ) ;
9
26
}
You can’t perform that action at this time.
0 commit comments