Skip to content

Commit

Permalink
chore: migrate few more type tests to TSTyche (jestjs#14786)
Browse files Browse the repository at this point in the history
  • Loading branch information
mrazauskas authored Dec 27, 2023
1 parent 6ed0ebe commit 1d30b3e
Show file tree
Hide file tree
Showing 10 changed files with 44 additions and 48 deletions.
2 changes: 1 addition & 1 deletion .eslintrc.cjs
Original file line number Diff line number Diff line change
Expand Up @@ -365,7 +365,7 @@ module.exports = {
'website/**',
'**/__benchmarks__/**',
'**/__tests__/**',
'packages/jest-types/**/*',
'**/__typetests__/**',
'.eslintplugin/**',
],
rules: {
Expand Down
3 changes: 3 additions & 0 deletions jest.config.ts.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,9 @@ export default {
runner: 'jest-runner-tsd',
testMatch: [
'**/__typetests__/**/*.test.ts',
'!**/packages/expect-utils/__typetests__/*.test.ts',
'!**/packages/jest/__typetests__/*.test.ts',
'!**/packages/jest-cli/__typetests__/*.test.ts',
'!**/packages/jest-types/__typetests__/config.test.ts',
],
},
Expand Down
44 changes: 21 additions & 23 deletions packages/expect-utils/__typetests__/utils.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,34 +5,32 @@
* LICENSE file in the root directory of this source tree.
*/

import {expectType} from 'tsd-lite';
import {expect, test} from 'tstyche';
import {isA} from '@jest/expect-utils';

// isA
test('isA', () => {
expect(isA('String', 'default')).type.toBeBoolean();
expect(isA<number>('Number', 123)).type.toBeBoolean();

expectType<boolean>(isA('String', 'default'));
expectType<boolean>(isA<number>('Number', 123));
const sample = {} as unknown;

const sample = {} as unknown;
if (isA('String', sample)) {
expect(sample).type.toBeUnknown();
}

expectType<unknown>(sample);
if (isA<string>('String', sample)) {
expect(sample).type.toBeString();
}

if (isA('String', sample)) {
expectType<unknown>(sample);
}
if (isA<number>('Number', sample)) {
expect(sample).type.toBeNumber();
}

if (isA<string>('String', sample)) {
expectType<string>(sample);
}
if (isA<Map<unknown, unknown>>('Map', sample)) {
expect(sample).type.toEqual<Map<unknown, unknown>>();
}

if (isA<number>('Number', sample)) {
expectType<number>(sample);
}

if (isA<Map<unknown, unknown>>('Map', sample)) {
expectType<Map<unknown, unknown>>(sample);
}

if (isA<Set<unknown>>('Set', sample)) {
expectType<Set<unknown>>(sample);
}
if (isA<Set<unknown>>('Set', sample)) {
expect(sample).type.toEqual<Set<unknown>>();
}
});
4 changes: 1 addition & 3 deletions packages/expect-utils/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -22,10 +22,8 @@
"jest-get-type": "workspace:*"
},
"devDependencies": {
"@tsd/typescript": "^5.0.4",
"immutable": "^4.0.0",
"jest-matcher-utils": "workspace:*",
"tsd-lite": "^0.8.0"
"jest-matcher-utils": "workspace:*"
},
"engines": {
"node": "^16.10.0 || ^18.12.0 || >=20.0.0"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,12 @@
*
* This source code is licensed under the MIT license found in the
* LICENSE file in the root directory of this source tree.
*
*/

import {expectType} from 'tsd-lite';
import {expect, test} from 'tstyche';
import type {Options} from 'yargs';
import {yargsOptions} from 'jest-cli';

expectType<{[key: string]: Options}>(yargsOptions);
test('yargsOptions', () => {
expect(yargsOptions).type.toEqual<{[key: string]: Options}>();
});
4 changes: 1 addition & 3 deletions packages/jest-cli/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -27,10 +27,8 @@
"yargs": "^17.3.1"
},
"devDependencies": {
"@tsd/typescript": "^5.0.4",
"@types/exit": "^0.1.30",
"@types/yargs": "^17.0.8",
"tsd-lite": "^0.8.0"
"@types/yargs": "^17.0.8"
},
"peerDependencies": {
"node-notifier": "^8.0.1 || ^9.0.0 || ^10.0.0"
Expand Down
11 changes: 7 additions & 4 deletions packages/jest/__typetests__/jest.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,13 @@
* LICENSE file in the root directory of this source tree.
*/

import {expectType} from 'tsd-lite';
import type {Config as ConfigTypes} from '@jest/types';
import {describe, expect, test} from 'tstyche';
import type {Config} from 'jest';

declare const config: Config;
describe('Config', () => {
test('is a reexport of the `InitialOptions`', () => {
type InitialOptions = import('@jest/types').Config.InitialOptions;

expectType<ConfigTypes.InitialOptions>(config);
expect<Config>().type.toEqual<InitialOptions>();
});
});
4 changes: 0 additions & 4 deletions packages/jest/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -20,10 +20,6 @@
"import-local": "^3.0.2",
"jest-cli": "workspace:*"
},
"devDependencies": {
"@tsd/typescript": "^5.0.4",
"tsd-lite": "^0.8.0"
},
"peerDependencies": {
"node-notifier": "^8.0.1 || ^9.0.0 || ^10.0.0"
},
Expand Down
7 changes: 6 additions & 1 deletion tstyche.config.json
Original file line number Diff line number Diff line change
@@ -1,3 +1,8 @@
{
"testFileMatch": ["**/packages/jest-types/__typetests__/config.test.ts"]
"testFileMatch": [
"**/packages/expect-utils/__typetests__/*.test.ts",
"**/packages/jest/__typetests__/*.test.ts",
"**/packages/jest-cli/__typetests__/*.test.ts",
"**/packages/jest-types/__typetests__/config.test.ts"
]
}
6 changes: 0 additions & 6 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -2955,11 +2955,9 @@ __metadata:
version: 0.0.0-use.local
resolution: "@jest/expect-utils@workspace:packages/expect-utils"
dependencies:
"@tsd/typescript": ^5.0.4
immutable: ^4.0.0
jest-get-type: "workspace:*"
jest-matcher-utils: "workspace:*"
tsd-lite: ^0.8.0
languageName: unknown
linkType: soft

Expand Down Expand Up @@ -12869,7 +12867,6 @@ __metadata:
"@jest/core": "workspace:*"
"@jest/test-result": "workspace:*"
"@jest/types": "workspace:*"
"@tsd/typescript": ^5.0.4
"@types/exit": ^0.1.30
"@types/yargs": ^17.0.8
chalk: ^4.0.0
Expand All @@ -12878,7 +12875,6 @@ __metadata:
jest-config: "workspace:*"
jest-util: "workspace:*"
jest-validate: "workspace:*"
tsd-lite: ^0.8.0
yargs: ^17.3.1
peerDependencies:
node-notifier: ^8.0.1 || ^9.0.0 || ^10.0.0
Expand Down Expand Up @@ -13595,10 +13591,8 @@ __metadata:
dependencies:
"@jest/core": "workspace:*"
"@jest/types": "workspace:*"
"@tsd/typescript": ^5.0.4
import-local: ^3.0.2
jest-cli: "workspace:*"
tsd-lite: ^0.8.0
peerDependencies:
node-notifier: ^8.0.1 || ^9.0.0 || ^10.0.0
peerDependenciesMeta:
Expand Down

0 comments on commit 1d30b3e

Please sign in to comment.