From 76cb9c2a39d477a64824a985ade40507e3bbade1 Mon Sep 17 00:00:00 2001 From: Adam Mathes Date: Fri, 13 Feb 2026 21:34:48 -0800 Subject: feat(vanilla): add testing infrastructure and tests (NK-wjnczv) --- vanilla/node_modules/ast-v8-to-istanbul/LICENSE | 21 + vanilla/node_modules/ast-v8-to-istanbul/README.md | 278 +++++++ .../ast-v8-to-istanbul/dist/index.d.mts | 568 ++++++++++++++ .../node_modules/ast-v8-to-istanbul/dist/index.mjs | 848 +++++++++++++++++++++ .../node_modules/ast-v8-to-istanbul/package.json | 71 ++ 5 files changed, 1786 insertions(+) create mode 100644 vanilla/node_modules/ast-v8-to-istanbul/LICENSE create mode 100644 vanilla/node_modules/ast-v8-to-istanbul/README.md create mode 100644 vanilla/node_modules/ast-v8-to-istanbul/dist/index.d.mts create mode 100644 vanilla/node_modules/ast-v8-to-istanbul/dist/index.mjs create mode 100644 vanilla/node_modules/ast-v8-to-istanbul/package.json (limited to 'vanilla/node_modules/ast-v8-to-istanbul') diff --git a/vanilla/node_modules/ast-v8-to-istanbul/LICENSE b/vanilla/node_modules/ast-v8-to-istanbul/LICENSE new file mode 100644 index 0000000..073bd2a --- /dev/null +++ b/vanilla/node_modules/ast-v8-to-istanbul/LICENSE @@ -0,0 +1,21 @@ +MIT License + +Copyright (c) 2026 Ari Perkkiö + +Permission is hereby granted, free of charge, to any person obtaining a copy +of this software and associated documentation files (the "Software"), to deal +in the Software without restriction, including without limitation the rights +to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +copies of the Software, and to permit persons to whom the Software is +furnished to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in all +copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +SOFTWARE. diff --git a/vanilla/node_modules/ast-v8-to-istanbul/README.md b/vanilla/node_modules/ast-v8-to-istanbul/README.md new file mode 100644 index 0000000..e4aa256 --- /dev/null +++ b/vanilla/node_modules/ast-v8-to-istanbul/README.md @@ -0,0 +1,278 @@ +# `ast-v8-to-istanbul` + +[![Version][version-badge]][npm-url] +[![Downloads][downloads-url]][npm-url] + +> - Speed of V8 coverage 🏎 +> - Accuracy of Istanbul coverage 🔍 + +[Ignoring code](#ignoring-code) | [Source maps](#source-maps) | [Istanbul Compatibility](#istanbul-compatibility) | [Limitations](#limitations) + +--- + +AST-aware [`v8-to-istanbul`](https://www.npmjs.com/package/v8-to-istanbul). + +Unopinionated - _bring-your-own_ AST parser and source maps. + +Passes all 195 tests[*](#istanbul-compatibility) of [`istanbul-lib-instrument`](https://github.com/istanbuljs/istanbuljs/tree/main/packages/istanbul-lib-instrument/test/specs). ✅ + +Test cases run against: +- `vite/parseAst` ✅ +- `acorn` ✅ +- `oxc-parser` ✅ +- `@babel/parser` ✅ + +See example report at https://ariperkkio.github.io/ast-v8-to-istanbul. + +```ts +import { convert } from "ast-v8-to-istanbul"; +import { parseAstAsync } from "vite"; +import type { CoverageMapData } from "istanbul-lib-coverage"; + +const data: CoverageMapData = await convert({ + // Bring-your-own AST parser + ast: parseAstAsync(), + + // Code of the executed file (not the source file) + code: "function sum(a, b) {\n return a + b ...", + + // Execution wrapper offset + wrapperLength: 0, + + // Script coverage of the executed file + coverage: { + scriptId: "123", + url: "file:///absolute/path/to/dist/index.js", + functions: [ + { + functionName: "sum", + ranges: [{ startOffset: 223, endOffset: 261, count: 0 }], + isBlockCoverage: false, + }, + // ... etc + ], + }, + + // Source map of the executed file + sourceMap: { + version: 3, + sources: ["../sources.ts"], + sourcesContent: ["export function sum(a: number, b: number) {\n..."], + mappings: ";AAAO,SAAS,...", + names: [], + }, +}); +``` + +## Ignoring code + +### Ignoring source code + +#### Ignore hints + +See live example at https://ariperkkio.github.io/ast-v8-to-istanbul/ignore-examples.html. + +The typical ignore hints from `nyc` are supported: https://github.com/istanbuljs/nyc?tab=readme-ov-file#parsing-hints-ignoring-lines: + +> * `/* istanbul ignore if */`: ignore the next if statement. +> * `/* istanbul ignore else */`: ignore the else portion of an if statement. +> * `/* istanbul ignore next */`: ignore the next _thing_ in the source-code (functions, if statements, classes, you name it). +> * `/* istanbul ignore file */`: ignore an entire source-file (this should be placed at the top of the file). + +In addition to `istanbul` keyword, you can use `v8`, `c8` and `node:coverage`: + +- `/* istanbul ignore if */` +- `/* v8 ignore else */` +- `/* c8 ignore file */` +- `/* node:coverage ignore next */` + +Also `start` and `stop` ignore hints from original [`v8-to-istanbul`](https://www.npmjs.com/package/v8-to-istanbul) are supported. +These ignore hints are checked from the original sources instead of transpiled code. + +> * `/* v8 ignore start */`: start ignoring lines +> * `/* v8 ignore stop */`: stop ignoring lines +> * ``: start ignoring lines +> * ``: stop ignoring lines +> * `anything /* v8 ignore start */ anything`: start ignoring lines +> * `anything /* v8 ignore stop */ anything`: stop ignoring lines + +#### Class methods + +The `ignore-class-method` from `nyc` is also supported: https://github.com/istanbuljs/nyc?tab=readme-ov-file#ignoring-methods + +> You can ignore every instance of a method simply by adding its name to the `ignore-class-method` array in your `nyc` config. + +```ts +import { convert } from "ast-v8-to-istanbul"; + +await convert({ + ignoreClassMethods: ['render'] +}); +``` + +#### Ignore after remapping + +You can ignore source code after coverage results have been remapped back to original sources using `ignoreSourceCode`. +This is a high level API that can be exposed to end-users by tooling developers. + +It's mostly intended for excluding code that is incorrectly shown in coverage report when compilers add generated code in the source maps. + +Note that as the exclusion happens after remapping, this option is slower than [`ignoreNode`](#ignoring-generated-code) option. + +```ts +function ignoreSourceCode( + code: string, + type: "function" | "statement" | "branch", + location: Record<"start" | "end", { line: number; column: number }>, +): boolean | void; +``` + +```ts +import { convert } from "ast-v8-to-istanbul"; + +await convert({ + ignoreSourceCode: (code, type, location) => { + // Ignore all "noop()" calls + if(type === "function" && code.includes("noop(")) { + return true; + } + + // In Vue "