mirror of
https://github.com/n8n-io/n8n.git
synced 2026-08-28 17:22:01 +08:00
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:
@@ -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
|
||||
|
||||
@@ -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;
|
||||
Reference in New Issue
Block a user