1010import { logging } from '@angular-devkit/core' ;
1111import { spawnSync } from 'child_process' ;
1212import * as glob from 'glob' ;
13- import * as Istanbul from 'istanbul' ;
1413import 'jasmine' ;
1514import { SpecReporter as JasmineSpecReporter } from 'jasmine-spec-reporter' ;
1615import { ParsedArgs } from 'minimist' ;
1716import { join , normalize , relative } from 'path' ;
18- import { Position , SourceMapConsumer } from 'source-map' ;
1917import * as ts from 'typescript' ;
2018import { packages } from '../lib/packages' ;
2119
22- const codeMap = require ( '../lib/istanbul-local' ) . codeMap ;
2320const Jasmine = require ( 'jasmine' ) ;
2421
2522const knownFlakes = [
@@ -33,16 +30,6 @@ require('source-map-support').install({
3330 hookRequire : true ,
3431} ) ;
3532
36- interface CoverageLocation {
37- start : Position ;
38- end : Position ;
39- }
40-
41- type CoverageType = any ; // tslint:disable-line:no-any
42- declare const global : {
43- __coverage__ : CoverageType ;
44- } ;
45-
4633function _exec ( command : string , args : string [ ] , opts : { cwd ?: string } , logger : logging . Logger ) {
4734 const { status, error, stdout } = spawnSync ( command , args , {
4835 stdio : [ 'ignore' , 'pipe' , 'inherit' ] ,
@@ -57,78 +44,6 @@ function _exec(command: string, args: string[], opts: { cwd?: string }, logger:
5744 return stdout . toString ( 'utf-8' ) ;
5845}
5946
60- // Add the Istanbul (not Constantinople) reporter.
61- const istanbulCollector = new Istanbul . Collector ( { } ) ;
62- const istanbulReporter = new Istanbul . Reporter ( undefined , 'coverage/' ) ;
63- istanbulReporter . addAll ( [ 'json' , 'lcov' ] ) ;
64-
65- class IstanbulReporter implements jasmine . CustomReporter {
66- // Update a location object from a SourceMap. Will ignore the location if the sourcemap does
67- // not have a valid mapping.
68- private _updateLocation ( consumer : SourceMapConsumer , location : CoverageLocation ) {
69- const start = consumer . originalPositionFor ( location . start ) ;
70- const end = consumer . originalPositionFor ( location . end ) ;
71-
72- // Filter invalid original positions.
73- if ( start . line !== null && start . column !== null ) {
74- // Filter unwanted properties.
75- location . start = { line : start . line , column : start . column } ;
76- }
77- if ( end . line !== null && end . column !== null ) {
78- location . end = { line : end . line , column : end . column } ;
79- }
80- }
81-
82- private _updateCoverageJsonSourceMap ( coverageJson : CoverageType ) {
83- // Update the coverageJson with the SourceMap.
84- for ( const path of Object . keys ( coverageJson ) ) {
85- const entry = codeMap . get ( path ) ;
86- if ( ! entry ) {
87- continue ;
88- }
89-
90- const consumer = entry . map ;
91- const coverage = coverageJson [ path ] ;
92-
93- // Update statement maps.
94- for ( const branchId of Object . keys ( coverage . branchMap ) ) {
95- const branch = coverage . branchMap [ branchId ] ;
96- let line : number | null = null ;
97- let column = 0 ;
98- do {
99- line = consumer . originalPositionFor ( { line : branch . line , column : column ++ } ) . line ;
100- } while ( line === null && column < 100 ) ;
101-
102- branch . line = line ;
103-
104- for ( const location of branch . locations ) {
105- this . _updateLocation ( consumer , location ) ;
106- }
107- }
108-
109- for ( const id of Object . keys ( coverage . statementMap ) ) {
110- const location = coverage . statementMap [ id ] ;
111- this . _updateLocation ( consumer , location ) ;
112- }
113-
114- for ( const id of Object . keys ( coverage . fnMap ) ) {
115- const fn = coverage . fnMap [ id ] ;
116- fn . line = consumer . originalPositionFor ( { line : fn . line , column : 0 } ) . line ;
117- this . _updateLocation ( consumer , fn . loc ) ;
118- }
119- }
120- }
121-
122- jasmineDone ( _runDetails : jasmine . RunDetails ) : void {
123- if ( global . __coverage__ ) {
124- this . _updateCoverageJsonSourceMap ( global . __coverage__ ) ;
125- istanbulCollector . add ( global . __coverage__ ) ;
126-
127- istanbulReporter . write ( istanbulCollector , true , ( ) => { } ) ;
128- }
129- }
130- }
131-
13247// Create a Jasmine runner and configure it.
13348const runner = new Jasmine ( { projectBaseDir : projectBaseDir } ) ;
13449
@@ -174,10 +89,6 @@ export default function(args: ParsedArgs, logger: logging.Logger) {
17489 const specGlob = args . large ? '*_spec_large.ts' : '*_spec.ts' ;
17590 const regex = args . glob ? args . glob : `packages/**/${ specGlob } ` ;
17691
177- if ( args [ 'code-coverage' ] ) {
178- runner . env . addReporter ( new IstanbulReporter ( ) ) ;
179- }
180-
18192 if ( args . large ) {
18293 // Default timeout for large specs is 2.5 minutes.
18394 jasmine . DEFAULT_TIMEOUT_INTERVAL = 150000 ;
0 commit comments