Skip to content

Commit

Permalink
test: remove unused code coverage infrastructure
Browse files Browse the repository at this point in the history
Closes angular#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.
  • Loading branch information
clydin authored and Keen Yee Liau committed Aug 8, 2019
1 parent d7b9650 commit 402349d
Show file tree
Hide file tree
Showing 7 changed files with 22 additions and 284 deletions.
17 changes: 6 additions & 11 deletions lib/README.md
Original file line number Diff line number Diff line change
@@ -1,16 +1,11 @@
# `/lib` Folder

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

`bootstrap-local.js` should be included when running files from this repository without compiling
first. It allows for compiling and loading packages in memory directly from the repo. Not only
does the `devkit-admin` scripts use this to include the library, but also all binaries linked
locally (like `schematics` and `ng`), when not using the npm published packages.

`istanbul-local.js` adds global hooks and information to be able to use code coverage with
`bootstrap-local.js`. Istanbul does not keep the sourcemaps properly in sync if they're available
in the code, which happens locally when transpiling TypeScript. It is currently used by the
`test` script and is included by `bootstrap-local.js` for integration.
first. It allows for compiling and loading packages in memory directly from the repo. Not only
does the `devkit-admin` scripts use this to include the library, but also all binaries linked
locally (like `schematics` and `ng`), when not using the npm published packages.
13 changes: 0 additions & 13 deletions lib/bootstrap-local.js
Original file line number Diff line number Diff line change
Expand Up @@ -30,16 +30,6 @@ const compilerOptions = ts.getParsedCommandLineOfConfigFile(
ts.sys,
).options;

let _istanbulRequireHook = null;
if (process.env['CODE_COVERAGE'] || process.argv.indexOf('--code-coverage') !== -1) {
debugLocal('setup code coverage');
_istanbulRequireHook = require('./istanbul-local').istanbulRequireHook;
// async keyword isn't supported by the Esprima version used by Istanbul version used by us.
// TODO: update istanbul to istanbul-lib-* (see http://istanbul.js.org/) and remove this hack.
compilerOptions.target = 'es2016';
}


// Check if we need to profile this CLI run.
let profiler = null;
if (process.env['DEVKIT_PROFILING']) {
Expand Down Expand Up @@ -103,9 +93,6 @@ require.extensions['.ts'] = function (m, filename) {
try {
let result = ts.transpile(source, compilerOptions, filename);

if (_istanbulRequireHook) {
result = _istanbulRequireHook(result, filename);
}
debugBuildTs('done');

// Send it to node to execute.
Expand Down
57 changes: 0 additions & 57 deletions lib/istanbul-local.js

This file was deleted.

5 changes: 1 addition & 4 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -94,15 +94,13 @@
"@types/express": "^4.16.0",
"@types/glob": "^7.0.0",
"@types/inquirer": "^0.0.44",
"@types/istanbul": "^0.4.30",
"@types/jasmine": "^3.3.8",
"@types/karma": "^3.0.2",
"@types/loader-utils": "^1.1.3",
"@types/minimist": "^1.2.0",
"@types/node": "10.9.4",
"@types/request": "^2.47.1",
"@types/semver": "^6.0.0",
"@types/source-map": "0.5.2",
"@types/webpack": "^4.4.11",
"@types/webpack-dev-server": "^3.1.0",
"@types/webpack-sources": "^0.1.5",
Expand All @@ -115,7 +113,6 @@
"gh-got": "^8.0.1",
"git-raw-commits": "^2.0.0",
"husky": "^1.3.1",
"istanbul": "^0.4.5",
"jasmine": "^3.3.1",
"jasmine-spec-reporter": "^4.2.1",
"karma": "~4.2.0",
Expand All @@ -131,7 +128,7 @@
"rxjs": "~6.4.0",
"sauce-connect": "https://saucelabs.com/downloads/sc-4.5.4-linux.tar.gz",
"semver": "6.3.0",
"source-map": "^0.5.6",
"source-map": "^0.7.3",
"source-map-support": "^0.5.0",
"spdx-satisfies": "^4.0.0",
"tar": "^4.4.4",
Expand Down
1 change: 0 additions & 1 deletion renovate.json
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@
"master"
],
"ignoreDeps": [
"source-map",
"@types/node",
"webpack-subresource-integrity"
],
Expand Down
89 changes: 0 additions & 89 deletions scripts/test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,16 +10,13 @@
import { logging } from '@angular-devkit/core';
import { spawnSync } from 'child_process';
import * as glob from 'glob';
import * as Istanbul from 'istanbul';
import 'jasmine';
import { SpecReporter as JasmineSpecReporter } from 'jasmine-spec-reporter';
import { ParsedArgs } from 'minimist';
import { join, normalize, relative } from 'path';
import { Position, SourceMapConsumer } from 'source-map';
import * as ts from 'typescript';
import { packages } from '../lib/packages';

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

const knownFlakes = [
Expand All @@ -33,16 +30,6 @@ require('source-map-support').install({
hookRequire: true,
});

interface CoverageLocation {
start: Position;
end: Position;
}

type CoverageType = any; // tslint:disable-line:no-any
declare const global: {
__coverage__: CoverageType;
};

function _exec(command: string, args: string[], opts: { cwd?: string }, logger: logging.Logger) {
const { status, error, stdout } = spawnSync(command, args, {
stdio: ['ignore', 'pipe', 'inherit'],
Expand All @@ -57,78 +44,6 @@ function _exec(command: string, args: string[], opts: { cwd?: string }, logger:
return stdout.toString('utf-8');
}

// Add the Istanbul (not Constantinople) reporter.
const istanbulCollector = new Istanbul.Collector({});
const istanbulReporter = new Istanbul.Reporter(undefined, 'coverage/');
istanbulReporter.addAll(['json', 'lcov']);

class IstanbulReporter implements jasmine.CustomReporter {
// Update a location object from a SourceMap. Will ignore the location if the sourcemap does
// not have a valid mapping.
private _updateLocation(consumer: SourceMapConsumer, location: CoverageLocation) {
const start = consumer.originalPositionFor(location.start);
const end = consumer.originalPositionFor(location.end);

// Filter invalid original positions.
if (start.line !== null && start.column !== null) {
// Filter unwanted properties.
location.start = { line: start.line, column: start.column };
}
if (end.line !== null && end.column !== null) {
location.end = { line: end.line, column: end.column };
}
}

private _updateCoverageJsonSourceMap(coverageJson: CoverageType) {
// Update the coverageJson with the SourceMap.
for (const path of Object.keys(coverageJson)) {
const entry = codeMap.get(path);
if (!entry) {
continue;
}

const consumer = entry.map;
const coverage = coverageJson[path];

// Update statement maps.
for (const branchId of Object.keys(coverage.branchMap)) {
const branch = coverage.branchMap[branchId];
let line: number | null = null;
let column = 0;
do {
line = consumer.originalPositionFor({ line: branch.line, column: column++ }).line;
} while (line === null && column < 100);

branch.line = line;

for (const location of branch.locations) {
this._updateLocation(consumer, location);
}
}

for (const id of Object.keys(coverage.statementMap)) {
const location = coverage.statementMap[id];
this._updateLocation(consumer, location);
}

for (const id of Object.keys(coverage.fnMap)) {
const fn = coverage.fnMap[id];
fn.line = consumer.originalPositionFor({ line: fn.line, column: 0 }).line;
this._updateLocation(consumer, fn.loc);
}
}
}

jasmineDone(_runDetails: jasmine.RunDetails): void {
if (global.__coverage__) {
this._updateCoverageJsonSourceMap(global.__coverage__);
istanbulCollector.add(global.__coverage__);

istanbulReporter.write(istanbulCollector, true, () => {});
}
}
}

// Create a Jasmine runner and configure it.
const runner = new Jasmine({ projectBaseDir: projectBaseDir });

Expand Down Expand Up @@ -174,10 +89,6 @@ export default function(args: ParsedArgs, logger: logging.Logger) {
const specGlob = args.large ? '*_spec_large.ts' : '*_spec.ts';
const regex = args.glob ? args.glob : `packages/**/${specGlob}`;

if (args['code-coverage']) {
runner.env.addReporter(new IstanbulReporter());
}

if (args.large) {
// Default timeout for large specs is 2.5 minutes.
jasmine.DEFAULT_TIMEOUT_INTERVAL = 150000;
Expand Down
Loading

0 comments on commit 402349d

Please sign in to comment.