From 5094cbf1e15dc9469d51c84ec881d14f2426073e Mon Sep 17 00:00:00 2001 From: Patrick Lafrance Date: Mon, 20 Jan 2025 11:58:59 -0500 Subject: [PATCH] chore: Moving Jest setup to JSDOM for the firefly-honeycomb project --- packages/firefly-honeycomb/jest-setup.js | 6 ++++++ packages/firefly-honeycomb/jest.config.ts | 5 ++++- packages/firefly-honeycomb/package.json | 1 + pnpm-lock.yaml | 3 +++ 4 files changed, 14 insertions(+), 1 deletion(-) create mode 100644 packages/firefly-honeycomb/jest-setup.js diff --git a/packages/firefly-honeycomb/jest-setup.js b/packages/firefly-honeycomb/jest-setup.js new file mode 100644 index 000000000..141e92bb6 --- /dev/null +++ b/packages/firefly-honeycomb/jest-setup.js @@ -0,0 +1,6 @@ +// https://github.com/mswjs/msw/issues/1796 + +import { TextDecoder, TextEncoder } from "node:util"; + +global.TextEncoder = TextEncoder; +global.TextDecoder = TextDecoder; diff --git a/packages/firefly-honeycomb/jest.config.ts b/packages/firefly-honeycomb/jest.config.ts index f1304f31c..1a54a4baa 100644 --- a/packages/firefly-honeycomb/jest.config.ts +++ b/packages/firefly-honeycomb/jest.config.ts @@ -2,7 +2,9 @@ import type { Config } from "jest"; import { swcConfig } from "./swc.jest.ts"; const config: Config = { - testRegex: "/tests/*/.*\\.test\\.(ts|tsx)$", + // JSDOM is required for OTel instrumentation like "@opentelemetry/instrumentation-document-load". + testEnvironment: "jsdom", + testRegex: "/tests/*/.*\\.test\\.ts$", testPathIgnorePatterns: ["/node_modules/", "/dist/"], transformIgnorePatterns: [ "node_modules/(?!.pnpm|memoize|mimic-function|@workleap/honeycomb)" @@ -10,6 +12,7 @@ const config: Config = { transform: { "^.+\\.(js|ts|tsx)$": ["@swc/jest", swcConfig as Record] }, + setupFilesAfterEnv: ["/jest-setup.js"], cacheDirectory: "./node_modules/.cache/jest", verbose: true }; diff --git a/packages/firefly-honeycomb/package.json b/packages/firefly-honeycomb/package.json index 7b6937d7e..67448d86c 100644 --- a/packages/firefly-honeycomb/package.json +++ b/packages/firefly-honeycomb/package.json @@ -63,6 +63,7 @@ "@workleap/typescript-configs": "3.0.2", "eslint": "8.57.0", "jest": "29.7.0", + "jest-environment-jsdom": "29.7.0", "ts-node": "10.9.2", "typescript": "5.5.4" }, diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml index c6c400c10..cafeb6d3d 100644 --- a/pnpm-lock.yaml +++ b/pnpm-lock.yaml @@ -364,6 +364,9 @@ importers: jest: specifier: 29.7.0 version: 29.7.0(@types/node@22.10.7)(ts-node@10.9.2(@swc/core@1.10.7(@swc/helpers@0.5.15))(@types/node@22.10.7)(typescript@5.5.4)) + jest-environment-jsdom: + specifier: 29.7.0 + version: 29.7.0 ts-node: specifier: 10.9.2 version: 10.9.2(@swc/core@1.10.7)(@types/node@22.10.7)(typescript@5.5.4)