Skip to content

Commit

Permalink
fix(jest-circus, @jest/types): disallow undefined TestContext (#12507)
Browse files Browse the repository at this point in the history
  • Loading branch information
mrazauskas authored Feb 27, 2022
1 parent f34599e commit c2872aa
Show file tree
Hide file tree
Showing 5 changed files with 9 additions and 10 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@
- `[expect]` Move typings of `.not`, `.rejects` and `.resolves` modifiers outside of `Matchers` interface ([#12346](https://github.com/facebook/jest/pull/12346))
- `[expect]` Throw useful error if `expect.extend` is called with invalid matchers ([#12488](https://github.com/facebook/jest/pull/12488))
- `[expect]` Fix `iterableEquality` ignores other properties ([#8359](https://github.com/facebook/jest/pull/8359))
- `[jest-circus, @jest/types]` Disallow undefined value in `TestContext` type ([#12507](https://github.com/facebook/jest/pull/12507))
- `[jest-config]` Correctly detect CI environment and update snapshots accordingly ([#12378](https://github.com/facebook/jest/pull/12378))
- `[jest-config]` Pass `moduleTypes` to `ts-node` to enforce CJS when transpiling ([#12397](https://github.com/facebook/jest/pull/12397))
- `[jest-config, jest-haste-map]` Allow searching for tests in `node_modules` by exposing `retainAllFiles` ([#11084](https://github.com/facebook/jest/pull/11084))
Expand Down
4 changes: 2 additions & 2 deletions e2e/__tests__/__snapshots__/callDoneTwice.test.ts.snap
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ exports[`\`done()\` should not be called more than once 1`] = `
50 |
51 | it('should fail', () => {
at done (__tests__/index.test.js:48:5)
at Object.done (__tests__/index.test.js:48:5)
Test suite failed to run
Expand All @@ -85,5 +85,5 @@ exports[`\`done()\` should not be called more than once 1`] = `
61 |
62 | it('should fail', () => {
at done (__tests__/index.test.js:59:5)"
at Object.done (__tests__/index.test.js:59:5)"
`;
2 changes: 1 addition & 1 deletion packages/jest-circus/src/run.ts
Original file line number Diff line number Diff line change
Expand Up @@ -142,7 +142,7 @@ const _callCircusHook = async ({
hook,
test,
describeBlock,
testContext,
testContext = {},
}: {
hook: Circus.Hook;
describeBlock?: Circus.DescribeBlock;
Expand Down
2 changes: 1 addition & 1 deletion packages/jest-circus/src/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -170,7 +170,7 @@ function checkIsError(error: unknown): error is Error {

export const callAsyncCircusFn = (
testOrHook: Circus.TestEntry | Circus.Hook,
testContext: Circus.TestContext | undefined,
testContext: Circus.TestContext,
{isHook, timeout}: {isHook: boolean; timeout: number},
): Promise<unknown> => {
let timeoutID: NodeJS.Timeout;
Expand Down
10 changes: 4 additions & 6 deletions packages/jest-types/src/Global.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,16 +15,14 @@ export type TestReturnValue = ValidTestReturnValues | TestReturnValuePromise;
export type TestContext = Record<string, unknown>;

export type DoneFn = (reason?: string | Error) => void;
// these should not be undefined

export type DoneTakingTestFn = (
this: TestContext | undefined,
this: TestContext,
done: DoneFn,
) => ValidTestReturnValues;
export type PromiseReturningTestFn = (
this: TestContext | undefined,
) => TestReturnValue;
export type PromiseReturningTestFn = (this: TestContext) => TestReturnValue;
export type GeneratorReturningTestFn = (
this: TestContext | undefined,
this: TestContext,
) => TestReturnValueGenerator;

// eslint-disable-next-line @typescript-eslint/ban-types
Expand Down

0 comments on commit c2872aa

Please sign in to comment.