Skip to content

Commit

Permalink
test: extend v8 coverage test suite
Browse files Browse the repository at this point in the history
  • Loading branch information
mrazauskas committed Sep 25, 2021
1 parent da7c4a4 commit de74997
Show file tree
Hide file tree
Showing 33 changed files with 523 additions and 63 deletions.
72 changes: 72 additions & 0 deletions e2e/__tests__/__snapshots__/coverageProviderV8.test.ts-.snap
Original file line number Diff line number Diff line change
@@ -0,0 +1,72 @@
// Jest Snapshot v1, https://goo.gl/fbAQLP

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 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[`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 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 |
----------|---------|----------|---------|---------|-------------------
`;
87 changes: 87 additions & 0 deletions e2e/__tests__/__snapshots__/coverageProviderV8.test.ts.snap
Original file line number Diff line number Diff line change
@@ -0,0 +1,87 @@
// Jest Snapshot v1, https://goo.gl/fbAQLP

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 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[`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 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 |
----------|---------|----------|---------|---------|-------------------
`;
25 changes: 0 additions & 25 deletions e2e/__tests__/__snapshots__/v8Coverage.test.ts.snap

This file was deleted.

96 changes: 96 additions & 0 deletions e2e/__tests__/coverageProviderV8.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,96 @@
/**
* 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 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();
});

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();
});
38 changes: 0 additions & 38 deletions e2e/__tests__/v8Coverage.test.ts

This file was deleted.

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 e2e/coverage-provider-v8/cjs-native-without-sourcemap/module.js
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};
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
{
"jest": {
"collectCoverageFrom": [
"<rootDir>/*.js"
],
"transform": {
}
}
}
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 = {};
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');
});

0 comments on commit de74997

Please sign in to comment.