mirror of
https://github.com/Comfy-Org/ComfyUI_frontend.git
synced 2026-03-02 19:49:58 +00:00
Lint module entry point (#635)
- Adds module entry point tests - Manually resolved lint rules for module entry point imports / exports (autofix could not resolve without causing issues)
This commit is contained in:
@@ -1,11 +1,11 @@
|
||||
import { describe, expect } from "vitest"
|
||||
import { beforeEach, describe, expect, vi } from "vitest"
|
||||
|
||||
import { clamp, LGraphCanvas, LiteGraph } from "@/litegraph"
|
||||
import { LiteGraphGlobal } from "@/LiteGraphGlobal"
|
||||
|
||||
import { test } from "./testExtensions"
|
||||
|
||||
describe.concurrent("Litegraph module", () => {
|
||||
describe("Litegraph module", () => {
|
||||
test("contains a global export", ({ expect }) => {
|
||||
expect(LiteGraph).toBeInstanceOf(LiteGraphGlobal)
|
||||
expect(LiteGraph.LGraphCanvas).toBe(LGraphCanvas)
|
||||
@@ -21,3 +21,35 @@ describe.concurrent("Litegraph module", () => {
|
||||
expect(clamp(Infinity, 18, 29)).toStrictEqual(29)
|
||||
})
|
||||
})
|
||||
|
||||
describe("Import order dependency", () => {
|
||||
beforeEach(() => {
|
||||
vi.resetModules()
|
||||
})
|
||||
|
||||
// Test can be safely removed if import order requirements are resolved.
|
||||
test("Throws when entry point is not imported first", async ({ expect }) => {
|
||||
async function importSubmoduleFirst() {
|
||||
const directImport = await import("@/LGraph")
|
||||
const entryPointImport = await import("@/litegraph")
|
||||
|
||||
// Unreachable.
|
||||
if (directImport !== entryPointImport) return
|
||||
}
|
||||
|
||||
await expect(importSubmoduleFirst).rejects.toThrow("Cannot set properties of undefined (setting 'link_type_colors')")
|
||||
})
|
||||
|
||||
test("Imports without error when entry point is imported first", async ({ expect }) => {
|
||||
async function importNormally() {
|
||||
const entryPointImport = await import("@/litegraph")
|
||||
const directImport = await import("@/LGraph")
|
||||
|
||||
// Sanity check that imports were cleared.
|
||||
expect(Object.is(LiteGraph, entryPointImport.LiteGraph)).toBe(false)
|
||||
expect(Object.is(LiteGraph.LGraph, directImport.LGraph)).toBe(false)
|
||||
}
|
||||
|
||||
await expect(importNormally()).resolves.toBeUndefined()
|
||||
})
|
||||
})
|
||||
|
||||
Reference in New Issue
Block a user