-
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.
feat(@angular-devkit/build-angular): karma-coverage w/ app builder
- Loading branch information
Showing
13 changed files
with
127 additions
and
26 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
43 changes: 43 additions & 0 deletions
43
packages/angular/build/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); | ||
}, | ||
}, | ||
}, | ||
}; | ||
} |
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
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
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
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