File tree Expand file tree Collapse file tree 3 files changed +57
-12
lines changed
Expand file tree Collapse file tree 3 files changed +57
-12
lines changed Original file line number Diff line number Diff line change 3232 "name" : {
3333 "type" : " string" ,
3434 "description" : " Name of the app."
35- },
35+ },
3636 "root" : {
3737 "type" : " string" ,
3838 "description" : " The root directory of the app."
270270 }
271271 },
272272 "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
273287 }
274288 },
275289 "additionalProperties" : false
435449 "description" : " The host the application will be served on" ,
436450 "type" : " string" ,
437451 "default" : " localhost"
438-
452+
439453 },
440454 "ssl" : {
441455 "description" : " Enables ssl for the application" ,
442456 "type" : " boolean" ,
443457 "default" : false
444-
458+
445459 },
446460 "sslKey" : {
447461 "description" : " The ssl key used by the server" ,
448462 "type" : " string" ,
449463 "default" : " ssl/server.key"
450-
464+
451465 },
452466 "sslCert" : {
453467 "description" : " The ssl certificate used by the server" ,
Original file line number Diff line number Diff line change 11import * as path from 'path' ;
2+ import * as glob from 'glob' ;
23import * as webpack from 'webpack' ;
34
45import { CliConfig } from '../config' ;
@@ -20,14 +21,27 @@ export function getTestConfig(testConfig: WebpackTestOptions) {
2021 const appConfig = CliConfig . fromProject ( ) . config . apps [ 0 ] ;
2122 const extraRules : any [ ] = [ ] ;
2223
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+
2441 extraRules . push ( {
2542 test : / \. ( j s | t s ) $ / , loader : 'istanbul-instrumenter-loader' ,
2643 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
3145 } ) ;
3246 }
3347
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' ;
24import { ng } from '../../utils/process' ;
35
46
5- export default function ( ) {
7+ export default function ( ) {
68 return ng ( 'test' , '--single-run' , '--code-coverage' )
79 . 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' ) ) ) ;
926}
You can’t perform that action at this time.
0 commit comments