diff --git a/test/fx.ts b/test/fx.ts index ab6a6504b..a3cad859a 100644 --- a/test/fx.ts +++ b/test/fx.ts @@ -1,8 +1,15 @@ import { DefaultAzureCredential } from "@azure/identity"; import { Frame, Locator, Page, expect } from "@playwright/test"; -import crypto from "crypto"; +import crypto, { webcrypto } from "crypto"; import { TestContainerContext } from "./testData"; +// The @azure/cosmos client signs requests with globalThis.crypto (Web Crypto API). +// In Node.js >= 19 it's already available; only assign the polyfill for older versions. +// This lives in fx.ts (imported by every spec) so the polyfill always runs. +if (!globalThis.crypto) { + Object.defineProperty(globalThis, "crypto", { value: webcrypto, writable: true, configurable: true }); +} + const RETRY_COUNT = 3; export interface TestNameOptions { diff --git a/test/testData.ts b/test/testData.ts index e9ba759f1..57fbfe5a7 100644 --- a/test/testData.ts +++ b/test/testData.ts @@ -9,7 +9,6 @@ import { JSONObject, } from "@azure/cosmos"; import { Buffer } from "node:buffer"; -import { webcrypto } from "node:crypto"; import { generateUniqueName, getAccountName, @@ -19,12 +18,6 @@ import { TestAccount, } from "./fx"; -// In Node.js >= 19, globalThis.crypto is already available as a read-only getter. -// Only assign the polyfill for older versions. -if (!globalThis.crypto) { - Object.defineProperty(globalThis, "crypto", { value: webcrypto, writable: true, configurable: true }); -} - export interface TestItem { id: string; partitionKey: string;