-
-
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: vm.script code coverage had been tampered (#10645)
- Loading branch information
jyunhan
committed
Oct 21, 2020
1 parent
9a07781
commit b3257be
Showing
8 changed files
with
124 additions
and
23 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,16 +1,26 @@ | ||
// Jest Snapshot v1, https://goo.gl/fbAQLP | ||
|
||
exports[`on node >=10 prints coverage 1`] = ` | ||
exports[`prints coverage 1`] = ` | ||
" console.log | ||
42 | ||
at Object.log (__tests__/Thing.test.js:10:9) | ||
----------|---------|----------|---------|---------|------------------- | ||
File | % Stmts | % Branch | % Funcs | % Lines | Uncovered Line #s | ||
----------|---------|----------|---------|---------|------------------- | ||
All files | 100 | 100 | 100 | 100 | | ||
Thing.js | 100 | 100 | 100 | 100 | | ||
x.css | 100 | 100 | 100 | 100 | | ||
----------|---------|----------|---------|---------|-------------------" | ||
-----------------|---------|----------|---------|---------|------------------- | ||
File | % Stmts | % Branch | % Funcs | % Lines | Uncovered Line #s | ||
-----------------|---------|----------|---------|---------|------------------- | ||
All files | 100 | 100 | 75 | 100 | | ||
Thing.js | 100 | 100 | 100 | 100 | | ||
cssTransform.js | 100 | 100 | 50 | 100 | | ||
x.css | 100 | 100 | 100 | 100 | | ||
-----------------|---------|----------|---------|---------|-------------------" | ||
`; | ||
|
||
exports[`vm script coverage generater 1`] = ` | ||
"-------------|---------|----------|---------|---------|------------------- | ||
File | % Stmts | % Branch | % Funcs | % Lines | Uncovered Line #s | ||
-------------|---------|----------|---------|---------|------------------- | ||
All files | 100 | 100 | 100 | 100 | | ||
vmscript.js | 100 | 100 | 100 | 100 | | ||
-------------|---------|----------|---------|---------|-------------------" | ||
`; |
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) Facebook, Inc. and its affiliates. All Rights Reserved. | ||
* | ||
* This source code is licensed under the MIT license found in the | ||
* LICENSE file in the root directory of this source tree. | ||
*/ | ||
|
||
const vm = require('vm'); | ||
const path = require('path'); | ||
const fs = require('fs'); | ||
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,6 @@ | ||
{ | ||
"jest": { | ||
"rootDir": "./", | ||
"testEnvironment": "node" | ||
} | ||
} |
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,23 @@ | ||
/** | ||
* Copyright (c) Facebook, Inc. and its affiliates. All Rights Reserved. | ||
* | ||
* 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; | ||
} | ||
} | ||
|
||
/* 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
# This file is generated by running "yarn install" inside your project. | ||
# Manual changes might be lost - proceed with caution! | ||
|
||
__metadata: | ||
version: 4 | ||
|
||
"root-workspace-0b6124@workspace:.": | ||
version: 0.0.0-use.local | ||
resolution: "root-workspace-0b6124@workspace:." | ||
languageName: unknown | ||
linkType: soft |
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