summaryrefslogtreecommitdiffhomepage
path: root/packages/server/src/helpers/iso/isoCrypto/getWebCrypto.test.ts
diff options
context:
space:
mode:
authorMatthew Miller <matthew@millerti.me>2024-03-05 18:48:24 -0800
committerGitHub <noreply@github.com>2024-03-05 18:48:24 -0800
commitc016aa8610096eaafb2e0627056dd00c2ec48a9f (patch)
tree286df955124cb88df2cc555692d5e77a4d4ab5ee /packages/server/src/helpers/iso/isoCrypto/getWebCrypto.test.ts
parent634ceabdb05f4b5e56132fff7c57598caa2401a8 (diff)
parent8328067b594230758af6224b25a25a93e5468145 (diff)
Merge pull request #535 from MasterKale/feat/532-update-getwebcrypto-node-v20-smaller
Update getWebCrypto for Node 20 (Approach 2)
Diffstat (limited to 'packages/server/src/helpers/iso/isoCrypto/getWebCrypto.test.ts')
-rw-r--r--packages/server/src/helpers/iso/isoCrypto/getWebCrypto.test.ts104
1 files changed, 0 insertions, 104 deletions
diff --git a/packages/server/src/helpers/iso/isoCrypto/getWebCrypto.test.ts b/packages/server/src/helpers/iso/isoCrypto/getWebCrypto.test.ts
index 24b37aa..9ab0ad2 100644
--- a/packages/server/src/helpers/iso/isoCrypto/getWebCrypto.test.ts
+++ b/packages/server/src/helpers/iso/isoCrypto/getWebCrypto.test.ts
@@ -23,101 +23,6 @@ Deno.test('should return globalThis.crypto when present', async () => {
mockGlobalThisCrypto.restore();
});
-Deno.test('should return node:crypto.webcrypto when globalThis.crypto is missing', async () => {
- // Clear whatever version of crypto might have been set
- _getWebCryptoInternals.setCachedCrypto(undefined);
-
- // Pretend globalThis.crypto doesn't exist
- const mockGlobalThisCrypto = stub(
- _getWebCryptoInternals,
- 'stubThisGlobalThisCrypto',
- // @ts-ignore: globalThis.crypto
- returnsNext([undefined]),
- );
-
- // Mock out just enough of the 'node:crypto' module
- const fakeNodeCrypto = { webcrypto: {} };
- const mockImportNodeCrypto = stub(
- _getWebCryptoInternals,
- 'stubThisImportNodeCrypto',
- // @ts-ignore: node:crypto
- returnsNext([Promise.resolve(fakeNodeCrypto)]),
- );
-
- const returnedCrypto = await getWebCrypto();
-
- assertEquals(returnedCrypto, fakeNodeCrypto.webcrypto);
-
- mockGlobalThisCrypto.restore();
- mockImportNodeCrypto.restore();
-});
-
-Deno.test(
- 'should return globalThis.crypto when present, while node:crypto.webcrypto is present',
- async () => {
- // Clear whatever version of crypto might have been set
- _getWebCryptoInternals.setCachedCrypto(undefined);
-
- // Pretend globalThis.crypto exists
- const fakeGlobalThisCrypto = {};
- const mockGlobalThisCrypto = stub(
- _getWebCryptoInternals,
- 'stubThisGlobalThisCrypto',
- // @ts-ignore: globalThis.crypto
- returnsNext([fakeGlobalThisCrypto]),
- );
-
- // Mock out just enough of the 'node:crypto' module, but like we're in Node v14
- const fakeNodeCrypto = { webcrypto: {} };
- const mockImportNodeCrypto = stub(
- _getWebCryptoInternals,
- 'stubThisImportNodeCrypto',
- // @ts-ignore: node:crypto
- returnsNext([Promise.resolve(fakeNodeCrypto)]),
- );
-
- const returnedCrypto = await getWebCrypto();
-
- assertEquals(returnedCrypto, fakeGlobalThisCrypto);
-
- mockGlobalThisCrypto.restore();
- mockImportNodeCrypto.restore();
- },
-);
-
-Deno.test(
- 'should return globalThis.crypto when present, while node:crypto is present but missing webcrypto',
- async () => {
- // Clear whatever version of crypto might have been set
- _getWebCryptoInternals.setCachedCrypto(undefined);
-
- // Pretend globalThis.crypto exists
- const fakeGlobalThisCrypto = {};
- const mockGlobalThisCrypto = stub(
- _getWebCryptoInternals,
- 'stubThisGlobalThisCrypto',
- // @ts-ignore: globalThis.crypto
- returnsNext([fakeGlobalThisCrypto]),
- );
-
- // Mock out just enough of the 'node:crypto' module, but like we're in Node v14
- const fakeNodeCrypto = { webcrypto: undefined };
- const mockImportNodeCrypto = stub(
- _getWebCryptoInternals,
- 'stubThisImportNodeCrypto',
- // @ts-ignore: node:crypto
- returnsNext([Promise.resolve(fakeNodeCrypto)]),
- );
-
- const returnedCrypto = await getWebCrypto();
-
- assertEquals(returnedCrypto, fakeGlobalThisCrypto);
-
- mockGlobalThisCrypto.restore();
- mockImportNodeCrypto.restore();
- },
-);
-
Deno.test('should raise MissingWebCrypto error when nothing is available', async () => {
// Clear whatever version of crypto might have been set
_getWebCryptoInternals.setCachedCrypto(undefined);
@@ -130,14 +35,6 @@ Deno.test('should raise MissingWebCrypto error when nothing is available', async
returnsNext([undefined]),
);
- // Pretend node:crypto doesn't exist
- const mockImportNodeCrypto = stub(
- _getWebCryptoInternals,
- 'stubThisImportNodeCrypto',
- // @ts-ignore: node:crypto
- returnsNext([Promise.resolve({ webcrypto: undefined })]),
- );
-
await assertRejects(
() => getWebCrypto(),
MissingWebCrypto,
@@ -145,5 +42,4 @@ Deno.test('should raise MissingWebCrypto error when nothing is available', async
);
mockGlobalThisCrypto.restore();
- mockImportNodeCrypto.restore();
});