-
-
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): correct
wrapperLength
value for ESM modules (#1…
- Loading branch information
1 parent
da7c4a4
commit d4fff6a
Showing
34 changed files
with
458 additions
and
64 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
87 changes: 87 additions & 0 deletions
87
e2e/__tests__/__snapshots__/coverageProviderV8.test.ts.snap
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,87 @@ | ||
// Jest Snapshot v1, https://goo.gl/fbAQLP | ||
|
||
exports[`on node >=12.16.0 prints correct coverage report, if a TS module is transpiled by custom transformer to ESM put under test 1`] = ` | ||
console.log | ||
this will print | ||
at covered (module.ts:13:11) | ||
--------------|---------|----------|---------|---------|------------------- | ||
File | % Stmts | % Branch | % Funcs | % Lines | Uncovered Line #s | ||
--------------|---------|----------|---------|---------|------------------- | ||
All files | 50 | 25 | 25 | 50 | | ||
module.ts | 80.77 | 50 | 50 | 80.77 | 16-18,21-22 | ||
types.ts | 0 | 0 | 0 | 0 | 1-8 | ||
uncovered.ts | 0 | 0 | 0 | 0 | 1-8 | ||
--------------|---------|----------|---------|---------|------------------- | ||
`; | ||
|
||
exports[`on node >=12.16.0 prints correct coverage report, if an ESM module is put under test without transformation 1`] = ` | ||
console.log | ||
this will print | ||
at covered (module.js:11:11) | ||
--------------|---------|----------|---------|---------|------------------- | ||
File | % Stmts | % Branch | % Funcs | % Lines | Uncovered Line #s | ||
--------------|---------|----------|---------|---------|------------------- | ||
All files | 59.38 | 50 | 33.33 | 59.38 | | ||
module.js | 79.17 | 66.67 | 50 | 79.17 | 14-16,19-20 | ||
uncovered.js | 0 | 0 | 0 | 0 | 1-8 | ||
--------------|---------|----------|---------|---------|------------------- | ||
`; | ||
|
||
exports[`prints correct coverage report, if a CJS module is put under test without transformation 1`] = ` | ||
console.log | ||
this will print | ||
at covered (module.js:11:11) | ||
--------------|---------|----------|---------|---------|------------------- | ||
File | % Stmts | % Branch | % Funcs | % Lines | Uncovered Line #s | ||
--------------|---------|----------|---------|---------|------------------- | ||
All files | 59.38 | 60 | 50 | 59.38 | | ||
module.js | 79.17 | 75 | 66.67 | 79.17 | 14-16,19-20 | ||
uncovered.js | 0 | 0 | 0 | 0 | 1-8 | ||
--------------|---------|----------|---------|---------|------------------- | ||
`; | ||
|
||
exports[`prints correct coverage report, if a TS module is transpiled by Babel to CJS and put under test 1`] = ` | ||
console.log | ||
this will print | ||
at log (module.ts:13:11) | ||
--------------|---------|----------|---------|---------|------------------- | ||
File | % Stmts | % Branch | % Funcs | % Lines | Uncovered Line #s | ||
--------------|---------|----------|---------|---------|------------------- | ||
All files | 50 | 25 | 25 | 50 | | ||
module.ts | 80.77 | 50 | 50 | 80.77 | 16-18,21-22 | ||
types.ts | 0 | 0 | 0 | 0 | 1-8 | ||
uncovered.ts | 0 | 0 | 0 | 0 | 1-8 | ||
--------------|---------|----------|---------|---------|------------------- | ||
`; | ||
|
||
exports[`prints coverage with empty sourcemaps 1`] = ` | ||
----------|---------|----------|---------|---------|------------------- | ||
File | % Stmts | % Branch | % Funcs | % Lines | Uncovered Line #s | ||
----------|---------|----------|---------|---------|------------------- | ||
All files | 100 | 100 | 100 | 100 | | ||
types.ts | 100 | 100 | 100 | 100 | | ||
----------|---------|----------|---------|---------|------------------- | ||
`; | ||
|
||
exports[`prints coverage with missing sourcemaps 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 | | ||
----------|---------|----------|---------|---------|------------------- | ||
`; |
This file was deleted.
Oops, something went wrong.
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,100 @@ | ||
/** | ||
* 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. | ||
*/ | ||
|
||
import * as path from 'path'; | ||
import wrap from 'jest-snapshot-serializer-raw'; | ||
import {onNodeVersions} from '@jest/test-utils'; | ||
import runJest from '../runJest'; | ||
|
||
const DIR = path.resolve(__dirname, '../coverage-provider-v8'); | ||
|
||
test('prints coverage with missing sourcemaps', () => { | ||
const sourcemapDir = path.join(DIR, 'no-sourcemap'); | ||
|
||
const {stdout, exitCode} = runJest( | ||
sourcemapDir, | ||
['--coverage', '--coverage-provider', 'v8'], | ||
{stripAnsi: true}, | ||
); | ||
|
||
expect(exitCode).toBe(0); | ||
expect(wrap(stdout)).toMatchSnapshot(); | ||
}); | ||
|
||
test('prints coverage with empty sourcemaps', () => { | ||
const sourcemapDir = path.join(DIR, 'empty-sourcemap'); | ||
|
||
const {stdout, exitCode} = runJest( | ||
sourcemapDir, | ||
['--coverage', '--coverage-provider', 'v8'], | ||
{stripAnsi: true}, | ||
); | ||
|
||
expect(exitCode).toBe(0); | ||
expect(wrap(stdout)).toMatchSnapshot(); | ||
}); | ||
|
||
test('prints correct coverage report, if a CJS module is put under test without transformation', () => { | ||
const sourcemapDir = path.join(DIR, 'cjs-native-without-sourcemap'); | ||
|
||
const {stdout, exitCode} = runJest( | ||
sourcemapDir, | ||
['--coverage', '--coverage-provider', 'v8', '--no-cache'], | ||
{stripAnsi: true}, | ||
); | ||
|
||
expect(exitCode).toBe(0); | ||
expect(wrap(stdout)).toMatchSnapshot(); | ||
}); | ||
|
||
test('prints correct coverage report, if a TS module is transpiled by Babel to CJS and put under test', () => { | ||
const sourcemapDir = path.join(DIR, 'cjs-with-babel-transformer'); | ||
|
||
const {stdout, exitCode} = runJest( | ||
sourcemapDir, | ||
['--coverage', '--coverage-provider', 'v8', '--no-cache'], | ||
{stripAnsi: true}, | ||
); | ||
|
||
expect(exitCode).toBe(0); | ||
expect(wrap(stdout)).toMatchSnapshot(); | ||
}); | ||
|
||
// The versions where vm.Module exists and commonjs with "exports" is not broken | ||
onNodeVersions('>=12.16.0', () => { | ||
test('prints correct coverage report, if an ESM module is put under test without transformation', () => { | ||
const sourcemapDir = path.join(DIR, 'esm-native-without-sourcemap'); | ||
|
||
const {stdout, exitCode} = runJest( | ||
sourcemapDir, | ||
['--coverage', '--coverage-provider', 'v8', '--no-cache'], | ||
{ | ||
nodeOptions: '--experimental-vm-modules --no-warnings', | ||
stripAnsi: true, | ||
}, | ||
); | ||
|
||
expect(exitCode).toBe(0); | ||
expect(wrap(stdout)).toMatchSnapshot(); | ||
}); | ||
|
||
test('prints correct coverage report, if a TS module is transpiled by custom transformer to ESM put under test', () => { | ||
const sourcemapDir = path.join(DIR, 'esm-with-custom-transformer'); | ||
|
||
const {stdout, exitCode} = runJest( | ||
sourcemapDir, | ||
['--coverage', '--coverage-provider', 'v8', '--no-cache'], | ||
{ | ||
nodeOptions: '--experimental-vm-modules --no-warnings', | ||
stripAnsi: true, | ||
}, | ||
); | ||
|
||
expect(exitCode).toBe(0); | ||
expect(wrap(stdout)).toMatchSnapshot(); | ||
}); | ||
}); |
This file was deleted.
Oops, something went wrong.
12 changes: 12 additions & 0 deletions
12
e2e/coverage-provider-v8/cjs-native-without-sourcemap/__tests__/test.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,12 @@ | ||
/** | ||
* 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 {value} = require('../module'); | ||
|
||
test('dummy', () => { | ||
expect(value).toBe('abc'); | ||
}); |
24 changes: 24 additions & 0 deletions
24
e2e/coverage-provider-v8/cjs-native-without-sourcemap/module.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,24 @@ | ||
/** | ||
* 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 value = 'abc'; | ||
|
||
function covered() { | ||
console.log('this will print'); | ||
} | ||
|
||
function uncovered() { | ||
console.log('this will not'); | ||
} | ||
|
||
if (value !== 'abc') { | ||
uncovered(); | ||
} | ||
|
||
covered(); | ||
|
||
module.exports = {value}; |
9 changes: 9 additions & 0 deletions
9
e2e/coverage-provider-v8/cjs-native-without-sourcemap/package.json
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": { | ||
"collectCoverageFrom": [ | ||
"<rootDir>/*.js" | ||
], | ||
"transform": { | ||
} | ||
} | ||
} |
8 changes: 8 additions & 0 deletions
8
e2e/coverage-provider-v8/cjs-native-without-sourcemap/uncovered.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,8 @@ | ||
/** | ||
* 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. | ||
*/ | ||
|
||
module.exports = {}; |
12 changes: 12 additions & 0 deletions
12
e2e/coverage-provider-v8/cjs-with-babel-transformer/__tests__/test.ts
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,12 @@ | ||
/** | ||
* 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. | ||
*/ | ||
|
||
import {value} from '../module'; | ||
|
||
test('dummy', () => { | ||
expect(value).toBe('abc'); | ||
}); |
26 changes: 26 additions & 0 deletions
26
e2e/coverage-provider-v8/cjs-with-babel-transformer/module.ts
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,26 @@ | ||
/** | ||
* 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. | ||
*/ | ||
|
||
import type {A} from './types'; | ||
|
||
const value: A = 'abc'; | ||
|
||
function covered() { | ||
console.log('this will print'); | ||
} | ||
|
||
function uncovered() { | ||
console.log('this will not'); | ||
} | ||
|
||
if (value !== 'abc') { | ||
uncovered(); | ||
} | ||
|
||
covered(); | ||
|
||
export {value}; |
13 changes: 13 additions & 0 deletions
13
e2e/coverage-provider-v8/cjs-with-babel-transformer/package.json
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,13 @@ | ||
{ | ||
"babel": { | ||
"presets": [ | ||
["@babel/preset-env", {"targets": {"node": "current"}}], | ||
"@babel/preset-typescript" | ||
] | ||
}, | ||
"jest": { | ||
"collectCoverageFrom": [ | ||
"<rootDir>/*.ts" | ||
] | ||
} | ||
} |
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,8 @@ | ||
/** | ||
* 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. | ||
*/ | ||
|
||
export type A = string; |
8 changes: 8 additions & 0 deletions
8
e2e/coverage-provider-v8/cjs-with-babel-transformer/uncovered.ts
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,8 @@ | ||
/** | ||
* 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. | ||
*/ | ||
|
||
export {}; |
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
Oops, something went wrong.