Skip to content

Commit

Permalink
chore: split out reporters into separate package (#7902)
Browse files Browse the repository at this point in the history
  • Loading branch information
SimenB authored Feb 15, 2019
1 parent fb1f326 commit b489779
Show file tree
Hide file tree
Showing 46 changed files with 163 additions and 103 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@
- `[docs]`: Fix image paths in SnapshotTesting.md for current and version 24 ([#7872](https://github.com/facebook/jest/pull/7872))
- `[babel-jest]`: Migrate to TypeScript ([#7862](https://github.com/facebook/jest/pull/7862))
- `[jest-resolve]`: Migrate to TypeScript ([#7871](https://github.com/facebook/jest/pull/7871))
- `[@jest/reporter]`: New package extracted from `jest-cli` ([#7902](https://github.com/facebook/jest/pull/7902))

### Performance

Expand Down
13 changes: 2 additions & 11 deletions packages/jest-cli/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,17 +4,14 @@
"version": "24.1.0",
"main": "build/jest.js",
"dependencies": {
"@jest/reporters": "^24.1.0",
"ansi-escapes": "^3.0.0",
"chalk": "^2.0.1",
"exit": "^0.1.2",
"glob": "^7.1.2",
"graceful-fs": "^4.1.15",
"import-local": "^2.0.0",
"is-ci": "^2.0.0",
"istanbul-api": "^2.1.1",
"istanbul-lib-coverage": "^2.0.2",
"istanbul-lib-instrument": "^3.0.1",
"istanbul-lib-source-maps": "^3.0.1",
"jest-changed-files": "^24.0.0",
"jest-config": "^24.1.0",
"jest-environment-jsdom": "^24.0.0",
Expand All @@ -29,15 +26,12 @@
"jest-util": "^24.0.0",
"jest-validate": "^24.0.0",
"jest-watcher": "^24.0.0",
"jest-worker": "^24.0.0",
"micromatch": "^3.1.10",
"node-notifier": "^5.2.1",
"p-each-series": "^1.0.0",
"pirates": "^4.0.0",
"prompts": "^2.0.1",
"realpath-native": "^1.1.0",
"rimraf": "^2.5.4",
"slash": "^2.0.0",
"string-length": "^2.0.0",
"strip-ansi": "^5.0.0",
"which": "^1.2.12",
Expand All @@ -49,14 +43,11 @@
"@types/glob": "^7.1.1",
"@types/graceful-fs": "^4.1.2",
"@types/is-ci": "^1.1.0",
"@types/istanbul-lib-coverage": "^1.1.0",
"@types/istanbul-lib-instrument": "^1.7.2",
"@types/istanbul-lib-source-maps": "^1.2.1",
"@types/micromatch": "^3.1.0",
"@types/node-notifier": "^0.0.28",
"@types/prompts": "^1.2.0",
"@types/rimraf": "^2.0.2",
"@types/string-length": "^2.0.0",
"@types/strip-ansi": "^3.0.0",
"@types/which": "^1.3.1",
"@types/yargs": "^12.0.2"
},
Expand Down
3 changes: 1 addition & 2 deletions packages/jest-cli/src/SearchSource.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,11 +15,10 @@ import type {ChangedFilesInfo} from 'types/ChangedFiles';
import path from 'path';
import micromatch from 'micromatch';
import DependencyResolver from 'jest-resolve-dependencies';
import testPathPatternToRegExp from './testPathPatternToRegexp';
import {escapePathForRegex} from 'jest-regex-util';
import {replaceRootDirInPath} from 'jest-config';
import {buildSnapshotResolver} from 'jest-snapshot';
import {replacePathSepForGlob} from 'jest-util';
import {replacePathSepForGlob, testPathPatternToRegExp} from 'jest-util';

type SearchResult = {|
noSCM?: boolean,
Expand Down
3 changes: 1 addition & 2 deletions packages/jest-cli/src/SnapshotInteractiveMode.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,7 @@ import chalk from 'chalk';
import ansiEscapes from 'ansi-escapes';
import {KEYS} from 'jest-watcher';

import {pluralize} from './reporters/utils';
import {specialChars} from 'jest-util';
import {pluralize, specialChars} from 'jest-util';

const {ARROW, CLEAR} = specialChars;

Expand Down
12 changes: 7 additions & 5 deletions packages/jest-cli/src/TestScheduler.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,16 +19,18 @@ import {
buildFailureTestResult,
makeEmptyAggregatedTestResult,
} from './testResultHelpers';
import CoverageReporter from './reporters/coverage_reporter';
import DefaultReporter from './reporters/default_reporter';
import {
CoverageReporter,
DefaultReporter,
NotifyReporter,
SummaryReporter,
VerboseReporter,
} from '@jest/reporters';
import exit from 'exit';
import NotifyReporter from './reporters/notify_reporter';
import ReporterDispatcher from './ReporterDispatcher';
import snapshot from 'jest-snapshot';
import SummaryReporter from './reporters/summary_reporter';
import TestRunner from 'jest-runner';
import TestWatcher from './TestWatcher';
import VerboseReporter from './reporters/verbose_reporter';
import {shouldRunInBand} from './testSchedulerHelper';

// The default jest-runner is required because it is the default test runner
Expand Down
6 changes: 2 additions & 4 deletions packages/jest-cli/src/__tests__/TestScheduler.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,11 @@
*
*/

'use strict';

import {SummaryReporter} from '@jest/reporters';
import TestScheduler from '../TestScheduler';
import SummaryReporter from '../reporters/summary_reporter';
import * as testSchedulerHelper from '../testSchedulerHelper';

jest.mock('../reporters/default_reporter');
jest.mock('@jest/reporters');
const mockSerialRunner = {
isSerial: true,
runTests: jest.fn(),
Expand Down
52 changes: 18 additions & 34 deletions packages/jest-cli/src/__tests__/watch.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -91,20 +91,23 @@ const regularUpdateGlobalConfig = require('../lib/update_global_config')
const updateGlobalConfig = jest.fn(regularUpdateGlobalConfig);
jest.doMock('../lib/update_global_config', () => updateGlobalConfig);

const watch = require('../watch').default;

const nextTick = () => new Promise(res => process.nextTick(res));

afterEach(runJestMock.mockReset);

describe('Watch mode flows', () => {
let watch;
let isInteractive;
let pipe;
let hasteMapInstances;
let globalConfig;
let contexts;
let stdin;

beforeEach(() => {
isInteractive = true;
jest.doMock('jest-util/build/isInteractive', () => isInteractive);
watch = require('../watch').default;
const config = {roots: [], testPathIgnorePatterns: [], testRegex: []};
pipe = {write: jest.fn()};
globalConfig = {watch: true};
Expand All @@ -114,6 +117,10 @@ describe('Watch mode flows', () => {
results = {snapshot: {}};
});

afterEach(() => {
jest.resetModules();
});

it('Correctly passing test path pattern', () => {
globalConfig.testPathPattern = 'test-*';

Expand Down Expand Up @@ -143,12 +150,7 @@ describe('Watch mode flows', () => {
});

it('Runs Jest once by default and shows usage', () => {
jest.unmock('jest-util');
const util = require('jest-util');
util.isInteractive = true;

const ci_watch = require('../watch').default;
ci_watch(globalConfig, contexts, pipe, hasteMapInstances, stdin);
watch(globalConfig, contexts, pipe, hasteMapInstances, stdin);
expect(runJestMock.mock.calls[0][0]).toMatchObject({
contexts,
globalConfig,
Expand All @@ -160,12 +162,11 @@ describe('Watch mode flows', () => {
});

it('Runs Jest in a non-interactive environment not showing usage', () => {
jest.unmock('jest-util');
const util = require('jest-util');
util.isInteractive = false;
jest.resetModules();
isInteractive = false;

const ci_watch = require('../watch').default;
ci_watch(globalConfig, contexts, pipe, hasteMapInstances, stdin);
watch = require('../watch').default;
watch(globalConfig, contexts, pipe, hasteMapInstances, stdin);
expect(runJestMock.mock.calls[0][0]).toMatchObject({
contexts,
globalConfig,
Expand Down Expand Up @@ -193,12 +194,7 @@ describe('Watch mode flows', () => {
});

it('shows prompts for WatchPlugins in alphabetical order', async () => {
jest.unmock('jest-util');
const util = require('jest-util');
util.isInteractive = true;

const ci_watch = require('../watch').default;
ci_watch(
watch(
{
...globalConfig,
rootDir: __dirname,
Expand All @@ -223,13 +219,9 @@ describe('Watch mode flows', () => {
});

it('shows update snapshot prompt (without interactive)', async () => {
jest.unmock('jest-util');
const util = require('jest-util');
util.isInteractive = true;
results = {snapshot: {failure: true}};

const ci_watch = require('../watch').default;
ci_watch(
watch(
{
...globalConfig,
rootDir: __dirname,
Expand All @@ -251,9 +243,6 @@ describe('Watch mode flows', () => {
});

it('shows update snapshot prompt (with interactive)', async () => {
jest.unmock('jest-util');
const util = require('jest-util');
util.isInteractive = true;
results = {
numFailedTests: 1,
snapshot: {
Expand All @@ -275,8 +264,7 @@ describe('Watch mode flows', () => {
],
};

const ci_watch = require('../watch').default;
ci_watch(
watch(
{
...globalConfig,
rootDir: __dirname,
Expand Down Expand Up @@ -938,11 +926,7 @@ describe('Watch mode flows', () => {
});

it('shows the correct usage for the f key in "only failed tests" mode', () => {
jest.unmock('jest-util');
const util = require('jest-util');
util.isInteractive = true;
const ci_watch = require('../watch').default;
ci_watch(globalConfig, contexts, pipe, hasteMapInstances, stdin);
watch(globalConfig, contexts, pipe, hasteMapInstances, stdin);

stdin.emit('f');
stdin.emit('w');
Expand Down
5 changes: 3 additions & 2 deletions packages/jest-cli/src/cli/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ import type {Argv} from 'types/Argv';
import type {GlobalConfig, Path} from 'types/Config';

import path from 'path';
import {Console, clearLine, createDirectory} from 'jest-util';
import {Console, clearLine, createDirectory, preRunMessage} from 'jest-util';
import {validateCLIOptions} from 'jest-validate';
import {readConfigs, deprecationEntries} from 'jest-config';
import * as args from './args';
Expand All @@ -22,7 +22,6 @@ import exit from 'exit';
import getChangedFilesPromise from '../getChangedFilesPromise';
import {formatHandleErrors} from '../collectHandles';
import handleDeprecationWarnings from '../lib/handle_deprecation_warnings';
import {print as preRunMessagePrint} from '../preRunMessage';
import runJest from '../runJest';
import Runtime from 'jest-runtime';
import TestWatcher from '../TestWatcher';
Expand All @@ -35,6 +34,8 @@ import init from '../lib/init';
import logDebugMessages from '../lib/log_debug_messages';
import getVersion from '../version';

const {print: preRunMessagePrint} = preRunMessage;

export async function run(maybeArgv?: Argv, project?: Path) {
try {
// $FlowFixMe:`allow reduced return
Expand Down
5 changes: 3 additions & 2 deletions packages/jest-cli/src/watch.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,7 @@ import exit from 'exit';
import HasteMap from 'jest-haste-map';
import {formatExecError} from 'jest-message-util';
import isValidPath from './lib/is_valid_path';
import {isInteractive, specialChars} from 'jest-util';
import {print as preRunMessagePrint} from './preRunMessage';
import {isInteractive, preRunMessage, specialChars} from 'jest-util';
import createContext from './lib/create_context';
import runJest from './runJest';
import updateGlobalConfig from './lib/update_global_config';
Expand All @@ -40,6 +39,8 @@ import {
import {ValidationError} from 'jest-validate';
import activeFilters from './lib/active_filters_message';

const {print: preRunMessagePrint} = preRunMessage;

let hasExitListener = false;

const INTERNAL_PLUGINS = [
Expand Down
3 changes: 3 additions & 0 deletions packages/jest-reporters/.npmignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
**/__mocks__/**
**/__tests__/**
src
46 changes: 46 additions & 0 deletions packages/jest-reporters/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
{
"name": "@jest/reporters",
"description": "Jest's reporters",
"version": "24.1.0",
"main": "build/index.js",
"dependencies": {
"chalk": "^2.0.1",
"exit": "^0.1.2",
"glob": "^7.1.2",
"jest-runtime": "^24.1.0",
"istanbul-api": "^2.1.1",
"istanbul-lib-coverage": "^2.0.2",
"istanbul-lib-instrument": "^3.0.1",
"istanbul-lib-source-maps": "^3.0.1",
"jest-util": "^24.0.0",
"jest-worker": "^24.0.0",
"node-notifier": "^5.2.1",
"slash": "^2.0.0",
"string-length": "^2.0.0"
},
"devDependencies": {
"@types/exit": "^0.1.30",
"@types/glob": "^7.1.1",
"@types/istanbul-lib-coverage": "^1.1.0",
"@types/istanbul-lib-instrument": "^1.7.2",
"@types/istanbul-lib-source-maps": "^1.2.1",
"@types/node-notifier": "^0.0.28",
"@types/slash": "^2.0.0",
"@types/string-length": "^2.0.0",
"strip-ansi": "^5.0.0"
},
"engines": {
"node": ">= 6"
},
"repository": {
"type": "git",
"url": "https://github.com/facebook/jest",
"directory": "packages/jest-reporters"
},
"bugs": {
"url": "https://github.com/facebook/jest/issues"
},
"homepage": "https://jestjs.io/",
"license": "MIT",
"gitHead": "b16789230fd45056a7f2fa199bae06c7a1780deb"
}
File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@
* This source code is licensed under the MIT license found in the
* LICENSE file in the root directory of this source tree.
*/
'use strict';

jest.mock('istanbul-lib-source-maps').mock('istanbul-api');

Expand Down Expand Up @@ -322,7 +321,7 @@ describe('onRunComplete', () => {
});
});

test(`getLastError() returns 'undefined' when file and directory path
test(`getLastError() returns 'undefined' when file and directory path
threshold groups overlap`, () => {
const covThreshold = {};
[
Expand Down Expand Up @@ -356,8 +355,8 @@ describe('onRunComplete', () => {
});
});

test(`that if globs or paths are specified alongside global, coverage
data for matching paths will be subtracted from overall coverage
test(`that if globs or paths are specified alongside global, coverage
data for matching paths will be subtracted from overall coverage
and thresholds will be applied independently`, () => {
const testReporter = new CoverageReporter(
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@

'use strict';

jest.mock('fs').mock('../../generateEmptyCoverage');
jest.mock('fs').mock('../generateEmptyCoverage');

const globalConfig = {collectCoverage: true};
const config = {};
Expand All @@ -21,7 +21,7 @@ beforeEach(() => {
jest.resetModules();

fs = require('fs');
generateEmptyCoverage = require('../../generateEmptyCoverage').default;
generateEmptyCoverage = require('../generateEmptyCoverage').default;
worker = require('../coverage_worker').worker;
});

Expand Down
Loading

0 comments on commit b489779

Please sign in to comment.