Skip to content

Commit 574e44f

Browse files
committed
fix(ci): fix cross-realm ArrayBuffer issue in Node 20 JSDOM tests
- Upgrade CI Node.js from 20 to 22 (Active LTS) to fix JSDOM cross-realm ArrayBuffer rejection by Web Crypto API - Always override globalThis.crypto with Node's native webcrypto in setupTests.ts to avoid JSDOM's partial crypto implementation
1 parent 265988f commit 574e44f

File tree

3 files changed

+8
-13
lines changed

3 files changed

+8
-13
lines changed

.github/workflows/ci.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -122,7 +122,7 @@ jobs:
122122
- name: Set up Node.js
123123
uses: actions/setup-node@v4
124124
with:
125-
node-version: '20'
125+
node-version: '22'
126126
cache: npm
127127
cache-dependency-path: frontend/package-lock.json
128128

frontend/src/setupTests.ts

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -27,14 +27,13 @@ import { webcrypto } from 'crypto';
2727
// @ts-ignore - Node.js util module
2828
import { TextEncoder, TextDecoder } from 'util';
2929

30-
// Polyfill globalThis.crypto for Node.js environment
31-
if (typeof globalThis.crypto === 'undefined') {
32-
Object.defineProperty(globalThis, 'crypto', {
33-
value: webcrypto,
34-
writable: false,
35-
configurable: false
36-
});
37-
}
30+
// Polyfill globalThis.crypto with Node's native webcrypto
31+
// This avoids JSDOM cross-realm ArrayBuffer issues with Web Crypto API
32+
Object.defineProperty(globalThis, 'crypto', {
33+
value: webcrypto,
34+
writable: true,
35+
configurable: true
36+
});
3837

3938
if (typeof globalThis.TextEncoder === 'undefined') {
4039
(globalThis as { TextEncoder: typeof TextEncoder }).TextEncoder = TextEncoder;

frontend/src/utils/__tests__/encryption.test.ts

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,4 @@
11
// src/utils/__tests__/encryption.test.ts
2-
/**
3-
* @jest-environment node
4-
*/
5-
62
/**
73
* Client-Side Encryption Unit Tests
84
* ═══════════════════════════════════════════════════════════════════════════════

0 commit comments

Comments
 (0)