Skip to content

Commit c8a8456

Browse files
authored
feat: create new @jest/schemas type (#12384)
1 parent c961be9 commit c8a8456

File tree

13 files changed

+119
-47
lines changed

13 files changed

+119
-47
lines changed

CHANGELOG.md

+1
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
- `[jest-environment-node]` [**BREAKING**] Add default `node` and `node-addon` conditions to `exportConditions` for `node` environment ([#11924](https://github.com/facebook/jest/pull/11924))
1111
- `[@jest/expect-utils]` New module exporting utils for `expect` ([#12323](https://github.com/facebook/jest/pull/12323))
1212
- `[jest-resolver]` [**BREAKING**] Add support for `package.json` `exports` ([11961](https://github.com/facebook/jest/pull/11961))
13+
- `[@jes/schemas]` New module for JSON schemas for Jest's config ([#12384](https://github.com/facebook/jest/pull/12384))
1314
- `[jest-worker]` [**BREAKING**] Allow only absolute `workerPath` ([#12343](https://github.com/facebook/jest/pull/12343))
1415

1516
### Fixes

packages/jest-schemas/.npmignore

+6
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
**/__mocks__/**
2+
**/__tests__/**
3+
src
4+
tsconfig.json
5+
tsconfig.tsbuildinfo
6+
api-extractor.json

packages/jest-schemas/README.md

+3
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
# `@jest/schemas`
2+
3+
Experimental and currently incomplete module for JSON schemas for [Jest's](https://jestjs.io/) configuration.

packages/jest-schemas/package.json

+28
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
{
2+
"name": "@jest/schemas",
3+
"version": "28.0.0-alpha.0",
4+
"repository": {
5+
"type": "git",
6+
"url": "https://github.com/facebook/jest.git",
7+
"directory": "packages/jest-schemas"
8+
},
9+
"license": "MIT",
10+
"main": "./build/index.js",
11+
"types": "./build/index.d.ts",
12+
"exports": {
13+
".": {
14+
"types": "./build/index.d.ts",
15+
"default": "./build/index.js"
16+
},
17+
"./package.json": "./package.json"
18+
},
19+
"dependencies": {
20+
"@sinclair/typebox": "^0.23.3"
21+
},
22+
"engines": {
23+
"node": "^12.13.0 || ^14.15.0 || ^16.13.0 || >=17.0.0"
24+
},
25+
"publishConfig": {
26+
"access": "public"
27+
}
28+
}

packages/jest-schemas/src/index.ts

+36
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
/**
2+
* Copyright (c) Facebook, Inc. and its affiliates. All Rights Reserved.
3+
*
4+
* This source code is licensed under the MIT license found in the
5+
* LICENSE file in the root directory of this source tree.
6+
*/
7+
8+
import {Static, Type} from '@sinclair/typebox';
9+
10+
const RawSnapshotFormat = Type.Partial(
11+
Type.Object({
12+
callToJSON: Type.Readonly(Type.Boolean()),
13+
escapeRegex: Type.Readonly(Type.Boolean()),
14+
escapeString: Type.Readonly(Type.Boolean()),
15+
highlight: Type.Readonly(Type.Boolean()),
16+
indent: Type.Readonly(Type.Number({minimum: 0})),
17+
maxDepth: Type.Readonly(Type.Number({minimum: 0})),
18+
min: Type.Readonly(Type.Boolean()),
19+
printBasicPrototype: Type.Readonly(Type.Boolean()),
20+
printFunctionName: Type.Readonly(Type.Boolean()),
21+
theme: Type.Readonly(
22+
Type.Partial(
23+
Type.Object({
24+
comment: Type.Readonly(Type.String()),
25+
content: Type.Readonly(Type.String()),
26+
prop: Type.Readonly(Type.String()),
27+
tag: Type.Readonly(Type.String()),
28+
value: Type.Readonly(Type.String()),
29+
}),
30+
),
31+
),
32+
}),
33+
);
34+
35+
export const SnapshotFormat = Type.Strict(RawSnapshotFormat);
36+
export type SnapshotFormat = Static<typeof RawSnapshotFormat>;

packages/jest-schemas/tsconfig.json

+9
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
{
2+
"extends": "../../tsconfig.json",
3+
"compilerOptions": {
4+
"rootDir": "src",
5+
"outDir": "build"
6+
},
7+
"include": ["./src/**/*"],
8+
"exclude": ["./**/__mocks__/**/*", "./**/__tests__/**/*"]
9+
}

packages/jest-types/package.json

+1
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020
"./package.json": "./package.json"
2121
},
2222
"dependencies": {
23+
"@jest/schemas": "28.0.0-alpha.0",
2324
"@types/istanbul-lib-coverage": "^2.0.0",
2425
"@types/istanbul-reports": "^3.0.0",
2526
"@types/node": "*",

packages/jest-types/src/Config.ts

+4-6
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
import type {ForegroundColor} from 'chalk';
99
import type {ReportOptions} from 'istanbul-reports';
1010
import type {Arguments} from 'yargs';
11+
import type {SnapshotFormat} from '@jest/schemas';
1112

1213
type CoverageProvider = 'babel' | 'v8';
1314

@@ -60,9 +61,6 @@ export interface ConfigGlobals {
6061
[K: string]: unknown;
6162
}
6263

63-
// This interface gets filled out when pretty-format is included
64-
export interface PrettyFormatOptions {}
65-
6664
export type DefaultOptions = {
6765
automock: boolean;
6866
bail: number;
@@ -228,7 +226,7 @@ export type InitialOptions = Partial<{
228226
slowTestThreshold: number;
229227
snapshotResolver: Path;
230228
snapshotSerializers: Array<Path>;
231-
snapshotFormat: PrettyFormatOptions;
229+
snapshotFormat: SnapshotFormat;
232230
errorOnDeprecated: boolean;
233231
testEnvironment: string;
234232
testEnvironmentOptions: Record<string, unknown>;
@@ -330,7 +328,7 @@ export type GlobalConfig = {
330328
rootDir: Path;
331329
silent?: boolean;
332330
skipFilter: boolean;
333-
snapshotFormat: PrettyFormatOptions;
331+
snapshotFormat: SnapshotFormat;
334332
errorOnDeprecated: boolean;
335333
testFailureExitCode: number;
336334
testNamePattern?: string;
@@ -393,7 +391,7 @@ export type ProjectConfig = {
393391
slowTestThreshold: number;
394392
snapshotResolver?: Path;
395393
snapshotSerializers: Array<Path>;
396-
snapshotFormat: PrettyFormatOptions;
394+
snapshotFormat: SnapshotFormat;
397395
testEnvironment: string;
398396
testEnvironmentOptions: Record<string, unknown>;
399397
testMatch: Array<Glob>;

packages/jest-types/tsconfig.json

+2-1
Original file line numberDiff line numberDiff line change
@@ -4,5 +4,6 @@
44
"rootDir": "src",
55
"outDir": "build"
66
},
7-
"include": ["./src/**/*"]
7+
"include": ["./src/**/*"],
8+
"references": [{"path": "../jest-schemas"}]
89
}

packages/pretty-format/package.json

+1
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020
},
2121
"author": "James Kyle <[email protected]>",
2222
"dependencies": {
23+
"@jest/schemas": "28.0.0-alpha.0",
2324
"ansi-regex": "^5.0.1",
2425
"ansi-styles": "^5.0.0",
2526
"react-is": "^17.0.1"

packages/pretty-format/src/types.ts

+10-39
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,8 @@
55
* LICENSE file in the root directory of this source tree.
66
*/
77

8+
import type {SnapshotFormat} from '@jest/schemas';
9+
810
export type Colors = {
911
comment: {close: string; open: string};
1012
content: {close: string; open: string};
@@ -16,52 +18,21 @@ type Indent = (arg0: string) => string;
1618
export type Refs = Array<unknown>;
1719
type Print = (arg0: unknown) => string;
1820

19-
export type Theme = {
20-
comment: string;
21-
content: string;
22-
prop: string;
23-
tag: string;
24-
value: string;
25-
};
26-
27-
type ThemeReceived = {
28-
comment?: string;
29-
content?: string;
30-
prop?: string;
31-
tag?: string;
32-
value?: string;
33-
};
21+
export type Theme = Options['theme'];
3422

3523
export type CompareKeys = ((a: string, b: string) => number) | undefined;
3624

37-
export type Options = {
38-
callToJSON: boolean;
25+
type RequiredOptions = Required<PrettyFormatOptions>;
26+
27+
export interface Options
28+
extends Omit<RequiredOptions, 'compareKeys' | 'theme'> {
3929
compareKeys: CompareKeys;
40-
escapeRegex: boolean;
41-
escapeString: boolean;
42-
highlight: boolean;
43-
indent: number;
44-
maxDepth: number;
45-
min: boolean;
46-
plugins: Plugins;
47-
printBasicPrototype: boolean;
48-
printFunctionName: boolean;
49-
theme: Theme;
50-
};
30+
theme: Required<RequiredOptions['theme']>;
31+
}
5132

52-
export interface PrettyFormatOptions {
53-
callToJSON?: boolean;
33+
export interface PrettyFormatOptions extends SnapshotFormat {
5434
compareKeys?: CompareKeys;
55-
escapeRegex?: boolean;
56-
escapeString?: boolean;
57-
highlight?: boolean;
58-
indent?: number;
59-
maxDepth?: number;
60-
min?: boolean;
6135
plugins?: Plugins;
62-
printBasicPrototype?: boolean;
63-
printFunctionName?: boolean;
64-
theme?: ThemeReceived;
6536
}
6637

6738
export type OptionsReceived = PrettyFormatOptions;

packages/pretty-format/tsconfig.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -6,5 +6,5 @@
66
},
77
"include": ["./src/**/*"],
88
"exclude": ["./**/__tests__/**/*"],
9-
"references": [{"path": "../jest-util"}]
9+
"references": [{"path": "../jest-schemas"}, {"path": "../jest-util"}]
1010
}

yarn.lock

+17
Original file line numberDiff line numberDiff line change
@@ -2753,6 +2753,14 @@ __metadata:
27532753
languageName: unknown
27542754
linkType: soft
27552755

2756+
"@jest/[email protected], @jest/schemas@workspace:packages/jest-schemas":
2757+
version: 0.0.0-use.local
2758+
resolution: "@jest/schemas@workspace:packages/jest-schemas"
2759+
dependencies:
2760+
"@sinclair/typebox": ^0.23.3
2761+
languageName: unknown
2762+
linkType: soft
2763+
27562764
"@jest/source-map@^28.0.0-alpha.0, @jest/source-map@workspace:packages/jest-source-map":
27572765
version: 0.0.0-use.local
27582766
resolution: "@jest/source-map@workspace:packages/jest-source-map"
@@ -2847,6 +2855,7 @@ __metadata:
28472855
version: 0.0.0-use.local
28482856
resolution: "@jest/types@workspace:packages/jest-types"
28492857
dependencies:
2858+
"@jest/schemas": 28.0.0-alpha.0
28502859
"@tsd/typescript": ~4.5.5
28512860
"@types/istanbul-lib-coverage": ^2.0.0
28522861
"@types/istanbul-reports": ^3.0.0
@@ -4359,6 +4368,13 @@ __metadata:
43594368
languageName: node
43604369
linkType: hard
43614370

4371+
"@sinclair/typebox@npm:^0.23.3":
4372+
version: 0.23.3
4373+
resolution: "@sinclair/typebox@npm:0.23.3"
4374+
checksum: c8d961c8af1b701e67641770376010634730076f0412dda34b01f1d6f54d98916414335b51929285ade43ab85bb14a372bbc287575ce4b1e0179d8af808ec4d7
4375+
languageName: node
4376+
linkType: hard
4377+
43624378
"@sindresorhus/is@npm:^0.14.0":
43634379
version: 0.14.0
43644380
resolution: "@sindresorhus/is@npm:0.14.0"
@@ -17802,6 +17818,7 @@ __metadata:
1780217818
version: 0.0.0-use.local
1780317819
resolution: "pretty-format@workspace:packages/pretty-format"
1780417820
dependencies:
17821+
"@jest/schemas": 28.0.0-alpha.0
1780517822
"@types/react": "*"
1780617823
"@types/react-is": ^17.0.0
1780717824
"@types/react-test-renderer": "*"

0 commit comments

Comments
 (0)