Skip to content

Commit b359ff9

Browse files
authored
chore: migrate type tests of @jest/reporters to TSTyche (#14982)
1 parent 71f0ba4 commit b359ff9

File tree

3 files changed

+66
-52
lines changed

3 files changed

+66
-52
lines changed

jest.config.ts.mjs

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -27,10 +27,7 @@ export default {
2727
modulePathIgnorePatterns: baseConfig.modulePathIgnorePatterns,
2828
roots: ['<rootDir>/packages'],
2929
runner: 'jest-runner-tsd',
30-
testMatch: [
31-
'**/packages/jest-reporters/__typetests__/jest-reporters.test.ts',
32-
'**/packages/jest-types/__typetests__/each.test.ts',
33-
],
30+
testMatch: ['**/packages/jest-types/__typetests__/each.test.ts'],
3431
},
3532
],
3633
reporters: ['default', 'github-actions'],

packages/jest-reporters/__typetests__/jest-reporters.test.ts

Lines changed: 64 additions & 48 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
* LICENSE file in the root directory of this source tree.
66
*/
77

8-
import {expectError, expectType} from 'tsd-lite';
8+
import {expect} from 'tstyche';
99
import {
1010
type AggregatedResult,
1111
type Config,
@@ -25,73 +25,89 @@ declare const testResult: TestResult;
2525

2626
// utils.formatTestPath()
2727

28-
expectType<string>(utils.formatTestPath(globalConfig, 'some/path'));
29-
expectType<string>(utils.formatTestPath(projectConfig, 'some/path'));
30-
expectError(utils.formatTestPath());
31-
expectError(utils.formatTestPath({}, 'some/path'));
32-
expectError(utils.formatTestPath(globalConfig, 123));
33-
expectError(utils.formatTestPath(projectConfig, 123));
28+
expect(utils.formatTestPath(globalConfig, 'some/path')).type.toBeString();
29+
expect(utils.formatTestPath(projectConfig, 'some/path')).type.toBeString();
30+
expect(utils.formatTestPath()).type.toRaiseError();
31+
expect(utils.formatTestPath({}, 'some/path')).type.toRaiseError();
32+
expect(utils.formatTestPath(globalConfig, 123)).type.toRaiseError();
33+
expect(utils.formatTestPath(projectConfig, 123)).type.toRaiseError();
3434

3535
// utils.getResultHeader()
3636

37-
expectType<string>(
37+
expect(
3838
utils.getResultHeader(testResult, globalConfig, projectConfig),
39-
);
40-
expectType<string>(utils.getResultHeader(testResult, globalConfig));
41-
expectError(utils.getResultHeader());
42-
expectError(utils.getResultHeader({}, globalConfig));
43-
expectError(utils.getResultHeader({}, globalConfig, projectConfig));
44-
expectError(utils.getResultHeader(testResult, {}));
45-
expectError(utils.getResultHeader(testResult, globalConfig, {}));
39+
).type.toBeString();
40+
expect(utils.getResultHeader(testResult, globalConfig)).type.toBeString();
41+
expect(utils.getResultHeader()).type.toRaiseError();
42+
expect(utils.getResultHeader({}, globalConfig)).type.toRaiseError();
43+
expect(
44+
utils.getResultHeader({}, globalConfig, projectConfig),
45+
).type.toRaiseError();
46+
expect(utils.getResultHeader(testResult, {})).type.toRaiseError();
47+
expect(utils.getResultHeader(testResult, globalConfig, {})).type.toRaiseError();
4648

4749
// utils.getSnapshotStatus()
4850

49-
expectType<Array<string>>(utils.getSnapshotStatus(snapshot, true));
50-
expectError(utils.getSnapshotStatus());
51-
expectError(utils.getSnapshotStatus({}, true));
52-
expectError(utils.getSnapshotStatus(snapshot, 123));
51+
expect(utils.getSnapshotStatus(snapshot, true)).type.toEqual<Array<string>>();
52+
expect(utils.getSnapshotStatus()).type.toRaiseError();
53+
expect(utils.getSnapshotStatus({}, true)).type.toRaiseError();
54+
expect(utils.getSnapshotStatus(snapshot, 123)).type.toRaiseError();
5355

5456
// utils.getSnapshotSummary()
5557

56-
expectType<Array<string>>(
58+
expect(
5759
utils.getSnapshotSummary(snapshotSummary, globalConfig, 'press `u`'),
58-
);
59-
expectError(utils.getSnapshotSummary());
60-
expectError(utils.getSnapshotSummary({}, globalConfig, 'press `u`'));
61-
expectError(utils.getSnapshotSummary(snapshotSummary, {}, 'press `u`'));
62-
expectError(utils.getSnapshotSummary(snapshotSummary, globalConfig, true));
60+
).type.toEqual<Array<string>>();
61+
expect(utils.getSnapshotSummary()).type.toRaiseError();
62+
expect(
63+
utils.getSnapshotSummary({}, globalConfig, 'press `u`'),
64+
).type.toRaiseError();
65+
expect(
66+
utils.getSnapshotSummary(snapshotSummary, {}, 'press `u`'),
67+
).type.toRaiseError();
68+
expect(
69+
utils.getSnapshotSummary(snapshotSummary, globalConfig, true),
70+
).type.toRaiseError();
6371

6472
// utils.getSummary()
6573

66-
expectType<string>(utils.getSummary(aggregatedResults, summaryOptions));
67-
expectType<string>(utils.getSummary(aggregatedResults));
68-
expectError(utils.getSummary());
69-
expectError(utils.getSummary({}));
70-
expectError(utils.getSummary(aggregatedResults, true));
74+
expect(utils.getSummary(aggregatedResults, summaryOptions)).type.toBeString();
75+
expect(utils.getSummary(aggregatedResults)).type.toBeString();
76+
expect(utils.getSummary()).type.toRaiseError();
77+
expect(utils.getSummary({})).type.toRaiseError();
78+
expect(utils.getSummary(aggregatedResults, true)).type.toRaiseError();
7179

7280
// utils.printDisplayName()
7381

74-
expectType<string>(utils.printDisplayName(projectConfig));
75-
expectError(utils.printDisplayName());
76-
expectError(utils.printDisplayName({}));
82+
expect(utils.printDisplayName(projectConfig)).type.toBeString();
83+
expect(utils.printDisplayName()).type.toRaiseError();
84+
expect(utils.printDisplayName({})).type.toRaiseError();
7785

7886
// utils.relativePath()
7987

80-
expectType<{basename: string; dirname: string}>(
81-
utils.relativePath(globalConfig, 'some/path'),
82-
);
83-
expectType<{basename: string; dirname: string}>(
84-
utils.relativePath(projectConfig, 'some/path'),
85-
);
86-
expectError(utils.relativePath());
87-
expectError(utils.relativePath({}, 'some/path'));
88-
expectError(utils.relativePath(projectConfig, true));
88+
expect(utils.relativePath(globalConfig, 'some/path')).type.toEqual<{
89+
basename: string;
90+
dirname: string;
91+
}>();
92+
expect(utils.relativePath(projectConfig, 'some/path')).type.toEqual<{
93+
basename: string;
94+
dirname: string;
95+
}>();
96+
expect(utils.relativePath()).type.toRaiseError();
97+
expect(utils.relativePath({}, 'some/path')).type.toRaiseError();
98+
expect(utils.relativePath(projectConfig, true)).type.toRaiseError();
8999

90100
// utils.trimAndFormatPath()
91101

92-
expectType<string>(utils.trimAndFormatPath(2, globalConfig, 'some/path', 4));
93-
expectError(utils.trimAndFormatPath());
94-
expectError(utils.trimAndFormatPath(true, globalConfig, 'some/path', 4));
95-
expectError(utils.trimAndFormatPath(2, {}, 'some/path', 4));
96-
expectError(utils.trimAndFormatPath(2, globalConfig, true, 4));
97-
expectError(utils.trimAndFormatPath(2, globalConfig, 'some/path', '4'));
102+
expect(
103+
utils.trimAndFormatPath(2, globalConfig, 'some/path', 4),
104+
).type.toBeString();
105+
expect(utils.trimAndFormatPath()).type.toRaiseError();
106+
expect(
107+
utils.trimAndFormatPath(true, globalConfig, 'some/path', 4),
108+
).type.toRaiseError();
109+
expect(utils.trimAndFormatPath(2, {}, 'some/path', 4)).type.toRaiseError();
110+
expect(utils.trimAndFormatPath(2, globalConfig, true, 4)).type.toRaiseError();
111+
expect(
112+
utils.trimAndFormatPath(2, globalConfig, 'some/path', '4'),
113+
).type.toRaiseError();

tstyche.config.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
"packages/jest-cli/__typetests__/*.test.ts",
77
"packages/jest-expect/__typetests__/*.test.ts",
88
"packages/jest-mock/__typetests__/*.test.ts",
9+
"packages/jest-reporters/__typetests__/*.test.ts",
910
"packages/jest-resolve/__typetests__/*.test.ts",
1011
"packages/jest-runner/__typetests__/*.test.ts",
1112
"packages/jest-snapshot/__typetests__/*.test.ts",

0 commit comments

Comments
 (0)