oxc-coverage-instrument 0.2.13 → 0.2.15
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/package.json +22 -10
- package/vitest.d.ts +39 -0
- package/vitest.js +72 -0
package/package.json
CHANGED
|
@@ -1,12 +1,24 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "oxc-coverage-instrument",
|
|
3
|
-
"version": "0.2.
|
|
4
|
-
"description": "Istanbul-compatible JavaScript/TypeScript coverage instrumentation using the Oxc AST.
|
|
3
|
+
"version": "0.2.15",
|
|
4
|
+
"description": "Istanbul-compatible JavaScript/TypeScript coverage instrumentation using the Oxc AST. 8-48x faster than istanbul-lib-instrument.",
|
|
5
5
|
"main": "index.js",
|
|
6
6
|
"types": "index.d.ts",
|
|
7
|
+
"exports": {
|
|
8
|
+
".": {
|
|
9
|
+
"types": "./index.d.ts",
|
|
10
|
+
"default": "./index.js"
|
|
11
|
+
},
|
|
12
|
+
"./vitest": {
|
|
13
|
+
"types": "./vitest.d.ts",
|
|
14
|
+
"default": "./vitest.js"
|
|
15
|
+
}
|
|
16
|
+
},
|
|
7
17
|
"files": [
|
|
8
18
|
"index.js",
|
|
9
|
-
"index.d.ts"
|
|
19
|
+
"index.d.ts",
|
|
20
|
+
"vitest.js",
|
|
21
|
+
"vitest.d.ts"
|
|
10
22
|
],
|
|
11
23
|
"keywords": [
|
|
12
24
|
"oxc",
|
|
@@ -49,12 +61,12 @@
|
|
|
49
61
|
"test": "node test.mjs"
|
|
50
62
|
},
|
|
51
63
|
"optionalDependencies": {
|
|
52
|
-
"@oxc-coverage-instrument/binding-darwin-arm64": "0.2.
|
|
53
|
-
"@oxc-coverage-instrument/binding-darwin-x64": "0.2.
|
|
54
|
-
"@oxc-coverage-instrument/binding-linux-x64-gnu": "0.2.
|
|
55
|
-
"@oxc-coverage-instrument/binding-linux-arm64-gnu": "0.2.
|
|
56
|
-
"@oxc-coverage-instrument/binding-linux-x64-musl": "0.2.
|
|
57
|
-
"@oxc-coverage-instrument/binding-win32-x64-msvc": "0.2.
|
|
58
|
-
"@oxc-coverage-instrument/binding-win32-arm64-msvc": "0.2.
|
|
64
|
+
"@oxc-coverage-instrument/binding-darwin-arm64": "0.2.15",
|
|
65
|
+
"@oxc-coverage-instrument/binding-darwin-x64": "0.2.15",
|
|
66
|
+
"@oxc-coverage-instrument/binding-linux-x64-gnu": "0.2.15",
|
|
67
|
+
"@oxc-coverage-instrument/binding-linux-arm64-gnu": "0.2.15",
|
|
68
|
+
"@oxc-coverage-instrument/binding-linux-x64-musl": "0.2.15",
|
|
69
|
+
"@oxc-coverage-instrument/binding-win32-x64-msvc": "0.2.15",
|
|
70
|
+
"@oxc-coverage-instrument/binding-win32-arm64-msvc": "0.2.15"
|
|
59
71
|
}
|
|
60
72
|
}
|
package/vitest.d.ts
ADDED
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Options for creating an Oxc-based coverage instrumenter.
|
|
3
|
+
*
|
|
4
|
+
* When used with Vitest's `coverage.instrumenter` option, the factory receives
|
|
5
|
+
* `InstrumenterOptions` with `coverageVariable` and `ignoreClassMethods`.
|
|
6
|
+
*/
|
|
7
|
+
export interface OxcInstrumenterOptions {
|
|
8
|
+
/** Global variable name for coverage data (Vitest passes `__VITEST_COVERAGE__`). */
|
|
9
|
+
coverageVariable?: string
|
|
10
|
+
/** Class method names to exclude from function coverage. */
|
|
11
|
+
ignoreClassMethods?: string[]
|
|
12
|
+
/** When true, adds truthy-value tracking (bT) for logical expressions. */
|
|
13
|
+
reportLogic?: boolean
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
/**
|
|
17
|
+
* Creates an instrumenter that implements the istanbul-lib-instrument
|
|
18
|
+
* Instrumenter interface, backed by oxc-coverage-instrument.
|
|
19
|
+
*
|
|
20
|
+
* @example
|
|
21
|
+
* ```ts
|
|
22
|
+
* import { defineConfig } from 'vitest/config'
|
|
23
|
+
* import { createOxcInstrumenter } from 'oxc-coverage-instrument/vitest'
|
|
24
|
+
*
|
|
25
|
+
* export default defineConfig({
|
|
26
|
+
* test: {
|
|
27
|
+
* coverage: {
|
|
28
|
+
* provider: 'istanbul',
|
|
29
|
+
* instrumenter: (options) => createOxcInstrumenter(options),
|
|
30
|
+
* }
|
|
31
|
+
* }
|
|
32
|
+
* })
|
|
33
|
+
* ```
|
|
34
|
+
*/
|
|
35
|
+
export declare function createOxcInstrumenter(options?: OxcInstrumenterOptions): {
|
|
36
|
+
instrumentSync(code: string, filename: string, inputSourceMap?: any): string
|
|
37
|
+
lastSourceMap(): any
|
|
38
|
+
lastFileCoverage(): any
|
|
39
|
+
}
|
package/vitest.js
ADDED
|
@@ -0,0 +1,72 @@
|
|
|
1
|
+
// Vitest Istanbul instrumenter adapter for oxc-coverage-instrument.
|
|
2
|
+
//
|
|
3
|
+
// Implements the istanbul-lib-instrument Instrumenter interface so it can be
|
|
4
|
+
// used as a drop-in replacement in @vitest/coverage-istanbul.
|
|
5
|
+
//
|
|
6
|
+
// Usage in vitest.config.ts:
|
|
7
|
+
//
|
|
8
|
+
// import { defineConfig } from 'vitest/config'
|
|
9
|
+
// import { createOxcInstrumenter } from 'oxc-coverage-instrument/vitest'
|
|
10
|
+
//
|
|
11
|
+
// export default defineConfig({
|
|
12
|
+
// test: {
|
|
13
|
+
// coverage: {
|
|
14
|
+
// provider: 'istanbul',
|
|
15
|
+
// instrumenter: (options) => createOxcInstrumenter(options),
|
|
16
|
+
// }
|
|
17
|
+
// }
|
|
18
|
+
// })
|
|
19
|
+
|
|
20
|
+
const { instrument } = require('./index.js');
|
|
21
|
+
|
|
22
|
+
/**
|
|
23
|
+
* Creates an instrumenter that implements the istanbul-lib-instrument
|
|
24
|
+
* Instrumenter interface, backed by oxc-coverage-instrument.
|
|
25
|
+
*
|
|
26
|
+
* When used with Vitest's `coverage.instrumenter` option, the factory receives
|
|
27
|
+
* `InstrumenterOptions` with `coverageVariable` and `ignoreClassMethods`.
|
|
28
|
+
* These are forwarded to the native instrumenter automatically.
|
|
29
|
+
*
|
|
30
|
+
* @param {object} [options]
|
|
31
|
+
* @param {string} [options.coverageVariable] - Global variable for coverage data.
|
|
32
|
+
* Vitest passes its internal `__VITEST_COVERAGE__`; defaults to `__coverage__`.
|
|
33
|
+
* @param {string[]} [options.ignoreClassMethods] - Class methods to skip.
|
|
34
|
+
* @param {boolean} [options.reportLogic] - Enable truthy-value tracking (bT).
|
|
35
|
+
* @returns {{ instrumentSync, lastSourceMap, lastFileCoverage }}
|
|
36
|
+
*/
|
|
37
|
+
function createOxcInstrumenter(options) {
|
|
38
|
+
options = options || {};
|
|
39
|
+
const coverageVariable = options.coverageVariable || '__coverage__';
|
|
40
|
+
const ignoreClassMethods = options.ignoreClassMethods || [];
|
|
41
|
+
const reportLogic = options.reportLogic || false;
|
|
42
|
+
|
|
43
|
+
let _lastSourceMap = null;
|
|
44
|
+
let _lastFileCoverage = null;
|
|
45
|
+
|
|
46
|
+
return {
|
|
47
|
+
instrumentSync(code, filename, inputSourceMap) {
|
|
48
|
+
const result = instrument(code, filename, {
|
|
49
|
+
coverageVariable,
|
|
50
|
+
sourceMap: true,
|
|
51
|
+
inputSourceMap: inputSourceMap ? JSON.stringify(inputSourceMap) : undefined,
|
|
52
|
+
reportLogic,
|
|
53
|
+
ignoreClassMethods,
|
|
54
|
+
});
|
|
55
|
+
|
|
56
|
+
_lastFileCoverage = JSON.parse(result.coverageMap);
|
|
57
|
+
_lastSourceMap = result.sourceMap ? JSON.parse(result.sourceMap) : null;
|
|
58
|
+
|
|
59
|
+
return result.code;
|
|
60
|
+
},
|
|
61
|
+
|
|
62
|
+
lastSourceMap() {
|
|
63
|
+
return _lastSourceMap;
|
|
64
|
+
},
|
|
65
|
+
|
|
66
|
+
lastFileCoverage() {
|
|
67
|
+
return _lastFileCoverage;
|
|
68
|
+
},
|
|
69
|
+
};
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
module.exports = { createOxcInstrumenter };
|