diff --git a/jest.config.ts.mjs b/jest.config.ts.mjs index f34a4a79c1ef..354a840e525c 100644 --- a/jest.config.ts.mjs +++ b/jest.config.ts.mjs @@ -37,6 +37,7 @@ export default { '!**/packages/jest-mock/__typetests__/*.test.ts', '!**/packages/jest-snapshot/__typetests__/*.test.ts', '!**/packages/jest-types/__typetests__/config.test.ts', + '!**/packages/jest-worker/__typetests__/*.test.ts', ], }, ], diff --git a/packages/jest-worker/__typetests__/jest-worker.test.ts b/packages/jest-worker/__typetests__/jest-worker.test.ts index 594810db0eb9..684ce362fb4a 100644 --- a/packages/jest-worker/__typetests__/jest-worker.test.ts +++ b/packages/jest-worker/__typetests__/jest-worker.test.ts @@ -5,7 +5,7 @@ * LICENSE file in the root directory of this source tree. */ -import {expectError, expectNotAssignable, expectType} from 'tsd-lite'; +import {expect, test} from 'tstyche'; import type {JestWorkerFarm} from 'jest-worker'; import type * as testWorker from './testWorker'; @@ -13,88 +13,90 @@ type TestWorker = { runTest: (a: string, b: number) => void; doSomething: () => void; isResult: boolean; - end: () => void; // reserved keys should be excluded from returned type + + // the reserved keys should not be included in the resulting type + end: () => void; getStderr: () => string; getStdout: () => string; setup: () => void; teardown: () => void; }; -// unknown JestWorkerFarm - declare const unknownWorkerFarm: JestWorkerFarm>; -expectError(unknownWorkerFarm.runTest()); -expectError(unknownWorkerFarm.runTestAsync()); - -expectError(unknownWorkerFarm.getResult()); -expectError(unknownWorkerFarm.isResult); +test('unknown JestWorkerFarm', () => { + expect(unknownWorkerFarm).type.not.toHaveProperty('runTest'); + expect(unknownWorkerFarm).type.not.toHaveProperty('runTestAsync'); -expectError(unknownWorkerFarm.setup()); -expectError(unknownWorkerFarm.teardown()); + expect(unknownWorkerFarm).type.not.toHaveProperty('getResult'); + expect(unknownWorkerFarm).type.not.toHaveProperty('isResult'); -expectType>(unknownWorkerFarm.end()); -expectType(unknownWorkerFarm.getStderr()); -expectType(unknownWorkerFarm.getStdout()); + expect(unknownWorkerFarm).type.not.toHaveProperty('setup'); + expect(unknownWorkerFarm).type.not.toHaveProperty('teardown'); -// detected JestWorkerFarm + expect(unknownWorkerFarm.start()).type.toEqual>(); + expect(unknownWorkerFarm.end()).type.toEqual< + Promise<{forceExited: boolean}> + >(); -declare const detectedWorkerFarm: JestWorkerFarm; + expect(unknownWorkerFarm.getStderr()).type.toEqual(); + expect(unknownWorkerFarm.getStdout()).type.toEqual(); +}); -expectType>(detectedWorkerFarm.runTest('abc', true)); -expectType>(detectedWorkerFarm.runTestAsync(123, 456)); +declare const inferredWorkerFarm: JestWorkerFarm; -expectType>(detectedWorkerFarm.doSomething()); -expectType>(detectedWorkerFarm.doSomething()); -expectType>(detectedWorkerFarm.doSomethingAsync()); -expectType>(detectedWorkerFarm.doSomethingAsync()); +test('inferred JestWorkerFarm', () => { + expect(inferredWorkerFarm.runTest('abc', true)).type.toEqual>(); + expect(inferredWorkerFarm.runTestAsync(123, 456)).type.toEqual< + Promise + >(); -expectError(detectedWorkerFarm.runTest()); -expectError(detectedWorkerFarm.runTest('abc')); -expectError(detectedWorkerFarm.runTestAsync()); -expectError(detectedWorkerFarm.runTestAsync(123)); -expectError(detectedWorkerFarm.doSomething(123)); -expectError(detectedWorkerFarm.doSomethingAsync('abc')); + expect(inferredWorkerFarm.doSomething()).type.toEqual>(); + expect(inferredWorkerFarm.doSomething()).type.toEqual>(); + expect(inferredWorkerFarm.doSomethingAsync()).type.toEqual>(); + expect(inferredWorkerFarm.doSomethingAsync()).type.toEqual>(); -expectError(detectedWorkerFarm.getResult()); -expectError(detectedWorkerFarm.isResult); + expect(inferredWorkerFarm.runTest()).type.toRaiseError(); + expect(inferredWorkerFarm.runTest('abc')).type.toRaiseError(); + expect(inferredWorkerFarm.runTestAsync()).type.toRaiseError(); + expect(inferredWorkerFarm.runTestAsync(123)).type.toRaiseError(); + expect(inferredWorkerFarm.doSomething(123)).type.toRaiseError(); + expect(inferredWorkerFarm.doSomethingAsync('abc')).type.toRaiseError(); -expectError(detectedWorkerFarm.setup()); -expectError(detectedWorkerFarm.teardown()); + expect(inferredWorkerFarm).type.not.toHaveProperty('getResult'); + expect(inferredWorkerFarm).type.not.toHaveProperty('isResult'); -expectNotAssignable>(detectedWorkerFarm.end()); -expectType>(detectedWorkerFarm.end()); + expect(inferredWorkerFarm).type.not.toHaveProperty('setup'); + expect(inferredWorkerFarm).type.not.toHaveProperty('teardown'); -expectNotAssignable>(detectedWorkerFarm.getStderr()); -expectType(detectedWorkerFarm.getStderr()); + expect(inferredWorkerFarm.start()).type.toEqual>(); + expect(inferredWorkerFarm.end()).type.toEqual< + Promise<{forceExited: boolean}> + >(); -expectNotAssignable>(detectedWorkerFarm.getStdout()); -expectType(detectedWorkerFarm.getStdout()); - -// typed JestWorkerFarm + expect(inferredWorkerFarm.getStderr()).type.toEqual(); + expect(inferredWorkerFarm.getStdout()).type.toEqual(); +}); declare const typedWorkerFarm: JestWorkerFarm; -expectType>(typedWorkerFarm.runTest('abc', 123)); -expectType>(typedWorkerFarm.doSomething()); - -expectError(typedWorkerFarm.runTest()); -expectError(typedWorkerFarm.runTest('abc')); -expectError(typedWorkerFarm.doSomething('abc')); - -expectError(typedWorkerFarm.isResult); -expectError(typedWorkerFarm.runTestAsync()); +test('typed JestWorkerFarm', () => { + expect(typedWorkerFarm.runTest('abc', 123)).type.toEqual>(); + expect(typedWorkerFarm.doSomething()).type.toEqual>(); -expectError(typedWorkerFarm.setup()); -expectError(typedWorkerFarm.teardown()); + expect(typedWorkerFarm.runTest()).type.toRaiseError(); + expect(typedWorkerFarm.runTest('abc')).type.toRaiseError(); + expect(typedWorkerFarm.doSomething('abc')).type.toRaiseError(); -expectType>(typedWorkerFarm.start()); + expect(typedWorkerFarm).type.not.toHaveProperty('isResult'); + expect(typedWorkerFarm).type.not.toHaveProperty('runTestAsync'); -expectNotAssignable>(typedWorkerFarm.end()); -expectType>(typedWorkerFarm.end()); + expect(typedWorkerFarm).type.not.toHaveProperty('setup'); + expect(typedWorkerFarm).type.not.toHaveProperty('teardown'); -expectNotAssignable>(typedWorkerFarm.getStderr()); -expectType(typedWorkerFarm.getStderr()); + expect(typedWorkerFarm.start()).type.toEqual>(); + expect(typedWorkerFarm.end()).type.toEqual>(); -expectNotAssignable>(typedWorkerFarm.getStdout()); -expectType(typedWorkerFarm.getStdout()); + expect(typedWorkerFarm.getStderr()).type.toEqual(); + expect(typedWorkerFarm.getStdout()).type.toEqual(); +}); diff --git a/tstyche.config.json b/tstyche.config.json index 41053794031e..cd52daa11c0e 100644 --- a/tstyche.config.json +++ b/tstyche.config.json @@ -7,6 +7,7 @@ "**/packages/jest-expect/__typetests__/*.test.ts", "**/packages/jest-mock/__typetests__/*.test.ts", "**/packages/jest-snapshot/__typetests__/*.test.ts", + "**/packages/jest-worker/__typetests__/*.test.ts" "**/packages/jest-types/__typetests__/config.test.ts" ] }