From 21674390c628b4d36841f5df4629ccfdb2fd0634 Mon Sep 17 00:00:00 2001 From: KIDANI Akito Date: Sun, 28 Jan 2018 22:02:53 +0900 Subject: [PATCH] Add summary_reporter.test.js (#5389) * add special option -- for npm update command * Update CHANGELOG.md * add testcase for summary_reporter.js * add testcase for yarn * Update CHANGELOG.md * import SummaryReporter at the top * remove duplicated definition of results * remove description * add snapshot test * update test title * remove duplicated line * add missing attributes for test results --- CHANGELOG.md | 3 +- .../summary_reporter.test.js.snap | 25 ++++++++ .../__tests__/summary_reporter.test.js | 60 +++++++++++++++++++ 3 files changed, 87 insertions(+), 1 deletion(-) create mode 100644 packages/jest-cli/src/reporters/__tests__/__snapshots__/summary_reporter.test.js.snap create mode 100644 packages/jest-cli/src/reporters/__tests__/summary_reporter.test.js diff --git a/CHANGELOG.md b/CHANGELOG.md index ed454b4f67d7..abc5632a67d4 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -12,7 +12,8 @@ * `[expect]` Support class instances in `.toHaveProperty()` matcher. ([#5367](https://github.com/facebook/jest/pull/5367)) * `[jest-cli]` Fix npm update command for snapshot summary. - ([#5376](https://github.com/facebook/jest/pull/5376)) + ([#5376](https://github.com/facebook/jest/pull/5376), + [5389](https://github.com/facebook/jest/pull/5389/)) * `[expect]` Make `rejects` and `resolves` synchronously validate its argument. ([#5364](https://github.com/facebook/jest/pull/5364)) * `[docs]` Add tutorial page for ES6 class mocks. diff --git a/packages/jest-cli/src/reporters/__tests__/__snapshots__/summary_reporter.test.js.snap b/packages/jest-cli/src/reporters/__tests__/__snapshots__/summary_reporter.test.js.snap new file mode 100644 index 000000000000..55fb2f7428f7 --- /dev/null +++ b/packages/jest-cli/src/reporters/__tests__/__snapshots__/summary_reporter.test.js.snap @@ -0,0 +1,25 @@ +// Jest Snapshot v1, https://goo.gl/fbAQLP + +exports[`snapshots needs update with npm test 1`] = ` +"Snapshot Summary + › 2 snapshot tests failed in 1 test suite. Inspect your code changes or run \`npm test -- -u\` to update them. + +Test Suites: 1 failed, 1 total +Tests: 1 failed, 1 total +Snapshots: 2 failed, 2 total +Time: 0.01s +Ran all test suites. +" +`; + +exports[`snapshots needs update with yarn test 1`] = ` +"Snapshot Summary + › 2 snapshot tests failed in 1 test suite. Inspect your code changes or run \`yarn test -u\` to update them. + +Test Suites: 1 failed, 1 total +Tests: 1 failed, 1 total +Snapshots: 2 failed, 2 total +Time: 0.01s +Ran all test suites. +" +`; diff --git a/packages/jest-cli/src/reporters/__tests__/summary_reporter.test.js b/packages/jest-cli/src/reporters/__tests__/summary_reporter.test.js new file mode 100644 index 000000000000..445815207efd --- /dev/null +++ b/packages/jest-cli/src/reporters/__tests__/summary_reporter.test.js @@ -0,0 +1,60 @@ +/** + * Copyright (c) 2014-present, Facebook, Inc. 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. + */ +'use strict'; + +import SummaryReporter from '../summary_reporter'; + +const env = Object.assign({}, process.env); +const now = Date.now; +const write = process.stderr.write; +const globalConfig = { + watch: false, +}; +const aggregatedResults = { + numFailedTestSuites: 1, + numFailedTests: 1, + numPassedTestSuites: 0, + numTotalTestSuites: 1, + numTotalTests: 1, + snapshot: { + filesUnmatched: 1, + total: 2, + unmatched: 2, + }, + startTime: 0, + testResults: {}, +}; + +let results = []; + +beforeEach(() => { + process.env.npm_lifecycle_event = 'test'; + process.env.npm_lifecycle_script = 'jest'; + process.stderr.write = result => results.push(result); + Date.now = () => 10; +}); + +afterEach(() => { + results = []; + process.env = env; + process.stderr.write = write; + Date.now = now; +}); + +test('snapshots needs update with npm test', () => { + process.env.npm_config_user_agent = 'npm'; + const testReporter = new SummaryReporter(globalConfig); + testReporter.onRunComplete(new Set(), aggregatedResults); + expect(results.join('')).toMatchSnapshot(); +}); + +test('snapshots needs update with yarn test', () => { + process.env.npm_config_user_agent = 'yarn'; + const testReporter = new SummaryReporter(globalConfig); + testReporter.onRunComplete(new Set(), aggregatedResults); + expect(results.join('')).toMatchSnapshot(); +});