Skip to content

Commit aef6c8b

Browse files
committed
Add One Double Zero as coverage provider
1 parent 0a0a9f7 commit aef6c8b

File tree

10 files changed

+424
-15
lines changed

10 files changed

+424
-15
lines changed
Lines changed: 115 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,115 @@
1+
// Jest Snapshot v1, https://goo.gl/fbAQLP
2+
3+
exports[`prints correct coverage report, if a CJS module is put under test without transformation 1`] = `
4+
" console.log
5+
this will print
6+
7+
at covered (module.js:11:11)
8+
9+
--------------|---------|----------|---------|---------|-------------------
10+
File | % Stmts | % Branch | % Funcs | % Lines | Uncovered Line #s
11+
--------------|---------|----------|---------|---------|-------------------
12+
All files | 60 | 50 | 50 | 60 |
13+
module.js | 66.66 | 50 | 50 | 66.66 | 14-15,19
14+
uncovered.js | 0 | 100 | 100 | 0 | 8
15+
--------------|---------|----------|---------|---------|-------------------"
16+
`;
17+
18+
exports[`prints correct coverage report, if a TS module is transpiled by Babel to CJS and put under test 1`] = `
19+
" console.log
20+
this will print
21+
22+
at log (module.ts:13:11)
23+
24+
--------------|---------|----------|---------|---------|-------------------
25+
File | % Stmts | % Branch | % Funcs | % Lines | Uncovered Line #s
26+
--------------|---------|----------|---------|---------|-------------------
27+
All files | 62.5 | 50 | 50 | 62.5 |
28+
module.ts | 62.5 | 50 | 50 | 62.5 | 16-17,21
29+
types.ts | 0 | 0 | 0 | 0 |
30+
uncovered.ts | 0 | 0 | 0 | 0 |
31+
--------------|---------|----------|---------|---------|-------------------"
32+
`;
33+
34+
exports[`prints correct coverage report, if a TS module is transpiled by custom transformer to ESM put under test 1`] = `
35+
" console.log
36+
this will print
37+
38+
at covered (module.ts:13:11)
39+
40+
--------------|---------|----------|---------|---------|-------------------
41+
File | % Stmts | % Branch | % Funcs | % Lines | Uncovered Line #s
42+
--------------|---------|----------|---------|---------|-------------------
43+
All files | 62.5 | 50 | 50 | 62.5 |
44+
module.ts | 62.5 | 50 | 50 | 62.5 | 16-17,21
45+
types.ts | 0 | 0 | 0 | 0 |
46+
uncovered.ts | 0 | 0 | 0 | 0 |
47+
--------------|---------|----------|---------|---------|-------------------"
48+
`;
49+
50+
exports[`prints correct coverage report, if an ESM module is put under test without transformation 1`] = `
51+
" console.log
52+
this will print
53+
54+
at covered (module.js:11:11)
55+
56+
--------------|---------|----------|---------|---------|-------------------
57+
File | % Stmts | % Branch | % Funcs | % Lines | Uncovered Line #s
58+
--------------|---------|----------|---------|---------|-------------------
59+
All files | 62.5 | 50 | 50 | 62.5 |
60+
module.js | 62.5 | 50 | 50 | 62.5 | 14-15,19
61+
uncovered.js | 0 | 0 | 0 | 0 |
62+
--------------|---------|----------|---------|---------|-------------------"
63+
`;
64+
65+
exports[`prints coverage with empty sourcemaps 1`] = `
66+
"----------|---------|----------|---------|---------|-------------------
67+
File | % Stmts | % Branch | % Funcs | % Lines | Uncovered Line #s
68+
----------|---------|----------|---------|---------|-------------------
69+
All files | 0 | 0 | 0 | 0 |
70+
----------|---------|----------|---------|---------|-------------------"
71+
`;
72+
73+
exports[`prints coverage with missing sourcemaps 1`] = `
74+
" console.log
75+
42
76+
77+
at Object.log (__tests__/Thing.test.js:10:9)
78+
79+
----------|---------|----------|---------|---------|-------------------
80+
File | % Stmts | % Branch | % Funcs | % Lines | Uncovered Line #s
81+
----------|---------|----------|---------|---------|-------------------
82+
All files | 100 | 100 | 100 | 100 |
83+
Thing.js | 100 | 100 | 100 | 100 |
84+
x.css | 0 | 0 | 0 | 0 |
85+
----------|---------|----------|---------|---------|-------------------"
86+
`;
87+
88+
exports[`reports coverage with \`resetModules\` 1`] = `
89+
" console.log
90+
this will print
91+
92+
at log (module.js:11:11)
93+
94+
console.log
95+
this will print
96+
97+
at log (module.js:11:11)
98+
99+
--------------|---------|----------|---------|---------|-------------------
100+
File | % Stmts | % Branch | % Funcs | % Lines | Uncovered Line #s
101+
--------------|---------|----------|---------|---------|-------------------
102+
All files | 60 | 50 | 50 | 60 |
103+
module.js | 66.66 | 50 | 50 | 66.66 | 14-15,19
104+
uncovered.js | 0 | 100 | 100 | 0 | 8
105+
--------------|---------|----------|---------|---------|-------------------"
106+
`;
107+
108+
exports[`vm script coverage generator 1`] = `
109+
"-------------|---------|----------|---------|---------|-------------------
110+
File | % Stmts | % Branch | % Funcs | % Lines | Uncovered Line #s
111+
-------------|---------|----------|---------|---------|-------------------
112+
All files | 80 | 75 | 66.66 | 80 |
113+
vmscript.js | 80 | 75 | 66.66 | 80 | 20-21
114+
-------------|---------|----------|---------|---------|-------------------"
115+
`;
Lines changed: 120 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,120 @@
1+
/**
2+
* Copyright (c) Meta Platforms, Inc. and affiliates.
3+
*
4+
* This source code is licensed under the MIT license found in the
5+
* LICENSE file in the root directory of this source tree.
6+
*/
7+
8+
import * as path from 'path';
9+
import runJest from '../runJest';
10+
11+
const DIR = path.resolve(__dirname, '../coverage-provider-v8');
12+
13+
test('prints coverage with missing sourcemaps', () => {
14+
const sourcemapDir = path.join(DIR, 'no-sourcemap');
15+
16+
const {stdout, exitCode} = runJest(
17+
sourcemapDir,
18+
['--coverage', '--coverage-provider', 'odz'],
19+
{stripAnsi: true},
20+
);
21+
22+
expect(exitCode).toBe(0);
23+
expect(stdout).toMatchSnapshot();
24+
});
25+
26+
test('prints coverage with empty sourcemaps', () => {
27+
const sourcemapDir = path.join(DIR, 'empty-sourcemap');
28+
29+
const {stdout, exitCode} = runJest(
30+
sourcemapDir,
31+
['--coverage', '--coverage-provider', 'odz'],
32+
{stripAnsi: true},
33+
);
34+
35+
expect(exitCode).toBe(0);
36+
expect(stdout).toMatchSnapshot();
37+
});
38+
39+
test('reports coverage with `resetModules`', () => {
40+
const sourcemapDir = path.join(DIR, 'with-resetModules');
41+
42+
const {stdout, exitCode} = runJest(
43+
sourcemapDir,
44+
['--coverage', '--coverage-provider', 'odz'],
45+
{stripAnsi: true},
46+
);
47+
48+
expect(exitCode).toBe(0);
49+
expect(stdout).toMatchSnapshot();
50+
});
51+
52+
test('prints correct coverage report, if a CJS module is put under test without transformation', () => {
53+
const sourcemapDir = path.join(DIR, 'cjs-native-without-sourcemap');
54+
55+
const {stdout, exitCode} = runJest(
56+
sourcemapDir,
57+
['--coverage', '--coverage-provider', 'odz', '--no-cache'],
58+
{stripAnsi: true},
59+
);
60+
61+
expect(exitCode).toBe(0);
62+
expect(stdout).toMatchSnapshot();
63+
});
64+
65+
test('prints correct coverage report, if a TS module is transpiled by Babel to CJS and put under test', () => {
66+
const sourcemapDir = path.join(DIR, 'cjs-with-babel-transformer');
67+
68+
const {stdout, exitCode} = runJest(
69+
sourcemapDir,
70+
['--coverage', '--coverage-provider', 'odz', '--no-cache'],
71+
{stripAnsi: true},
72+
);
73+
74+
expect(exitCode).toBe(0);
75+
expect(stdout).toMatchSnapshot();
76+
});
77+
78+
test('prints correct coverage report, if an ESM module is put under test without transformation', () => {
79+
const sourcemapDir = path.join(DIR, 'esm-native-without-sourcemap');
80+
81+
const {stdout, exitCode} = runJest(
82+
sourcemapDir,
83+
['--coverage', '--coverage-provider', 'odz', '--no-cache'],
84+
{
85+
nodeOptions: '--experimental-vm-modules --no-warnings',
86+
stripAnsi: true,
87+
},
88+
);
89+
90+
expect(exitCode).toBe(0);
91+
expect(stdout).toMatchSnapshot();
92+
});
93+
94+
test('prints correct coverage report, if a TS module is transpiled by custom transformer to ESM put under test', () => {
95+
const sourcemapDir = path.join(DIR, 'esm-with-custom-transformer');
96+
97+
const {stdout, exitCode} = runJest(
98+
sourcemapDir,
99+
['--coverage', '--coverage-provider', 'odz', '--no-cache'],
100+
{
101+
nodeOptions: '--experimental-vm-modules --no-warnings',
102+
stripAnsi: true,
103+
},
104+
);
105+
106+
expect(exitCode).toBe(0);
107+
expect(stdout).toMatchSnapshot();
108+
});
109+
110+
test('vm script coverage generator', () => {
111+
const dir = path.resolve(__dirname, '../vmscript-coverage');
112+
const {stdout, exitCode} = runJest(
113+
dir,
114+
['--coverage', '--coverage-provider', 'odz'],
115+
{stripAnsi: true},
116+
);
117+
118+
expect(exitCode).toBe(0);
119+
expect(stdout).toMatchSnapshot();
120+
});

e2e/coverage-provider-v8/no-sourcemap/package.json

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,10 @@
66
"transform": {
77
"\\.[jt]sx?$": "babel-jest",
88
"\\.css$": "<rootDir>/cssTransform.js"
9-
}
9+
},
10+
"collectCoverageFrom": [
11+
"<rootDir>/Thing.js",
12+
"<rootDir>/x.css"
13+
]
1014
}
1115
}

package.json

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -204,5 +204,8 @@
204204
"psl": "patch:psl@npm:^1.9.0#./.yarn/patches/psl-npm-1.9.0-a546edad1a.patch",
205205
"ts-node@^10.5.0": "patch:ts-node@npm:^10.5.0#./.yarn/patches/ts-node-npm-10.9.1-6c268be7f4.patch"
206206
},
207-
"packageManager": "[email protected]"
207+
"packageManager": "[email protected]",
208+
"dependencies": {
209+
"one-double-zero": "1.0.0-beta.12"
210+
}
208211
}

packages/jest-cli/src/args.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -213,8 +213,8 @@ export const options: {[key: string]: Options} = {
213213
type: 'array',
214214
},
215215
coverageProvider: {
216-
choices: ['babel', 'v8'],
217-
description: 'Select between Babel and V8 to collect coverage',
216+
choices: ['babel', 'v8', 'odz'],
217+
description: 'Select between Babel, V8 and One Double Zero to collect coverage',
218218
requiresArg: true,
219219
},
220220
coverageReporters: {

0 commit comments

Comments
 (0)