Skip to content

Commit 402349d

Browse files
clydinKeen Yee Liau
authored and
Keen Yee Liau
committed
test: remove unused code coverage infrastructure
Closes #13228 It is currently unused and requires an old version of the `source-map` package. This old version conflicts with the use of newer versions that are required to provide the necessary functionality and performance within the published packages.
1 parent d7b9650 commit 402349d

File tree

7 files changed

+22
-284
lines changed

7 files changed

+22
-284
lines changed

lib/README.md

+6-11
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,11 @@
11
# `/lib` Folder
22

3-
This folder includes bootstrap code for the various tools included in this repository. Also
4-
included is the packages meta-information package in `packages.ts`. This is used to read and
5-
understand all the monorepo information (contained in the `.monorepo.json` file, and `package.json`
3+
This folder includes bootstrap code for the various tools included in this repository. Also
4+
included is the packages meta-information package in `packages.ts`. This is used to read and
5+
understand all the monorepo information (contained in the `.monorepo.json` file, and `package.json`
66
files across the repo).
77

88
`bootstrap-local.js` should be included when running files from this repository without compiling
9-
first. It allows for compiling and loading packages in memory directly from the repo. Not only
10-
does the `devkit-admin` scripts use this to include the library, but also all binaries linked
11-
locally (like `schematics` and `ng`), when not using the npm published packages.
12-
13-
`istanbul-local.js` adds global hooks and information to be able to use code coverage with
14-
`bootstrap-local.js`. Istanbul does not keep the sourcemaps properly in sync if they're available
15-
in the code, which happens locally when transpiling TypeScript. It is currently used by the
16-
`test` script and is included by `bootstrap-local.js` for integration.
9+
first. It allows for compiling and loading packages in memory directly from the repo. Not only
10+
does the `devkit-admin` scripts use this to include the library, but also all binaries linked
11+
locally (like `schematics` and `ng`), when not using the npm published packages.

lib/bootstrap-local.js

-13
Original file line numberDiff line numberDiff line change
@@ -30,16 +30,6 @@ const compilerOptions = ts.getParsedCommandLineOfConfigFile(
3030
ts.sys,
3131
).options;
3232

33-
let _istanbulRequireHook = null;
34-
if (process.env['CODE_COVERAGE'] || process.argv.indexOf('--code-coverage') !== -1) {
35-
debugLocal('setup code coverage');
36-
_istanbulRequireHook = require('./istanbul-local').istanbulRequireHook;
37-
// async keyword isn't supported by the Esprima version used by Istanbul version used by us.
38-
// TODO: update istanbul to istanbul-lib-* (see http://istanbul.js.org/) and remove this hack.
39-
compilerOptions.target = 'es2016';
40-
}
41-
42-
4333
// Check if we need to profile this CLI run.
4434
let profiler = null;
4535
if (process.env['DEVKIT_PROFILING']) {
@@ -103,9 +93,6 @@ require.extensions['.ts'] = function (m, filename) {
10393
try {
10494
let result = ts.transpile(source, compilerOptions, filename);
10595

106-
if (_istanbulRequireHook) {
107-
result = _istanbulRequireHook(result, filename);
108-
}
10996
debugBuildTs('done');
11097

11198
// Send it to node to execute.

lib/istanbul-local.js

-57
This file was deleted.

package.json

+1-4
Original file line numberDiff line numberDiff line change
@@ -94,15 +94,13 @@
9494
"@types/express": "^4.16.0",
9595
"@types/glob": "^7.0.0",
9696
"@types/inquirer": "^0.0.44",
97-
"@types/istanbul": "^0.4.30",
9897
"@types/jasmine": "^3.3.8",
9998
"@types/karma": "^3.0.2",
10099
"@types/loader-utils": "^1.1.3",
101100
"@types/minimist": "^1.2.0",
102101
"@types/node": "10.9.4",
103102
"@types/request": "^2.47.1",
104103
"@types/semver": "^6.0.0",
105-
"@types/source-map": "0.5.2",
106104
"@types/webpack": "^4.4.11",
107105
"@types/webpack-dev-server": "^3.1.0",
108106
"@types/webpack-sources": "^0.1.5",
@@ -115,7 +113,6 @@
115113
"gh-got": "^8.0.1",
116114
"git-raw-commits": "^2.0.0",
117115
"husky": "^1.3.1",
118-
"istanbul": "^0.4.5",
119116
"jasmine": "^3.3.1",
120117
"jasmine-spec-reporter": "^4.2.1",
121118
"karma": "~4.2.0",
@@ -131,7 +128,7 @@
131128
"rxjs": "~6.4.0",
132129
"sauce-connect": "https://saucelabs.com/downloads/sc-4.5.4-linux.tar.gz",
133130
"semver": "6.3.0",
134-
"source-map": "^0.5.6",
131+
"source-map": "^0.7.3",
135132
"source-map-support": "^0.5.0",
136133
"spdx-satisfies": "^4.0.0",
137134
"tar": "^4.4.4",

renovate.json

-1
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,6 @@
1818
"master"
1919
],
2020
"ignoreDeps": [
21-
"source-map",
2221
"@types/node",
2322
"webpack-subresource-integrity"
2423
],

scripts/test.ts

-89
Original file line numberDiff line numberDiff line change
@@ -10,16 +10,13 @@
1010
import { logging } from '@angular-devkit/core';
1111
import { spawnSync } from 'child_process';
1212
import * as glob from 'glob';
13-
import * as Istanbul from 'istanbul';
1413
import 'jasmine';
1514
import { SpecReporter as JasmineSpecReporter } from 'jasmine-spec-reporter';
1615
import { ParsedArgs } from 'minimist';
1716
import { join, normalize, relative } from 'path';
18-
import { Position, SourceMapConsumer } from 'source-map';
1917
import * as ts from 'typescript';
2018
import { packages } from '../lib/packages';
2119

22-
const codeMap = require('../lib/istanbul-local').codeMap;
2320
const Jasmine = require('jasmine');
2421

2522
const 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-
4633
function _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.
13348
const 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

Comments
 (0)