10
10
import { logging } from '@angular-devkit/core' ;
11
11
import { spawnSync } from 'child_process' ;
12
12
import * as glob from 'glob' ;
13
- import * as Istanbul from 'istanbul' ;
14
13
import 'jasmine' ;
15
14
import { SpecReporter as JasmineSpecReporter } from 'jasmine-spec-reporter' ;
16
15
import { ParsedArgs } from 'minimist' ;
17
16
import { join , normalize , relative } from 'path' ;
18
- import { Position , SourceMapConsumer } from 'source-map' ;
19
17
import * as ts from 'typescript' ;
20
18
import { packages } from '../lib/packages' ;
21
19
22
- const codeMap = require ( '../lib/istanbul-local' ) . codeMap ;
23
20
const Jasmine = require ( 'jasmine' ) ;
24
21
25
22
const knownFlakes = [
@@ -33,16 +30,6 @@ require('source-map-support').install({
33
30
hookRequire : true ,
34
31
} ) ;
35
32
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
-
46
33
function _exec ( command : string , args : string [ ] , opts : { cwd ?: string } , logger : logging . Logger ) {
47
34
const { status, error, stdout } = spawnSync ( command , args , {
48
35
stdio : [ 'ignore' , 'pipe' , 'inherit' ] ,
@@ -57,78 +44,6 @@ function _exec(command: string, args: string[], opts: { cwd?: string }, logger:
57
44
return stdout . toString ( 'utf-8' ) ;
58
45
}
59
46
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
-
132
47
// Create a Jasmine runner and configure it.
133
48
const runner = new Jasmine ( { projectBaseDir : projectBaseDir } ) ;
134
49
@@ -174,10 +89,6 @@ export default function(args: ParsedArgs, logger: logging.Logger) {
174
89
const specGlob = args . large ? '*_spec_large.ts' : '*_spec.ts' ;
175
90
const regex = args . glob ? args . glob : `packages/**/${ specGlob } ` ;
176
91
177
- if ( args [ 'code-coverage' ] ) {
178
- runner . env . addReporter ( new IstanbulReporter ( ) ) ;
179
- }
180
-
181
92
if ( args . large ) {
182
93
// Default timeout for large specs is 2.5 minutes.
183
94
jasmine . DEFAULT_TIMEOUT_INTERVAL = 150000 ;
0 commit comments