Skip to content

Commit

Permalink
Avoid duplicating types for pretty format
Browse files Browse the repository at this point in the history
  • Loading branch information
orta committed Jul 12, 2021
1 parent 8d5ea2e commit cd76e67
Show file tree
Hide file tree
Showing 5 changed files with 11 additions and 5 deletions.
1 change: 0 additions & 1 deletion packages/jest-config/src/normalize.ts
Expand Up @@ -27,7 +27,6 @@ import {
tryRealpath,
} from 'jest-util';
import {ValidationError, validate} from 'jest-validate';
import {DEFAULT_OPTIONS as PRETTY_FORMAT_DEFAULTS} from 'pretty-format';
import DEFAULT_CONFIG from './Defaults';
import DEPRECATED_CONFIG from './Deprecated';
import {validateReporters} from './ReporterValidationErrors';
Expand Down
4 changes: 3 additions & 1 deletion packages/jest-jasmine2/src/setup_jest_globals.ts
Expand Up @@ -106,12 +106,14 @@ export default async ({

patchJasmine();
const {expand, updateSnapshot} = globalConfig;
const {prettierPath} = config;
const {prettierPath, inlineSnapshotFormat, snapshotFormat} = config;
const snapshotResolver = await buildSnapshotResolver(config, localRequire);
const snapshotPath = snapshotResolver.resolveSnapshotPath(testPath);
const snapshotState = new SnapshotState(snapshotPath, {
expand,
inlineSnapshotFormat,
prettierPath,
snapshotFormat,
updateSnapshot,
});
// @ts-expect-error: snapshotState is a jest extension of `expect`
Expand Down
4 changes: 3 additions & 1 deletion packages/jest-types/src/Config.ts
Expand Up @@ -8,7 +8,6 @@
import type {ForegroundColor} from 'chalk';
import type {ReportOptions} from 'istanbul-reports';
import type {Arguments} from 'yargs';
import type {OptionsReceived as PrettyFormatOptions} from 'pretty-format';

type CoverageProvider = 'babel' | 'v8';

Expand Down Expand Up @@ -61,6 +60,9 @@ export interface ConfigGlobals {
[K: string]: unknown;
}

// This interface gets filled out when pretty-format is included
interface PrettyFormatOptions {}

export type DefaultOptions = {
automock: boolean;
bail: number;
Expand Down
1 change: 1 addition & 0 deletions packages/jest-types/src/index.ts
@@ -1,3 +1,4 @@

/**
* Copyright (c) Facebook, Inc. and its affiliates. All Rights Reserved.
*
Expand Down
6 changes: 4 additions & 2 deletions packages/pretty-format/src/types.ts
Expand Up @@ -46,7 +46,7 @@ export type Options = {
theme: Theme;
};

export type OptionsReceived = {
export interface PrettyFormatOptions {
callToJSON?: boolean;
escapeRegex?: boolean;
escapeString?: boolean;
Expand All @@ -58,7 +58,9 @@ export type OptionsReceived = {
printBasicPrototype?: boolean;
printFunctionName?: boolean;
theme?: ThemeReceived;
};
}

export type OptionsReceived = PrettyFormatOptions;

export type Config = {
callToJSON: boolean;
Expand Down

0 comments on commit cd76e67

Please sign in to comment.