Skip to content

Commit

Permalink
Replace one-double-zero with one-double-zero-core
Browse files Browse the repository at this point in the history
one-double-zero-core embarks its own lightweight parser, instead of
depending on the gigantic TypeScript package.
  • Loading branch information
ericmorand committed Jan 22, 2025
1 parent cf49e94 commit c575d8d
Show file tree
Hide file tree
Showing 4 changed files with 75 additions and 3 deletions.
2 changes: 1 addition & 1 deletion packages/jest-reporters/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@
"jest-message-util": "workspace:*",
"jest-util": "workspace:*",
"jest-worker": "workspace:*",
"one-double-zero": "1.0.0-beta.14",
"one-double-zero-core": "^1.0.0-alpha.0",
"slash": "^3.0.0",
"string-length": "^4.0.1",
"strip-ansi": "^6.0.0",
Expand Down
2 changes: 1 addition & 1 deletion packages/jest-reporters/src/CoverageReporter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ import {
type ProcessCoverage,
type SourceMap,
createOneDoubleZero,
} from 'one-double-zero';
} from 'one-double-zero-core';
import v8toIstanbul = require('v8-to-istanbul');
import type {
AggregatedResult,
Expand Down
61 changes: 61 additions & 0 deletions packages/jest-reporters/src/__tests__/CoverageReporter.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ beforeEach(() => {
},
'non_covered_file.js': '',
'relative_path_file.js': '',
'statement.js': 'const foo = 5;',
};
fileTree[`${process.cwd()}/path-test`] = {
'100pc_coverage_file.js': '',
Expand Down Expand Up @@ -448,4 +449,64 @@ describe('onRunComplete', () => {
expect(testReporter.getLastError()).toBeUndefined();
});
});

test('getLastError() returns an error when threshold is not met for global (odz)', () => {
const testReporter = new CoverageReporter({
collectCoverage: true,
coverageProvider: 'odz',
coverageThreshold: {
global: {
statements: 100,
},
},
});
/**
* @type {Array<V8CoverageResult>}
*/
const v8CoverageResults = [
[
{
codeTransformResult: {
code: 'const foo = 5;',
originalCode: 'const foo = 5;',
sourceMapPath: '',
wrapperLength: 0,
},
result: {
functions: [
{
functionName: '',
isBlockCoverage: true,
ranges: [
{
count: 0,
endOffset: 14,
startOffset: 0,
},
],
},
],
url: 'path-test-files/statement.js',
},
},
],
];

testReporter._v8CoverageResults = v8CoverageResults;
testReporter.log = jest.fn();

const testContext = {
config: {
rootDir: '.',
},
hasteFS: {
matchFilesWithGlob: () => ['path-test-files/statement.js'],
},
};
return testReporter
.onRunComplete(new Set([testContext]), {}, mockAggResults)
.then(() => {
expect(testReporter.getLastError().message.split('\n')).toHaveLength(1);
});
});
});
13 changes: 12 additions & 1 deletion yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -3862,6 +3862,7 @@ __metadata:
jest-worker: "workspace:*"
mock-fs: ^5.1.2
node-notifier: ^10.0.0
one-double-zero-core: ^1.0.0-alpha.0
slash: ^3.0.0
string-length: ^4.0.1
strip-ansi: ^6.0.0
Expand Down Expand Up @@ -13389,7 +13390,7 @@ __metadata:
languageName: node
linkType: hard

"istanbul-lib-coverage@npm:^3.0.0, istanbul-lib-coverage@npm:^3.2.0":
"istanbul-lib-coverage@npm:^3.0.0, istanbul-lib-coverage@npm:^3.2.0, istanbul-lib-coverage@npm:^3.2.2":
version: 3.2.2
resolution: "istanbul-lib-coverage@npm:3.2.2"
checksum: 2367407a8d13982d8f7a859a35e7f8dd5d8f75aae4bb5484ede3a9ea1b426dc245aff28b976a2af48ee759fdd9be374ce2bd2669b644f31e76c5f46a2e29a831
Expand Down Expand Up @@ -17007,6 +17008,16 @@ __metadata:
languageName: node
linkType: hard

"one-double-zero-core@npm:^1.0.0-alpha.0":
version: 1.0.0-alpha.0
resolution: "one-double-zero-core@npm:1.0.0-alpha.0"
dependencies:
"@jridgewell/trace-mapping": ^0.3.25
istanbul-lib-coverage: ^3.2.2
checksum: 0831ba26ede8b95a697bd09f79b270a2eede2d2317830c5c11a5b714c8211081f5f30a7e3f863e4bb4de6755e4b47305828865f8e7a0fde0e18a4a87b74f9576
languageName: node
linkType: hard

"onetime@npm:^5.1.2":
version: 5.1.2
resolution: "onetime@npm:5.1.2"
Expand Down

0 comments on commit c575d8d

Please sign in to comment.