From cb079b80c5751c4792c641eedb2623193d13d075 Mon Sep 17 00:00:00 2001 From: Matsu Date: Mon, 6 Jul 2026 12:18:11 +0300 Subject: [PATCH] test(editor): Stub node-icon svg imports in frontend vitest config (#33626) Co-authored-by: Claude Opus 4.8 (1M context) --- packages/@n8n/vitest-config/frontend.ts | 13 +++++++++++++ packages/@n8n/vitest-config/svg-stub.ts | 9 +++++++++ 2 files changed, 22 insertions(+) create mode 100644 packages/@n8n/vitest-config/svg-stub.ts diff --git a/packages/@n8n/vitest-config/frontend.ts b/packages/@n8n/vitest-config/frontend.ts index bd143c871c0..d753ac87a5e 100644 --- a/packages/@n8n/vitest-config/frontend.ts +++ b/packages/@n8n/vitest-config/frontend.ts @@ -1,11 +1,24 @@ +import { fileURLToPath } from 'node:url'; import { coverageConfigDefaults, defineConfig } from 'vitest/config'; import type { InlineConfig } from 'vitest/node'; import { coverageExcludes } from './coverage-excludes.js'; +// Resolves to the empty component that stands in for `.svg` imports (see below). +const svgStub = fileURLToPath(new URL('./svg-stub.js', import.meta.url)); + export const createVitestConfig = (options: InlineConfig = {}) => { const vitestConfig = defineConfig({ test: { + // Redirect the node-icon `.svg` imports (the ~80 files under + // `N8nIcon/nodes/`) to an inert component. `node-icons.ts` is imported + // lazily (on the first `node:*` icon render), so its bulk async + // `vite-svg-loader` transforms can kick off late and resolve after jsdom + // tears down — failing an otherwise-green run with `EnvironmentTeardownError`. + // Scoped to `nodes/` because those icons never appear in component + // snapshots (unlike the eagerly-imported `custom/` icons), and to + // `test.alias` so it never leaks into production/dev builds. See svg-stub.ts. + alias: [{ find: /^.*\/nodes\/[^/]+\.svg(\?.*)?$/, replacement: svgStub }], silent: true, globals: true, // Restore `vi.spyOn` spies to their original implementation before each test, so diff --git a/packages/@n8n/vitest-config/svg-stub.ts b/packages/@n8n/vitest-config/svg-stub.ts new file mode 100644 index 00000000000..e7ba8a86dee --- /dev/null +++ b/packages/@n8n/vitest-config/svg-stub.ts @@ -0,0 +1,9 @@ +// Inert stand-in for `.svg` imports in the frontend vitest harness. +// +// `icons.ts` / `node-icons.ts` statically import ~100 `.svg` files that +// `vite-svg-loader` transforms on demand (async). In jsdom an in-flight +// transform can resolve *after* the environment tears down, surfacing as an +// `EnvironmentTeardownError` that turns an otherwise-green shard red. Aliasing +// every `.svg` import to this empty functional component removes the racy +// transform (see frontend.ts). +export default () => null;