-
-
Notifications
You must be signed in to change notification settings - Fork 6.5k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix(jest-runtime, @jest/transform): allow V8 coverage provider to col…
…lect coverage from files which were not loaded explicitly (#13974) Co-authored-by: GP4cK <[email protected]>
- Loading branch information
1 parent
679b5ad
commit 0060728
Showing
9 changed files
with
155 additions
and
2 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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
/** | ||
* Copyright (c) Meta Platforms, Inc. and affiliates. | ||
* | ||
* This source code is licensed under the MIT license found in the | ||
* LICENSE file in the root directory of this source tree. | ||
*/ | ||
|
||
const fs = require('fs'); | ||
const path = require('path'); | ||
const vm = require('vm'); | ||
const filePath = path.resolve(__dirname, '../package/vmscript.js'); | ||
|
||
test('extract coverage', () => { | ||
const content = fs.readFileSync(filePath, {encoding: 'utf8'}); | ||
|
||
const case1 = vm.runInNewContext( | ||
content, | ||
{ | ||
inputObject: { | ||
number: 0, | ||
}, | ||
}, | ||
{ | ||
filename: filePath, | ||
}, | ||
); | ||
|
||
const case2 = vm.runInNewContext( | ||
content, | ||
{ | ||
inputObject: { | ||
number: 7, | ||
}, | ||
}, | ||
{ | ||
filename: filePath, | ||
}, | ||
); | ||
|
||
expect(case1).toBe(false); | ||
expect(case2).toBe(true); | ||
}); |
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,9 @@ | ||
{ | ||
"jest": { | ||
"rootDir": "./", | ||
"testEnvironment": "node", | ||
"collectCoverageFrom": [ | ||
"package/**/*.js" | ||
] | ||
} | ||
} |
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,27 @@ | ||
/** | ||
* Copyright (c) Meta Platforms, Inc. and affiliates. | ||
* | ||
* This source code is licensed under the MIT license found in the | ||
* LICENSE file in the root directory of this source tree. | ||
*/ | ||
|
||
function addOne(inputNumber) { | ||
return ++inputNumber; | ||
} | ||
|
||
function isEven(inputNumber) { | ||
if (inputNumber % 2 === 0) { | ||
return true; | ||
} else { | ||
return false; | ||
} | ||
} | ||
|
||
function notCovered() { | ||
return 'not covered'; | ||
} | ||
|
||
/* global inputObject */ | ||
if (inputObject.number / 1 === inputObject.number) { | ||
isEven(addOne(inputObject.number)); | ||
} |
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