Skip to content

Commit

Permalink
fix(expect): objectContaining should recurse into sub-objects (jest…
Browse files Browse the repository at this point in the history
  • Loading branch information
jyunhan committed Oct 20, 2020
1 parent 9a07781 commit 3daecc6
Show file tree
Hide file tree
Showing 8 changed files with 71 additions and 3 deletions.
9 changes: 9 additions & 0 deletions e2e/__tests__/__snapshots__/v8Coverage.test.ts.snap
Expand Up @@ -14,3 +14,12 @@ All files | 100 | 100 | 100 | 100 |
x.css | 100 | 100 | 100 | 100 |
----------|---------|----------|---------|---------|-------------------"
`;

exports[`on node >=10 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 |
-------------|---------|----------|---------|---------|-------------------"
`;
11 changes: 11 additions & 0 deletions e2e/__tests__/v8Coverage.test.ts
Expand Up @@ -9,6 +9,9 @@ import * as path from 'path';
import {onNodeVersions} from '@jest/test-utils';
import runJest from '../runJest';

// import {wrap} from 'jest-snapshot-serializer-raw';
// import {runYarn} from '../Utils';

const DIR = path.resolve(__dirname, '../v8-coverage');

onNodeVersions('>=10', () => {
Expand All @@ -26,4 +29,12 @@ onNodeVersions('>=10', () => {
expect(exitCode).toBe(0);
expect(stdout).toMatchSnapshot();
});

test('vm script coverage generater', () => {
const dir = path.resolve(__dirname, '../vmscript-coverage');
const {stdout, exitCode} = runJest(dir, ['--coverage', '--coverage-provider', 'v8'], { stripAnsi: true });

expect(exitCode).toBe(0);
expect(stdout).toMatchSnapshot();
});
});
3 changes: 1 addition & 2 deletions e2e/v8-coverage/no-sourcemap/package.json
Expand Up @@ -4,8 +4,7 @@
"jest": {
"testEnvironment": "node",
"transform": {
"\\.[jt]sx?$": "babel-jest",
"\\.css$": "<rootDir>/cssTransform.js"
"\\.[jt]sx?$": "babel-jest"
}
}
}
18 changes: 18 additions & 0 deletions e2e/vmscript-coverage/__tests__/extract-coverage.test.js
@@ -0,0 +1,18 @@
/**
* 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 result1 = vm.runInNewContext(content,{inputObject: { number: 0 },console}, {filename: filePath});
const result2 = vm.runInNewContext(content,{inputObject: { number: 7 },console}, {filename: filePath});
expect(result1).toBe(false)
expect(result2).toBe(true)
});
6 changes: 6 additions & 0 deletions e2e/vmscript-coverage/package.json
@@ -0,0 +1,6 @@
{
"jest": {
"rootDir": "./",
"testEnvironment": "node"
}
}
15 changes: 15 additions & 0 deletions e2e/vmscript-coverage/package/vmscript.js
@@ -0,0 +1,15 @@
function addOne(inputNumber) {
return ++inputNumber
}

function isEvan(inputNumber) {
if (inputNumber % 2 === 0) {
return true
} else {
return false
}
}

if (!!inputObject) {
result = isEvan(addOne(inputObject.number))
}
11 changes: 11 additions & 0 deletions e2e/vmscript-coverage/yarn.lock
@@ -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
1 change: 0 additions & 1 deletion packages/jest-runtime/src/index.ts
Expand Up @@ -827,7 +827,6 @@ class Runtime {
res =>
// TODO: will this work on windows? It might be better if `shouldInstrument` deals with it anyways
res.url.startsWith(this._config.rootDir) &&
this._fileTransforms.has(res.url) &&
shouldInstrument(res.url, this._coverageOptions, this._config),
)
.map(result => {
Expand Down

0 comments on commit 3daecc6

Please sign in to comment.