From 5580e2884cbbe189416902197c62fd28bb6ce5a3 Mon Sep 17 00:00:00 2001 From: Lorenzo Rapetti Date: Tue, 26 Feb 2019 15:11:18 +0100 Subject: [PATCH 01/10] Initial migration of @jest/reporters to TypeScript --- packages/jest-reporters/package.json | 8 + .../src/{Status.js => Status.ts} | 41 ++-- .../{base_reporter.js => base_reporter.ts} | 29 +-- ...erage_reporter.js => coverage_reporter.ts} | 216 +++++++++--------- ...{coverage_worker.js => coverage_worker.ts} | 28 +-- ...efault_reporter.js => default_reporter.ts} | 46 ++-- ...tyCoverage.js => generateEmptyCoverage.ts} | 26 +-- ..._result_header.js => get_result_header.ts} | 12 +- ...pshot_status.js => get_snapshot_status.ts} | 5 +- ...hot_summary.js => get_snapshot_summary.ts} | 8 +- ...{notify_reporter.js => notify_reporter.ts} | 26 +-- ...ummary_reporter.js => summary_reporter.ts} | 32 +-- packages/jest-reporters/src/types.ts | 118 ++++++++++ .../jest-reporters/src/{utils.js => utils.ts} | 36 ++- ...erbose_reporter.js => verbose_reporter.ts} | 35 ++- packages/jest-reporters/tsconfig.json | 16 ++ yarn.lock | 5 + 17 files changed, 405 insertions(+), 282 deletions(-) rename packages/jest-reporters/src/{Status.js => Status.ts} (81%) rename packages/jest-reporters/src/{base_reporter.js => base_reporter.ts} (57%) rename packages/jest-reporters/src/{coverage_reporter.js => coverage_reporter.ts} (66%) rename packages/jest-reporters/src/{coverage_worker.js => coverage_worker.ts} (63%) rename packages/jest-reporters/src/{default_reporter.js => default_reporter.ts} (84%) rename packages/jest-reporters/src/{generateEmptyCoverage.js => generateEmptyCoverage.ts} (75%) rename packages/jest-reporters/src/{get_result_header.js => get_result_header.ts} (85%) rename packages/jest-reporters/src/{get_snapshot_status.js => get_snapshot_status.ts} (93%) rename packages/jest-reporters/src/{get_snapshot_summary.js => get_snapshot_summary.ts} (95%) rename packages/jest-reporters/src/{notify_reporter.js => notify_reporter.ts} (88%) rename packages/jest-reporters/src/{summary_reporter.js => summary_reporter.ts} (89%) create mode 100644 packages/jest-reporters/src/types.ts rename packages/jest-reporters/src/{utils.js => utils.ts} (91%) rename packages/jest-reporters/src/{verbose_reporter.js => verbose_reporter.ts} (83%) create mode 100644 packages/jest-reporters/tsconfig.json diff --git a/packages/jest-reporters/package.json b/packages/jest-reporters/package.json index fceb1f9e0de0..ccf41f992d2a 100644 --- a/packages/jest-reporters/package.json +++ b/packages/jest-reporters/package.json @@ -3,8 +3,12 @@ "description": "Jest's reporters", "version": "24.1.0", "main": "build/index.js", + "types": "build/index.d.ts", "dependencies": { + "@jest/core": "^24.1.0", + "@jest/environment": "^24.1.0", "@jest/transform": "^24.1.0", + "@jest/types": "^24.1.0", "chalk": "^2.0.1", "exit": "^0.1.2", "glob": "^7.1.2", @@ -12,6 +16,9 @@ "istanbul-lib-coverage": "^2.0.2", "istanbul-lib-instrument": "^3.0.1", "istanbul-lib-source-maps": "^3.0.1", + "jest-haste-map": "^24.0.0", + "jest-resolve": "^24.1.0", + "jest-runtime": "^24.1.0", "jest-util": "^24.0.0", "jest-worker": "^24.0.0", "node-notifier": "^5.2.1", @@ -21,6 +28,7 @@ "devDependencies": { "@types/exit": "^0.1.30", "@types/glob": "^7.1.1", + "@types/istanbul": "^0.4.30", "@types/istanbul-lib-coverage": "^1.1.0", "@types/istanbul-lib-instrument": "^1.7.2", "@types/istanbul-lib-source-maps": "^1.2.1", diff --git a/packages/jest-reporters/src/Status.js b/packages/jest-reporters/src/Status.ts similarity index 81% rename from packages/jest-reporters/src/Status.js rename to packages/jest-reporters/src/Status.ts index 6dbb87f73d6b..2534df48243b 100644 --- a/packages/jest-reporters/src/Status.js +++ b/packages/jest-reporters/src/Status.ts @@ -4,15 +4,13 @@ * 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 {AggregatedResult, TestResult} from 'types/TestResult'; -import type {ProjectConfig, Path} from 'types/Config'; -import type {ReporterOnStartOptions} from 'types/Reporters'; +import {TestResult, Config} from '@jest/types'; import chalk from 'chalk'; import stringLength from 'string-length'; +import {ReporterOnStartOptions} from './types'; import { getSummary, trimAndFormatPath, @@ -29,13 +27,13 @@ const RUNNING = chalk.reset.inverse.yellow.bold(RUNNING_TEXT) + ' '; * shifting the whole list. */ class CurrentTestList { - _array: Array<{testPath: Path, config: ProjectConfig} | null>; + _array: Array<{testPath: Config.Path; config: Config.ProjectConfig} | null>; constructor() { this._array = []; } - add(testPath, config) { + add(testPath: Config.Path, config: Config.ProjectConfig) { const index = this._array.indexOf(null); const record = {config, testPath}; if (index !== -1) { @@ -45,9 +43,9 @@ class CurrentTestList { } } - delete(testPath) { + delete(testPath: Config.Path) { const record = this._array.find( - record => record && record.testPath === testPath, + record => record !== null && record.testPath === testPath, ); this._array[this._array.indexOf(record || null)] = null; } @@ -63,16 +61,16 @@ class CurrentTestList { * from the terminal. */ export default class Status { - _cache: ?{content: string, clear: string}; - _callback: () => void; + _cache: {content: string; clear: string} | null; + _callback?: () => void; _currentTests: CurrentTestList; _done: boolean; _emitScheduled: boolean; _estimatedTime: number; _height: number; - _interval: IntervalID; - _aggregatedResults: AggregatedResult; - _lastUpdated: number; + _interval?: NodeJS.Timeout; + _aggregatedResults?: TestResult.AggregatedResult; + _lastUpdated?: number; _showStatus: boolean; constructor() { @@ -90,7 +88,7 @@ export default class Status { } runStarted( - aggregatedResults: AggregatedResult, + aggregatedResults: TestResult.AggregatedResult, options: ReporterOnStartOptions, ) { this._estimatedTime = (options && options.estimatedTime) || 0; @@ -102,11 +100,11 @@ export default class Status { runFinished() { this._done = true; - clearInterval(this._interval); + if (this._interval) clearInterval(this._interval); this._emit(); } - testStarted(testPath: Path, config: ProjectConfig) { + testStarted(testPath: Config.Path, config: Config.ProjectConfig) { this._currentTests.add(testPath, config); if (!this._showStatus) { this._emit(); @@ -116,9 +114,9 @@ export default class Status { } testFinished( - config: ProjectConfig, - testResult: TestResult, - aggregatedResults: AggregatedResult, + config: Config.ProjectConfig, + testResult: TestResult.TestResult, + aggregatedResults: TestResult.AggregatedResult, ) { const {testFilePath} = testResult; this._aggregatedResults = aggregatedResults; @@ -135,8 +133,7 @@ export default class Status { return {clear: '', content: ''}; } - // $FlowFixMe - const width: number = process.stdout.columns; + const width: number = process.stdout.columns!; let content = '\n'; this._currentTests.get().forEach(record => { if (record) { @@ -181,7 +178,7 @@ export default class Status { _emit() { this._cache = null; this._lastUpdated = Date.now(); - this._callback(); + if (this._callback) this._callback(); } _debouncedEmit() { diff --git a/packages/jest-reporters/src/base_reporter.js b/packages/jest-reporters/src/base_reporter.ts similarity index 57% rename from packages/jest-reporters/src/base_reporter.js rename to packages/jest-reporters/src/base_reporter.ts index 9cd86e89fb6a..6746c8c389ae 100644 --- a/packages/jest-reporters/src/base_reporter.js +++ b/packages/jest-reporters/src/base_reporter.ts @@ -4,37 +4,40 @@ * 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 {AggregatedResult, TestResult} from 'types/TestResult'; -import type {Context} from 'types/Context'; -import type {Test} from 'types/TestRunner'; -import type {ReporterOnStartOptions} from 'types/Reporters'; - +import {TestResult} from '@jest/types'; import {preRunMessage} from 'jest-util'; +import {ReporterOnStartOptions, Context, Test, Reporter} from './types'; const {remove: preRunMessageRemove} = preRunMessage; -export default class BaseReporter { - _error: ?Error; +export default class BaseReporter implements Reporter { + _error?: Error; log(message: string) { process.stderr.write(message + '\n'); } - onRunStart(results: AggregatedResult, options: ReporterOnStartOptions) { + onRunStart( + results: TestResult.AggregatedResult, + options: ReporterOnStartOptions, + ) { preRunMessageRemove(process.stderr); } - onTestResult(test: Test, testResult: TestResult, results: AggregatedResult) {} + onTestResult( + test: Test, + testResult: TestResult.TestResult, + results: TestResult.AggregatedResult, + ) {} onTestStart(test: Test) {} onRunComplete( contexts: Set, - aggregatedResults: AggregatedResult, - ): ?Promise {} + aggregatedResults: TestResult.AggregatedResult, + ): Promise | void {} _setError(error: Error) { this._error = error; @@ -42,7 +45,7 @@ export default class BaseReporter { // Return an error that occurred during reporting. This error will // define whether the test run was successful or failed. - getLastError(): ?Error { + getLastError() { return this._error; } } diff --git a/packages/jest-reporters/src/coverage_reporter.js b/packages/jest-reporters/src/coverage_reporter.ts similarity index 66% rename from packages/jest-reporters/src/coverage_reporter.js rename to packages/jest-reporters/src/coverage_reporter.ts index d8466110f720..298585efdb19 100644 --- a/packages/jest-reporters/src/coverage_reporter.js +++ b/packages/jest-reporters/src/coverage_reporter.ts @@ -4,48 +4,45 @@ * 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 { - AggregatedResult, - CoverageMap, - FileCoverage, - CoverageSummary, - TestResult, -} from 'types/TestResult'; -import typeof {worker} from './coverage_worker'; - -import type {GlobalConfig, Path} from 'types/Config'; -import type {Context} from 'types/Context'; -import type {Test} from 'types/TestRunner'; +import path from 'path'; +import {TestResult, Config} from '@jest/types'; import {clearLine, isInteractive} from 'jest-util'; +// @ts-ignore Apparently there aren't any types for this package? import {createReporter} from 'istanbul-api'; import chalk from 'chalk'; -import istanbulCoverage from 'istanbul-lib-coverage'; -import libSourceMaps from 'istanbul-lib-source-maps'; +import istanbulCoverage, { + CoverageMap, + FileCoverage, + Totals, +} from 'istanbul-lib-coverage'; +import libSourceMaps, {MapStore} from 'istanbul-lib-source-maps'; import Worker from 'jest-worker'; -import BaseReporter from './base_reporter'; -import path from 'path'; import glob from 'glob'; +import BaseReporter from './base_reporter'; +import { + Context, + Test, + CoverageSummary, + CoverageWorker, + CoverageReporterOptions, +} from './types'; const FAIL_COLOR = chalk.bold.red; const RUNNING_TEST_COLOR = chalk.bold.dim; -type CoverageWorker = {worker: worker}; - -export type CoverageReporterOptions = { - changedFiles?: Set, -}; - export default class CoverageReporter extends BaseReporter { _coverageMap: CoverageMap; - _globalConfig: GlobalConfig; - _sourceMapStore: any; + _globalConfig: Config.GlobalConfig; + _sourceMapStore: MapStore; _options: CoverageReporterOptions; - constructor(globalConfig: GlobalConfig, options?: CoverageReporterOptions) { + constructor( + globalConfig: Config.GlobalConfig, + options?: CoverageReporterOptions, + ) { super(); this._coverageMap = istanbulCoverage.createCoverageMap({}); this._globalConfig = globalConfig; @@ -55,8 +52,8 @@ export default class CoverageReporter extends BaseReporter { onTestResult( test: Test, - testResult: TestResult, - aggregatedResults: AggregatedResult, + testResult: TestResult.TestResult, + aggregatedResults: TestResult.AggregatedResult, ) { if (testResult.coverage) { this._coverageMap.merge(testResult.coverage); @@ -64,12 +61,12 @@ export default class CoverageReporter extends BaseReporter { delete testResult.coverage; Object.keys(testResult.sourceMaps).forEach(sourcePath => { - let inputSourceMap: ?Object; + let inputSourceMap: any; try { const coverage: FileCoverage = this._coverageMap.fileCoverageFor( sourcePath, ); - ({inputSourceMap} = coverage.toJSON()); + ({inputSourceMap} = coverage.toJSON() as any); } finally { if (inputSourceMap) { this._sourceMapStore.registerMap(sourcePath, inputSourceMap); @@ -86,7 +83,7 @@ export default class CoverageReporter extends BaseReporter { async onRunComplete( contexts: Set, - aggregatedResults: AggregatedResult, + aggregatedResults: TestResult.AggregatedResult, ) { await this._addUntestedFiles(this._globalConfig, contexts); const {map, sourceFinder} = this._sourceMapStore.transformCoverage( @@ -122,10 +119,10 @@ export default class CoverageReporter extends BaseReporter { } async _addUntestedFiles( - globalConfig: GlobalConfig, + globalConfig: Config.GlobalConfig, contexts: Set, ): Promise { - const files = []; + const files: Array<{config: Config.ProjectConfig; path: string}> = []; contexts.forEach(context => { const config = context.config; @@ -154,7 +151,7 @@ export default class CoverageReporter extends BaseReporter { ); } - let worker: CoverageWorker; + let worker: CoverageWorker | Worker; if (this._globalConfig.maxWorkers <= 1) { worker = require('./coverage_worker'); @@ -170,7 +167,7 @@ export default class CoverageReporter extends BaseReporter { const filename = fileObj.path; const config = fileObj.config; - if (!this._coverageMap.data[filename]) { + if (!this._coverageMap.data[filename] && 'worker' in worker) { try { const result = await worker.worker({ config, @@ -210,38 +207,41 @@ export default class CoverageReporter extends BaseReporter { clearLine(process.stderr); } - if (worker && typeof worker.end === 'function') { + if (worker && 'end' in worker && typeof worker.end === 'function') { worker.end(); } } - _checkThreshold(globalConfig: GlobalConfig, map: CoverageMap) { + _checkThreshold(globalConfig: Config.GlobalConfig, map: CoverageMap) { if (globalConfig.coverageThreshold) { - function check(name, thresholds, actuals) { - return ['statements', 'branches', 'lines', 'functions'].reduce( - (errors, key) => { - const actual = actuals[key].pct; - const actualUncovered = actuals[key].total - actuals[key].covered; - const threshold = thresholds[key]; - - if (threshold != null) { - if (threshold < 0) { - if (threshold * -1 < actualUncovered) { - errors.push( - `Jest: Uncovered count for ${key} (${actualUncovered})` + - `exceeds ${name} threshold (${-1 * threshold})`, - ); - } - } else if (actual < threshold) { + function check( + name: string, + thresholds: {[index: string]: number}, + actuals: {[index: string]: Totals}, + ) { + return ['statements', 'branches', 'lines', 'functions'].reduce< + string[] + >((errors, key) => { + const actual = actuals[key].pct; + const actualUncovered = actuals[key].total - actuals[key].covered; + const threshold = thresholds[key]; + + if (threshold != null) { + if (threshold < 0) { + if (threshold * -1 < actualUncovered) { errors.push( - `Jest: "${name}" coverage threshold for ${key} (${threshold}%) not met: ${actual}%`, + `Jest: Uncovered count for ${key} (${actualUncovered})` + + `exceeds ${name} threshold (${-1 * threshold})`, ); } + } else if (actual < threshold) { + errors.push( + `Jest: "${name}" coverage threshold for ${key} (${threshold}%) not met: ${actual}%`, + ); } - return errors; - }, - [], - ); + } + return errors; + }, []); } const THRESHOLD_GROUP_TYPES = { @@ -251,73 +251,71 @@ export default class CoverageReporter extends BaseReporter { }; const coveredFiles = map.files(); const thresholdGroups = Object.keys(globalConfig.coverageThreshold); - const groupTypeByThresholdGroup = {}; - const filesByGlob = {}; - - const coveredFilesSortedIntoThresholdGroup = coveredFiles.reduce( - (files, file) => { - const pathOrGlobMatches = thresholdGroups.reduce( - (agg, thresholdGroup) => { - const absoluteThresholdGroup = path.resolve(thresholdGroup); - - // The threshold group might be a path: - - if (file.indexOf(absoluteThresholdGroup) === 0) { - groupTypeByThresholdGroup[thresholdGroup] = - THRESHOLD_GROUP_TYPES.PATH; - return agg.concat([[file, thresholdGroup]]); - } + const groupTypeByThresholdGroup: {[index: string]: string} = {}; + const filesByGlob: {[index: string]: string[]} = {}; + + const coveredFilesSortedIntoThresholdGroup = coveredFiles.reduce< + Array<[string, string | undefined]> + >((files, file) => { + const pathOrGlobMatches = thresholdGroups.reduce< + Array<[string, string]> + >((agg, thresholdGroup) => { + const absoluteThresholdGroup = path.resolve(thresholdGroup); + + // The threshold group might be a path: + + if (file.indexOf(absoluteThresholdGroup) === 0) { + groupTypeByThresholdGroup[thresholdGroup] = + THRESHOLD_GROUP_TYPES.PATH; + return agg.concat([[file, thresholdGroup]]); + } - // If the threshold group is not a path it might be a glob: + // If the threshold group is not a path it might be a glob: - // Note: glob.sync is slow. By memoizing the files matching each glob - // (rather than recalculating it for each covered file) we save a tonne - // of execution time. - if (filesByGlob[absoluteThresholdGroup] === undefined) { - filesByGlob[absoluteThresholdGroup] = glob - .sync(absoluteThresholdGroup) - .map(filePath => path.resolve(filePath)); - } + // Note: glob.sync is slow. By memoizing the files matching each glob + // (rather than recalculating it for each covered file) we save a tonne + // of execution time. + if (filesByGlob[absoluteThresholdGroup] === undefined) { + filesByGlob[absoluteThresholdGroup] = glob + .sync(absoluteThresholdGroup) + .map(filePath => path.resolve(filePath)); + } - if (filesByGlob[absoluteThresholdGroup].indexOf(file) > -1) { - groupTypeByThresholdGroup[thresholdGroup] = - THRESHOLD_GROUP_TYPES.GLOB; - return agg.concat([[file, thresholdGroup]]); - } + if (filesByGlob[absoluteThresholdGroup].indexOf(file) > -1) { + groupTypeByThresholdGroup[thresholdGroup] = + THRESHOLD_GROUP_TYPES.GLOB; + return agg.concat([[file, thresholdGroup]]); + } - return agg; - }, - [], - ); + return agg; + }, []); - if (pathOrGlobMatches.length > 0) { - return files.concat(pathOrGlobMatches); - } + if (pathOrGlobMatches.length > 0) { + return files.concat(pathOrGlobMatches); + } - // Neither a glob or a path? Toss it in global if there's a global threshold: - if (thresholdGroups.indexOf(THRESHOLD_GROUP_TYPES.GLOBAL) > -1) { - groupTypeByThresholdGroup[THRESHOLD_GROUP_TYPES.GLOBAL] = - THRESHOLD_GROUP_TYPES.GLOBAL; - return files.concat([[file, THRESHOLD_GROUP_TYPES.GLOBAL]]); - } + // Neither a glob or a path? Toss it in global if there's a global threshold: + if (thresholdGroups.indexOf(THRESHOLD_GROUP_TYPES.GLOBAL) > -1) { + groupTypeByThresholdGroup[THRESHOLD_GROUP_TYPES.GLOBAL] = + THRESHOLD_GROUP_TYPES.GLOBAL; + return files.concat([[file, THRESHOLD_GROUP_TYPES.GLOBAL]]); + } - // A covered file that doesn't have a threshold: - return files.concat([[file, undefined]]); - }, - [], - ); + // A covered file that doesn't have a threshold: + return files.concat([[file, undefined]]); + }, []); - const getFilesInThresholdGroup = thresholdGroup => + const getFilesInThresholdGroup = (thresholdGroup: string) => coveredFilesSortedIntoThresholdGroup .filter(fileAndGroup => fileAndGroup[1] === thresholdGroup) .map(fileAndGroup => fileAndGroup[0]); - function combineCoverage(filePaths) { + function combineCoverage(filePaths: string[]) { return filePaths .map(filePath => map.fileCoverageFor(filePath)) .reduce( ( - combinedCoverage: ?CoverageSummary, + combinedCoverage: CoverageSummary | null | undefined, nextFileCoverage: FileCoverage, ) => { if (combinedCoverage === undefined || combinedCoverage === null) { diff --git a/packages/jest-reporters/src/coverage_worker.js b/packages/jest-reporters/src/coverage_worker.ts similarity index 63% rename from packages/jest-reporters/src/coverage_worker.js rename to packages/jest-reporters/src/coverage_worker.ts index 13c41e4dceea..595933967f4a 100644 --- a/packages/jest-reporters/src/coverage_worker.js +++ b/packages/jest-reporters/src/coverage_worker.ts @@ -4,26 +4,26 @@ * 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 {GlobalConfig, ProjectConfig, Path} from 'types/Config'; -import type {CoverageReporterOptions} from './coverage_reporter'; - -import exit from 'exit'; import fs from 'fs'; +import {Config} from '@jest/types'; +import exit from 'exit'; +// @ts-ignore +import {CoverageReporterOptions} from './coverage_reporter'; + import generateEmptyCoverage, { - type CoverageWorkerResult, + CoverageWorkerResult, } from './generateEmptyCoverage'; -export type CoverageWorkerData = {| - globalConfig: GlobalConfig, - config: ProjectConfig, - path: Path, - options?: CoverageReporterOptions, -|}; +export type CoverageWorkerData = { + globalConfig: Config.GlobalConfig; + config: Config.ProjectConfig; + path: Config.Path; + options?: CoverageReporterOptions; +}; -export type {CoverageWorkerResult}; +export {CoverageWorkerResult}; // Make sure uncaught errors are logged before we exit. process.on('uncaughtException', err => { @@ -36,7 +36,7 @@ export function worker({ globalConfig, path, options, -}: CoverageWorkerData): ?CoverageWorkerResult { +}: CoverageWorkerData): CoverageWorkerResult | null { return generateEmptyCoverage( fs.readFileSync(path, 'utf8'), path, diff --git a/packages/jest-reporters/src/default_reporter.js b/packages/jest-reporters/src/default_reporter.ts similarity index 84% rename from packages/jest-reporters/src/default_reporter.js rename to packages/jest-reporters/src/default_reporter.ts index a842f663997a..d1fba23c7b05 100644 --- a/packages/jest-reporters/src/default_reporter.js +++ b/packages/jest-reporters/src/default_reporter.ts @@ -4,18 +4,13 @@ * This source code is licensed under the MIT license found in the * LICENSE file in the root directory of this source tree. * - * @flow */ -/* global stream$Writable, tty$WriteStream */ - -import type {AggregatedResult, TestResult} from 'types/TestResult'; -import type {GlobalConfig, Path, ProjectConfig} from 'types/Config'; -import type {Test} from 'types/TestRunner'; -import type {ReporterOnStartOptions} from 'types/Reporters'; +import {TestResult, Config} from '@jest/types'; import {clearLine, getConsoleOutput, isInteractive} from 'jest-util'; import chalk from 'chalk'; +import {Test, ReporterOnStartOptions} from './types'; import BaseReporter from './base_reporter'; import Status from './Status'; import getResultHeader from './get_result_header'; @@ -29,12 +24,12 @@ const TITLE_BULLET = chalk.bold('\u25cf '); export default class DefaultReporter extends BaseReporter { _clear: string; // ANSI clear sequence for the last printed status _err: write; - _globalConfig: GlobalConfig; + _globalConfig: Config.GlobalConfig; _out: write; _status: Status; _bufferedOutput: Set; - constructor(globalConfig: GlobalConfig) { + constructor(globalConfig: Config.GlobalConfig) { super(); this._globalConfig = globalConfig; this._clear = ''; @@ -50,11 +45,11 @@ export default class DefaultReporter extends BaseReporter { }); } - _wrapStdio(stream: stream$Writable | tty$WriteStream) { + _wrapStdio(stream: NodeJS.WritableStream | NodeJS.WriteStream) { const originalWrite = stream.write; - let buffer = []; - let timeout = null; + let buffer: string[] = []; + let timeout: NodeJS.Timeout | null = null; const flushBufferedOutput = () => { const string = buffer.join(''); @@ -88,8 +83,7 @@ export default class DefaultReporter extends BaseReporter { } }; - // $FlowFixMe - stream.write = chunk => { + stream.write = (chunk: string) => { buffer.push(chunk); debouncedFlush(); return true; @@ -126,7 +120,7 @@ export default class DefaultReporter extends BaseReporter { } onRunStart( - aggregatedResults: AggregatedResult, + aggregatedResults: TestResult.AggregatedResult, options: ReporterOnStartOptions, ) { this._status.runStarted(aggregatedResults, options); @@ -148,8 +142,8 @@ export default class DefaultReporter extends BaseReporter { onTestResult( test: Test, - testResult: TestResult, - aggregatedResults: AggregatedResult, + testResult: TestResult.TestResult, + aggregatedResults: TestResult.AggregatedResult, ) { this.testFinished(test.context.config, testResult, aggregatedResults); if (!testResult.skipped) { @@ -168,17 +162,17 @@ export default class DefaultReporter extends BaseReporter { } testFinished( - config: ProjectConfig, - testResult: TestResult, - aggregatedResults: AggregatedResult, + config: Config.ProjectConfig, + testResult: TestResult.TestResult, + aggregatedResults: TestResult.AggregatedResult, ) { this._status.testFinished(config, testResult, aggregatedResults); } printTestFileHeader( - testPath: Path, - config: ProjectConfig, - result: TestResult, + testPath: Config.Path, + config: Config.ProjectConfig, + result: TestResult.TestResult, ) { this.log(getResultHeader(result, this._globalConfig, config)); const consoleBuffer = result.console; @@ -197,9 +191,9 @@ export default class DefaultReporter extends BaseReporter { } printTestFileFailureMessage( - testPath: Path, - config: ProjectConfig, - result: TestResult, + testPath: Config.Path, + config: Config.ProjectConfig, + result: TestResult.TestResult, ) { if (result.failureMessage) { this.log(result.failureMessage); diff --git a/packages/jest-reporters/src/generateEmptyCoverage.js b/packages/jest-reporters/src/generateEmptyCoverage.ts similarity index 75% rename from packages/jest-reporters/src/generateEmptyCoverage.js rename to packages/jest-reporters/src/generateEmptyCoverage.ts index 493d251646d6..e0c7f9addd1c 100644 --- a/packages/jest-reporters/src/generateEmptyCoverage.js +++ b/packages/jest-reporters/src/generateEmptyCoverage.ts @@ -4,29 +4,25 @@ * 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 {GlobalConfig, ProjectConfig, Path} from 'types/Config'; - +import {Config} from '@jest/types'; import {readInitialCoverage} from 'istanbul-lib-instrument'; -import {classes} from 'istanbul-lib-coverage'; +import {FileCoverage} from 'istanbul-lib-coverage'; import {shouldInstrument, ScriptTransformer} from '@jest/transform'; -export type CoverageWorkerResult = {| - coverage: any, - sourceMapPath: ?string, -|}; - -const {FileCoverage} = classes; +export type CoverageWorkerResult = { + coverage: any; + sourceMapPath?: string | null; +}; export default function( source: string, - filename: Path, - globalConfig: GlobalConfig, - config: ProjectConfig, - changedFiles: ?Set, -): ?CoverageWorkerResult { + filename: Config.Path, + globalConfig: Config.GlobalConfig, + config: Config.ProjectConfig, + changedFiles?: Set, +): CoverageWorkerResult | null { const coverageOptions = { changedFiles, collectCoverage: globalConfig.collectCoverage, diff --git a/packages/jest-reporters/src/get_result_header.js b/packages/jest-reporters/src/get_result_header.ts similarity index 85% rename from packages/jest-reporters/src/get_result_header.js rename to packages/jest-reporters/src/get_result_header.ts index ada0082ce073..ad7c6af35b6c 100644 --- a/packages/jest-reporters/src/get_result_header.js +++ b/packages/jest-reporters/src/get_result_header.ts @@ -4,11 +4,9 @@ * 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 {GlobalConfig, ProjectConfig} from 'types/Config'; -import type {TestResult} from 'types/TestResult'; +import {Config, TestResult} from '@jest/types'; import chalk from 'chalk'; import {formatTestPath, printDisplayName} from './utils'; @@ -28,9 +26,9 @@ const PASS = chalk.supportsColor : PASS_TEXT; export default ( - result: TestResult, - globalConfig: GlobalConfig, - projectConfig?: ProjectConfig, + result: TestResult.TestResult, + globalConfig: Config.GlobalConfig, + projectConfig?: Config.ProjectConfig, ) => { const testPath = result.testFilePath; const status = @@ -46,7 +44,7 @@ export default ( } if (result.memoryUsage) { - const toMB = bytes => Math.floor(bytes / 1024 / 1024); + const toMB = (bytes: number) => Math.floor(bytes / 1024 / 1024); testDetail.push(`${toMB(result.memoryUsage)} MB heap size`); } diff --git a/packages/jest-reporters/src/get_snapshot_status.js b/packages/jest-reporters/src/get_snapshot_status.ts similarity index 93% rename from packages/jest-reporters/src/get_snapshot_status.js rename to packages/jest-reporters/src/get_snapshot_status.ts index 8406fa3fa3a2..2de1b76dfd7e 100644 --- a/packages/jest-reporters/src/get_snapshot_status.js +++ b/packages/jest-reporters/src/get_snapshot_status.ts @@ -4,10 +4,9 @@ * 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 {TestResult} from 'types/TestResult'; +import {TestResult} from '@jest/types'; import chalk from 'chalk'; @@ -21,7 +20,7 @@ const SNAPSHOT_UPDATED = chalk.bold.green; const SNAPSHOT_OUTDATED = chalk.bold.yellow; export default ( - snapshot: $PropertyType, + snapshot: TestResult.TestResult['snapshot'], afterUpdate: boolean, ): Array => { const statuses = []; diff --git a/packages/jest-reporters/src/get_snapshot_summary.js b/packages/jest-reporters/src/get_snapshot_summary.ts similarity index 95% rename from packages/jest-reporters/src/get_snapshot_summary.js rename to packages/jest-reporters/src/get_snapshot_summary.ts index 60eea8aa0cab..16b0ac5ee33c 100644 --- a/packages/jest-reporters/src/get_snapshot_summary.js +++ b/packages/jest-reporters/src/get_snapshot_summary.ts @@ -4,11 +4,9 @@ * 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 {SnapshotSummary} from 'types/TestResult'; -import type {GlobalConfig} from 'types/Config'; +import {Config, TestResult} from '@jest/types'; import chalk from 'chalk'; import {pluralize} from 'jest-util'; @@ -26,8 +24,8 @@ const SNAPSHOT_SUMMARY = chalk.bold; const SNAPSHOT_UPDATED = chalk.bold.green; export default ( - snapshots: SnapshotSummary, - globalConfig: GlobalConfig, + snapshots: TestResult.SnapshotSummary, + globalConfig: Config.GlobalConfig, updateCommand: string, ): Array => { const summary = []; diff --git a/packages/jest-reporters/src/notify_reporter.js b/packages/jest-reporters/src/notify_reporter.ts similarity index 88% rename from packages/jest-reporters/src/notify_reporter.js rename to packages/jest-reporters/src/notify_reporter.ts index 9a6c9a27f3cb..4b632b6ec0dd 100644 --- a/packages/jest-reporters/src/notify_reporter.js +++ b/packages/jest-reporters/src/notify_reporter.ts @@ -4,18 +4,14 @@ * 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 {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 exit from 'exit'; +import {Config, TestResult} from '@jest/types'; import notifier from 'node-notifier'; +import {TestSchedulerContext, Context} from './types'; import BaseReporter from './base_reporter'; const isDarwin = process.platform === 'darwin'; @@ -23,12 +19,12 @@ const isDarwin = process.platform === 'darwin'; const icon = path.resolve(__dirname, '../assets/jest_logo.png'); export default class NotifyReporter extends BaseReporter { - _startRun: (globalConfig: GlobalConfig) => *; - _globalConfig: GlobalConfig; + _startRun: (globalConfig: Config.GlobalConfig) => any; + _globalConfig: Config.GlobalConfig; _context: TestSchedulerContext; constructor( - globalConfig: GlobalConfig, - startRun: (globalConfig: GlobalConfig) => *, + globalConfig: Config.GlobalConfig, + startRun: (globalConfig: Config.GlobalConfig) => any, context: TestSchedulerContext, ) { super(); @@ -37,7 +33,10 @@ export default class NotifyReporter extends BaseReporter { this._context = context; } - onRunComplete(contexts: Set, result: AggregatedResult): void { + onRunComplete( + contexts: Set, + result: TestResult.AggregatedResult, + ): void { const success = result.numFailedTests === 0 && result.numRuntimeErrorTestSuites === 0; @@ -117,13 +116,14 @@ export default class NotifyReporter extends BaseReporter { } else { notifier.notify( { + // @ts-ignore @types/node-notifier doesn't have `actions` actions: [restartAnswer, quitAnswer], closeLabel: 'Close', icon, message, title, }, - (err, _, metadata) => { + (err: any, _: any, metadata: any) => { if (err || !metadata) { return; } diff --git a/packages/jest-reporters/src/summary_reporter.js b/packages/jest-reporters/src/summary_reporter.ts similarity index 89% rename from packages/jest-reporters/src/summary_reporter.js rename to packages/jest-reporters/src/summary_reporter.ts index 863ab6e0db41..aed2b54b7eab 100644 --- a/packages/jest-reporters/src/summary_reporter.js +++ b/packages/jest-reporters/src/summary_reporter.ts @@ -4,16 +4,15 @@ * 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 {AggregatedResult, SnapshotSummary} from 'types/TestResult'; -import type {GlobalConfig} from 'types/Config'; -import type {Context} from 'types/Context'; -import type {ReporterOnStartOptions} from 'types/Reporters'; +import {TestResult, Config} from '@jest/types'; import chalk from 'chalk'; import {testPathPatternToRegExp} from 'jest-util'; + +import {Context, ReporterOnStartOptions} from './types'; + import BaseReporter from './base_reporter'; import {getSummary} from './utils'; import getResultHeader from './get_result_header'; @@ -50,9 +49,9 @@ const NPM_EVENTS = new Set([ export default class SummaryReporter extends BaseReporter { _estimatedTime: number; - _globalConfig: GlobalConfig; + _globalConfig: Config.GlobalConfig; - constructor(globalConfig: GlobalConfig) { + constructor(globalConfig: Config.GlobalConfig) { super(); this._globalConfig = globalConfig; this._estimatedTime = 0; @@ -70,14 +69,17 @@ export default class SummaryReporter extends BaseReporter { } onRunStart( - aggregatedResults: AggregatedResult, + aggregatedResults: TestResult.AggregatedResult, options: ReporterOnStartOptions, ) { super.onRunStart(aggregatedResults, options); this._estimatedTime = options.estimatedTime; } - onRunComplete(contexts: Set, aggregatedResults: AggregatedResult) { + onRunComplete( + contexts: Set, + aggregatedResults: TestResult.AggregatedResult, + ) { const {numTotalTestSuites, testResults, wasInterrupted} = aggregatedResults; if (numTotalTestSuites) { const lastResult = testResults[testResults.length - 1]; @@ -116,8 +118,8 @@ export default class SummaryReporter extends BaseReporter { } _printSnapshotSummary( - snapshots: SnapshotSummary, - globalConfig: GlobalConfig, + snapshots: TestResult.SnapshotSummary, + globalConfig: Config.GlobalConfig, ) { if ( snapshots.added || @@ -127,7 +129,7 @@ export default class SummaryReporter extends BaseReporter { snapshots.updated ) { let updateCommand; - const event = process.env.npm_lifecycle_event; + const event = process.env.npm_lifecycle_event || ''; const prefix = NPM_EVENTS.has(event) ? '' : 'run '; const isYarn = typeof process.env.npm_config_user_agent === 'string' && @@ -161,8 +163,8 @@ export default class SummaryReporter extends BaseReporter { } _printSummary( - aggregatedResults: AggregatedResult, - globalConfig: GlobalConfig, + aggregatedResults: TestResult.AggregatedResult, + globalConfig: Config.GlobalConfig, ) { // If there were any failing tests and there was a large number of tests // executed, re-print the failing results at the end of execution output. @@ -188,7 +190,7 @@ export default class SummaryReporter extends BaseReporter { } } - _getTestSummary(contexts: Set, globalConfig: GlobalConfig) { + _getTestSummary(contexts: Set, globalConfig: Config.GlobalConfig) { const getMatchingTestsInfo = () => { const prefix = globalConfig.findRelatedTests ? ' related to files matching ' diff --git a/packages/jest-reporters/src/types.ts b/packages/jest-reporters/src/types.ts new file mode 100644 index 000000000000..8e11f90d5b5d --- /dev/null +++ b/packages/jest-reporters/src/types.ts @@ -0,0 +1,118 @@ +/** + * 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. + * + */ + +import {Config, TestResult} from '@jest/types'; +import {JestEnvironment as Environment} from '@jest/environment'; +import {ModuleMap, FS as HasteFS} from 'jest-haste-map'; +import HasteResolver from 'jest-resolve'; +import Runtime from 'jest-runtime'; +// @ts-ignore Not migrated yet +import {TestWatcher as _TestWatcher} from '@jest/core'; +import {worker} from './coverage_worker'; + +export type ReporterOnStartOptions = { + estimatedTime: number; + showStatus: boolean; +}; + +export type Context = { + config: Config.ProjectConfig; + hasteFS: HasteFS; + moduleMap: ModuleMap; + resolver: HasteResolver; +}; + +export type Test = { + context: Context; + duration?: number; + path: Config.Path; +}; + +export type TestWatcher = _TestWatcher; + +export type CoverageWorker = {worker: typeof worker}; + +export type CoverageReporterOptions = { + changedFiles?: Set; +}; + +export type OnTestStart = (test: Test) => Promise; +export type OnTestFailure = ( + test: Test, + error: TestResult.SerializableError, +) => Promise; +export type OnTestSuccess = ( + test: Test, + result: TestResult.TestResult, +) => Promise; + +export interface Reporter { + readonly onTestResult: ( + test: Test, + testResult: TestResult.TestResult, + aggregatedResult: TestResult.AggregatedResult, + ) => Promise | void; + readonly onRunStart: ( + results: TestResult.AggregatedResult, + options: ReporterOnStartOptions, + ) => Promise | void; + readonly onTestStart: (test: Test) => Promise | void; + readonly onRunComplete: ( + contexts: Set, + results: TestResult.AggregatedResult, + ) => Promise | void; + readonly getLastError: () => Error | void; +} + +type FileCoverageTotal = { + total: number; + covered: number; + skipped: number; + pct: number; +}; + +export type CoverageSummary = { + lines: FileCoverageTotal; + statements: FileCoverageTotal; + branches: FileCoverageTotal; + functions: FileCoverageTotal; + merge: (other: CoverageSummary) => void; +}; + +export type SummaryOptions = { + estimatedTime?: number; + roundTime?: boolean; + width?: number; +}; + +export type TestFramework = ( + globalConfig: Config.GlobalConfig, + config: Config.ProjectConfig, + environment: Environment, + runtime: Runtime, + testPath: string, +) => Promise; + +export type TestRunnerOptions = { + serial: boolean; +}; + +export type TestRunnerContext = { + changedFiles?: Set; +}; + +export type TestRunData = Array<{ + context: Context; + matches: {allTests: number; tests: Array; total: number}; +}>; + +export type TestSchedulerContext = { + firstRun: boolean; + previousSuccess: boolean; + changedFiles?: Set; +}; diff --git a/packages/jest-reporters/src/utils.js b/packages/jest-reporters/src/utils.ts similarity index 91% rename from packages/jest-reporters/src/utils.js rename to packages/jest-reporters/src/utils.ts index f2f17e52f0a2..734c34d7df33 100644 --- a/packages/jest-reporters/src/utils.js +++ b/packages/jest-reporters/src/utils.ts @@ -4,26 +4,21 @@ * 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, ProjectConfig, GlobalConfig} from 'types/Config'; -import type {AggregatedResult} from 'types/TestResult'; +// import type {Path, ProjectConfig, GlobalConfig} from 'types/Config'; +// import type {AggregatedResult} from 'types/TestResult'; import path from 'path'; +import {Config, TestResult} from '@jest/types'; import chalk from 'chalk'; import slash from 'slash'; import {pluralize} from 'jest-util'; - -type SummaryOptions = {| - estimatedTime?: number, - roundTime?: boolean, - width?: number, -|}; +import {SummaryOptions} from './types'; const PROGRESS_BAR_WIDTH = 40; -export const printDisplayName = (config: ProjectConfig) => { +export const printDisplayName = (config: Config.ProjectConfig) => { const {displayName} = config; if (displayName) { @@ -37,8 +32,8 @@ export const printDisplayName = (config: ProjectConfig) => { export const trimAndFormatPath = ( pad: number, - config: ProjectConfig | GlobalConfig, - testPath: Path, + config: Config.ProjectConfig | Config.GlobalConfig, + testPath: Config.Path, columns: number, ): string => { const maxLength = columns - pad; @@ -73,28 +68,31 @@ export const trimAndFormatPath = ( }; export const formatTestPath = ( - config: GlobalConfig | ProjectConfig, - testPath: Path, + config: Config.GlobalConfig | Config.ProjectConfig, + testPath: Config.Path, ) => { const {dirname, basename} = relativePath(config, testPath); return slash(chalk.dim(dirname + path.sep) + chalk.bold(basename)); }; export const relativePath = ( - config: GlobalConfig | ProjectConfig, - testPath: Path, + config: Config.GlobalConfig | Config.ProjectConfig, + testPath: Config.Path, ) => { // this function can be called with ProjectConfigs or GlobalConfigs. GlobalConfigs // do not have config.cwd, only config.rootDir. Try using config.cwd, fallback // to config.rootDir. (Also, some unit just use config.rootDir, which is ok) - testPath = path.relative(config.cwd || config.rootDir, testPath); + testPath = path.relative( + (config as Config.ProjectConfig).cwd || config.rootDir, + testPath, + ); const dirname = path.dirname(testPath); const basename = path.basename(testPath); return {basename, dirname}; }; export const getSummary = ( - aggregatedResults: AggregatedResult, + aggregatedResults: TestResult.AggregatedResult, options?: SummaryOptions, ) => { let runTime = (Date.now() - aggregatedResults.startTime) / 1000; @@ -180,7 +178,7 @@ export const getSummary = ( return [suites, tests, snapshots, time].join('\n'); }; -const renderTime = (runTime, estimatedTime, width) => { +const renderTime = (runTime: number, estimatedTime: number, width: number) => { // If we are more than one second over the estimated time, highlight it. const renderedTime = estimatedTime && runTime >= estimatedTime + 1 diff --git a/packages/jest-reporters/src/verbose_reporter.js b/packages/jest-reporters/src/verbose_reporter.ts similarity index 83% rename from packages/jest-reporters/src/verbose_reporter.js rename to packages/jest-reporters/src/verbose_reporter.ts index 4a1ecc646e08..4e8ada29def7 100644 --- a/packages/jest-reporters/src/verbose_reporter.js +++ b/packages/jest-reporters/src/verbose_reporter.ts @@ -4,40 +4,33 @@ * 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 {GlobalConfig} from 'types/Config'; -import type { - AggregatedResult, - AssertionResult, - Suite, - TestResult, -} from 'types/TestResult'; -import type {Test} from 'types/TestRunner'; +import {Config, TestResult} from '@jest/types'; import chalk from 'chalk'; import {specialChars} from 'jest-util'; +import {Test} from './types'; import DefaultReporter from './default_reporter'; const {ICONS} = specialChars; export default class VerboseReporter extends DefaultReporter { - _globalConfig: GlobalConfig; + _globalConfig: Config.GlobalConfig; - constructor(globalConfig: GlobalConfig) { + constructor(globalConfig: Config.GlobalConfig) { super(globalConfig); this._globalConfig = globalConfig; } static filterTestResults( - testResults: Array, - ): Array { + testResults: Array, + ): Array { return testResults.filter(({status}) => status !== 'pending'); } - static groupTestsBySuites(testResults: Array) { - const root = {suites: [], tests: [], title: ''}; + static groupTestsBySuites(testResults: Array) { + const root: TestResult.Suite = {suites: [], tests: [], title: ''}; testResults.forEach(testResult => { let targetSuite = root; @@ -59,8 +52,8 @@ export default class VerboseReporter extends DefaultReporter { onTestResult( test: Test, - result: TestResult, - aggregatedResults: AggregatedResult, + result: TestResult.TestResult, + aggregatedResults: TestResult.AggregatedResult, ) { super.testFinished(test.context.config, result, aggregatedResults); if (!result.skipped) { @@ -81,12 +74,12 @@ export default class VerboseReporter extends DefaultReporter { super.forceFlushBufferedOutput(); } - _logTestResults(testResults: Array) { + _logTestResults(testResults: Array) { this._logSuite(VerboseReporter.groupTestsBySuites(testResults), 0); this._logLine(); } - _logSuite(suite: Suite, indentLevel: number) { + _logSuite(suite: TestResult.Suite, indentLevel: number) { if (suite.title) { this._logLine(suite.title, indentLevel); } @@ -108,13 +101,13 @@ export default class VerboseReporter extends DefaultReporter { } } - _logTest(test: AssertionResult, indentLevel: number) { + _logTest(test: TestResult.AssertionResult, indentLevel: number) { const status = this._getIcon(test.status); const time = test.duration ? ` (${test.duration.toFixed(0)}ms)` : ''; this._logLine(status + ' ' + chalk.dim(test.title + time), indentLevel); } - _logTests(tests: Array, indentLevel: number) { + _logTests(tests: Array, indentLevel: number) { if (this._globalConfig.expand) { tests.forEach(test => this._logTest(test, indentLevel)); } else { diff --git a/packages/jest-reporters/tsconfig.json b/packages/jest-reporters/tsconfig.json new file mode 100644 index 000000000000..ddb1c2ecad2f --- /dev/null +++ b/packages/jest-reporters/tsconfig.json @@ -0,0 +1,16 @@ +{ + "extends": "../../tsconfig.json", + "compilerOptions": { + "rootDir": "src", + "outDir": "build" + }, + "references": [ + {"path": "../jest-types"}, + {"path": "../jest-util"}, + {"path": "../jest-worker"}, + {"path": "../jest-haste-map"}, + {"path": "../jest-resolve"}, + {"path": "../jest-runtime"}, + {"path": "../jest-environment"} + ] +} diff --git a/yarn.lock b/yarn.lock index 3a7d5cb3e17a..2c9e8ec66f15 100644 --- a/yarn.lock +++ b/yarn.lock @@ -1643,6 +1643,11 @@ "@types/istanbul-lib-coverage" "*" source-map "^0.6.1" +"@types/istanbul@^0.4.30": + version "0.4.30" + resolved "https://registry.yarnpkg.com/@types/istanbul/-/istanbul-0.4.30.tgz#073159320ab3296b2cfeb481f756a1f8f4c9c8e4" + integrity sha512-+hQU4fh2G96ze78uI5/V6+SRDZD1UnVrFn23i2eDetwfbBq3s0/zYP92xj/3qyvVMM3WnvS88N56zjz+HmL04A== + "@types/jest-diff@*": version "20.0.1" resolved "https://registry.yarnpkg.com/@types/jest-diff/-/jest-diff-20.0.1.tgz#35cc15b9c4f30a18ef21852e255fdb02f6d59b89" From 52c2c456dacb9669721c0eef1f92ccd19bca7d49 Mon Sep 17 00:00:00 2001 From: Lorenzo Rapetti Date: Tue, 26 Feb 2019 15:17:58 +0100 Subject: [PATCH 02/10] Remove @types/istanbul --- packages/jest-reporters/package.json | 1 - yarn.lock | 5 ----- 2 files changed, 6 deletions(-) diff --git a/packages/jest-reporters/package.json b/packages/jest-reporters/package.json index ccf41f992d2a..c72458d6616c 100644 --- a/packages/jest-reporters/package.json +++ b/packages/jest-reporters/package.json @@ -28,7 +28,6 @@ "devDependencies": { "@types/exit": "^0.1.30", "@types/glob": "^7.1.1", - "@types/istanbul": "^0.4.30", "@types/istanbul-lib-coverage": "^1.1.0", "@types/istanbul-lib-instrument": "^1.7.2", "@types/istanbul-lib-source-maps": "^1.2.1", diff --git a/yarn.lock b/yarn.lock index 2c9e8ec66f15..3a7d5cb3e17a 100644 --- a/yarn.lock +++ b/yarn.lock @@ -1643,11 +1643,6 @@ "@types/istanbul-lib-coverage" "*" source-map "^0.6.1" -"@types/istanbul@^0.4.30": - version "0.4.30" - resolved "https://registry.yarnpkg.com/@types/istanbul/-/istanbul-0.4.30.tgz#073159320ab3296b2cfeb481f756a1f8f4c9c8e4" - integrity sha512-+hQU4fh2G96ze78uI5/V6+SRDZD1UnVrFn23i2eDetwfbBq3s0/zYP92xj/3qyvVMM3WnvS88N56zjz+HmL04A== - "@types/jest-diff@*": version "20.0.1" resolved "https://registry.yarnpkg.com/@types/jest-diff/-/jest-diff-20.0.1.tgz#35cc15b9c4f30a18ef21852e255fdb02f6d59b89" From 106f4171e8621d79f495b86a53d0816de645ed62 Mon Sep 17 00:00:00 2001 From: Lorenzo Rapetti Date: Tue, 26 Feb 2019 15:38:34 +0100 Subject: [PATCH 03/10] Migrate index.js to TypeScript --- packages/jest-reporters/src/{index.js => index.ts} | 1 - 1 file changed, 1 deletion(-) rename packages/jest-reporters/src/{index.js => index.ts} (98%) diff --git a/packages/jest-reporters/src/index.js b/packages/jest-reporters/src/index.ts similarity index 98% rename from packages/jest-reporters/src/index.js rename to packages/jest-reporters/src/index.ts index c714b0cce89c..db7c5c5223c2 100644 --- a/packages/jest-reporters/src/index.js +++ b/packages/jest-reporters/src/index.ts @@ -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. * - * @flow */ export {default as BaseReporter} from './base_reporter'; From 460603fd77ea512a5dd2c7cd7974e66f4b142b14 Mon Sep 17 00:00:00 2001 From: Lorenzo Rapetti Date: Tue, 26 Feb 2019 15:42:08 +0100 Subject: [PATCH 04/10] Add changelog entry --- CHANGELOG.md | 1 + 1 file changed, 1 insertion(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index e6e9e2d3890b..efbc6b35d04c 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -61,6 +61,7 @@ - `[jest-runner]`: Migrate to TypeScript ([#7968](https://github.com/facebook/jest/pull/7968)) - `[jest-runtime]`: Migrate to TypeScript ([#7964](https://github.com/facebook/jest/pull/7964), [#7988](https://github.com/facebook/jest/pull/7988)) - `[@jest/fake-timers]`: Extract FakeTimers class from `jest-util` into a new separate package ([#7987](https://github.com/facebook/jest/pull/7987)) +- `[@jest/reporters]`: Migrate to TypeScript ([#7994](https://github.com/facebook/jest/pull/7994)) ### Performance From 4c90bccddc7e38260b8589e3909b87745764b12d Mon Sep 17 00:00:00 2001 From: Lorenzo Rapetti Date: Fri, 1 Mar 2019 09:58:27 +0100 Subject: [PATCH 05/10] Add typings --- .../__snapshots__/snapshot.test.js.snap | 5 + .../__tests__/snapshot.test.js | 1 + .../__tests__/basic-support.test.js | 2 + .../__snapshots__/basic-support.test.js.snap | 7 + .../__tests__/basic-support.test.js | 1 + packages/jest-reporters/package.json | 2 - packages/jest-reporters/src/Status.ts | 7 +- .../__tests__/generateEmptyCoverage.test.js | 3 - packages/jest-reporters/src/base_reporter.ts | 20 +- .../jest-reporters/src/coverage_reporter.ts | 45 ++-- .../jest-reporters/src/default_reporter.ts | 26 +- packages/jest-reporters/src/istanbul-api.d.ts | 14 + .../src/istanbul-lib-coverage.d.ts | 127 +++++++++ .../jest-reporters/src/node-notifier.d.ts | 242 ++++++++++++++++++ .../jest-reporters/src/notify_reporter.ts | 11 +- .../jest-reporters/src/summary_reporter.ts | 15 +- packages/jest-reporters/src/types.ts | 15 -- .../jest-reporters/src/verbose_reporter.ts | 19 +- packages/jest-types/src/Config.ts | 15 +- yarn.lock | 7 - 20 files changed, 487 insertions(+), 97 deletions(-) create mode 100644 e2e/snapshot-escape/__tests__/__snapshots__/snapshot.test.js.snap create mode 100644 e2e/to-match-inline-snapshot/__tests__/basic-support.test.js create mode 100644 e2e/to-match-snapshot/__tests__/__snapshots__/basic-support.test.js.snap create mode 100644 e2e/to-match-snapshot/__tests__/basic-support.test.js create mode 100644 packages/jest-reporters/src/istanbul-api.d.ts create mode 100644 packages/jest-reporters/src/istanbul-lib-coverage.d.ts create mode 100644 packages/jest-reporters/src/node-notifier.d.ts diff --git a/e2e/snapshot-escape/__tests__/__snapshots__/snapshot.test.js.snap b/e2e/snapshot-escape/__tests__/__snapshots__/snapshot.test.js.snap new file mode 100644 index 000000000000..6d61032b1690 --- /dev/null +++ b/e2e/snapshot-escape/__tests__/__snapshots__/snapshot.test.js.snap @@ -0,0 +1,5 @@ +// Jest Snapshot v1, https://goo.gl/fbAQLP + +exports[`escape strings 1`] = `"one: \\\\'"`; + +exports[`escape strings two 1`] = `"two: '\\""`; diff --git a/e2e/snapshot-escape/__tests__/snapshot.test.js b/e2e/snapshot-escape/__tests__/snapshot.test.js index c8e9a8179e45..d5df95d7469d 100644 --- a/e2e/snapshot-escape/__tests__/snapshot.test.js +++ b/e2e/snapshot-escape/__tests__/snapshot.test.js @@ -8,3 +8,4 @@ // prettier-ignore test('escape strings', () => expect('one: \\\'').toMatchSnapshot()); +test('escape strings two', () => expect('two: \'"').toMatchSnapshot()); diff --git a/e2e/to-match-inline-snapshot/__tests__/basic-support.test.js b/e2e/to-match-inline-snapshot/__tests__/basic-support.test.js new file mode 100644 index 000000000000..91983c3f64ec --- /dev/null +++ b/e2e/to-match-inline-snapshot/__tests__/basic-support.test.js @@ -0,0 +1,2 @@ +test('inline snapshots', () => + expect({apple: 'original value'}).toMatchInlineSnapshot()); diff --git a/e2e/to-match-snapshot/__tests__/__snapshots__/basic-support.test.js.snap b/e2e/to-match-snapshot/__tests__/__snapshots__/basic-support.test.js.snap new file mode 100644 index 000000000000..6bf3a2470ffc --- /dev/null +++ b/e2e/to-match-snapshot/__tests__/__snapshots__/basic-support.test.js.snap @@ -0,0 +1,7 @@ +// Jest Snapshot v1, https://goo.gl/fbAQLP + +exports[`snapshots 1`] = ` +Object { + "apple": "original value", +} +`; diff --git a/e2e/to-match-snapshot/__tests__/basic-support.test.js b/e2e/to-match-snapshot/__tests__/basic-support.test.js new file mode 100644 index 000000000000..e3b673273086 --- /dev/null +++ b/e2e/to-match-snapshot/__tests__/basic-support.test.js @@ -0,0 +1 @@ +test('snapshots', () => expect({apple: 'updated value'}).toMatchSnapshot()); diff --git a/packages/jest-reporters/package.json b/packages/jest-reporters/package.json index c72458d6616c..8f26b2c48c35 100644 --- a/packages/jest-reporters/package.json +++ b/packages/jest-reporters/package.json @@ -28,10 +28,8 @@ "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" diff --git a/packages/jest-reporters/src/Status.ts b/packages/jest-reporters/src/Status.ts index 2534df48243b..5b065b83c397 100644 --- a/packages/jest-reporters/src/Status.ts +++ b/packages/jest-reporters/src/Status.ts @@ -27,7 +27,10 @@ const RUNNING = chalk.reset.inverse.yellow.bold(RUNNING_TEXT) + ' '; * shifting the whole list. */ class CurrentTestList { - _array: Array<{testPath: Config.Path; config: Config.ProjectConfig} | null>; + private _array: Array<{ + testPath: Config.Path; + config: Config.ProjectConfig; + } | null>; constructor() { this._array = []; @@ -114,7 +117,7 @@ export default class Status { } testFinished( - config: Config.ProjectConfig, + _config: Config.ProjectConfig, testResult: TestResult.TestResult, aggregatedResults: TestResult.AggregatedResult, ) { diff --git a/packages/jest-reporters/src/__tests__/generateEmptyCoverage.test.js b/packages/jest-reporters/src/__tests__/generateEmptyCoverage.test.js index 00ae3f7a7ad8..d5d9555c76b8 100644 --- a/packages/jest-reporters/src/__tests__/generateEmptyCoverage.test.js +++ b/packages/jest-reporters/src/__tests__/generateEmptyCoverage.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. * - * @flow */ import istanbulCoverage from 'istanbul-lib-coverage'; @@ -13,7 +12,6 @@ import generateEmptyCoverage from '../generateEmptyCoverage'; import path from 'path'; import os from 'os'; -//$FlowFixMe: Converted to TS import {makeGlobalConfig, makeProjectConfig} from '../../../../TestUtils'; jest.mock('@jest/transform', () => ({ @@ -64,6 +62,5 @@ it('generates an empty coverage object for a file without running it', () => { coverage = sourceMapStore.transformCoverage(coverageMap).map; } - // $FlowFixMe: IDK... expect(coverage.data).toMatchSnapshot({path: expect.any(String)}); }); diff --git a/packages/jest-reporters/src/base_reporter.ts b/packages/jest-reporters/src/base_reporter.ts index 6746c8c389ae..46ecff911f81 100644 --- a/packages/jest-reporters/src/base_reporter.ts +++ b/packages/jest-reporters/src/base_reporter.ts @@ -13,33 +13,33 @@ import {ReporterOnStartOptions, Context, Test, Reporter} from './types'; const {remove: preRunMessageRemove} = preRunMessage; export default class BaseReporter implements Reporter { - _error?: Error; + private _error?: Error; log(message: string) { process.stderr.write(message + '\n'); } onRunStart( - results: TestResult.AggregatedResult, - options: ReporterOnStartOptions, + _results: TestResult.AggregatedResult, + _options: ReporterOnStartOptions, ) { preRunMessageRemove(process.stderr); } onTestResult( - test: Test, - testResult: TestResult.TestResult, - results: TestResult.AggregatedResult, + _test: Test, + _testResult: TestResult.TestResult, + _results: TestResult.AggregatedResult, ) {} - onTestStart(test: Test) {} + onTestStart(_test: Test) {} onRunComplete( - contexts: Set, - aggregatedResults: TestResult.AggregatedResult, + _contexts: Set, + _aggregatedResults: TestResult.AggregatedResult, ): Promise | void {} - _setError(error: Error) { + protected _setError(error: Error) { this._error = error; } diff --git a/packages/jest-reporters/src/coverage_reporter.ts b/packages/jest-reporters/src/coverage_reporter.ts index 298585efdb19..3ef398b8b43c 100644 --- a/packages/jest-reporters/src/coverage_reporter.ts +++ b/packages/jest-reporters/src/coverage_reporter.ts @@ -6,38 +6,36 @@ * */ +// TODO: Remove this +/// +/// + import path from 'path'; import {TestResult, Config} from '@jest/types'; import {clearLine, isInteractive} from 'jest-util'; -// @ts-ignore Apparently there aren't any types for this package? import {createReporter} from 'istanbul-api'; import chalk from 'chalk'; import istanbulCoverage, { CoverageMap, FileCoverage, - Totals, + CoverageSummary, + CoverageSummaryData, } from 'istanbul-lib-coverage'; import libSourceMaps, {MapStore} from 'istanbul-lib-source-maps'; import Worker from 'jest-worker'; import glob from 'glob'; import BaseReporter from './base_reporter'; -import { - Context, - Test, - CoverageSummary, - CoverageWorker, - CoverageReporterOptions, -} from './types'; +import {Context, Test, CoverageWorker, CoverageReporterOptions} from './types'; const FAIL_COLOR = chalk.bold.red; const RUNNING_TEST_COLOR = chalk.bold.dim; export default class CoverageReporter extends BaseReporter { - _coverageMap: CoverageMap; - _globalConfig: Config.GlobalConfig; - _sourceMapStore: MapStore; - _options: CoverageReporterOptions; + private _coverageMap: CoverageMap; + private _globalConfig: Config.GlobalConfig; + private _sourceMapStore: MapStore; + private _options: CoverageReporterOptions; constructor( globalConfig: Config.GlobalConfig, @@ -51,9 +49,9 @@ export default class CoverageReporter extends BaseReporter { } onTestResult( - test: Test, + _test: Test, testResult: TestResult.TestResult, - aggregatedResults: TestResult.AggregatedResult, + _aggregatedResults: TestResult.AggregatedResult, ) { if (testResult.coverage) { this._coverageMap.merge(testResult.coverage); @@ -118,7 +116,7 @@ export default class CoverageReporter extends BaseReporter { this._checkThreshold(this._globalConfig, map); } - async _addUntestedFiles( + private async _addUntestedFiles( globalConfig: Config.GlobalConfig, contexts: Set, ): Promise { @@ -212,18 +210,23 @@ export default class CoverageReporter extends BaseReporter { } } - _checkThreshold(globalConfig: Config.GlobalConfig, map: CoverageMap) { + private _checkThreshold(globalConfig: Config.GlobalConfig, map: CoverageMap) { if (globalConfig.coverageThreshold) { function check( name: string, thresholds: {[index: string]: number}, - actuals: {[index: string]: Totals}, + actuals: CoverageSummaryData, ) { return ['statements', 'branches', 'lines', 'functions'].reduce< string[] >((errors, key) => { - const actual = actuals[key].pct; - const actualUncovered = actuals[key].total - actuals[key].covered; + // Without this TypeScript complains if i put + // `key: keyof CoverageSummaryData` or if i call `actuals[key]` + // without casting + const typedKey: keyof CoverageSummaryData = key as keyof CoverageSummaryData; + const actual = actuals[typedKey].pct; + const actualUncovered = + actuals[typedKey].total - actuals[typedKey].covered; const threshold = thresholds[key]; if (threshold != null) { @@ -327,7 +330,7 @@ export default class CoverageReporter extends BaseReporter { ); } - let errors = []; + let errors: string[] = []; thresholdGroups.forEach(thresholdGroup => { switch (groupTypeByThresholdGroup[thresholdGroup]) { diff --git a/packages/jest-reporters/src/default_reporter.ts b/packages/jest-reporters/src/default_reporter.ts index d1fba23c7b05..17337ab64919 100644 --- a/packages/jest-reporters/src/default_reporter.ts +++ b/packages/jest-reporters/src/default_reporter.ts @@ -22,12 +22,12 @@ type FlushBufferedOutput = () => void; const TITLE_BULLET = chalk.bold('\u25cf '); export default class DefaultReporter extends BaseReporter { - _clear: string; // ANSI clear sequence for the last printed status - _err: write; - _globalConfig: Config.GlobalConfig; - _out: write; - _status: Status; - _bufferedOutput: Set; + private _clear: string; // ANSI clear sequence for the last printed status + private _err: write; + protected _globalConfig: Config.GlobalConfig; + private _out: write; + private _status: Status; + private _bufferedOutput: Set; constructor(globalConfig: Config.GlobalConfig) { super(); @@ -45,7 +45,7 @@ export default class DefaultReporter extends BaseReporter { }); } - _wrapStdio(stream: NodeJS.WritableStream | NodeJS.WriteStream) { + private _wrapStdio(stream: NodeJS.WritableStream | NodeJS.WriteStream) { const originalWrite = stream.write; let buffer: string[] = []; @@ -97,7 +97,7 @@ export default class DefaultReporter extends BaseReporter { } } - _clearStatus() { + private _clearStatus() { if (isInteractive) { if (this._globalConfig.useStderr) { this._err(this._clear); @@ -107,7 +107,7 @@ export default class DefaultReporter extends BaseReporter { } } - _printStatus() { + private _printStatus() { const {content, clear} = this._status.get(); this._clear = clear; if (isInteractive) { @@ -133,9 +133,7 @@ export default class DefaultReporter extends BaseReporter { onRunComplete() { this.forceFlushBufferedOutput(); this._status.runFinished(); - // $FlowFixMe process.stdout.write = this._out; - // $FlowFixMe process.stderr.write = this._err; clearLine(process.stderr); } @@ -170,7 +168,7 @@ export default class DefaultReporter extends BaseReporter { } printTestFileHeader( - testPath: Config.Path, + _testPath: Config.Path, config: Config.ProjectConfig, result: TestResult.TestResult, ) { @@ -191,8 +189,8 @@ export default class DefaultReporter extends BaseReporter { } printTestFileFailureMessage( - testPath: Config.Path, - config: Config.ProjectConfig, + _testPath: Config.Path, + _config: Config.ProjectConfig, result: TestResult.TestResult, ) { if (result.failureMessage) { diff --git a/packages/jest-reporters/src/istanbul-api.d.ts b/packages/jest-reporters/src/istanbul-api.d.ts new file mode 100644 index 000000000000..55fc4f97c331 --- /dev/null +++ b/packages/jest-reporters/src/istanbul-api.d.ts @@ -0,0 +1,14 @@ +declare module 'istanbul-api' { + class Reporter { + constructor(config?: object, options?: object); + add(format: string): void; + addAll(formats: string[]): void; + write(coverageMap: object, options: object): void; + config: object; + dir: string; + reports: object; + summarizer: string; + } + + function createReporter(config?: object, options?: object): Reporter; +} diff --git a/packages/jest-reporters/src/istanbul-lib-coverage.d.ts b/packages/jest-reporters/src/istanbul-lib-coverage.d.ts new file mode 100644 index 000000000000..efaf3e46f7c5 --- /dev/null +++ b/packages/jest-reporters/src/istanbul-lib-coverage.d.ts @@ -0,0 +1,127 @@ +// Type definitions for istanbul-lib-coverage 2.0.3 +// Project: https://github.com/istanbuljs/istanbuljs +// Definitions by: Jason Cheatham +// Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped +// TypeScript Version: 2.4 + +declare module 'istanbul-lib-coverage' { + export interface CoverageSummaryData { + lines: Totals; + statements: Totals; + branches: Totals; + functions: Totals; + } + + export class CoverageSummary { + constructor(data: CoverageSummary | CoverageSummaryData); + merge(obj: CoverageSummary): CoverageSummary; + toJSON(): CoverageSummaryData; + isEmpty(): boolean; + data: CoverageSummaryData; + lines: Totals; + statements: Totals; + branches: Totals; + functions: Totals; + } + + export interface CoverageMapData { + [key: string]: FileCoverage; + } + + export class CoverageMap { + constructor(data: CoverageMapData | CoverageMap); + addFileCoverage( + pathOrObject: string | FileCoverage | FileCoverageData, + ): void; + files(): string[]; + fileCoverageFor(filename: string): FileCoverage; + filter(callback: (key: string) => boolean): void; + getCoverageSummary(): CoverageSummary; + merge(data: CoverageMapData | CoverageMap): void; + toJSON(): CoverageMapData; + data: CoverageMapData; + } + + export interface Location { + line: number; + column: number; + } + + export interface Range { + start: Location; + end: Location; + } + + export interface BranchMapping { + loc: Range; + type: string; + locations: Range[]; + line: number; + } + + export interface FunctionMapping { + name: string; + decl: Range; + loc: Range; + line: number; + } + + export interface FileCoverageData { + path: string; + statementMap: {[key: string]: Range}; + fnMap: {[key: string]: FunctionMapping}; + branchMap: {[key: string]: BranchMapping}; + s: {[key: string]: number}; + f: {[key: string]: number}; + b: {[key: string]: number[]}; + } + + export interface Totals { + total: number; + covered: number; + skipped: number; + pct: number; + } + + export interface Coverage { + covered: number; + total: number; + coverage: number; + } + + export class FileCoverage implements FileCoverageData { + constructor(data: string | FileCoverage | FileCoverageData); + merge(other: FileCoverageData): void; + getBranchCoverageByLine(): {[line: number]: Coverage}; + getLineCoverage(): {[line: number]: number}; + getUncoveredLines(): number[]; + resetHits(): void; + computeBranchTotals(): Totals; + computeSimpleTotals(): Totals; + toSummary(): CoverageSummary; + toJSON(): object; + + data: FileCoverageData; + path: string; + statementMap: {[key: string]: Range}; + fnMap: {[key: string]: FunctionMapping}; + branchMap: {[key: string]: BranchMapping}; + s: {[key: string]: number}; + f: {[key: string]: number}; + b: {[key: string]: number[]}; + } + + export const classes: { + FileCoverage: FileCoverage; + }; + + export function createCoverageMap( + data?: CoverageMap | CoverageMapData, + ): CoverageMap; + export function createCoverageSummary( + obj?: CoverageSummary | CoverageSummaryData, + ): CoverageSummary; + export function createFileCoverage( + pathOrObject: string | FileCoverage | FileCoverageData, + ): FileCoverage; +} diff --git a/packages/jest-reporters/src/node-notifier.d.ts b/packages/jest-reporters/src/node-notifier.d.ts new file mode 100644 index 000000000000..817a1f0ddad9 --- /dev/null +++ b/packages/jest-reporters/src/node-notifier.d.ts @@ -0,0 +1,242 @@ +// Type definitions for node-notifier 5.4.0 +// Project: https://github.com/mikaelbr/node-notifier +// Definitions by: Qubo +// Lorenzo Rapetti +// Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped + +/// + +// TODO: Replace with @types/node-notifier +declare module 'node-notifier' { + import NotificationCenter = require('node-notifier/notifiers/notificationcenter'); + import NotifySend = require('node-notifier/notifiers/notifysend'); + import WindowsToaster = require('node-notifier/notifiers/toaster'); + import WindowsBalloon = require('node-notifier/notifiers/balloon'); + import Growl = require('node-notifier/notifiers/growl'); + + namespace nodeNotifier { + interface NodeNotifier extends NodeJS.EventEmitter { + notify( + notification?: NotificationCenter.Notification, + callback?: NotificationCallback, + ): NotificationCenter; + notify( + notification?: WindowsToaster.Notification, + callback?: NotificationCallback, + ): WindowsToaster; + notify( + notification?: WindowsBalloon.Notification, + callback?: NotificationCallback, + ): WindowsBalloon; + notify( + notification?: NotifySend.Notification, + callback?: NotificationCallback, + ): NotifySend; + notify( + notification?: Growl.Notification, + callback?: NotificationCallback, + ): Growl; + notify( + notification?: Notification, + callback?: NotificationCallback, + ): NodeNotifier; + notify( + notification?: string, + callback?: NotificationCallback, + ): NodeNotifier; + NotificationCenter: typeof NotificationCenter; + NotifySend: typeof NotifySend; + WindowsToaster: typeof WindowsToaster; + WindowsBalloon: typeof WindowsBalloon; + Growl: typeof Growl; + } + + interface Notification { + title?: string; + message?: string; + /** Absolute path (not balloons) */ + icon?: string; + /** Wait with callback until user action is taken on notification */ + wait?: boolean; + } + + interface NotificationCallback { + (err: any, response: any, metadata?: any): any; + } + + interface Option { + withFallback?: boolean; + customPath?: string; + } + } + + const nodeNotifier: nodeNotifier.NodeNotifier; + + export = nodeNotifier; +} + +declare module 'node-notifier/notifiers/notificationcenter' { + import notifier = require('node-notifier'); + + class NotificationCenter { + constructor(option?: notifier.Option); + notify( + notification?: NotificationCenter.Notification, + callback?: notifier.NotificationCallback, + ): NotificationCenter; + } + + namespace NotificationCenter { + interface Notification extends notifier.Notification { + /** + * Case Sensitive string for location of sound file, or use one of macOS' native sounds. + */ + sound?: boolean | string; + subtitle?: string; + /** Attach image? (Absolute path) */ + contentImage?: string; + /** URL to open on click */ + open?: string; + /** + * The amount of seconds before the notification closes. + * Takes precedence over wait if both are defined. + */ + timeout?: number; + /** Label for cancel button */ + closeLabel?: string; + /** Action label or list of labels in case of dropdown. */ + actions?: string | string[]; + /** Label to be used if there are multiple actions */ + dropdownLabel?: string; + /** + * If notification should take input. + * Value passed as third argument in callback and event emitter. + */ + reply?: boolean; + } + } + + export = NotificationCenter; +} + +declare module 'node-notifier/notifiers/notifysend' { + import notifier = require('node-notifier'); + + class NotifySend { + constructor(option?: notifier.Option); + notify( + notification?: NotifySend.Notification, + callback?: notifier.NotificationCallback, + ): NotifySend; + } + + namespace NotifySend { + interface Notification { + title?: string; + message?: string; + icon?: string; + /** Specifies the urgency level (low, normal, critical). */ + urgency?: string; + /** Specifies the timeout in milliseconds at which to expire the notification */ + time?: number; + /** Specifies the notification category */ + category?: string; + /** Specifies basic extra data to pass. Valid types are int, double, string and byte. */ + hint?: string; + } + } + + export = NotifySend; +} + +declare module 'node-notifier/notifiers/toaster' { + import notifier = require('node-notifier'); + + class WindowsToaster { + constructor(option?: notifier.Option); + notify( + notification?: WindowsToaster.Notification, + callback?: notifier.NotificationCallback, + ): WindowsToaster; + } + + namespace WindowsToaster { + interface Notification extends notifier.Notification { + /** + * Defined by http://msdn.microsoft.com/en-us/library/windows/apps/hh761492.aspx + */ + sound?: boolean | string; + /** ID to use for closing notification. */ + id?: number; + /** App.ID and app Name. Defaults to no value, causing SnoreToast text to be visible. */ + appID?: string; + /** Refer to previously created notification to close. */ + remove?: number; + /** + * Creates a shortcut in the start menu which point to the + * executable , appID used for the notifications. + */ + install?: string; + } + } + + export = WindowsToaster; +} + +declare module 'node-notifier/notifiers/growl' { + import notifier = require('node-notifier'); + + class Growl { + constructor(option?: Growl.Option); + notify( + notification?: Growl.Notification, + callback?: notifier.NotificationCallback, + ): Growl; + } + + namespace Growl { + interface Option { + name?: string; + host?: string; + port?: number; + } + + interface Notification extends notifier.Notification { + /** whether or not to sticky the notification (defaults to false) */ + sticky?: boolean; + /** type of notification to use (defaults to the first registered type) */ + label?: string; + /** the priority of the notification from lowest (-2) to highest (2) */ + priority?: number; + } + } + + export = Growl; +} + +declare module 'node-notifier/notifiers/balloon' { + import notifier = require('node-notifier'); + + class WindowsBalloon { + constructor(option?: notifier.Option); + notify( + notification?: WindowsBalloon.Notification, + callback?: notifier.NotificationCallback, + ): WindowsBalloon; + } + + namespace WindowsBalloon { + interface Notification { + title?: string; + message?: string; + /** How long to show balloons in ms */ + time?: number; + /** Wait with callback until user action is taken on notification */ + wait?: boolean; + /** The notification type */ + type?: 'info' | 'warn' | 'error'; + } + } + + export = WindowsBalloon; +} diff --git a/packages/jest-reporters/src/notify_reporter.ts b/packages/jest-reporters/src/notify_reporter.ts index 4b632b6ec0dd..3c16708a4632 100644 --- a/packages/jest-reporters/src/notify_reporter.ts +++ b/packages/jest-reporters/src/notify_reporter.ts @@ -6,6 +6,9 @@ * */ +// TODO: Remove this +/// + import path from 'path'; import util from 'util'; import exit from 'exit'; @@ -19,9 +22,10 @@ const isDarwin = process.platform === 'darwin'; const icon = path.resolve(__dirname, '../assets/jest_logo.png'); export default class NotifyReporter extends BaseReporter { - _startRun: (globalConfig: Config.GlobalConfig) => any; - _globalConfig: Config.GlobalConfig; - _context: TestSchedulerContext; + private _startRun: (globalConfig: Config.GlobalConfig) => any; + private _globalConfig: Config.GlobalConfig; + private _context: TestSchedulerContext; + constructor( globalConfig: Config.GlobalConfig, startRun: (globalConfig: Config.GlobalConfig) => any, @@ -116,7 +120,6 @@ export default class NotifyReporter extends BaseReporter { } else { notifier.notify( { - // @ts-ignore @types/node-notifier doesn't have `actions` actions: [restartAnswer, quitAnswer], closeLabel: 'Close', icon, diff --git a/packages/jest-reporters/src/summary_reporter.ts b/packages/jest-reporters/src/summary_reporter.ts index aed2b54b7eab..ab894c3bc31a 100644 --- a/packages/jest-reporters/src/summary_reporter.ts +++ b/packages/jest-reporters/src/summary_reporter.ts @@ -48,8 +48,8 @@ const NPM_EVENTS = new Set([ ]); export default class SummaryReporter extends BaseReporter { - _estimatedTime: number; - _globalConfig: Config.GlobalConfig; + private _estimatedTime: number; + private _globalConfig: Config.GlobalConfig; constructor(globalConfig: Config.GlobalConfig) { super(); @@ -62,7 +62,7 @@ export default class SummaryReporter extends BaseReporter { // in Node.js 0.10 and still persists in Node.js 6.7+. // Let's print the test failure summary character by character which is safer // when hundreds of tests are failing. - _write(string: string) { + private _write(string: string) { for (let i = 0; i < string.length; i++) { process.stderr.write(string.charAt(i)); } @@ -117,7 +117,7 @@ export default class SummaryReporter extends BaseReporter { } } - _printSnapshotSummary( + private _printSnapshotSummary( snapshots: TestResult.SnapshotSummary, globalConfig: Config.GlobalConfig, ) { @@ -162,7 +162,7 @@ export default class SummaryReporter extends BaseReporter { } } - _printSummary( + private _printSummary( aggregatedResults: TestResult.AggregatedResult, globalConfig: Config.GlobalConfig, ) { @@ -190,7 +190,10 @@ export default class SummaryReporter extends BaseReporter { } } - _getTestSummary(contexts: Set, globalConfig: Config.GlobalConfig) { + private _getTestSummary( + contexts: Set, + globalConfig: Config.GlobalConfig, + ) { const getMatchingTestsInfo = () => { const prefix = globalConfig.findRelatedTests ? ' related to files matching ' diff --git a/packages/jest-reporters/src/types.ts b/packages/jest-reporters/src/types.ts index 8e11f90d5b5d..2310c80f4633 100644 --- a/packages/jest-reporters/src/types.ts +++ b/packages/jest-reporters/src/types.ts @@ -69,21 +69,6 @@ export interface Reporter { readonly getLastError: () => Error | void; } -type FileCoverageTotal = { - total: number; - covered: number; - skipped: number; - pct: number; -}; - -export type CoverageSummary = { - lines: FileCoverageTotal; - statements: FileCoverageTotal; - branches: FileCoverageTotal; - functions: FileCoverageTotal; - merge: (other: CoverageSummary) => void; -}; - export type SummaryOptions = { estimatedTime?: number; roundTime?: boolean; diff --git a/packages/jest-reporters/src/verbose_reporter.ts b/packages/jest-reporters/src/verbose_reporter.ts index 4e8ada29def7..64f321b7c233 100644 --- a/packages/jest-reporters/src/verbose_reporter.ts +++ b/packages/jest-reporters/src/verbose_reporter.ts @@ -16,7 +16,7 @@ import DefaultReporter from './default_reporter'; const {ICONS} = specialChars; export default class VerboseReporter extends DefaultReporter { - _globalConfig: Config.GlobalConfig; + protected _globalConfig: Config.GlobalConfig; constructor(globalConfig: Config.GlobalConfig) { super(globalConfig); @@ -74,12 +74,12 @@ export default class VerboseReporter extends DefaultReporter { super.forceFlushBufferedOutput(); } - _logTestResults(testResults: Array) { + private _logTestResults(testResults: Array) { this._logSuite(VerboseReporter.groupTestsBySuites(testResults), 0); this._logLine(); } - _logSuite(suite: TestResult.Suite, indentLevel: number) { + private _logSuite(suite: TestResult.Suite, indentLevel: number) { if (suite.title) { this._logLine(suite.title, indentLevel); } @@ -89,7 +89,7 @@ export default class VerboseReporter extends DefaultReporter { suite.suites.forEach(suite => this._logSuite(suite, indentLevel + 1)); } - _getIcon(status: string) { + private _getIcon(status: string) { if (status === 'failed') { return chalk.red(ICONS.failed); } else if (status === 'pending') { @@ -101,13 +101,16 @@ export default class VerboseReporter extends DefaultReporter { } } - _logTest(test: TestResult.AssertionResult, indentLevel: number) { + private _logTest(test: TestResult.AssertionResult, indentLevel: number) { const status = this._getIcon(test.status); const time = test.duration ? ` (${test.duration.toFixed(0)}ms)` : ''; this._logLine(status + ' ' + chalk.dim(test.title + time), indentLevel); } - _logTests(tests: Array, indentLevel: number) { + private _logTests( + tests: Array, + indentLevel: number, + ) { if (this._globalConfig.expand) { tests.forEach(test => this._logTest(test, indentLevel)); } else { @@ -146,7 +149,7 @@ export default class VerboseReporter extends DefaultReporter { } } - _logSummedTests( + private _logSummedTests( prefix: string, icon: string, count: number, @@ -156,7 +159,7 @@ export default class VerboseReporter extends DefaultReporter { this._logLine(`${icon} ${text}`, indentLevel); } - _logLine(str?: string, indentLevel?: number) { + private _logLine(str?: string, indentLevel?: number) { const indentation = ' '.repeat(indentLevel || 0); this.log(indentation + (str || '')); } diff --git a/packages/jest-types/src/Config.ts b/packages/jest-types/src/Config.ts index bdd9c64efc39..18ef181d6b71 100644 --- a/packages/jest-types/src/Config.ts +++ b/packages/jest-types/src/Config.ts @@ -223,6 +223,15 @@ type NotifyMode = | 'success-change' | 'failure-change'; +type CoverageThreshold = { + [path: string]: { + [key: string]: number; + }; + global: { + [key: string]: number; + }; +}; + export type GlobalConfig = { bail: number; changedSince: string; @@ -238,11 +247,7 @@ export type GlobalConfig = { coverageDirectory: string; coveragePathIgnorePatterns?: Array; coverageReporters: Array; - coverageThreshold: { - global: { - [key: string]: number; - }; - }; + coverageThreshold: CoverageThreshold; detectLeaks: boolean; detectOpenHandles: boolean; enabledTestsMap: diff --git a/yarn.lock b/yarn.lock index 3a7d5cb3e17a..20d0509804d5 100644 --- a/yarn.lock +++ b/yarn.lock @@ -1706,13 +1706,6 @@ resolved "https://registry.yarnpkg.com/@types/natural-compare/-/natural-compare-1.4.0.tgz#b3c54f7edc339758d573c5dcac7808c58cf8c31e" integrity sha512-bNtBj6AF1F90jp54KRPOrYfilGNfPr2kpaUN7rMJjauAtfGBXzT/T/REZN6jb4qUs9FTxU37kir3Nrn5WsTUDw== -"@types/node-notifier@^0.0.28": - version "0.0.28" - resolved "https://registry.yarnpkg.com/@types/node-notifier/-/node-notifier-0.0.28.tgz#86ba3d3aa8d918352cc3191d88de328b20dc93c1" - integrity sha1-hro9OqjZGDUswxkdiN4yiyDck8E= - dependencies: - "@types/node" "*" - "@types/node@*", "@types/node@^10.12.24": version "10.12.24" resolved "https://registry.yarnpkg.com/@types/node/-/node-10.12.24.tgz#b13564af612a22a20b5d95ca40f1bffb3af315cf" From 3f7d6e9aae880429629fbe75e2b6e3bdbd4c125c Mon Sep 17 00:00:00 2001 From: Lorenzo Rapetti Date: Sun, 3 Mar 2019 15:47:58 +0100 Subject: [PATCH 06/10] Fix tests and typings --- .../__tests__/__snapshots__/snapshot.test.js.snap | 5 ----- .../__tests__/basic-support.test.js | 2 -- .../__tests__/__snapshots__/basic-support.test.js.snap | 7 ------- e2e/to-match-snapshot/__tests__/basic-support.test.js | 1 - packages/jest-reporters/package.json | 1 - packages/jest-reporters/src/coverage_worker.ts | 3 +-- packages/jest-reporters/src/generateEmptyCoverage.ts | 7 ++++++- packages/jest-reporters/src/istanbul-lib-coverage.d.ts | 2 +- packages/jest-reporters/src/types.ts | 4 ---- 9 files changed, 8 insertions(+), 24 deletions(-) delete mode 100644 e2e/snapshot-escape/__tests__/__snapshots__/snapshot.test.js.snap delete mode 100644 e2e/to-match-inline-snapshot/__tests__/basic-support.test.js delete mode 100644 e2e/to-match-snapshot/__tests__/__snapshots__/basic-support.test.js.snap delete mode 100644 e2e/to-match-snapshot/__tests__/basic-support.test.js diff --git a/e2e/snapshot-escape/__tests__/__snapshots__/snapshot.test.js.snap b/e2e/snapshot-escape/__tests__/__snapshots__/snapshot.test.js.snap deleted file mode 100644 index 6d61032b1690..000000000000 --- a/e2e/snapshot-escape/__tests__/__snapshots__/snapshot.test.js.snap +++ /dev/null @@ -1,5 +0,0 @@ -// Jest Snapshot v1, https://goo.gl/fbAQLP - -exports[`escape strings 1`] = `"one: \\\\'"`; - -exports[`escape strings two 1`] = `"two: '\\""`; diff --git a/e2e/to-match-inline-snapshot/__tests__/basic-support.test.js b/e2e/to-match-inline-snapshot/__tests__/basic-support.test.js deleted file mode 100644 index 91983c3f64ec..000000000000 --- a/e2e/to-match-inline-snapshot/__tests__/basic-support.test.js +++ /dev/null @@ -1,2 +0,0 @@ -test('inline snapshots', () => - expect({apple: 'original value'}).toMatchInlineSnapshot()); diff --git a/e2e/to-match-snapshot/__tests__/__snapshots__/basic-support.test.js.snap b/e2e/to-match-snapshot/__tests__/__snapshots__/basic-support.test.js.snap deleted file mode 100644 index 6bf3a2470ffc..000000000000 --- a/e2e/to-match-snapshot/__tests__/__snapshots__/basic-support.test.js.snap +++ /dev/null @@ -1,7 +0,0 @@ -// Jest Snapshot v1, https://goo.gl/fbAQLP - -exports[`snapshots 1`] = ` -Object { - "apple": "original value", -} -`; diff --git a/e2e/to-match-snapshot/__tests__/basic-support.test.js b/e2e/to-match-snapshot/__tests__/basic-support.test.js deleted file mode 100644 index e3b673273086..000000000000 --- a/e2e/to-match-snapshot/__tests__/basic-support.test.js +++ /dev/null @@ -1 +0,0 @@ -test('snapshots', () => expect({apple: 'updated value'}).toMatchSnapshot()); diff --git a/packages/jest-reporters/package.json b/packages/jest-reporters/package.json index 8f26b2c48c35..2f1d5bd0e8aa 100644 --- a/packages/jest-reporters/package.json +++ b/packages/jest-reporters/package.json @@ -5,7 +5,6 @@ "main": "build/index.js", "types": "build/index.d.ts", "dependencies": { - "@jest/core": "^24.1.0", "@jest/environment": "^24.1.0", "@jest/transform": "^24.1.0", "@jest/types": "^24.1.0", diff --git a/packages/jest-reporters/src/coverage_worker.ts b/packages/jest-reporters/src/coverage_worker.ts index 595933967f4a..661f2705d54a 100644 --- a/packages/jest-reporters/src/coverage_worker.ts +++ b/packages/jest-reporters/src/coverage_worker.ts @@ -9,8 +9,7 @@ import fs from 'fs'; import {Config} from '@jest/types'; import exit from 'exit'; -// @ts-ignore -import {CoverageReporterOptions} from './coverage_reporter'; +import {CoverageReporterOptions} from './types'; import generateEmptyCoverage, { CoverageWorkerResult, diff --git a/packages/jest-reporters/src/generateEmptyCoverage.ts b/packages/jest-reporters/src/generateEmptyCoverage.ts index e0c7f9addd1c..cbb71bfbaca0 100644 --- a/packages/jest-reporters/src/generateEmptyCoverage.ts +++ b/packages/jest-reporters/src/generateEmptyCoverage.ts @@ -6,11 +6,16 @@ * */ +// TODO: Remove this +/// + import {Config} from '@jest/types'; import {readInitialCoverage} from 'istanbul-lib-instrument'; -import {FileCoverage} from 'istanbul-lib-coverage'; +import {classes} from 'istanbul-lib-coverage'; import {shouldInstrument, ScriptTransformer} from '@jest/transform'; +const FileCoverage = classes.FileCoverage; + export type CoverageWorkerResult = { coverage: any; sourceMapPath?: string | null; diff --git a/packages/jest-reporters/src/istanbul-lib-coverage.d.ts b/packages/jest-reporters/src/istanbul-lib-coverage.d.ts index efaf3e46f7c5..d1cec9c16efa 100644 --- a/packages/jest-reporters/src/istanbul-lib-coverage.d.ts +++ b/packages/jest-reporters/src/istanbul-lib-coverage.d.ts @@ -112,7 +112,7 @@ declare module 'istanbul-lib-coverage' { } export const classes: { - FileCoverage: FileCoverage; + FileCoverage: typeof FileCoverage; }; export function createCoverageMap( diff --git a/packages/jest-reporters/src/types.ts b/packages/jest-reporters/src/types.ts index 2310c80f4633..f723f04b354b 100644 --- a/packages/jest-reporters/src/types.ts +++ b/packages/jest-reporters/src/types.ts @@ -11,8 +11,6 @@ import {JestEnvironment as Environment} from '@jest/environment'; import {ModuleMap, FS as HasteFS} from 'jest-haste-map'; import HasteResolver from 'jest-resolve'; import Runtime from 'jest-runtime'; -// @ts-ignore Not migrated yet -import {TestWatcher as _TestWatcher} from '@jest/core'; import {worker} from './coverage_worker'; export type ReporterOnStartOptions = { @@ -33,8 +31,6 @@ export type Test = { path: Config.Path; }; -export type TestWatcher = _TestWatcher; - export type CoverageWorker = {worker: typeof worker}; export type CoverageReporterOptions = { From 878eb3871f3cf63457fbc26fc301e8e500b5b5e4 Mon Sep 17 00:00:00 2001 From: Lorenzo Rapetti Date: Sun, 3 Mar 2019 16:24:29 +0100 Subject: [PATCH 07/10] Make linter happy --- .../jest-reporters/src/coverage_reporter.ts | 8 +++---- .../jest-reporters/src/default_reporter.ts | 2 +- packages/jest-reporters/src/istanbul-api.d.ts | 10 ++++++++- .../src/istanbul-lib-coverage.d.ts | 22 ++++++++++--------- .../jest-reporters/src/node-notifier.d.ts | 14 +++++++----- 5 files changed, 34 insertions(+), 22 deletions(-) diff --git a/packages/jest-reporters/src/coverage_reporter.ts b/packages/jest-reporters/src/coverage_reporter.ts index 3ef398b8b43c..b8333b63af38 100644 --- a/packages/jest-reporters/src/coverage_reporter.ts +++ b/packages/jest-reporters/src/coverage_reporter.ts @@ -218,7 +218,7 @@ export default class CoverageReporter extends BaseReporter { actuals: CoverageSummaryData, ) { return ['statements', 'branches', 'lines', 'functions'].reduce< - string[] + Array >((errors, key) => { // Without this TypeScript complains if i put // `key: keyof CoverageSummaryData` or if i call `actuals[key]` @@ -255,7 +255,7 @@ export default class CoverageReporter extends BaseReporter { const coveredFiles = map.files(); const thresholdGroups = Object.keys(globalConfig.coverageThreshold); const groupTypeByThresholdGroup: {[index: string]: string} = {}; - const filesByGlob: {[index: string]: string[]} = {}; + const filesByGlob: {[index: string]: Array} = {}; const coveredFilesSortedIntoThresholdGroup = coveredFiles.reduce< Array<[string, string | undefined]> @@ -313,7 +313,7 @@ export default class CoverageReporter extends BaseReporter { .filter(fileAndGroup => fileAndGroup[1] === thresholdGroup) .map(fileAndGroup => fileAndGroup[0]); - function combineCoverage(filePaths: string[]) { + function combineCoverage(filePaths: Array) { return filePaths .map(filePath => map.fileCoverageFor(filePath)) .reduce( @@ -330,7 +330,7 @@ export default class CoverageReporter extends BaseReporter { ); } - let errors: string[] = []; + let errors: Array = []; thresholdGroups.forEach(thresholdGroup => { switch (groupTypeByThresholdGroup[thresholdGroup]) { diff --git a/packages/jest-reporters/src/default_reporter.ts b/packages/jest-reporters/src/default_reporter.ts index 17337ab64919..db68c5b7a217 100644 --- a/packages/jest-reporters/src/default_reporter.ts +++ b/packages/jest-reporters/src/default_reporter.ts @@ -48,7 +48,7 @@ export default class DefaultReporter extends BaseReporter { private _wrapStdio(stream: NodeJS.WritableStream | NodeJS.WriteStream) { const originalWrite = stream.write; - let buffer: string[] = []; + let buffer: Array = []; let timeout: NodeJS.Timeout | null = null; const flushBufferedOutput = () => { diff --git a/packages/jest-reporters/src/istanbul-api.d.ts b/packages/jest-reporters/src/istanbul-api.d.ts index 55fc4f97c331..5ac536fa3075 100644 --- a/packages/jest-reporters/src/istanbul-api.d.ts +++ b/packages/jest-reporters/src/istanbul-api.d.ts @@ -1,8 +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. + * + */ + declare module 'istanbul-api' { class Reporter { constructor(config?: object, options?: object); add(format: string): void; - addAll(formats: string[]): void; + addAll(formats: Array): void; write(coverageMap: object, options: object): void; config: object; dir: string; diff --git a/packages/jest-reporters/src/istanbul-lib-coverage.d.ts b/packages/jest-reporters/src/istanbul-lib-coverage.d.ts index d1cec9c16efa..bdcfe7dc54ca 100644 --- a/packages/jest-reporters/src/istanbul-lib-coverage.d.ts +++ b/packages/jest-reporters/src/istanbul-lib-coverage.d.ts @@ -1,8 +1,10 @@ -// Type definitions for istanbul-lib-coverage 2.0.3 -// Project: https://github.com/istanbuljs/istanbuljs -// Definitions by: Jason Cheatham -// Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped -// TypeScript Version: 2.4 +/** + * 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. + * + */ declare module 'istanbul-lib-coverage' { export interface CoverageSummaryData { @@ -33,7 +35,7 @@ declare module 'istanbul-lib-coverage' { addFileCoverage( pathOrObject: string | FileCoverage | FileCoverageData, ): void; - files(): string[]; + files(): Array; fileCoverageFor(filename: string): FileCoverage; filter(callback: (key: string) => boolean): void; getCoverageSummary(): CoverageSummary; @@ -55,7 +57,7 @@ declare module 'istanbul-lib-coverage' { export interface BranchMapping { loc: Range; type: string; - locations: Range[]; + locations: Array; line: number; } @@ -73,7 +75,7 @@ declare module 'istanbul-lib-coverage' { branchMap: {[key: string]: BranchMapping}; s: {[key: string]: number}; f: {[key: string]: number}; - b: {[key: string]: number[]}; + b: {[key: string]: Array}; } export interface Totals { @@ -94,7 +96,7 @@ declare module 'istanbul-lib-coverage' { merge(other: FileCoverageData): void; getBranchCoverageByLine(): {[line: number]: Coverage}; getLineCoverage(): {[line: number]: number}; - getUncoveredLines(): number[]; + getUncoveredLines(): Array; resetHits(): void; computeBranchTotals(): Totals; computeSimpleTotals(): Totals; @@ -108,7 +110,7 @@ declare module 'istanbul-lib-coverage' { branchMap: {[key: string]: BranchMapping}; s: {[key: string]: number}; f: {[key: string]: number}; - b: {[key: string]: number[]}; + b: {[key: string]: Array}; } export const classes: { diff --git a/packages/jest-reporters/src/node-notifier.d.ts b/packages/jest-reporters/src/node-notifier.d.ts index 817a1f0ddad9..b2a1e14fa255 100644 --- a/packages/jest-reporters/src/node-notifier.d.ts +++ b/packages/jest-reporters/src/node-notifier.d.ts @@ -1,8 +1,10 @@ -// Type definitions for node-notifier 5.4.0 -// Project: https://github.com/mikaelbr/node-notifier -// Definitions by: Qubo -// Lorenzo Rapetti -// Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped +/** + * 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. + * + */ /// @@ -105,7 +107,7 @@ declare module 'node-notifier/notifiers/notificationcenter' { /** Label for cancel button */ closeLabel?: string; /** Action label or list of labels in case of dropdown. */ - actions?: string | string[]; + actions?: string | Array; /** Label to be used if there are multiple actions */ dropdownLabel?: string; /** From 923a3f78a8e149b810719879407fd6dfa79f94c3 Mon Sep 17 00:00:00 2001 From: Lorenzo Rapetti Date: Sun, 3 Mar 2019 19:33:28 +0100 Subject: [PATCH 08/10] Update typings and tests --- .../__tests__/snapshot.test.js | 1 - packages/jest-reporters/src/Status.ts | 22 ++++++++----------- .../jest-reporters/src/node-notifier.d.ts | 14 +++++++++++- .../jest-reporters/src/notify_reporter.ts | 2 +- packages/jest-reporters/src/utils.ts | 3 --- packages/jest-reporters/tsconfig.json | 8 +++---- yarn.lock | 10 +-------- 7 files changed, 28 insertions(+), 32 deletions(-) diff --git a/e2e/snapshot-escape/__tests__/snapshot.test.js b/e2e/snapshot-escape/__tests__/snapshot.test.js index d5df95d7469d..c8e9a8179e45 100644 --- a/e2e/snapshot-escape/__tests__/snapshot.test.js +++ b/e2e/snapshot-escape/__tests__/snapshot.test.js @@ -8,4 +8,3 @@ // prettier-ignore test('escape strings', () => expect('one: \\\'').toMatchSnapshot()); -test('escape strings two', () => expect('two: \'"').toMatchSnapshot()); diff --git a/packages/jest-reporters/src/Status.ts b/packages/jest-reporters/src/Status.ts index 5b065b83c397..8c74e939ab48 100644 --- a/packages/jest-reporters/src/Status.ts +++ b/packages/jest-reporters/src/Status.ts @@ -64,17 +64,15 @@ class CurrentTestList { * from the terminal. */ export default class Status { - _cache: {content: string; clear: string} | null; - _callback?: () => void; - _currentTests: CurrentTestList; - _done: boolean; - _emitScheduled: boolean; - _estimatedTime: number; - _height: number; - _interval?: NodeJS.Timeout; - _aggregatedResults?: TestResult.AggregatedResult; - _lastUpdated?: number; - _showStatus: boolean; + private _cache: {content: string; clear: string} | null; + private _callback?: () => void; + private _currentTests: CurrentTestList; + private _done: boolean; + private _emitScheduled: boolean; + private _estimatedTime: number; + private _interval?: NodeJS.Timeout; + private _aggregatedResults?: TestResult.AggregatedResult; + private _showStatus: boolean; constructor() { this._cache = null; @@ -82,7 +80,6 @@ export default class Status { this._done = false; this._emitScheduled = false; this._estimatedTime = 0; - this._height = 0; this._showStatus = false; } @@ -180,7 +177,6 @@ export default class Status { _emit() { this._cache = null; - this._lastUpdated = Date.now(); if (this._callback) this._callback(); } diff --git a/packages/jest-reporters/src/node-notifier.d.ts b/packages/jest-reporters/src/node-notifier.d.ts index b2a1e14fa255..7575461ba712 100644 --- a/packages/jest-reporters/src/node-notifier.d.ts +++ b/packages/jest-reporters/src/node-notifier.d.ts @@ -62,8 +62,20 @@ declare module 'node-notifier' { wait?: boolean; } + interface NotificationMetadata { + activationType?: string; + activationAt?: string; + deliveredAt?: string; + activationValue?: string; + activationValueIndex?: string; + } + interface NotificationCallback { - (err: any, response: any, metadata?: any): any; + ( + err: Error | null, + response: string, + metadata?: NotificationMetadata, + ): void; } interface Option { diff --git a/packages/jest-reporters/src/notify_reporter.ts b/packages/jest-reporters/src/notify_reporter.ts index 3c16708a4632..1a65aff57704 100644 --- a/packages/jest-reporters/src/notify_reporter.ts +++ b/packages/jest-reporters/src/notify_reporter.ts @@ -126,7 +126,7 @@ export default class NotifyReporter extends BaseReporter { message, title, }, - (err: any, _: any, metadata: any) => { + (err, _, metadata) => { if (err || !metadata) { return; } diff --git a/packages/jest-reporters/src/utils.ts b/packages/jest-reporters/src/utils.ts index 734c34d7df33..61a29c450a1c 100644 --- a/packages/jest-reporters/src/utils.ts +++ b/packages/jest-reporters/src/utils.ts @@ -6,9 +6,6 @@ * */ -// import type {Path, ProjectConfig, GlobalConfig} from 'types/Config'; -// import type {AggregatedResult} from 'types/TestResult'; - import path from 'path'; import {Config, TestResult} from '@jest/types'; import chalk from 'chalk'; diff --git a/packages/jest-reporters/tsconfig.json b/packages/jest-reporters/tsconfig.json index ddb1c2ecad2f..5f38de20815b 100644 --- a/packages/jest-reporters/tsconfig.json +++ b/packages/jest-reporters/tsconfig.json @@ -5,12 +5,12 @@ "outDir": "build" }, "references": [ - {"path": "../jest-types"}, - {"path": "../jest-util"}, - {"path": "../jest-worker"}, + {"path": "../jest-environment"}, {"path": "../jest-haste-map"}, {"path": "../jest-resolve"}, {"path": "../jest-runtime"}, - {"path": "../jest-environment"} + {"path": "../jest-types"}, + {"path": "../jest-util"}, + {"path": "../jest-worker"} ] } diff --git a/yarn.lock b/yarn.lock index c6372a68ca2e..35dfdc279ddb 100644 --- a/yarn.lock +++ b/yarn.lock @@ -1777,14 +1777,6 @@ "@types/prop-types" "*" csstype "^2.2.0" -"@types/readable-stream@^2.3.0": - version "2.3.1" - resolved "https://registry.yarnpkg.com/@types/readable-stream/-/readable-stream-2.3.1.tgz#59d458b51c84c585caea06e296e2225057c9ea8e" - integrity sha512-Dp6t95yGEOm2y669mQrSl0kUg+oL+bJEiCWMyDv0Yq+FcVvjzNRLTAqJks2LDBYYrazZXNI7lZXq3lp7MOvt4A== - dependencies: - "@types/node" "*" - safe-buffer "*" - "@types/resolve@*": version "0.0.8" resolved "https://registry.yarnpkg.com/@types/resolve/-/resolve-0.0.8.tgz#f26074d238e02659e323ce1a13d041eee280e194" @@ -11509,7 +11501,7 @@ rxjs@^6.4.0: dependencies: tslib "^1.9.0" -safe-buffer@*, safe-buffer@5.1.2, safe-buffer@^5.0.1, safe-buffer@^5.1.0, safe-buffer@^5.1.1, safe-buffer@^5.1.2, safe-buffer@~5.1.0, safe-buffer@~5.1.1: +safe-buffer@5.1.2, safe-buffer@^5.0.1, safe-buffer@^5.1.0, safe-buffer@^5.1.1, safe-buffer@^5.1.2, safe-buffer@~5.1.0, safe-buffer@~5.1.1: version "5.1.2" resolved "https://registry.yarnpkg.com/safe-buffer/-/safe-buffer-5.1.2.tgz#991ec69d296e0313747d59bdfd2b745c35f8828d" integrity sha512-Gd2UZBJDkXlY7GbJxfsE8/nvKkUEU1G38c1siN6QP6a9PT9MmHB8GnpscSmMJSoF8LOIrt8ud/wPtojys4G6+g== From e38a0919f67428ace1d8402e77d1a7e319687b4f Mon Sep 17 00:00:00 2001 From: Simen Bekkhus Date: Sun, 3 Mar 2019 20:17:58 +0100 Subject: [PATCH 09/10] tweaks --- packages/jest-reporters/package.json | 1 + packages/jest-reporters/src/Status.ts | 7 +++---- .../__tests__/generateEmptyCoverage.test.js | 1 - .../src/__tests__/get_snapshot_status.test.js | 1 - .../src/__tests__/notify_reporter.test.js | 1 - .../src/__tests__/utils.test.js | 1 - .../src/__tests__/verbose_reporter.test.js | 1 - packages/jest-reporters/src/base_reporter.ts | 1 - .../jest-reporters/src/coverage_reporter.ts | 19 +++++++------------ .../jest-reporters/src/coverage_worker.ts | 1 - .../jest-reporters/src/default_reporter.ts | 1 - .../src/generateEmptyCoverage.ts | 1 - .../jest-reporters/src/get_result_header.ts | 1 - .../jest-reporters/src/get_snapshot_status.ts | 1 - .../src/get_snapshot_summary.ts | 1 - packages/jest-reporters/src/index.ts | 1 - packages/jest-reporters/src/istanbul-api.d.ts | 1 - .../src/istanbul-lib-coverage.d.ts | 1 - .../jest-reporters/src/node-notifier.d.ts | 1 - .../jest-reporters/src/notify_reporter.ts | 1 - .../jest-reporters/src/summary_reporter.ts | 1 - packages/jest-reporters/src/types.ts | 1 - packages/jest-reporters/src/utils.ts | 1 - .../jest-reporters/src/verbose_reporter.ts | 1 - 24 files changed, 11 insertions(+), 37 deletions(-) diff --git a/packages/jest-reporters/package.json b/packages/jest-reporters/package.json index 2f1d5bd0e8aa..39ff7a54f21d 100644 --- a/packages/jest-reporters/package.json +++ b/packages/jest-reporters/package.json @@ -22,6 +22,7 @@ "jest-worker": "^24.0.0", "node-notifier": "^5.2.1", "slash": "^2.0.0", + "source-map": "^0.6.0", "string-length": "^2.0.0" }, "devDependencies": { diff --git a/packages/jest-reporters/src/Status.ts b/packages/jest-reporters/src/Status.ts index 8c74e939ab48..099dbe200739 100644 --- a/packages/jest-reporters/src/Status.ts +++ b/packages/jest-reporters/src/Status.ts @@ -3,7 +3,6 @@ * * This source code is licensed under the MIT license found in the * LICENSE file in the root directory of this source tree. - * */ import {TestResult, Config} from '@jest/types'; @@ -175,12 +174,12 @@ export default class Status { return (this._cache = {clear, content}); } - _emit() { + private _emit() { this._cache = null; if (this._callback) this._callback(); } - _debouncedEmit() { + private _debouncedEmit() { if (!this._emitScheduled) { // Perf optimization to avoid two separate renders When // one test finishes and another test starts executing. @@ -192,7 +191,7 @@ export default class Status { } } - _tick() { + private _tick() { this._debouncedEmit(); } } diff --git a/packages/jest-reporters/src/__tests__/generateEmptyCoverage.test.js b/packages/jest-reporters/src/__tests__/generateEmptyCoverage.test.js index d5d9555c76b8..678913cab672 100644 --- a/packages/jest-reporters/src/__tests__/generateEmptyCoverage.test.js +++ b/packages/jest-reporters/src/__tests__/generateEmptyCoverage.test.js @@ -3,7 +3,6 @@ * * This source code is licensed under the MIT license found in the * LICENSE file in the root directory of this source tree. - * */ import istanbulCoverage from 'istanbul-lib-coverage'; diff --git a/packages/jest-reporters/src/__tests__/get_snapshot_status.test.js b/packages/jest-reporters/src/__tests__/get_snapshot_status.test.js index 6d722e2a7d9b..dbbaee15773b 100644 --- a/packages/jest-reporters/src/__tests__/get_snapshot_status.test.js +++ b/packages/jest-reporters/src/__tests__/get_snapshot_status.test.js @@ -3,7 +3,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'; diff --git a/packages/jest-reporters/src/__tests__/notify_reporter.test.js b/packages/jest-reporters/src/__tests__/notify_reporter.test.js index 274a2ca5d21c..9460c82ef1b7 100644 --- a/packages/jest-reporters/src/__tests__/notify_reporter.test.js +++ b/packages/jest-reporters/src/__tests__/notify_reporter.test.js @@ -3,7 +3,6 @@ * * This source code is licensed under the MIT license found in the * LICENSE file in the root directory of this source tree. - * */ import type {TestSchedulerContext} from 'types/TestScheduler'; diff --git a/packages/jest-reporters/src/__tests__/utils.test.js b/packages/jest-reporters/src/__tests__/utils.test.js index 3f45dc600d19..d842b3e5a600 100644 --- a/packages/jest-reporters/src/__tests__/utils.test.js +++ b/packages/jest-reporters/src/__tests__/utils.test.js @@ -3,7 +3,6 @@ * * This source code is licensed under the MIT license found in the * LICENSE file in the root directory of this source tree. - * */ import path from 'path'; diff --git a/packages/jest-reporters/src/__tests__/verbose_reporter.test.js b/packages/jest-reporters/src/__tests__/verbose_reporter.test.js index 206ce42ffc41..a13f6bd614bb 100644 --- a/packages/jest-reporters/src/__tests__/verbose_reporter.test.js +++ b/packages/jest-reporters/src/__tests__/verbose_reporter.test.js @@ -3,7 +3,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'; diff --git a/packages/jest-reporters/src/base_reporter.ts b/packages/jest-reporters/src/base_reporter.ts index 46ecff911f81..36c7c57670b9 100644 --- a/packages/jest-reporters/src/base_reporter.ts +++ b/packages/jest-reporters/src/base_reporter.ts @@ -3,7 +3,6 @@ * * This source code is licensed under the MIT license found in the * LICENSE file in the root directory of this source tree. - * */ import {TestResult} from '@jest/types'; diff --git a/packages/jest-reporters/src/coverage_reporter.ts b/packages/jest-reporters/src/coverage_reporter.ts index b8333b63af38..c3f2004858a0 100644 --- a/packages/jest-reporters/src/coverage_reporter.ts +++ b/packages/jest-reporters/src/coverage_reporter.ts @@ -3,7 +3,6 @@ * * This source code is licensed under the MIT license found in the * LICENSE file in the root directory of this source tree. - * */ // TODO: Remove this @@ -25,6 +24,7 @@ import istanbulCoverage, { import libSourceMaps, {MapStore} from 'istanbul-lib-source-maps'; import Worker from 'jest-worker'; import glob from 'glob'; +import {RawSourceMap} from 'source-map'; import BaseReporter from './base_reporter'; import {Context, Test, CoverageWorker, CoverageReporterOptions} from './types'; @@ -59,7 +59,7 @@ export default class CoverageReporter extends BaseReporter { delete testResult.coverage; Object.keys(testResult.sourceMaps).forEach(sourcePath => { - let inputSourceMap: any; + let inputSourceMap: RawSourceMap | undefined; try { const coverage: FileCoverage = this._coverageMap.fileCoverageFor( sourcePath, @@ -217,16 +217,11 @@ export default class CoverageReporter extends BaseReporter { thresholds: {[index: string]: number}, actuals: CoverageSummaryData, ) { - return ['statements', 'branches', 'lines', 'functions'].reduce< - Array - >((errors, key) => { - // Without this TypeScript complains if i put - // `key: keyof CoverageSummaryData` or if i call `actuals[key]` - // without casting - const typedKey: keyof CoverageSummaryData = key as keyof CoverageSummaryData; - const actual = actuals[typedKey].pct; - const actualUncovered = - actuals[typedKey].total - actuals[typedKey].covered; + return (['statements', 'branches', 'lines', 'functions'] as Array< + keyof CoverageSummaryData + >).reduce>((errors, key) => { + const actual = actuals[key].pct; + const actualUncovered = actuals[key].total - actuals[key].covered; const threshold = thresholds[key]; if (threshold != null) { diff --git a/packages/jest-reporters/src/coverage_worker.ts b/packages/jest-reporters/src/coverage_worker.ts index 661f2705d54a..6461a7973fde 100644 --- a/packages/jest-reporters/src/coverage_worker.ts +++ b/packages/jest-reporters/src/coverage_worker.ts @@ -3,7 +3,6 @@ * * This source code is licensed under the MIT license found in the * LICENSE file in the root directory of this source tree. - * */ import fs from 'fs'; diff --git a/packages/jest-reporters/src/default_reporter.ts b/packages/jest-reporters/src/default_reporter.ts index db68c5b7a217..686207e1d3ae 100644 --- a/packages/jest-reporters/src/default_reporter.ts +++ b/packages/jest-reporters/src/default_reporter.ts @@ -3,7 +3,6 @@ * * This source code is licensed under the MIT license found in the * LICENSE file in the root directory of this source tree. - * */ import {TestResult, Config} from '@jest/types'; diff --git a/packages/jest-reporters/src/generateEmptyCoverage.ts b/packages/jest-reporters/src/generateEmptyCoverage.ts index cbb71bfbaca0..6ea3567566d9 100644 --- a/packages/jest-reporters/src/generateEmptyCoverage.ts +++ b/packages/jest-reporters/src/generateEmptyCoverage.ts @@ -3,7 +3,6 @@ * * This source code is licensed under the MIT license found in the * LICENSE file in the root directory of this source tree. - * */ // TODO: Remove this diff --git a/packages/jest-reporters/src/get_result_header.ts b/packages/jest-reporters/src/get_result_header.ts index ad7c6af35b6c..43c8b2301d94 100644 --- a/packages/jest-reporters/src/get_result_header.ts +++ b/packages/jest-reporters/src/get_result_header.ts @@ -3,7 +3,6 @@ * * This source code is licensed under the MIT license found in the * LICENSE file in the root directory of this source tree. - * */ import {Config, TestResult} from '@jest/types'; diff --git a/packages/jest-reporters/src/get_snapshot_status.ts b/packages/jest-reporters/src/get_snapshot_status.ts index 2de1b76dfd7e..91c4e692eb90 100644 --- a/packages/jest-reporters/src/get_snapshot_status.ts +++ b/packages/jest-reporters/src/get_snapshot_status.ts @@ -3,7 +3,6 @@ * * This source code is licensed under the MIT license found in the * LICENSE file in the root directory of this source tree. - * */ import {TestResult} from '@jest/types'; diff --git a/packages/jest-reporters/src/get_snapshot_summary.ts b/packages/jest-reporters/src/get_snapshot_summary.ts index 16b0ac5ee33c..19027f821aca 100644 --- a/packages/jest-reporters/src/get_snapshot_summary.ts +++ b/packages/jest-reporters/src/get_snapshot_summary.ts @@ -3,7 +3,6 @@ * * This source code is licensed under the MIT license found in the * LICENSE file in the root directory of this source tree. - * */ import {Config, TestResult} from '@jest/types'; diff --git a/packages/jest-reporters/src/index.ts b/packages/jest-reporters/src/index.ts index db7c5c5223c2..d706797ee0fd 100644 --- a/packages/jest-reporters/src/index.ts +++ b/packages/jest-reporters/src/index.ts @@ -3,7 +3,6 @@ * * This source code is licensed under the MIT license found in the * LICENSE file in the root directory of this source tree. - * */ export {default as BaseReporter} from './base_reporter'; diff --git a/packages/jest-reporters/src/istanbul-api.d.ts b/packages/jest-reporters/src/istanbul-api.d.ts index 5ac536fa3075..d39fef7f7ee6 100644 --- a/packages/jest-reporters/src/istanbul-api.d.ts +++ b/packages/jest-reporters/src/istanbul-api.d.ts @@ -3,7 +3,6 @@ * * This source code is licensed under the MIT license found in the * LICENSE file in the root directory of this source tree. - * */ declare module 'istanbul-api' { diff --git a/packages/jest-reporters/src/istanbul-lib-coverage.d.ts b/packages/jest-reporters/src/istanbul-lib-coverage.d.ts index bdcfe7dc54ca..360455ca42b5 100644 --- a/packages/jest-reporters/src/istanbul-lib-coverage.d.ts +++ b/packages/jest-reporters/src/istanbul-lib-coverage.d.ts @@ -3,7 +3,6 @@ * * This source code is licensed under the MIT license found in the * LICENSE file in the root directory of this source tree. - * */ declare module 'istanbul-lib-coverage' { diff --git a/packages/jest-reporters/src/node-notifier.d.ts b/packages/jest-reporters/src/node-notifier.d.ts index 7575461ba712..27a27e1211dd 100644 --- a/packages/jest-reporters/src/node-notifier.d.ts +++ b/packages/jest-reporters/src/node-notifier.d.ts @@ -3,7 +3,6 @@ * * This source code is licensed under the MIT license found in the * LICENSE file in the root directory of this source tree. - * */ /// diff --git a/packages/jest-reporters/src/notify_reporter.ts b/packages/jest-reporters/src/notify_reporter.ts index 1a65aff57704..b6755b85b25c 100644 --- a/packages/jest-reporters/src/notify_reporter.ts +++ b/packages/jest-reporters/src/notify_reporter.ts @@ -3,7 +3,6 @@ * * This source code is licensed under the MIT license found in the * LICENSE file in the root directory of this source tree. - * */ // TODO: Remove this diff --git a/packages/jest-reporters/src/summary_reporter.ts b/packages/jest-reporters/src/summary_reporter.ts index ab894c3bc31a..9a873cbe0ef7 100644 --- a/packages/jest-reporters/src/summary_reporter.ts +++ b/packages/jest-reporters/src/summary_reporter.ts @@ -3,7 +3,6 @@ * * This source code is licensed under the MIT license found in the * LICENSE file in the root directory of this source tree. - * */ import {TestResult, Config} from '@jest/types'; diff --git a/packages/jest-reporters/src/types.ts b/packages/jest-reporters/src/types.ts index f723f04b354b..cfdde6598abc 100644 --- a/packages/jest-reporters/src/types.ts +++ b/packages/jest-reporters/src/types.ts @@ -3,7 +3,6 @@ * * This source code is licensed under the MIT license found in the * LICENSE file in the root directory of this source tree. - * */ import {Config, TestResult} from '@jest/types'; diff --git a/packages/jest-reporters/src/utils.ts b/packages/jest-reporters/src/utils.ts index 61a29c450a1c..d078b584fbf0 100644 --- a/packages/jest-reporters/src/utils.ts +++ b/packages/jest-reporters/src/utils.ts @@ -3,7 +3,6 @@ * * This source code is licensed under the MIT license found in the * LICENSE file in the root directory of this source tree. - * */ import path from 'path'; diff --git a/packages/jest-reporters/src/verbose_reporter.ts b/packages/jest-reporters/src/verbose_reporter.ts index 64f321b7c233..74ac6794f27c 100644 --- a/packages/jest-reporters/src/verbose_reporter.ts +++ b/packages/jest-reporters/src/verbose_reporter.ts @@ -3,7 +3,6 @@ * * This source code is licensed under the MIT license found in the * LICENSE file in the root directory of this source tree. - * */ import {Config, TestResult} from '@jest/types'; From cc9c071322df827c21bab88e6e1105571b02b3e7 Mon Sep 17 00:00:00 2001 From: Simen Bekkhus Date: Sun, 3 Mar 2019 23:39:38 +0100 Subject: [PATCH 10/10] remove extra newlines --- packages/jest-reporters/src/summary_reporter.ts | 3 --- 1 file changed, 3 deletions(-) diff --git a/packages/jest-reporters/src/summary_reporter.ts b/packages/jest-reporters/src/summary_reporter.ts index 9a873cbe0ef7..cf392376c53f 100644 --- a/packages/jest-reporters/src/summary_reporter.ts +++ b/packages/jest-reporters/src/summary_reporter.ts @@ -6,12 +6,9 @@ */ import {TestResult, Config} from '@jest/types'; - import chalk from 'chalk'; import {testPathPatternToRegExp} from 'jest-util'; - import {Context, ReporterOnStartOptions} from './types'; - import BaseReporter from './base_reporter'; import {getSummary} from './utils'; import getResultHeader from './get_result_header';