From 9f1f1918452893e5368c48110dd74082f503f642 Mon Sep 17 00:00:00 2001 From: Simen Bekkhus Date: Mon, 23 Nov 2020 13:13:01 +0100 Subject: [PATCH 1/4] chore: update to TypeScript@4.1 --- e2e/runJest.ts | 2 +- packages/jest-circus/src/utils.ts | 4 ++-- packages/jest-snapshot/src/utils.ts | 2 +- packages/pretty-format/src/plugins/ReactElement.ts | 4 ++-- yarn.lock | 12 ++++++------ 5 files changed, 12 insertions(+), 12 deletions(-) diff --git a/e2e/runJest.ts b/e2e/runJest.ts index 51b982b73752..f3aba215e226 100644 --- a/e2e/runJest.ts +++ b/e2e/runJest.ts @@ -208,7 +208,7 @@ export const runContinuous = function ( }, async waitUntil(fn: ConditionFunction) { - await new Promise(resolve => { + await new Promise(resolve => { const check = (state: StdErrAndOutString) => { if (fn(state)) { pending.delete(check); diff --git a/packages/jest-circus/src/utils.ts b/packages/jest-circus/src/utils.ts index ea0f1858fc60..7d4c43b1088b 100644 --- a/packages/jest-circus/src/utils.ts +++ b/packages/jest-circus/src/utils.ts @@ -180,7 +180,7 @@ export const callAsyncCircusFn = ( const {fn, asyncError} = testOrHook; - return new Promise((resolve, reject) => { + return new Promise((resolve, reject) => { timeoutID = setTimeout( () => reject(_makeTimeoutMessage(timeout, isHook)), timeout, @@ -266,7 +266,7 @@ export const callAsyncCircusFn = ( returnedValue !== null && typeof returnedValue.then === 'function' ) { - returnedValue.then(resolve, reject); + returnedValue.then(() => resolve(), reject); return; } diff --git a/packages/jest-snapshot/src/utils.ts b/packages/jest-snapshot/src/utils.ts index bfaa4d5024eb..ac20dfd9aa80 100644 --- a/packages/jest-snapshot/src/utils.ts +++ b/packages/jest-snapshot/src/utils.ts @@ -74,7 +74,7 @@ const validateSnapshotVersion = (snapshotContents: string) => { }; function isObject(item: unknown): boolean { - return item && typeof item === 'object' && !Array.isArray(item); + return item != null && typeof item === 'object' && !Array.isArray(item); } export const testNameToKey = (testName: Config.Path, count: number): string => diff --git a/packages/pretty-format/src/plugins/ReactElement.ts b/packages/pretty-format/src/plugins/ReactElement.ts index 0856d43bd237..112b22a8a741 100644 --- a/packages/pretty-format/src/plugins/ReactElement.ts +++ b/packages/pretty-format/src/plugins/ReactElement.ts @@ -16,7 +16,7 @@ import { // Given element.props.children, or subtree during recursive traversal, // return flattened array of children. -const getChildren = (arg: Array, children = []) => { +const getChildren = (arg: unknown, children: Array = []) => { if (Array.isArray(arg)) { arg.forEach(item => { getChildren(item, children); @@ -115,7 +115,7 @@ export const serialize: NewPlugin['serialize'] = ( ); export const test: NewPlugin['test'] = (val: unknown) => - val && ReactIs.isElement(val); + val != null && ReactIs.isElement(val); const plugin: NewPlugin = {serialize, test}; diff --git a/yarn.lock b/yarn.lock index f9a17510e06e..b8b0c454596f 100644 --- a/yarn.lock +++ b/yarn.lock @@ -19408,22 +19408,22 @@ react-native@0.63.2: linkType: hard "typescript@*, typescript@^4.0.2, typescript@^4.0.3": - version: 4.0.5 - resolution: "typescript@npm:4.0.5" + version: 4.1.5 + resolution: "typescript@npm:4.1.5" bin: tsc: bin/tsc tsserver: bin/tsserver - checksum: ce94d4bbb914cc9d6fbd42e1476ab18c3292b262b8ba7ba76cd167a858545207a604e75bf1efbb75b8654c8f85deaa19795c3ef00098d7612855139b4ecc0240 + checksum: 29157c84426ac94ce97aac836264f303a26bd9fb30865650229e3406a36ca2e89735ef4b8878075ba1b95fa4d3ff9810057b64888700c28e20b4034a6db4da83 languageName: node linkType: hard "typescript@patch:typescript@*#builtin, typescript@patch:typescript@^4.0.2#builtin, typescript@patch:typescript@^4.0.3#builtin": - version: 4.0.5 - resolution: "typescript@patch:typescript@npm%3A4.0.5#builtin::version=4.0.5&hash=cc6730" + version: 4.1.5 + resolution: "typescript@patch:typescript@npm%3A4.1.5#builtin::version=4.1.5&hash=cc6730" bin: tsc: bin/tsc tsserver: bin/tsserver - checksum: ada6fea7657a51d1b842682d31233e53a3cf509b0edbd6288fda3cfd01643d0190b7ea77837527c4d282c90e61690e19dbfd91be6913e7e7292aa0b588d3506c + checksum: 58cc7786be0f8485c124944883b1384287532e4867ec37f1fb5cb2811dbc10f7a9decccad89097f924043285f3515bfd8223c61dbb4f88af00b2d8dc2ef73207 languageName: node linkType: hard From 5ed6467365e77097831e46efa15d484b8e90848a Mon Sep 17 00:00:00 2001 From: Simen Bekkhus Date: Thu, 18 Feb 2021 20:13:55 +0100 Subject: [PATCH 2/4] add ignores --- packages/jest-jasmine2/src/PCancelable.ts | 2 ++ 1 file changed, 2 insertions(+) diff --git a/packages/jest-jasmine2/src/PCancelable.ts b/packages/jest-jasmine2/src/PCancelable.ts index 8481cf8a397f..58029ba2f59b 100644 --- a/packages/jest-jasmine2/src/PCancelable.ts +++ b/packages/jest-jasmine2/src/PCancelable.ts @@ -26,6 +26,7 @@ export default class PCancelable extends Promise { reject: (reason?: unknown) => void, ) => void, ) { + // @ts-expect-error super(resolve => resolve()); this._promise = new Promise((resolve, reject) => { @@ -37,6 +38,7 @@ export default class PCancelable extends Promise { }, val => { this._pending = false; + // @ts-expect-error resolve(val); }, err => { From d8a1889ca040333af6de6e9b6e07d6c2887403ed Mon Sep 17 00:00:00 2001 From: Simen Bekkhus Date: Thu, 18 Feb 2021 20:42:22 +0100 Subject: [PATCH 3/4] Revert "add ignores" This reverts commit 5ed6467365e77097831e46efa15d484b8e90848a. --- packages/jest-jasmine2/src/PCancelable.ts | 2 -- 1 file changed, 2 deletions(-) diff --git a/packages/jest-jasmine2/src/PCancelable.ts b/packages/jest-jasmine2/src/PCancelable.ts index 58029ba2f59b..8481cf8a397f 100644 --- a/packages/jest-jasmine2/src/PCancelable.ts +++ b/packages/jest-jasmine2/src/PCancelable.ts @@ -26,7 +26,6 @@ export default class PCancelable extends Promise { reject: (reason?: unknown) => void, ) => void, ) { - // @ts-expect-error super(resolve => resolve()); this._promise = new Promise((resolve, reject) => { @@ -38,7 +37,6 @@ export default class PCancelable extends Promise { }, val => { this._pending = false; - // @ts-expect-error resolve(val); }, err => { From 77cbab7f01ebeeeac714072526211f4b755be1fc Mon Sep 17 00:00:00 2001 From: Simen Bekkhus Date: Thu, 18 Feb 2021 21:27:37 +0100 Subject: [PATCH 4/4] implements instead --- packages/jest-jasmine2/src/PCancelable.ts | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/packages/jest-jasmine2/src/PCancelable.ts b/packages/jest-jasmine2/src/PCancelable.ts index 8481cf8a397f..2c7b0aa826fe 100644 --- a/packages/jest-jasmine2/src/PCancelable.ts +++ b/packages/jest-jasmine2/src/PCancelable.ts @@ -12,7 +12,7 @@ class CancelError extends Error { } } -export default class PCancelable extends Promise { +export default class PCancelable implements PromiseLike { private _pending = true; private _canceled = false; private _promise: Promise; @@ -22,12 +22,10 @@ export default class PCancelable extends Promise { constructor( executor: ( onCancel: (cancelHandler: () => void) => void, - resolve: (value?: T | PromiseLike) => void, + resolve: (value: T | PromiseLike) => void, reject: (reason?: unknown) => void, ) => void, ) { - super(resolve => resolve()); - this._promise = new Promise((resolve, reject) => { this._reject = reject;