Skip to content
Merged
Show file tree
Hide file tree
Changes from 8 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,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))
- `[jest-repl]`: Migrate to TypeScript ([#8000](https://github.com/facebook/jest/pull/8000))
- `[jest-validate]`: Migrate to TypeScript ([#7991](https://github.com/facebook/jest/pull/7991))
- `[docs]`: Update CONTRIBUTING.md to add information about running jest with `jest-circus` locally ([#8013](https://github.com/facebook/jest/pull/8013)).
Expand Down
1 change: 1 addition & 0 deletions e2e/snapshot-escape/__tests__/snapshot.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,3 +8,4 @@

// prettier-ignore
test('escape strings', () => expect('one: \\\'').toMatchSnapshot());
test('escape strings two', () => expect('two: \'"').toMatchSnapshot());
8 changes: 6 additions & 2 deletions packages/jest-reporters/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,15 +3,21 @@
"description": "Jest's reporters",
"version": "24.1.0",
"main": "build/index.js",
"types": "build/index.d.ts",
"dependencies": {
"@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",
"istanbul-api": "^2.1.1",
"istanbul-lib-coverage": "^2.0.2",
"istanbul-lib-instrument": "^3.0.1",
"istanbul-lib-source-maps": "^3.0.1",
"jest-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",
Expand All @@ -21,10 +27,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"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -29,13 +27,16 @@ const RUNNING = chalk.reset.inverse.yellow.bold(RUNNING_TEXT) + ' ';
* shifting the whole list.
*/
class CurrentTestList {
_array: Array<{testPath: Path, config: ProjectConfig} | null>;
private _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) {
Expand All @@ -45,9 +46,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;
}
Expand All @@ -63,16 +64,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() {
Expand All @@ -90,7 +91,7 @@ export default class Status {
}

runStarted(
aggregatedResults: AggregatedResult,
aggregatedResults: TestResult.AggregatedResult,
options: ReporterOnStartOptions,
) {
this._estimatedTime = (options && options.estimatedTime) || 0;
Expand All @@ -102,11 +103,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();
Expand All @@ -116,9 +117,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;
Expand All @@ -135,8 +136,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) {
Expand Down Expand Up @@ -181,7 +181,7 @@ export default class Status {
_emit() {
this._cache = null;
this._lastUpdated = Date.now();
this._callback();
if (this._callback) this._callback();
}

_debouncedEmit() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@
* This source code is licensed under the MIT license found in the
* LICENSE file in the root directory of this source tree.
*
* @flow
*/

import istanbulCoverage from 'istanbul-lib-coverage';
Expand All @@ -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', () => ({
Expand Down Expand Up @@ -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)});
});
Original file line number Diff line number Diff line change
Expand Up @@ -4,45 +4,48 @@
* 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 {
private _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) {}
onTestStart(_test: Test) {}

onRunComplete(
contexts: Set<Context>,
aggregatedResults: AggregatedResult,
): ?Promise<void> {}
_contexts: Set<Context>,
_aggregatedResults: TestResult.AggregatedResult,
): Promise<void> | void {}

_setError(error: Error) {
protected _setError(error: Error) {
this._error = error;
}

// 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;
}
}
Loading