Skip to content

Commit 3daecc6

Browse files
author
jyunhan
committed
fix(expect): objectContaining should recurse into sub-objects (jestjs#10508)
1 parent 9a07781 commit 3daecc6

File tree

8 files changed

+71
-3
lines changed

8 files changed

+71
-3
lines changed

e2e/__tests__/__snapshots__/v8Coverage.test.ts.snap

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,3 +14,12 @@ All files | 100 | 100 | 100 | 100 |
1414
x.css | 100 | 100 | 100 | 100 |
1515
----------|---------|----------|---------|---------|-------------------"
1616
`;
17+
18+
exports[`on node >=10 vm script coverage generater 1`] = `
19+
"-------------|---------|----------|---------|---------|-------------------
20+
File | % Stmts | % Branch | % Funcs | % Lines | Uncovered Line #s
21+
-------------|---------|----------|---------|---------|-------------------
22+
All files | 100 | 100 | 100 | 100 |
23+
vmscript.js | 100 | 100 | 100 | 100 |
24+
-------------|---------|----------|---------|---------|-------------------"
25+
`;

e2e/__tests__/v8Coverage.test.ts

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,9 @@ import * as path from 'path';
99
import {onNodeVersions} from '@jest/test-utils';
1010
import runJest from '../runJest';
1111

12+
// import {wrap} from 'jest-snapshot-serializer-raw';
13+
// import {runYarn} from '../Utils';
14+
1215
const DIR = path.resolve(__dirname, '../v8-coverage');
1316

1417
onNodeVersions('>=10', () => {
@@ -26,4 +29,12 @@ onNodeVersions('>=10', () => {
2629
expect(exitCode).toBe(0);
2730
expect(stdout).toMatchSnapshot();
2831
});
32+
33+
test('vm script coverage generater', () => {
34+
const dir = path.resolve(__dirname, '../vmscript-coverage');
35+
const {stdout, exitCode} = runJest(dir, ['--coverage', '--coverage-provider', 'v8'], { stripAnsi: true });
36+
37+
expect(exitCode).toBe(0);
38+
expect(stdout).toMatchSnapshot();
39+
});
2940
});

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

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,7 @@
44
"jest": {
55
"testEnvironment": "node",
66
"transform": {
7-
"\\.[jt]sx?$": "babel-jest",
8-
"\\.css$": "<rootDir>/cssTransform.js"
7+
"\\.[jt]sx?$": "babel-jest"
98
}
109
}
1110
}
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
/**
2+
* Copyright (c) Facebook, Inc. and its affiliates. All Rights Reserved.
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+
const vm = require('vm');
8+
const path = require('path');
9+
const fs = require('fs');
10+
const filePath = path.resolve(__dirname, '../package/vmscript.js');
11+
12+
test('extract coverage', () => {
13+
const content = fs.readFileSync(filePath, {encoding: 'utf8'});
14+
const result1 = vm.runInNewContext(content,{inputObject: { number: 0 },console}, {filename: filePath});
15+
const result2 = vm.runInNewContext(content,{inputObject: { number: 7 },console}, {filename: filePath});
16+
expect(result1).toBe(false)
17+
expect(result2).toBe(true)
18+
});

e2e/vmscript-coverage/package.json

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
{
2+
"jest": {
3+
"rootDir": "./",
4+
"testEnvironment": "node"
5+
}
6+
}
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
function addOne(inputNumber) {
2+
return ++inputNumber
3+
}
4+
5+
function isEvan(inputNumber) {
6+
if (inputNumber % 2 === 0) {
7+
return true
8+
} else {
9+
return false
10+
}
11+
}
12+
13+
if (!!inputObject) {
14+
result = isEvan(addOne(inputObject.number))
15+
}

e2e/vmscript-coverage/yarn.lock

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
# This file is generated by running "yarn install" inside your project.
2+
# Manual changes might be lost - proceed with caution!
3+
4+
__metadata:
5+
version: 4
6+
7+
"root-workspace-0b6124@workspace:.":
8+
version: 0.0.0-use.local
9+
resolution: "root-workspace-0b6124@workspace:."
10+
languageName: unknown
11+
linkType: soft

packages/jest-runtime/src/index.ts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -827,7 +827,6 @@ class Runtime {
827827
res =>
828828
// TODO: will this work on windows? It might be better if `shouldInstrument` deals with it anyways
829829
res.url.startsWith(this._config.rootDir) &&
830-
this._fileTransforms.has(res.url) &&
831830
shouldInstrument(res.url, this._coverageOptions, this._config),
832831
)
833832
.map(result => {

0 commit comments

Comments
 (0)