From 3e7e1b2d22e53b28e092e1af450578686dc7ec83 Mon Sep 17 00:00:00 2001 From: Nik Graf Date: Thu, 30 Mar 2023 10:56:07 +0200 Subject: [PATCH] improve test setup --- packages/naisho-core/package.json | 3 +++ packages/naisho-core/test/config/jestTestSetup.ts | 13 +++---------- .../test/config/jestTestSetupAfterEnv.ts | 7 +++++++ packages/workspace-chain/package.json | 3 +++ .../workspace-chain/test/config/jestTestSetup.ts | 9 ++------- .../test/config/jestTestSetupAfterEnv.ts | 4 ++++ 6 files changed, 22 insertions(+), 17 deletions(-) create mode 100644 packages/naisho-core/test/config/jestTestSetupAfterEnv.ts create mode 100644 packages/workspace-chain/test/config/jestTestSetupAfterEnv.ts diff --git a/packages/naisho-core/package.json b/packages/naisho-core/package.json index bb4af2dd5..b18f9bab6 100644 --- a/packages/naisho-core/package.json +++ b/packages/naisho-core/package.json @@ -26,6 +26,9 @@ }, "jest": { "setupFilesAfterEnv": [ + "/test/config/jestTestSetupAfterEnv.ts" + ], + "setupFiles": [ "/test/config/jestTestSetup.ts" ] } diff --git a/packages/naisho-core/test/config/jestTestSetup.ts b/packages/naisho-core/test/config/jestTestSetup.ts index 833de20aa..2428f9f21 100644 --- a/packages/naisho-core/test/config/jestTestSetup.ts +++ b/packages/naisho-core/test/config/jestTestSetup.ts @@ -1,12 +1,5 @@ -import sodium from "libsodium-wrappers"; -import { WebSocket } from "mock-socket"; +import sodium from "react-native-libsodium"; -// @ts-expect-error -global.setImmediate = jest.useRealTimers; -global.WebSocket = WebSocket; - -jest.setTimeout(25000); - -beforeEach(async () => { +module.exports = async function () { await sodium.ready; -}); +}; diff --git a/packages/naisho-core/test/config/jestTestSetupAfterEnv.ts b/packages/naisho-core/test/config/jestTestSetupAfterEnv.ts new file mode 100644 index 000000000..e96430832 --- /dev/null +++ b/packages/naisho-core/test/config/jestTestSetupAfterEnv.ts @@ -0,0 +1,7 @@ +import { WebSocket } from "mock-socket"; + +// @ts-expect-error +global.setImmediate = jest.useRealTimers; +global.WebSocket = WebSocket; + +jest.setTimeout(25000); diff --git a/packages/workspace-chain/package.json b/packages/workspace-chain/package.json index 09ec96f2f..c9cd7909e 100644 --- a/packages/workspace-chain/package.json +++ b/packages/workspace-chain/package.json @@ -22,6 +22,9 @@ }, "jest": { "setupFilesAfterEnv": [ + "/test/config/jestTestSetupAfterEnv.ts" + ], + "setupFiles": [ "/test/config/jestTestSetup.ts" ] } diff --git a/packages/workspace-chain/test/config/jestTestSetup.ts b/packages/workspace-chain/test/config/jestTestSetup.ts index be5c81993..2428f9f21 100644 --- a/packages/workspace-chain/test/config/jestTestSetup.ts +++ b/packages/workspace-chain/test/config/jestTestSetup.ts @@ -1,10 +1,5 @@ import sodium from "react-native-libsodium"; -// @ts-expect-error -global.setImmediate = jest.useRealTimers; - -jest.setTimeout(25000); - -beforeEach(async () => { +module.exports = async function () { await sodium.ready; -}); +}; diff --git a/packages/workspace-chain/test/config/jestTestSetupAfterEnv.ts b/packages/workspace-chain/test/config/jestTestSetupAfterEnv.ts new file mode 100644 index 000000000..c8cbf4e37 --- /dev/null +++ b/packages/workspace-chain/test/config/jestTestSetupAfterEnv.ts @@ -0,0 +1,4 @@ +// @ts-expect-error +global.setImmediate = jest.useRealTimers; + +jest.setTimeout(25000);