test(editor): Stub node-icon svg imports in frontend vitest config (#33626)

Co-authored-by: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
This commit is contained in:
Matsu
2026-07-06 12:18:11 +03:00
committed by GitHub
parent 36c37f4488
commit cb079b80c5
2 changed files with 22 additions and 0 deletions
+13
View File
@@ -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
+9
View File
@@ -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;