Skip to content

Commit

Permalink
chore: split out reporters into separate package
Browse files Browse the repository at this point in the history
  • Loading branch information
SimenB committed Feb 14, 2019
1 parent 06c2567 commit cf85688
Show file tree
Hide file tree
Showing 45 changed files with 144 additions and 69 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Expand Up @@ -37,6 +37,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`

### Performance

Expand Down
13 changes: 2 additions & 11 deletions packages/jest-cli/package.json
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.0.8",
"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
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
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
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
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
5 changes: 3 additions & 2 deletions packages/jest-cli/src/cli/index.js
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
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
@@ -0,0 +1,3 @@
**/__mocks__/**
**/__tests__/**
src
45 changes: 45 additions & 0 deletions packages/jest-reporters/package.json
@@ -0,0 +1,45 @@
{
"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",
"istanbul-api": "^2.0.8",
"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.
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
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
Expand Up @@ -6,14 +6,11 @@
*
*/

'use strict';

import TestScheduler from '../TestScheduler';
import NotifyReporter from '../reporters/notify_reporter';
import type {TestSchedulerContext} from '../TestScheduler';
import type {TestSchedulerContext} from 'types/TestScheduler';
import NotifyReporter from '../notify_reporter';
import type {AggregatedResult} from '../../../../types/TestResult';

jest.mock('../reporters/default_reporter');
jest.mock('../default_reporter');
jest.mock('node-notifier', () => ({
notify: jest.fn(),
}));
Expand Down Expand Up @@ -68,15 +65,6 @@ const notifyEvents = [
aggregatedResultsFailure,
];

test('.addReporter() .removeReporter()', () => {
const scheduler = new TestScheduler({}, {}, {...initialContext});
const reporter = new NotifyReporter();
scheduler.addReporter(reporter);
expect(scheduler._dispatcher._reporters).toContain(reporter);
scheduler.removeReporter(NotifyReporter);
expect(scheduler._dispatcher._reporters).not.toContain(reporter);
});

const testModes = ({notifyMode, arl, rootDir, moduleName}) => {
const notify = require('node-notifier');

Expand Down
Expand Up @@ -12,7 +12,9 @@ import type {Context} from 'types/Context';
import type {Test} from 'types/TestRunner';
import type {ReporterOnStartOptions} from 'types/Reporters';

import {remove as preRunMessageRemove} from '../preRunMessage';
import {preRunMessage} from 'jest-util';

const {remove: preRunMessageRemove} = preRunMessage;

export default class BaseReporter {
_error: ?Error;
Expand Down
Expand Up @@ -12,8 +12,9 @@ import type {CoverageReporterOptions} from './coverage_reporter';

import exit from 'exit';
import fs from 'fs';
import generateEmptyCoverage from '../generateEmptyCoverage';
import type {CoverageWorkerResult} from '../generateEmptyCoverage';
import generateEmptyCoverage, {
type CoverageWorkerResult,
} from './generateEmptyCoverage';

export type CoverageWorkerData = {|
globalConfig: GlobalConfig,
Expand Down
Expand Up @@ -9,9 +9,9 @@

import type {TestResult} from 'types/TestResult';

const chalk = require('chalk');
import chalk from 'chalk';

const {pluralize} = require('./utils');
import {pluralize} from 'jest-util';

const ARROW = ' \u203A ';
const DOT = ' \u2022 ';
Expand Down
Expand Up @@ -11,7 +11,8 @@ import type {SnapshotSummary} from 'types/TestResult';
import type {GlobalConfig} from 'types/Config';

import chalk from 'chalk';
import {formatTestPath, pluralize} from './utils';
import {pluralize} from 'jest-util';
import {formatTestPath} from './utils';

const ARROW = ' \u203A ';
const DOWN_ARROW = ' \u21B3 ';
Expand Down
15 changes: 15 additions & 0 deletions packages/jest-reporters/src/index.js
@@ -0,0 +1,15 @@
/**
* 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.
*
* @flow
*/

export {default as BaseReporter} from './base_reporter';
export {default as CoverageReporter} from './coverage_reporter';
export {default as DefaultReporter} from './default_reporter';
export {default as NotifyReporter} from './notify_reporter';
export {default as SummaryReporter} from './summary_reporter';
export {default as VerboseReporter} from './verbose_reporter';
Expand Up @@ -9,14 +9,14 @@

import type {GlobalConfig} from 'types/Config';
import type {AggregatedResult} from 'types/TestResult';
import type {TestSchedulerContext} from 'types/TestScheduler';
import type {Context} from 'types/Context';

import exit from 'exit';
import path from 'path';
import util from 'util';
import notifier from 'node-notifier';
import BaseReporter from './base_reporter';
import type {TestSchedulerContext} from '../TestScheduler';

const isDarwin = process.platform === 'darwin';

Expand Down
Expand Up @@ -13,11 +13,11 @@ import type {Context} from 'types/Context';
import type {ReporterOnStartOptions} from 'types/Reporters';

import chalk from 'chalk';
import {testPathPatternToRegExp} from 'jest-util';
import BaseReporter from './base_reporter';
import {getSummary} from './utils';
import getResultHeader from './get_result_header';
import getSnapshotSummary from './get_snapshot_summary';
import testPathPatternToRegExp from '../testPathPatternToRegexp';

const TEST_SUMMARY_THRESHOLD = 20;

Expand Down

0 comments on commit cf85688

Please sign in to comment.