Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Make the tests more robust by using extractSummary method to compare
stderr snapshots.
Do a replace on the stderr which has a full path to a failed
glob threshold file which won't match when the test runs on windows
(appveyor)
  • Loading branch information
rhys williams committed May 31, 2018
commit 68a822b1f135a6e3bb6af912e6359fe30913c2ed
44 changes: 30 additions & 14 deletions e2e/__tests__/__snapshots__/coverage_threshold.test.js.snap
Original file line number Diff line number Diff line change
@@ -1,11 +1,15 @@
// Jest Snapshot v1, https://goo.gl/fbAQLP

exports[`excludes tests matched by path threshold groups from global group: stderr 1`] = `
exports[`excludes tests matched by path threshold groups from global group 1`] = `
"PASS __tests__/banana.test.js
✓ banana (<<REPLACED>>)
✓ banana

Jest: \\"global\\" coverage threshold for lines (100%) not met: 0%
Test Suites: 1 passed, 1 total
"
`;

exports[`excludes tests matched by path threshold groups from global group 2`] = `
"Test Suites: 1 passed, 1 total
Tests: 1 passed, 1 total
Snapshots: 0 total
Time: <<REPLACED>>
Expand Down Expand Up @@ -33,12 +37,16 @@ All files | 100 | 100 | 100 | 100 | |
-----------|----------|----------|----------|----------|-------------------|"
`;

exports[`exits with 1 if coverage threshold is not met: stderr 1`] = `
exports[`exits with 1 if coverage threshold is not met 1`] = `
"PASS __tests__/a-banana.js
✓ banana (<<REPLACED>>)
✓ banana

Jest: \\"global\\" coverage threshold for lines (90%) not met: 50%
Test Suites: 1 passed, 1 total
"
`;

exports[`exits with 1 if coverage threshold is not met 2`] = `
"Test Suites: 1 passed, 1 total
Tests: 1 passed, 1 total
Snapshots: 0 total
Time: <<REPLACED>>
Expand All @@ -56,12 +64,16 @@ All files | 50 | 100 | 0 | 50 |
"
`;

exports[`exits with 1 if path threshold group is not found in coverage data: stderr 1`] = `
exports[`exits with 1 if path threshold group is not found in coverage data 1`] = `
"PASS __tests__/banana.test.js
✓ banana (<<REPLACED>>)
✓ banana

Jest: Coverage data for apple.js was not found.
Test Suites: 1 passed, 1 total
"
`;

exports[`exits with 1 if path threshold group is not found in coverage data 2`] = `
"Test Suites: 1 passed, 1 total
Tests: 1 passed, 1 total
Snapshots: 0 total
Time: <<REPLACED>>
Expand All @@ -79,14 +91,18 @@ All files | 100 | 100 | 100 | 100 | |
"
`;

exports[`file is matched by all path and glob threshold groups: stderr 1`] = `
exports[`file is matched by all path and glob threshold groups 1`] = `
"PASS __tests__/banana.test.js
✓ banana (<<REPLACED>>)
✓ banana

Jest: \\"./\\" coverage threshold for lines (100%) not met: 50%
Jest: \\"<<REPLACED>>/e2e/coverage-threshold/banana.js\\" coverage threshold for lines (100%) not met: 50%
Jest: \\"banana.js\\" coverage threshold for lines (100%) not met: 50%
Test Suites: 1 passed, 1 total
Jest: \\"<<FULL_PATH_TO_BANANA_JS>>\\" coverage threshold for lines (100%) not met: 50%
Jest: \\"./banana.js\\" coverage threshold for lines (100%) not met: 50%
"
`;

exports[`file is matched by all path and glob threshold groups 2`] = `
"Test Suites: 1 passed, 1 total
Tests: 1 passed, 1 total
Snapshots: 0 total
Time: <<REPLACED>>
Expand Down
36 changes: 23 additions & 13 deletions e2e/__tests__/coverage_threshold.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,18 +10,14 @@
'use strict';

const path = require('path');
const {cleanup, writeFiles} = require('../Utils');
const {cleanup, writeFiles, extractSummary} = require('../Utils');
const runJest = require('../runJest');

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

beforeEach(() => cleanup(DIR));
afterAll(() => cleanup(DIR));

const replaceTime = str => {
return str.replace(/\d*\.?\d+m?s/g, '<<REPLACED>>');
};

test('exits with 1 if coverage threshold is not met', () => {
const pkgJson = {
jest: {
Expand Down Expand Up @@ -49,9 +45,12 @@ test('exits with 1 if coverage threshold is not met', () => {
});

const {stdout, stderr, status} = runJest(DIR, ['--coverage', '--ci=false']);
const {rest, summary} = extractSummary(stderr);

expect(status).toBe(1);
expect(rest).toMatchSnapshot();
expect(summary).toMatchSnapshot();
expect(stdout).toMatchSnapshot('stdout');
expect(replaceTime(stderr)).toMatchSnapshot('stderr');
});

test('exits with 1 if path threshold group is not found in coverage data', () => {
Expand Down Expand Up @@ -81,10 +80,12 @@ test('exits with 1 if path threshold group is not found in coverage data', () =>
});

const {stdout, stderr, status} = runJest(DIR, ['--coverage', '--ci=false']);
const {rest, summary} = extractSummary(stderr);

expect(status).toBe(1);
expect(rest).toMatchSnapshot();
expect(summary).toMatchSnapshot();
expect(stdout).toMatchSnapshot('stdout');
expect(replaceTime(stderr)).toMatchSnapshot('stderr');
});

test('exits with 0 if global threshold group is not found in coverage data', () => {
Expand Down Expand Up @@ -157,10 +158,12 @@ test('excludes tests matched by path threshold groups from global group', () =>
});

const {stdout, stderr, status} = runJest(DIR, ['--coverage', '--ci=false']);
const {rest, summary} = extractSummary(stderr);

expect(status).toBe(1);
expect(rest).toMatchSnapshot();
expect(summary).toMatchSnapshot();
expect(stdout).toMatchSnapshot('stdout');
expect(replaceTime(stderr)).toMatchSnapshot('stderr');
});

test('file is matched by all path and glob threshold groups', () => {
Expand All @@ -172,10 +175,10 @@ test('file is matched by all path and glob threshold groups', () => {
'./': {
lines: 100,
},
'ban*.js': {
'./ban*.js': {
lines: 100,
},
'banana.js': {
'./banana.js': {
lines: 100,
},
},
Expand All @@ -196,10 +199,17 @@ test('file is matched by all path and glob threshold groups', () => {
});

const {stdout, stderr, status} = runJest(DIR, ['--coverage', '--ci=false']);
const {rest, summary} = extractSummary(
/* This test also runs on windows and when the glob fails it outputs
the system specific absolute path to the test file. */
stderr.replace(
path.resolve(DIR, './banana.js'),
'<<FULL_PATH_TO_BANANA_JS>>',
),
);

expect(status).toBe(1);
expect(rest).toMatchSnapshot();
expect(summary).toMatchSnapshot();
expect(stdout).toMatchSnapshot('stdout');
expect(
replaceTime(stderr).replace(process.cwd(), '<<REPLACED>>'),
).toMatchSnapshot('stderr');
});