diff --git a/CHANGELOG.md b/CHANGELOG.md index 7418adb3c9d2..9bfdfa66e605 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -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 diff --git a/packages/jest-cli/package.json b/packages/jest-cli/package.json index 98364d921fc4..c168519633fc 100644 --- a/packages/jest-cli/package.json +++ b/packages/jest-cli/package.json @@ -4,6 +4,7 @@ "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", @@ -11,10 +12,6 @@ "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", @@ -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", @@ -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" }, diff --git a/packages/jest-cli/src/SearchSource.js b/packages/jest-cli/src/SearchSource.js index 52d83bdb3f5a..bba5158d00e6 100644 --- a/packages/jest-cli/src/SearchSource.js +++ b/packages/jest-cli/src/SearchSource.js @@ -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, diff --git a/packages/jest-cli/src/SnapshotInteractiveMode.js b/packages/jest-cli/src/SnapshotInteractiveMode.js index d21910269b29..07c2a5a8f478 100644 --- a/packages/jest-cli/src/SnapshotInteractiveMode.js +++ b/packages/jest-cli/src/SnapshotInteractiveMode.js @@ -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; diff --git a/packages/jest-cli/src/TestScheduler.js b/packages/jest-cli/src/TestScheduler.js index 28511803998a..3427f60aa576 100644 --- a/packages/jest-cli/src/TestScheduler.js +++ b/packages/jest-cli/src/TestScheduler.js @@ -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 diff --git a/packages/jest-cli/src/__tests__/TestScheduler.test.js b/packages/jest-cli/src/__tests__/TestScheduler.test.js index 37e0ec836290..d99f93de8cb2 100644 --- a/packages/jest-cli/src/__tests__/TestScheduler.test.js +++ b/packages/jest-cli/src/__tests__/TestScheduler.test.js @@ -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(), diff --git a/packages/jest-cli/src/__tests__/watch.test.js b/packages/jest-cli/src/__tests__/watch.test.js index 8fd2b2926157..3d480a29fc23 100644 --- a/packages/jest-cli/src/__tests__/watch.test.js +++ b/packages/jest-cli/src/__tests__/watch.test.js @@ -91,13 +91,13 @@ 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; @@ -105,6 +105,9 @@ describe('Watch mode flows', () => { 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}; @@ -114,6 +117,10 @@ describe('Watch mode flows', () => { results = {snapshot: {}}; }); + afterEach(() => { + jest.resetModules(); + }); + it('Correctly passing test path pattern', () => { globalConfig.testPathPattern = 'test-*'; @@ -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, @@ -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, @@ -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, @@ -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, @@ -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: { @@ -275,8 +264,7 @@ describe('Watch mode flows', () => { ], }; - const ci_watch = require('../watch').default; - ci_watch( + watch( { ...globalConfig, rootDir: __dirname, @@ -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'); diff --git a/packages/jest-cli/src/cli/index.js b/packages/jest-cli/src/cli/index.js index a5d766fdd490..69a3ba889d78 100644 --- a/packages/jest-cli/src/cli/index.js +++ b/packages/jest-cli/src/cli/index.js @@ -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'; @@ -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'; @@ -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 diff --git a/packages/jest-cli/src/watch.js b/packages/jest-cli/src/watch.js index 3a060b1474e8..f630f8b085a4 100644 --- a/packages/jest-cli/src/watch.js +++ b/packages/jest-cli/src/watch.js @@ -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'; @@ -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 = [ diff --git a/packages/jest-reporters/.npmignore b/packages/jest-reporters/.npmignore new file mode 100644 index 000000000000..85e48fe7b0a4 --- /dev/null +++ b/packages/jest-reporters/.npmignore @@ -0,0 +1,3 @@ +**/__mocks__/** +**/__tests__/** +src diff --git a/packages/jest-reporters/package.json b/packages/jest-reporters/package.json new file mode 100644 index 000000000000..ac961627707c --- /dev/null +++ b/packages/jest-reporters/package.json @@ -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" +} diff --git a/packages/jest-cli/src/reporters/Status.js b/packages/jest-reporters/src/Status.js similarity index 100% rename from packages/jest-cli/src/reporters/Status.js rename to packages/jest-reporters/src/Status.js diff --git a/packages/jest-cli/src/__tests__/__snapshots__/generateEmptyCoverage.test.js.snap b/packages/jest-reporters/src/__tests__/__snapshots__/generateEmptyCoverage.test.js.snap similarity index 100% rename from packages/jest-cli/src/__tests__/__snapshots__/generateEmptyCoverage.test.js.snap rename to packages/jest-reporters/src/__tests__/__snapshots__/generateEmptyCoverage.test.js.snap diff --git a/packages/jest-cli/src/reporters/__tests__/__snapshots__/get_snapshot_status.test.js.snap b/packages/jest-reporters/src/__tests__/__snapshots__/get_snapshot_status.test.js.snap similarity index 100% rename from packages/jest-cli/src/reporters/__tests__/__snapshots__/get_snapshot_status.test.js.snap rename to packages/jest-reporters/src/__tests__/__snapshots__/get_snapshot_status.test.js.snap diff --git a/packages/jest-cli/src/reporters/__tests__/__snapshots__/get_snapshot_summary.test.js.snap b/packages/jest-reporters/src/__tests__/__snapshots__/get_snapshot_summary.test.js.snap similarity index 100% rename from packages/jest-cli/src/reporters/__tests__/__snapshots__/get_snapshot_summary.test.js.snap rename to packages/jest-reporters/src/__tests__/__snapshots__/get_snapshot_summary.test.js.snap diff --git a/packages/jest-cli/src/__tests__/__snapshots__/notify_reporter.test.js.snap b/packages/jest-reporters/src/__tests__/__snapshots__/notify_reporter.test.js.snap similarity index 100% rename from packages/jest-cli/src/__tests__/__snapshots__/notify_reporter.test.js.snap rename to packages/jest-reporters/src/__tests__/__snapshots__/notify_reporter.test.js.snap diff --git a/packages/jest-cli/src/reporters/__tests__/__snapshots__/summary_reporter.test.js.snap b/packages/jest-reporters/src/__tests__/__snapshots__/summary_reporter.test.js.snap similarity index 100% rename from packages/jest-cli/src/reporters/__tests__/__snapshots__/summary_reporter.test.js.snap rename to packages/jest-reporters/src/__tests__/__snapshots__/summary_reporter.test.js.snap diff --git a/packages/jest-cli/src/reporters/__tests__/__snapshots__/utils.test.js.snap b/packages/jest-reporters/src/__tests__/__snapshots__/utils.test.js.snap similarity index 100% rename from packages/jest-cli/src/reporters/__tests__/__snapshots__/utils.test.js.snap rename to packages/jest-reporters/src/__tests__/__snapshots__/utils.test.js.snap diff --git a/packages/jest-cli/src/reporters/__tests__/coverage_reporter.test.js b/packages/jest-reporters/src/__tests__/coverage_reporter.test.js similarity index 99% rename from packages/jest-cli/src/reporters/__tests__/coverage_reporter.test.js rename to packages/jest-reporters/src/__tests__/coverage_reporter.test.js index a93b1cc71749..1cebec0afdfd 100644 --- a/packages/jest-cli/src/reporters/__tests__/coverage_reporter.test.js +++ b/packages/jest-reporters/src/__tests__/coverage_reporter.test.js @@ -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'); @@ -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 = {}; [ @@ -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( { diff --git a/packages/jest-cli/src/reporters/__tests__/coverage_worker.test.js b/packages/jest-reporters/src/__tests__/coverage_worker.test.js similarity index 91% rename from packages/jest-cli/src/reporters/__tests__/coverage_worker.test.js rename to packages/jest-reporters/src/__tests__/coverage_worker.test.js index fe9d1f1bb5db..b3351ba29006 100644 --- a/packages/jest-cli/src/reporters/__tests__/coverage_worker.test.js +++ b/packages/jest-reporters/src/__tests__/coverage_worker.test.js @@ -7,7 +7,7 @@ 'use strict'; -jest.mock('fs').mock('../../generateEmptyCoverage'); +jest.mock('fs').mock('../generateEmptyCoverage'); const globalConfig = {collectCoverage: true}; const config = {}; @@ -21,7 +21,7 @@ beforeEach(() => { jest.resetModules(); fs = require('fs'); - generateEmptyCoverage = require('../../generateEmptyCoverage').default; + generateEmptyCoverage = require('../generateEmptyCoverage').default; worker = require('../coverage_worker').worker; }); diff --git a/packages/jest-cli/src/reporters/__tests__/default_reporter.test.js b/packages/jest-reporters/src/__tests__/default_reporter.test.js similarity index 100% rename from packages/jest-cli/src/reporters/__tests__/default_reporter.test.js rename to packages/jest-reporters/src/__tests__/default_reporter.test.js diff --git a/packages/jest-cli/src/__tests__/generateEmptyCoverage.test.js b/packages/jest-reporters/src/__tests__/generateEmptyCoverage.test.js similarity index 100% rename from packages/jest-cli/src/__tests__/generateEmptyCoverage.test.js rename to packages/jest-reporters/src/__tests__/generateEmptyCoverage.test.js diff --git a/packages/jest-cli/src/reporters/__tests__/get_snapshot_status.test.js b/packages/jest-reporters/src/__tests__/get_snapshot_status.test.js similarity index 100% rename from packages/jest-cli/src/reporters/__tests__/get_snapshot_status.test.js rename to packages/jest-reporters/src/__tests__/get_snapshot_status.test.js diff --git a/packages/jest-cli/src/reporters/__tests__/get_snapshot_summary.test.js b/packages/jest-reporters/src/__tests__/get_snapshot_summary.test.js similarity index 100% rename from packages/jest-cli/src/reporters/__tests__/get_snapshot_summary.test.js rename to packages/jest-reporters/src/__tests__/get_snapshot_summary.test.js diff --git a/packages/jest-cli/src/__tests__/notify_reporter.test.js b/packages/jest-reporters/src/__tests__/notify_reporter.test.js similarity index 88% rename from packages/jest-cli/src/__tests__/notify_reporter.test.js rename to packages/jest-reporters/src/__tests__/notify_reporter.test.js index 424b6f212d1a..274a2ca5d21c 100644 --- a/packages/jest-cli/src/__tests__/notify_reporter.test.js +++ b/packages/jest-reporters/src/__tests__/notify_reporter.test.js @@ -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(), })); @@ -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'); diff --git a/packages/jest-cli/src/reporters/__tests__/summary_reporter.test.js b/packages/jest-reporters/src/__tests__/summary_reporter.test.js similarity index 100% rename from packages/jest-cli/src/reporters/__tests__/summary_reporter.test.js rename to packages/jest-reporters/src/__tests__/summary_reporter.test.js diff --git a/packages/jest-cli/src/reporters/__tests__/utils.test.js b/packages/jest-reporters/src/__tests__/utils.test.js similarity index 100% rename from packages/jest-cli/src/reporters/__tests__/utils.test.js rename to packages/jest-reporters/src/__tests__/utils.test.js diff --git a/packages/jest-cli/src/reporters/__tests__/verbose_reporter.test.js b/packages/jest-reporters/src/__tests__/verbose_reporter.test.js similarity index 100% rename from packages/jest-cli/src/reporters/__tests__/verbose_reporter.test.js rename to packages/jest-reporters/src/__tests__/verbose_reporter.test.js diff --git a/packages/jest-cli/src/reporters/base_reporter.js b/packages/jest-reporters/src/base_reporter.js similarity index 92% rename from packages/jest-cli/src/reporters/base_reporter.js rename to packages/jest-reporters/src/base_reporter.js index 15e4bb613ebe..9cd86e89fb6a 100644 --- a/packages/jest-cli/src/reporters/base_reporter.js +++ b/packages/jest-reporters/src/base_reporter.js @@ -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; diff --git a/packages/jest-cli/src/reporters/coverage_reporter.js b/packages/jest-reporters/src/coverage_reporter.js similarity index 100% rename from packages/jest-cli/src/reporters/coverage_reporter.js rename to packages/jest-reporters/src/coverage_reporter.js diff --git a/packages/jest-cli/src/reporters/coverage_worker.js b/packages/jest-reporters/src/coverage_worker.js similarity index 88% rename from packages/jest-cli/src/reporters/coverage_worker.js rename to packages/jest-reporters/src/coverage_worker.js index 6a7feded80e1..13c41e4dceea 100644 --- a/packages/jest-cli/src/reporters/coverage_worker.js +++ b/packages/jest-reporters/src/coverage_worker.js @@ -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, diff --git a/packages/jest-cli/src/reporters/default_reporter.js b/packages/jest-reporters/src/default_reporter.js similarity index 100% rename from packages/jest-cli/src/reporters/default_reporter.js rename to packages/jest-reporters/src/default_reporter.js diff --git a/packages/jest-cli/src/generateEmptyCoverage.js b/packages/jest-reporters/src/generateEmptyCoverage.js similarity index 100% rename from packages/jest-cli/src/generateEmptyCoverage.js rename to packages/jest-reporters/src/generateEmptyCoverage.js diff --git a/packages/jest-cli/src/reporters/get_result_header.js b/packages/jest-reporters/src/get_result_header.js similarity index 100% rename from packages/jest-cli/src/reporters/get_result_header.js rename to packages/jest-reporters/src/get_result_header.js diff --git a/packages/jest-cli/src/reporters/get_snapshot_status.js b/packages/jest-reporters/src/get_snapshot_status.js similarity index 95% rename from packages/jest-cli/src/reporters/get_snapshot_status.js rename to packages/jest-reporters/src/get_snapshot_status.js index b4822af53578..8406fa3fa3a2 100644 --- a/packages/jest-cli/src/reporters/get_snapshot_status.js +++ b/packages/jest-reporters/src/get_snapshot_status.js @@ -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 '; diff --git a/packages/jest-cli/src/reporters/get_snapshot_summary.js b/packages/jest-reporters/src/get_snapshot_summary.js similarity index 97% rename from packages/jest-cli/src/reporters/get_snapshot_summary.js rename to packages/jest-reporters/src/get_snapshot_summary.js index b5a3a63cb891..60eea8aa0cab 100644 --- a/packages/jest-cli/src/reporters/get_snapshot_summary.js +++ b/packages/jest-reporters/src/get_snapshot_summary.js @@ -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 '; diff --git a/packages/jest-reporters/src/index.js b/packages/jest-reporters/src/index.js new file mode 100644 index 000000000000..c714b0cce89c --- /dev/null +++ b/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'; diff --git a/packages/jest-cli/src/reporters/notify_reporter.js b/packages/jest-reporters/src/notify_reporter.js similarity index 98% rename from packages/jest-cli/src/reporters/notify_reporter.js rename to packages/jest-reporters/src/notify_reporter.js index 3ab911c12844..9a6c9a27f3cb 100644 --- a/packages/jest-cli/src/reporters/notify_reporter.js +++ b/packages/jest-reporters/src/notify_reporter.js @@ -9,6 +9,7 @@ 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'; @@ -16,7 +17,6 @@ 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'; diff --git a/packages/jest-cli/src/reporters/summary_reporter.js b/packages/jest-reporters/src/summary_reporter.js similarity index 99% rename from packages/jest-cli/src/reporters/summary_reporter.js rename to packages/jest-reporters/src/summary_reporter.js index d51a1a6eef6a..863ab6e0db41 100644 --- a/packages/jest-cli/src/reporters/summary_reporter.js +++ b/packages/jest-reporters/src/summary_reporter.js @@ -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; diff --git a/packages/jest-cli/src/reporters/utils.js b/packages/jest-reporters/src/utils.js similarity index 98% rename from packages/jest-cli/src/reporters/utils.js rename to packages/jest-reporters/src/utils.js index 997ca3a0a3a7..f2f17e52f0a2 100644 --- a/packages/jest-cli/src/reporters/utils.js +++ b/packages/jest-reporters/src/utils.js @@ -13,6 +13,7 @@ import type {AggregatedResult} from 'types/TestResult'; import path from 'path'; import chalk from 'chalk'; import slash from 'slash'; +import {pluralize} from 'jest-util'; type SummaryOptions = {| estimatedTime?: number, @@ -92,9 +93,6 @@ export const relativePath = ( return {basename, dirname}; }; -export const pluralize = (word: string, count: number) => - `${count} ${word}${count === 1 ? '' : 's'}`; - export const getSummary = ( aggregatedResults: AggregatedResult, options?: SummaryOptions, diff --git a/packages/jest-cli/src/reporters/verbose_reporter.js b/packages/jest-reporters/src/verbose_reporter.js similarity index 100% rename from packages/jest-cli/src/reporters/verbose_reporter.js rename to packages/jest-reporters/src/verbose_reporter.js diff --git a/packages/jest-util/src/index.ts b/packages/jest-util/src/index.ts index 5ea75756a5c5..66c38c2b63e0 100644 --- a/packages/jest-util/src/index.ts +++ b/packages/jest-util/src/index.ts @@ -23,6 +23,9 @@ import deepCyclicCopy from './deepCyclicCopy'; import convertDescriptorToString from './convertDescriptorToString'; import * as specialChars from './specialChars'; import replacePathSepForGlob from './replacePathSepForGlob'; +import testPathPatternToRegExp from './testPathPatternToRegExp'; +import * as preRunMessage from './preRunMessage'; +import pluralize from './pluralize'; export = { BufferedConsole, @@ -40,7 +43,10 @@ export = { getFailedSnapshotTests, installCommonGlobals, isInteractive, + pluralize, + preRunMessage, replacePathSepForGlob, setGlobal, specialChars, + testPathPatternToRegExp, }; diff --git a/packages/jest-util/src/pluralize.ts b/packages/jest-util/src/pluralize.ts new file mode 100644 index 000000000000..95f29391cc5a --- /dev/null +++ b/packages/jest-util/src/pluralize.ts @@ -0,0 +1,10 @@ +/** + * 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. + */ + +export default function pluralize(word: string, count: number) { + return `${count} ${word}${count === 1 ? '' : 's'}`; +} diff --git a/packages/jest-cli/src/preRunMessage.js b/packages/jest-util/src/preRunMessage.ts similarity index 65% rename from packages/jest-cli/src/preRunMessage.js rename to packages/jest-util/src/preRunMessage.ts index 3089222cb6b2..d6c8979fa1e6 100644 --- a/packages/jest-cli/src/preRunMessage.js +++ b/packages/jest-util/src/preRunMessage.ts @@ -3,21 +3,19 @@ * * This source code is licensed under the MIT license found in the * LICENSE file in the root directory of this source tree. - * - * @flow */ -import {clearLine, isInteractive} from 'jest-util'; - import chalk from 'chalk'; +import clearLine from './clearLine'; +import isInteractive from './isInteractive'; -export const print = (stream: stream$Writable | tty$WriteStream) => { +export const print = (stream: NodeJS.WritableStream) => { if (isInteractive) { stream.write(chalk.bold.dim('Determining test suites to run...')); } }; -export const remove = (stream: stream$Writable | tty$WriteStream) => { +export const remove = (stream: NodeJS.WritableStream) => { if (isInteractive) { clearLine(stream); } diff --git a/packages/jest-cli/src/testPathPatternToRegexp.js b/packages/jest-util/src/testPathPatternToRegExp.ts similarity index 74% rename from packages/jest-cli/src/testPathPatternToRegexp.js rename to packages/jest-util/src/testPathPatternToRegExp.ts index 8bc775f23b78..c64f8d2af7da 100644 --- a/packages/jest-cli/src/testPathPatternToRegexp.js +++ b/packages/jest-util/src/testPathPatternToRegExp.ts @@ -3,11 +3,12 @@ * * This source code is licensed under the MIT license found in the * LICENSE file in the root directory of this source tree. - * - * @flow */ +import {Config} from '@jest/types'; + // Because we serialize/deserialize globalConfig when we spawn workers, // we can't pass regular expression. Using this shared function on both sides // will ensure that we produce consistent regexp for testPathPattern. -export default (testPathPattern: string) => new RegExp(testPathPattern, 'i'); +export default (testPathPattern: Config.GlobalConfig['testPathPattern']) => + new RegExp(testPathPattern, 'i'); diff --git a/types/TestScheduler.js b/types/TestScheduler.js new file mode 100644 index 000000000000..eab290edb364 --- /dev/null +++ b/types/TestScheduler.js @@ -0,0 +1,16 @@ +/** + * 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 + */ + +import type {Path} from './Config'; + +export type TestSchedulerContext = {| + firstRun: boolean, + previousSuccess: boolean, + changedFiles?: Set, +|};