From 52ac9780271d55e0474308d953141a907416efb8 Mon Sep 17 00:00:00 2001 From: Danijel Martinek Date: Tue, 5 May 2026 14:48:20 +0200 Subject: [PATCH] fix(core-typescript): tighten jsdom config tests + document cycle avoidance MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - Replace arrayContaining with toEqual on setupFiles + include — captures actual mergeConfig array-concatenation behavior so future changes to setup/node.ts surface in this test. - Document in core-typescript/AGENTS.md why @repo/core-testing is not a devDep here (would create a circular dependency with core-testing). Reviewer: superpowers:code-reviewer (Task 2 of Plan 7). Co-Authored-By: Claude Sonnet 4.6 --- packages/core-typescript/AGENTS.md | 9 +++++++ .../core-typescript/vitest.base.jsdom.test.ts | 27 +++++++++++++------ 2 files changed, 28 insertions(+), 8 deletions(-) diff --git a/packages/core-typescript/AGENTS.md b/packages/core-typescript/AGENTS.md index 872fa7c..3af3204 100644 --- a/packages/core-typescript/AGENTS.md +++ b/packages/core-typescript/AGENTS.md @@ -4,6 +4,15 @@ Shared TypeScript base configs (`tsconfig.json` files) and Vitest base config, consumed by all packages. +## Why `@repo/core-testing` is not a devDependency here + +Plan 7 Step 9 originally said to add it. Doing so creates a circular dependency +because `@repo/core-testing` already depends on `@repo/core-typescript` for its +own tsconfig. The base configs reference `@repo/core-testing/setup/{node,jsdom}` +as STRING paths in `setupFiles` — these are resolved at Vitest execution time +by the consuming feature package, not by `core-typescript` itself. Each feature +package therefore lists `@repo/core-testing` in its own `devDependencies`. + ## What it owns - **`base.json`** — Base `tsconfig.json`: target ES2022, module ESM, `experimentalDecorators` + `emitDecoratorMetadata` for InversifyJS diff --git a/packages/core-typescript/vitest.base.jsdom.test.ts b/packages/core-typescript/vitest.base.jsdom.test.ts index 539f5a0..9f0c54e 100644 --- a/packages/core-typescript/vitest.base.jsdom.test.ts +++ b/packages/core-typescript/vitest.base.jsdom.test.ts @@ -1,19 +1,30 @@ import { describe, it, expect } from "vitest"; import { jsdomVitestConfig } from "./vitest.base.jsdom"; +// jsdomVitestConfig is built with mergeConfig(nodeVitestConfig, ...). +// mergeConfig concatenates arrays rather than replacing them, so: +// - setupFiles inherits the node setup file (currently a no-op) AND adds the jsdom one +// - include inherits the node patterns AND adds the tsx-aware patterns (the file globs deduplicate at resolution) +// We assert the EXACT merged arrays so any future change to setup/node.ts or to include +// behavior is consciously visible in this test. + describe("jsdomVitestConfig", () => { it("uses jsdom environment", () => { expect(jsdomVitestConfig.test?.environment).toBe("jsdom"); }); - it("loads the jsdom setup file", () => { - expect(jsdomVitestConfig.test?.setupFiles).toEqual( - expect.arrayContaining(["@repo/core-testing/setup/jsdom"]), - ); + it("loads both the node setup (no-op) and jsdom setup files", () => { + expect(jsdomVitestConfig.test?.setupFiles).toEqual([ + "@repo/core-testing/setup/node", + "@repo/core-testing/setup/jsdom", + ]); }); - it("includes tsx files", () => { - expect(jsdomVitestConfig.test?.include).toEqual( - expect.arrayContaining(["src/**/*.test.{ts,tsx}", "tests/**/*.test.{ts,tsx}"]), - ); + it("merges include globs from node base with the tsx-aware patterns", () => { + expect(jsdomVitestConfig.test?.include).toEqual([ + "src/**/*.test.ts", + "tests/**/*.test.ts", + "src/**/*.test.{ts,tsx}", + "tests/**/*.test.{ts,tsx}", + ]); }); it("inherits clearMocks from node base", () => { expect(jsdomVitestConfig.test?.clearMocks).toBe(true);