Skip to content

Commit

Permalink
Concurrent reporter
Browse files Browse the repository at this point in the history
  • Loading branch information
aaronabramov committed Aug 23, 2016
1 parent 081bdd5 commit 00e596b
Show file tree
Hide file tree
Showing 23 changed files with 899 additions and 157 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,11 @@ exports[`test console printing 1`] = `
console.error __tests__/console2-test.js:18
This is an error from another test file.
"
suites: 2 passed (2 total)
tests: 2 passed (2 total)
snapshots: 0 passed (0 total)"
`;

exports[`test console printing with --verbose 1`] = `
Expand Down
79 changes: 79 additions & 0 deletions integration_tests/__tests__/__snapshots__/snapshot-test.js.snap
Original file line number Diff line number Diff line change
@@ -0,0 +1,79 @@
exports[`Snapshot Validation deletes a snapshot when a test does removes all the snapshots 1`] = `
"suites: 3 passed (3 total)
tests: 7 passed (7 total)
snapshots: 7 added, 0 passed (7 total)
time: <<REPLACED>>
"
`;
exports[`Snapshot Validation deletes a snapshot when a test does removes all the snapshots 2`] = `
"suites: 3 passed (3 total)
tests: 5 passed (5 total)
snapshots: 4 passed (4 total)
time: <<REPLACED>>
"
`;
exports[`Snapshot Validation deletes the snapshot if the test file has been removed 1`] = `
"suites: 3 passed (3 total)
tests: 7 passed (7 total)
snapshots: 7 added, 0 passed (7 total)
time: <<REPLACED>>
"
`;
exports[`Snapshot Validation deletes the snapshot if the test file has been removed 2`] = `
"suites: 2 passed (2 total)
tests: 4 passed (4 total)
snapshots: 4 passed (4 total)
time: <<REPLACED>>
"
`;
exports[`Snapshot Validation updates the snapshot when a test removes some snapshots 1`] = `
"suites: 3 passed (3 total)
tests: 7 passed (7 total)
snapshots: 7 added, 0 passed (7 total)
time: <<REPLACED>>
"
`;
exports[`Snapshot Validation updates the snapshot when a test removes some snapshots 2`] = `
"suites: 3 passed (3 total)
tests: 7 passed (7 total)
snapshots: 1 updated, 5 passed (6 total)
time: <<REPLACED>>
"
`;
exports[`Snapshot works as expected 1`] = `
"suites: 2 passed (2 total)
tests: 4 passed (4 total)
snapshots: 4 added, 0 passed (4 total)
time: <<REPLACED>>
"
`;
exports[`Snapshot works with escaped characters 1`] = `
"suites: 1 passed (1 total)
tests: 1 passed (1 total)
snapshots: 1 added, 0 passed (1 total)
time: <<REPLACED>>
"
`;
exports[`Snapshot works with escaped characters 2`] = `
"suites: 1 passed (1 total)
tests: 2 passed (2 total)
snapshots: 1 added, 1 passed (2 total)
time: <<REPLACED>>
"
`;
exports[`Snapshot works with escaped characters 3`] = `
"suites: 1 passed (1 total)
tests: 2 passed (2 total)
snapshots: 2 passed (2 total)
time: <<REPLACED>>
"
`;
47 changes: 47 additions & 0 deletions integration_tests/__tests__/__snapshots__/stack_trace-test.js.snap
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
exports[`Stack Trace does not print a stack trace for errors when --noStackTrace is given 1`] = `
"suites: 1 failed, 1 passed (1 total)
tests: 3 failed, 0 passed (3 total)
snapshots: 0 passed (0 total)
time: <<REPLACED>>
"
`;
exports[`Stack Trace does not print a stack trace for matching errors when --noStackTrace is given 1`] = `
"suites: 1 failed, 1 passed (1 total)
tests: 1 failed, 0 passed (1 total)
snapshots: 0 passed (0 total)
time: <<REPLACED>>
"
`;
exports[`Stack Trace does not print a stack trace for runtime errors when --noStackTrace is given 1`] = `
"suites: 1 failed, 0 passed (1 total)
tests: 0 passed (0 total)
snapshots: 0 passed (0 total)
time: <<REPLACED>>
"
`;
exports[`Stack Trace prints a stack trace for errors 1`] = `
"suites: 1 failed, 1 passed (1 total)
tests: 3 failed, 0 passed (3 total)
snapshots: 0 passed (0 total)
time: <<REPLACED>>
"
`;
exports[`Stack Trace prints a stack trace for matching errors 1`] = `
"suites: 1 failed, 1 passed (1 total)
tests: 1 failed, 0 passed (1 total)
snapshots: 0 passed (0 total)
time: <<REPLACED>>
"
`;
exports[`Stack Trace prints a stack trace for runtime errors 1`] = `
"suites: 1 failed, 0 passed (1 total)
tests: 0 passed (0 total)
snapshots: 0 passed (0 total)
time: <<REPLACED>>
"
`;
2 changes: 1 addition & 1 deletion integration_tests/__tests__/json_reporter-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ describe('JSON Reporter', () => {
const stderr = result.stderr.toString();
let jsonResult;

expect(stderr).toMatch(/1 test failed, 1 test passed/);
expect(stderr).toMatch(/1 failed, 1 passed/);
expect(result.status).toBe(1);

try {
Expand Down
29 changes: 12 additions & 17 deletions integration_tests/__tests__/snapshot-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
*/
'use strict';

const {getSummary} = require('../utils');
const fs = require('fs');
const path = require('path');
const runJest = require('../runJest');
Expand Down Expand Up @@ -97,8 +98,7 @@ describe('Snapshot', () => {

const info = result.stderr.toString();
expect(info).toMatch('4 snapshots written in 2 test files');
expect(info).toMatch('4 tests passed');
expect(info).toMatch('4 total in 2 test suites, 4 snapshots');
expect(getSummary(info)).toMatchSnapshot();
});

it('works with escaped characters', () => {
Expand All @@ -107,8 +107,8 @@ describe('Snapshot', () => {
let stderr = result.stderr.toString();

expect(stderr).toMatch('1 snapshot written');
expect(stderr).toMatch('1 total in 1 test suite, 1 snapshot,');
expect(result.status).toBe(0);
expect(getSummary(stderr)).toMatchSnapshot();

// Write the second snapshot
const testData =
Expand All @@ -121,7 +121,7 @@ describe('Snapshot', () => {
stderr = result.stderr.toString();

expect(stderr).toMatch('1 snapshot written');
expect(stderr).toMatch('2 total in 1 test suite, 2 snapshots,');
expect(getSummary(stderr)).toMatchSnapshot();
expect(result.status).toBe(0);

// Now let's check again if everything still passes.
Expand All @@ -130,7 +130,7 @@ describe('Snapshot', () => {
stderr = result.stderr.toString();

expect(stderr).not.toMatch('Snapshot Summary');
expect(stderr).toMatch('2 total in 1 test suite, 2 snapshots,');
expect(getSummary(stderr)).toMatchSnapshot();
expect(result.status).toBe(0);
});

Expand All @@ -155,11 +155,9 @@ describe('Snapshot', () => {
const infoFR = firstRun.stderr.toString();
const infoSR = secondRun.stderr.toString();
expect(infoFR).toMatch('7 snapshots written in 3 test files');
expect(infoFR).toMatch('7 tests passed');
expect(infoFR).toMatch('7 total in 3 test suites');
expect(infoSR).toMatch('1 snapshot file removed');
expect(infoSR).toMatch('4 tests passed');
expect(infoSR).toMatch('4 total in 2 test suites');
expect(getSummary(infoFR)).toMatchSnapshot();
expect(getSummary(infoSR)).toMatchSnapshot();
});

it('deletes a snapshot when a test does removes all the snapshots', () => {
Expand All @@ -176,11 +174,10 @@ describe('Snapshot', () => {
const infoFR = firstRun.stderr.toString();
const infoSR = secondRun.stderr.toString();
expect(infoFR).toMatch('7 snapshots written in 3 test files');
expect(infoFR).toMatch('7 tests passed');
expect(infoFR).toMatch('7 total in 3 test suites');
expect(infoSR).toMatch('1 snapshot file removed');
expect(infoSR).toMatch('5 tests passed');
expect(infoSR).toMatch('5 total in 3 test suites, 4 snapshots');
expect(getSummary(infoFR)).toMatchSnapshot();
expect(getSummary(infoSR)).toMatchSnapshot();

});

it('updates the snapshot when a test removes some snapshots', () => {
Expand Down Expand Up @@ -218,12 +215,10 @@ describe('Snapshot', () => {
const infoFR = firstRun.stderr.toString();
const infoSR = secondRun.stderr.toString();
expect(infoFR).toMatch('7 snapshots written in 3 test files');
expect(infoFR).toMatch('7 tests passed');
expect(infoFR).toMatch('7 total in 3 test suites, 7 snapshots');
expect(getSummary(infoFR)).toMatchSnapshot();
expect(infoSR).toMatch('1 snapshot updated in 1 test file');
expect(infoSR).toMatch('1 obsolete snapshot removed');
expect(infoSR).toMatch('7 tests passed');
expect(infoSR).toMatch('7 total in 3 test suites, 6 snapshots');
expect(getSummary(infoSR)).toMatchSnapshot();
});
});

Expand Down
18 changes: 8 additions & 10 deletions integration_tests/__tests__/stack_trace-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,16 +8,16 @@
'use strict';

const runJest = require('../runJest');
const {getSummary} = require('../utils');

describe('Stack Trace', () => {

it('prints a stack trace for runtime errors', () => {
const result = runJest('stack_trace', ['runtime-error-test.js']);
const stderr = result.stderr.toString();

expect(stderr).toMatch(
/1 test suite failed, 0 tests passed/
);
expect(getSummary(stderr)).toMatchSnapshot();

expect(result.status).toBe(1);
expect(stderr).toMatch(
/ReferenceError: thisIsARuntimeError is not defined/
Expand All @@ -34,9 +34,7 @@ describe('Stack Trace', () => {
]);
const stderr = result.stderr.toString();

expect(stderr).toMatch(
/1 test suite failed, 0 tests passed/
);
expect(getSummary(stderr)).toMatchSnapshot();
expect(result.status).toBe(1);

expect(stderr).toMatch(
Expand All @@ -51,7 +49,7 @@ describe('Stack Trace', () => {
const result = runJest('stack_trace', ['stack-trace-test.js']);
const stderr = result.stderr.toString();

expect(stderr).toMatch(/1 test failed, 0 tests passed/);
expect(getSummary(stderr)).toMatchSnapshot();
expect(result.status).toBe(1);

expect(stderr).toMatch(
Expand All @@ -66,7 +64,7 @@ describe('Stack Trace', () => {
]);
const stderr = result.stderr.toString();

expect(stderr).toMatch(/1 test failed, 0 tests passed/);
expect(getSummary(stderr)).toMatchSnapshot();
expect(result.status).toBe(1);

expect(stderr).not.toMatch(
Expand All @@ -78,7 +76,7 @@ describe('Stack Trace', () => {
const result = runJest('stack_trace', ['test-error-test.js']);
const stderr = result.stderr.toString();

expect(stderr).toMatch(/3 tests failed, 0 tests passed/);
expect(getSummary(stderr)).toMatchSnapshot();
expect(result.status).toBe(1);

expect(stderr).toMatch(/this is unexpected\./);
Expand Down Expand Up @@ -107,7 +105,7 @@ describe('Stack Trace', () => {
]);
const stderr = result.stderr.toString();

expect(stderr).toMatch(/3 tests failed, 0 tests passed/);
expect(getSummary(stderr)).toMatchSnapshot();
expect(result.status).toBe(1);

expect(stderr).not.toMatch(
Expand Down
14 changes: 14 additions & 0 deletions integration_tests/utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,21 @@ const fileExists = filePath => {
}
};

const getSummary = stdout => {
const match = stdout.match(/suites:.*\ntests.*\nsnapshots.*\ntime.*\n*$/g);
if (!match) {
throw new Error(`
Could not find test summary in the output.
OUTPUT:
${stdout}
`);
}

return match[0].replace(/\d*\.\d*s/, '<<REPLACED>>');
};

module.exports = {
getSummary,
fileExists,
linkJestPackage,
run,
Expand Down
2 changes: 2 additions & 0 deletions packages/jest-cli/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,8 @@
"json-stable-stringify": "^1.0.0",
"node-notifier": "^4.6.0",
"sane": "^1.2.0",
"strip-ansi": "^3.0.1",
"throat": "^3.0.0",
"which": "^1.1.1",
"worker-farm": "^1.3.1",
"yargs": "^5.0.0"
Expand Down
Loading

0 comments on commit 00e596b

Please sign in to comment.