Skip to content

Commit

Permalink
Add “GlobalConfig” type. (jestjs#3328)
Browse files Browse the repository at this point in the history
  • Loading branch information
cpojer authored and skovhus committed Apr 29, 2017
1 parent 4acc42d commit 1ce0a10
Show file tree
Hide file tree
Showing 9 changed files with 52 additions and 24 deletions.
6 changes: 3 additions & 3 deletions packages/jest-cli/src/TestRunner.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ import type {
SerializableError as TestError,
TestResult,
} from 'types/TestResult';
import type {Config} from 'types/Config';
import type {GlobalConfig} from 'types/Config';
import type {Context} from 'types/Context';
import type {PathPattern} from './SearchSource';
import type {Test, Tests} from 'types/TestRunner';
Expand Down Expand Up @@ -56,11 +56,11 @@ type OnTestSuccess = (test: Test, result: TestResult) => void;
const TEST_WORKER_PATH = require.resolve('./TestWorker');

class TestRunner {
_config: Config;
_config: GlobalConfig;
_options: Options;
_dispatcher: ReporterDispatcher;

constructor(config: Config, options: Options) {
constructor(config: GlobalConfig, options: Options) {
this._config = config;
this._dispatcher = new ReporterDispatcher();
this._options = options;
Expand Down
6 changes: 3 additions & 3 deletions packages/jest-cli/src/reporters/BaseReporter.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
'use strict';

import type {AggregatedResult, TestResult} from 'types/TestResult';
import type {Config} from 'types/Config';
import type {GlobalConfig} from 'types/Config';
import type {Context} from 'types/Context';
import type {Test} from 'types/TestRunner';
import type {ReporterOnStartOptions} from 'types/Reporters';
Expand All @@ -25,7 +25,7 @@ class BaseReporter {
}

onRunStart(
config: Config,
config: GlobalConfig,
results: AggregatedResult,
options: ReporterOnStartOptions,
) {
Expand All @@ -38,7 +38,7 @@ class BaseReporter {

onRunComplete(
contexts: Set<Context>,
config: Config,
config: GlobalConfig,
aggregatedResults: AggregatedResult,
): ?Promise<any> {}

Expand Down
6 changes: 3 additions & 3 deletions packages/jest-cli/src/reporters/CoverageReporter.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
'use strict';

import type {AggregatedResult, CoverageMap, TestResult} from 'types/TestResult';
import type {Config} from 'types/Config';
import type {GlobalConfig} from 'types/Config';
import type {Context} from 'types/Context';
import type {Test} from 'types/TestRunner';

Expand Down Expand Up @@ -61,7 +61,7 @@ class CoverageReporter extends BaseReporter {

onRunComplete(
contexts: Set<Context>,
config: Config,
config: GlobalConfig,
aggregatedResults: AggregatedResult,
) {
this._addUntestedFiles(contexts);
Expand Down Expand Up @@ -155,7 +155,7 @@ class CoverageReporter extends BaseReporter {
}
}

_checkThreshold(map: CoverageMap, config: Config) {
_checkThreshold(map: CoverageMap, config: GlobalConfig) {
if (config.coverageThreshold) {
const results = map.getCoverageSummary().toJSON();

Expand Down
4 changes: 2 additions & 2 deletions packages/jest-cli/src/reporters/DefaultReporter.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
'use strict';

import type {AggregatedResult, TestResult} from 'types/TestResult';
import type {Config, Path} from 'types/Config';
import type {Config, GlobalConfig, Path} from 'types/Config';
import type {Test} from 'types/TestRunner';
import type {ReporterOnStartOptions} from 'types/Reporters';

Expand Down Expand Up @@ -106,7 +106,7 @@ class DefaultReporter extends BaseReporter {
}

onRunStart(
config: Config,
config: GlobalConfig,
aggregatedResults: AggregatedResult,
options: ReporterOnStartOptions,
) {
Expand Down
4 changes: 2 additions & 2 deletions packages/jest-cli/src/reporters/NotifyReporter.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
'use strict';

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

const BaseReporter = require('./BaseReporter');
Expand All @@ -32,7 +32,7 @@ class NotifyReporter extends BaseReporter {

onRunComplete(
contexts: Set<Context>,
config: Config,
config: GlobalConfig,
result: AggregatedResult,
): void {
const success =
Expand Down
10 changes: 5 additions & 5 deletions packages/jest-cli/src/reporters/SummaryReporter.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
'use strict';

import type {AggregatedResult, SnapshotSummary} from 'types/TestResult';
import type {Config} from 'types/Config';
import type {GlobalConfig} from 'types/Config';
import type {Context} from 'types/Context';
import type {Options as SummaryReporterOptions} from '../TestRunner';
import type {PathPattern} from '../SearchSource';
Expand Down Expand Up @@ -80,7 +80,7 @@ class SummaryReporter extends BaseReporter {
}

onRunStart(
config: Config,
config: GlobalConfig,
aggregatedResults: AggregatedResult,
options: ReporterOnStartOptions,
) {
Expand All @@ -90,7 +90,7 @@ class SummaryReporter extends BaseReporter {

onRunComplete(
contexts: Set<Context>,
config: Config,
config: GlobalConfig,
aggregatedResults: AggregatedResult,
) {
const {numTotalTestSuites, testResults, wasInterrupted} = aggregatedResults;
Expand Down Expand Up @@ -130,7 +130,7 @@ class SummaryReporter extends BaseReporter {
}
}

_printSnapshotSummary(snapshots: SnapshotSummary, config: Config) {
_printSnapshotSummary(snapshots: SnapshotSummary, config: GlobalConfig) {
if (
snapshots.added ||
snapshots.filesRemoved ||
Expand Down Expand Up @@ -215,7 +215,7 @@ class SummaryReporter extends BaseReporter {
}
}

_printSummary(aggregatedResults: AggregatedResult, config: Config) {
_printSummary(aggregatedResults: AggregatedResult, 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.
const failedTests = aggregatedResults.numFailedTests;
Expand Down
4 changes: 2 additions & 2 deletions packages/jest-cli/src/reporters/getResultHeader.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,8 @@
*/
'use strict';

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

const {formatTestPath} = require('./utils');
const chalk = require('chalk');
Expand All @@ -21,7 +21,7 @@ const LONG_TEST_COLOR = chalk.reset.bold.bgRed;
const FAIL = chalk.reset.inverse.bold.red(' FAIL ');
const PASS = chalk.reset.inverse.bold.green(' PASS ');

module.exports = (result: TestResult, config: Config) => {
module.exports = (result: TestResult, config: {rootDir: Path}) => {
const testPath = result.testFilePath;
const status = result.numFailingTests > 0 || result.testExecError
? FAIL
Expand Down
8 changes: 4 additions & 4 deletions packages/jest-cli/src/reporters/utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@

'use strict';

import type {Config, Path} from 'types/Config';
import type {Path} from 'types/Config';
import type {AggregatedResult} from 'types/TestResult';

const chalk = require('chalk');
Expand All @@ -27,7 +27,7 @@ const PROGRESS_BAR_WIDTH = 40;

const trimAndFormatPath = (
pad: number,
config: Config,
config: {rootDir: Path},
testPath: Path,
columns: number,
): string => {
Expand Down Expand Up @@ -62,12 +62,12 @@ const trimAndFormatPath = (
);
};

const formatTestPath = (config: Config, testPath: Path) => {
const formatTestPath = (config: {rootDir: Path}, testPath: Path) => {
const {dirname, basename} = relativePath(config, testPath);
return chalk.dim(dirname + path.sep) + chalk.bold(basename);
};

const relativePath = (config: Config, testPath: Path) => {
const relativePath = (config: {rootDir: Path}, testPath: Path) => {
testPath = path.relative(config.rootDir, testPath);
const dirname = path.dirname(testPath);
const basename = path.basename(testPath);
Expand Down
28 changes: 28 additions & 0 deletions types/Config.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,34 @@ export type HasteConfig = {|

export type ConfigGlobals = Object;

export type GlobalConfig = {
bail: boolean,
collectCoverage: boolean,
collectCoverageFrom: Array<Glob>,
collectCoverageOnlyFrom: {[key: string]: boolean},
coverageDirectory: string,
coveragePathIgnorePatterns: Array<string>,
coverageReporters: Array<string>,
coverageThreshold: {global: {[key: string]: number}},
expand: boolean,
forceExit: boolean,
mapCoverage: boolean,
logHeapUsage: boolean,
logTransformErrors: ?boolean,
noStackTrace: boolean,
notify: boolean,
replname: ?string,
rootDir: Path,
silent: boolean,
testNamePattern: string,
testResultsProcessor: ?string,
updateSnapshot: boolean,
useStderr: boolean,
verbose: ?boolean,
watch: boolean,
watchman: boolean,
};

export type DefaultConfig = {|
automock: boolean,
bail: boolean,
Expand Down

0 comments on commit 1ce0a10

Please sign in to comment.