Skip to content

Commit c8305d1

Browse files
committed
chore: enforce module-scope Vitest mock rule
Amp-Thread-ID: https://ampcode.com/threads/T-01a02581-5939-70ee-9867-37aed3d43d47
1 parent 180e551 commit c8305d1

4 files changed

Lines changed: 6 additions & 9 deletions

File tree

.oxlintrc.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -134,7 +134,7 @@
134134
{
135135
"files": ["**/*.test.{ts,tsx}"],
136136
"rules": {
137-
"comfy/no-module-scope-vitest-mocks": "warn",
137+
"comfy/no-module-scope-vitest-mocks": "error",
138138
"comfy/no-redundant-vitest-cleanup": "error"
139139
}
140140
},

src/base/common/downloadUtil.test.ts

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import { fromAny, fromPartial } from '@total-typescript/shoehorn'
2+
import type { MockInstance } from 'vitest'
23
import { beforeEach, describe, expect, it, vi } from 'vitest'
34

45
import {
@@ -25,13 +26,8 @@ vi.mock('@/platform/updates/common/toastStore', () => ({
2526
useToastStore: vi.fn(() => ({ addAlert: vi.fn() }))
2627
}))
2728

28-
// Global stubs
29-
let createObjectURLSpy = vi
30-
.spyOn(URL, 'createObjectURL')
31-
.mockReturnValue('blob:mock-url')
32-
let revokeObjectURLSpy = vi
33-
.spyOn(URL, 'revokeObjectURL')
34-
.mockImplementation(() => {})
29+
let createObjectURLSpy: MockInstance<typeof URL.createObjectURL>
30+
let revokeObjectURLSpy: MockInstance<typeof URL.revokeObjectURL>
3531

3632
describe('downloadUtil', () => {
3733
let mockLink: HTMLAnchorElement

src/scripts/ui.storageResilience.test.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ import { describe, expect, it, vi } from 'vitest'
1919

2020
// Node >= 25's unconfigured Web Storage stub, installed before the import below
2121
// so the module-scope `new ComfyApp()` restores against it.
22+
// oxlint-disable-next-line comfy/no-module-scope-vitest-mocks -- must precede import-time ComfyApp construction
2223
vi.stubGlobal('localStorage', {} as Storage)
2324

2425
// Imported once here rather than per test behind `vi.resetModules()`, which

tools/oxlint-plugins/vitestCleanup.config.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515
"**/tools/**/*.test.{ts,tsx}"
1616
],
1717
"rules": {
18-
"comfy/no-module-scope-vitest-mocks": "warn",
18+
"comfy/no-module-scope-vitest-mocks": "error",
1919
"comfy/no-redundant-vitest-cleanup": "error"
2020
}
2121
}

0 commit comments

Comments
 (0)