Files
e4a03dce4f fix: Add JSON import assertions for Node.js ESM compatibility (#5507)
Added `with { type: 'json' }` assertions to all JSON imports to ensure compatibility with Node.js ES modules and Playwright environments. This follows the current ESM specification where JSON imports require explicit type assertions.

Affected areas:
- Tailwind config
- i18n locale imports (36 files)
- Test fixtures and spec files
- API client feature flags
- Core color palettes

References:
- https://nodejs.org/api/esm.html
- https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Statements/import/with

🤖 Generated with [Claude Code](https://claude.ai/code)

Co-authored-by: Claude <[email protected]>
2025-09-11 20:22:21 -07:00

83 lines
2.7 KiB
TypeScript

import { test as baseTest } from 'vitest'
import { LGraph } from '@/lib/litegraph/src/LGraph'
import { LiteGraph } from '@/lib/litegraph/src/litegraph'
import type {
ISerialisedGraph,
SerialisableGraph
} from '@/lib/litegraph/src/types/serialisation'
import floatingBranch from './assets/floatingBranch.json' with { type: 'json' }
import floatingLink from './assets/floatingLink.json' with { type: 'json' }
import linkedNodes from './assets/linkedNodes.json' with { type: 'json' }
import reroutesComplex from './assets/reroutesComplex.json' with { type: 'json' }
import {
basicSerialisableGraph,
minimalSerialisableGraph,
oldSchemaGraph
} from './assets/testGraphs'
interface LitegraphFixtures {
minimalGraph: LGraph
minimalSerialisableGraph: SerialisableGraph
oldSchemaGraph: ISerialisedGraph
floatingLinkGraph: ISerialisedGraph
linkedNodesGraph: ISerialisedGraph
floatingBranchGraph: LGraph
reroutesComplexGraph: LGraph
}
/** These fixtures alter global state, and are difficult to reset. Relies on a single test per-file to reset state. */
interface DirtyFixtures {
basicSerialisableGraph: SerialisableGraph
}
export const test = baseTest.extend<LitegraphFixtures>({
// eslint-disable-next-line no-empty-pattern
minimalGraph: async ({}, use) => {
// Before each test function
const serialisable = structuredClone(minimalSerialisableGraph)
const lGraph = new LGraph(serialisable)
// use the fixture value
await use(lGraph)
},
minimalSerialisableGraph: structuredClone(minimalSerialisableGraph),
oldSchemaGraph: structuredClone(oldSchemaGraph),
floatingLinkGraph: structuredClone(
floatingLink as unknown as ISerialisedGraph
),
linkedNodesGraph: structuredClone(linkedNodes as unknown as ISerialisedGraph),
// eslint-disable-next-line no-empty-pattern
floatingBranchGraph: async ({}, use) => {
const cloned = structuredClone(
floatingBranch as unknown as ISerialisedGraph
)
const graph = new LGraph(cloned)
await use(graph)
},
// eslint-disable-next-line no-empty-pattern
reroutesComplexGraph: async ({}, use) => {
const cloned = structuredClone(
reroutesComplex as unknown as ISerialisedGraph
)
const graph = new LGraph(cloned)
await use(graph)
}
})
/** Test that use {@link DirtyFixtures}. One test per file. */
export const dirtyTest = test.extend<DirtyFixtures>({
// eslint-disable-next-line no-empty-pattern
basicSerialisableGraph: async ({}, use) => {
if (!basicSerialisableGraph.nodes) throw new Error('Invalid test object')
// Register node types
for (const node of basicSerialisableGraph.nodes) {
LiteGraph.registerNodeType(node.type!, LiteGraph.LGraphNode)
}
await use(structuredClone(basicSerialisableGraph))
}
})