-
Notifications
You must be signed in to change notification settings - Fork 12k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix(@angular-devkit/build-angular): use istanbul-lib-instrument direc…
…tly for karma code coverage The `istanbul-lib-instrument` package provides the required functionality needed to instrument code for test coverage within the context of the Angular CLI. Since the build pipeline already contains a customized babel preset, this package can be integrated directly into the pipeline. This reduces the number of dependencies required for `@angular-devkit/build-angular` including the deprecated `inflight` package. (cherry picked from commit fb2981d)
- Loading branch information
1 parent
bdd168f
commit 86e031d
Showing
7 changed files
with
271 additions
and
60 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
43 changes: 43 additions & 0 deletions
43
packages/angular_devkit/build_angular/src/tools/babel/plugins/add-code-coverage.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
/** | ||
* @license | ||
* Copyright Google LLC All Rights Reserved. | ||
* | ||
* Use of this source code is governed by an MIT-style license that can be | ||
* found in the LICENSE file at https://angular.dev/license | ||
*/ | ||
|
||
import { NodePath, PluginObj, types } from '@babel/core'; | ||
import { Visitor, programVisitor } from 'istanbul-lib-instrument'; | ||
import assert from 'node:assert'; | ||
|
||
/** | ||
* A babel plugin factory function for adding istanbul instrumentation. | ||
* | ||
* @returns A babel plugin object instance. | ||
*/ | ||
export default function (): PluginObj { | ||
const visitors = new WeakMap<NodePath, Visitor>(); | ||
|
||
return { | ||
visitor: { | ||
Program: { | ||
enter(path, state) { | ||
const visitor = programVisitor(types, state.filename, { | ||
// Babel returns a Converter object from the `convert-source-map` package | ||
inputSourceMap: (state.file.inputMap as undefined | { toObject(): object })?.toObject(), | ||
}); | ||
visitors.set(path, visitor); | ||
|
||
visitor.enter(path); | ||
}, | ||
exit(path) { | ||
const visitor = visitors.get(path); | ||
assert(visitor, 'Instrumentation visitor should always be present for program path.'); | ||
|
||
visitor.exit(path); | ||
visitors.delete(path); | ||
}, | ||
}, | ||
}, | ||
}; | ||
} |
20 changes: 20 additions & 0 deletions
20
packages/angular_devkit/build_angular/src/tools/babel/plugins/types.d.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
/** | ||
* @license | ||
* Copyright Google LLC All Rights Reserved. | ||
* | ||
* Use of this source code is governed by an MIT-style license that can be | ||
* found in the LICENSE file at https://angular.dev/license | ||
*/ | ||
|
||
declare module 'istanbul-lib-instrument' { | ||
export interface Visitor { | ||
enter(path: import('@babel/core').NodePath<types.Program>): void; | ||
exit(path: import('@babel/core').NodePath<types.Program>): void; | ||
} | ||
|
||
export function programVisitor( | ||
types: typeof import('@babel/core').types, | ||
filePath?: string, | ||
options?: { inputSourceMap?: object | null }, | ||
): Visitor; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.