chore: migrate the `Config` type test to TSTyche (#14687)

This commit is contained in:
Tom Mrazauskas 2023-12-25 18:55:37 +02:00 committed by GitHub
parent 341f529deb
commit 35f45f32c8
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
6 changed files with 145 additions and 112 deletions

View File

@ -48,7 +48,7 @@ jobs:
- name: ts integration - name: ts integration
run: yarn test-ts --selectProjects ts-integration run: yarn test-ts --selectProjects ts-integration
- name: type tests - name: type tests
run: yarn test-ts --selectProjects type-tests run: yarn tstyche --target 5.0,latest && yarn test-ts --selectProjects type-tests
- name: verify TypeScript@5.0 compatibility - name: verify TypeScript@5.0 compatibility
run: yarn verify-old-ts run: yarn verify-old-ts
- name: run ESLint with type info - name: run ESLint with type info

View File

@ -27,7 +27,10 @@ export default {
modulePathIgnorePatterns: baseConfig.modulePathIgnorePatterns, modulePathIgnorePatterns: baseConfig.modulePathIgnorePatterns,
roots: ['<rootDir>/packages'], roots: ['<rootDir>/packages'],
runner: 'jest-runner-tsd', runner: 'jest-runner-tsd',
testMatch: ['**/__typetests__/**/*.test.ts'], testMatch: [
'**/__typetests__/**/*.test.ts',
'!**/packages/jest-types/__typetests__/config.test.ts',
],
}, },
], ],
reporters: ['default', 'github-actions'], reporters: ['default', 'github-actions'],

View File

@ -79,6 +79,7 @@
"strip-json-comments": "^3.1.1", "strip-json-comments": "^3.1.1",
"tempy": "^1.0.0", "tempy": "^1.0.0",
"ts-node": "^10.5.0", "ts-node": "^10.5.0",
"tstyche": "^1.0.0-beta.6",
"typescript": "^5.0.4", "typescript": "^5.0.4",
"webpack": "^5.68.0", "webpack": "^5.68.0",
"webpack-node-externals": "^3.0.0", "webpack-node-externals": "^3.0.0",
@ -110,7 +111,7 @@
"test-ci-partial:parallel": "yarn jest --color --config jest.config.ci.mjs", "test-ci-partial:parallel": "yarn jest --color --config jest.config.ci.mjs",
"test-leak": "yarn jest -i --detectLeaks --color jest-mock jest-diff jest-repl pretty-format", "test-leak": "yarn jest -i --detectLeaks --color jest-mock jest-diff jest-repl pretty-format",
"test-ts": "yarn jest --config jest.config.ts.mjs", "test-ts": "yarn jest --config jest.config.ts.mjs",
"test-types": "yarn test-ts --selectProjects type-tests", "test-types": "yarn tstyche && yarn test-ts --selectProjects type-tests",
"test": "yarn lint && yarn jest", "test": "yarn lint && yarn jest",
"typecheck": "yarn typecheck:examples && yarn typecheck:tests", "typecheck": "yarn typecheck:examples && yarn typecheck:tests",
"typecheck:examples": "tsc -p examples/angular --noEmit && tsc -p examples/expect-extend --noEmit && tsc -p examples/typescript --noEmit", "typecheck:examples": "tsc -p examples/angular --noEmit && tsc -p examples/expect-extend --noEmit && tsc -p examples/typescript --noEmit",

View File

@ -5,115 +5,126 @@
* LICENSE file in the root directory of this source tree. * LICENSE file in the root directory of this source tree.
*/ */
import {expectAssignable, expectNotAssignable} from 'tsd-lite'; import {describe, expect, test} from 'tstyche';
import type {Config} from '@jest/types'; import type {Config} from 'jest';
expectAssignable<Config.InitialOptions>({}); const config: Config = {};
expectAssignable<Config.InitialOptions>({ describe('Config', () => {
coverageThreshold: { test('coverageThreshold', () => {
'./src/api/very-important-module.js': { expect(config).type.toBeAssignable({
branches: 100, coverageThreshold: {
functions: 100, './src/api/very-important-module.js': {
lines: 100, branches: 100,
statements: 100, functions: 100,
}, lines: 100,
'./src/components/': { statements: 100,
branches: 40, },
statements: 40, './src/components/': {
}, branches: 40,
'./src/reducers/**/*.js': { statements: 40,
statements: 90, },
}, './src/reducers/**/*.js': {
global: { statements: 90,
branches: 50, },
functions: 50, global: {
lines: 50, branches: 50,
statements: 50, functions: 50,
}, lines: 50,
}, statements: 50,
projects: [ },
// projects can be globs or objects },
'./src/**', });
{ });
displayName: 'A Project',
rootDir: './src/components', test('fakeTimers', () => {
}, const doNotFake = [
], 'Date' as const,
}); 'hrtime' as const,
'nextTick' as const,
const doNotFake: Array<Config.FakeableAPI> = [ 'performance' as const,
'Date', 'queueMicrotask' as const,
'hrtime', 'requestAnimationFrame' as const,
'nextTick', 'cancelAnimationFrame' as const,
'performance', 'requestIdleCallback' as const,
'queueMicrotask', 'cancelIdleCallback' as const,
'requestAnimationFrame', 'setImmediate' as const,
'cancelAnimationFrame', 'clearImmediate' as const,
'requestIdleCallback', 'setInterval' as const,
'cancelIdleCallback', 'clearInterval' as const,
'setImmediate', 'setTimeout' as const,
'clearImmediate', 'clearTimeout' as const,
'setInterval', ];
'clearInterval',
'setTimeout', expect(config).type.toBeAssignable({
'clearTimeout', fakeTimers: {
]; advanceTimers: true,
doNotFake,
expectAssignable<Config.InitialOptions>({ enableGlobally: true,
fakeTimers: { now: 1_483_228_800_000,
advanceTimers: true, timerLimit: 1000,
doNotFake, },
enableGlobally: true, });
now: 1_483_228_800_000,
timerLimit: 1000, expect(config).type.toBeAssignable({
}, fakeTimers: {
}); advanceTimers: 40,
now: Date.now(),
expectAssignable<Config.InitialOptions>({ },
fakeTimers: { });
advanceTimers: 40,
now: Date.now(), expect(config).type.not.toBeAssignable({
}, fakeTimers: {
}); now: new Date(),
},
expectNotAssignable<Config.InitialOptions>({ });
fakeTimers: {
now: new Date(), expect(config).type.toBeAssignable({
}, fakeTimers: {
}); enableGlobally: true,
legacyFakeTimers: true as const,
expectAssignable<Config.InitialOptions>({ },
fakeTimers: { });
enableGlobally: true,
legacyFakeTimers: true as const, expect(config).type.not.toBeAssignable({
}, fakeTimers: {
}); advanceTimers: true,
legacyFakeTimers: true as const,
expectNotAssignable<Config.InitialOptions>({ },
fakeTimers: { });
advanceTimers: true,
legacyFakeTimers: true as const, expect(config).type.not.toBeAssignable({
}, fakeTimers: {
}); doNotFake,
legacyFakeTimers: true as const,
expectNotAssignable<Config.InitialOptions>({ },
fakeTimers: { });
doNotFake,
legacyFakeTimers: true as const, expect(config).type.not.toBeAssignable({
}, fakeTimers: {
}); legacyFakeTimers: true as const,
now: 1_483_228_800_000,
expectNotAssignable<Config.InitialOptions>({ },
fakeTimers: { });
legacyFakeTimers: true as const,
now: 1_483_228_800_000, expect(config).type.not.toBeAssignable({
}, fakeTimers: {
}); legacyFakeTimers: true as const,
timerLimit: 1000,
expectNotAssignable<Config.InitialOptions>({ },
fakeTimers: { });
legacyFakeTimers: true as const, });
timerLimit: 1000,
}, test('projects', () => {
expect(config).type.toBeAssignable({
projects: [
// projects can be globs or objects
'./src/**',
{
displayName: 'A Project',
rootDir: './src/components',
},
],
});
});
}); });

3
tstyche.config.json Normal file
View File

@ -0,0 +1,3 @@
{
"testFileMatch": ["**/packages/jest-types/__typetests__/config.test.ts"]
}

View File

@ -3067,6 +3067,7 @@ __metadata:
strip-json-comments: ^3.1.1 strip-json-comments: ^3.1.1
tempy: ^1.0.0 tempy: ^1.0.0
ts-node: ^10.5.0 ts-node: ^10.5.0
tstyche: ^1.0.0-beta.6
typescript: ^5.0.4 typescript: ^5.0.4
webpack: ^5.68.0 webpack: ^5.68.0
webpack-node-externals: ^3.0.0 webpack-node-externals: ^3.0.0
@ -21161,6 +21162,20 @@ __metadata:
languageName: node languageName: node
linkType: hard linkType: hard
"tstyche@npm:^1.0.0-beta.6":
version: 1.0.0-beta.6
resolution: "tstyche@npm:1.0.0-beta.6"
peerDependencies:
typescript: 4.x || 5.x
peerDependenciesMeta:
typescript:
optional: true
bin:
tstyche: ./build/bin.js
checksum: 197ef69d05b8a82f5d0d4a618ed36102d906badb537712d4399387f2ed822b076d37d8a4c2b8e2d13582fb733d0737794b6789a4635bde23bd41f520ddb8c337
languageName: node
linkType: hard
"tsutils@npm:^3.21.0": "tsutils@npm:^3.21.0":
version: 3.21.0 version: 3.21.0
resolution: "tsutils@npm:3.21.0" resolution: "tsutils@npm:3.21.0"