Skip to content

Commit ce7b824

Browse files
DrJKLampagent
andauthored
test: centralize unit test isolation and shared automocks (Comfy-Org#15104)
## Summary Combine the test-isolation cleanup and shared component automocks from the stacked PR series into one merge. The aggregate removes redundant per-suite setup while preserving within-test resets and behavior-specific cleanup. ## Constituent changes - Comfy-Org#15072 — remove 249 redundant `mockReset()`, `mockClear()`, and `vi.clearAllMocks()` calls across 120 files, relying on Vitest's configured `mockReset` and `restoreMocks` behavior. - Comfy-Org#15074 — clear `sessionStorage` in the shared Vitest `beforeEach` and remove 28 redundant cleanup calls across 21 suites, retaining the fast-check iteration reset. - Comfy-Org#15075 — rely on the shared testing Pinia and remove 67 redundant `setActivePinia(createPinia())` calls across 60 files, retaining deliberate within-test and independent-store resets. - Comfy-Org#15082 — clear `document.body` in the shared Vitest setup and remove 28 redundant body resets across 26 suites, preserving behavior-specific DOM replacement. - Comfy-Org#15084 — centralize Testing Library cleanup, including scoped website cleanup for its `globals: false` project, and remove 23 redundant lifecycle registrations while preserving mid-test cleanup. - Comfy-Org#15090 — reset browser history to `/` in the shared Vitest setup and remove five suite-local URL resets while retaining URL mutations used as test inputs. - Comfy-Org#15100 — replace three inline Select test doubles with opt-in colocated Vitest automocks for the Select component family and include Vue manual mocks in Knip's Vitest entry pattern. - Comfy-Org#15101 — replace five inline Slider factories with an opt-in colocated range-input automock that preserves accessibility, numeric conversion, bounds, step, and array-valued `v-model` behavior. - Comfy-Org#15104 — replace two queue-menu Popover factories with an opt-in colocated automock and shared close spy, reset by Vitest's configured `mockReset` behavior. ## Verification - root unit suite: 1,160 files passed; 15,926 tests passed, 8 skipped - `pnpm lint` - `pnpm typecheck` - `pnpm format:check` - `pnpm knip` --------- Co-authored-by: Amp <amp@ampcode.com>
1 parent d2f611b commit ce7b824

243 files changed

Lines changed: 219 additions & 1130 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

apps/website/src/components/pricing/CloudPricingSection.test.ts

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,9 @@
11
// @vitest-environment happy-dom
2-
import { cleanup, render, screen } from '@testing-library/vue'
3-
import { afterEach, describe, expect, it } from 'vitest'
2+
import { render, screen } from '@testing-library/vue'
3+
import { describe, expect, it } from 'vitest'
44

55
import CloudPricingSection from './CloudPricingSection.vue'
66

7-
afterEach(() => {
8-
cleanup()
9-
})
10-
117
function isBefore(first: Element, second: Element) {
128
return Boolean(
139
first.compareDocumentPosition(second) & Node.DOCUMENT_POSITION_FOLLOWING

apps/website/src/components/pricing/PricingFreeBanner.test.ts

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,10 @@
11
// @vitest-environment happy-dom
2-
import { cleanup, render, screen } from '@testing-library/vue'
3-
import { afterEach, describe, expect, it } from 'vitest'
2+
import { render, screen } from '@testing-library/vue'
3+
import { describe, expect, it } from 'vitest'
44
import type { ComponentProps } from 'vue-component-type-helpers'
55

66
import PricingFreeBanner from './PricingFreeBanner.vue'
77

8-
afterEach(() => {
9-
cleanup()
10-
})
11-
128
type BannerProps = ComponentProps<typeof PricingFreeBanner>
139

1410
const defaultProps = {

apps/website/src/components/product/local/MobileDownloadEmailForm.test.ts

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
// @vitest-environment happy-dom
22
import userEvent from '@testing-library/user-event'
3-
import { cleanup, fireEvent, render, screen } from '@testing-library/vue'
4-
import { afterEach, beforeEach, describe, expect, it, vi } from 'vitest'
3+
import { fireEvent, render, screen } from '@testing-library/vue'
4+
import { beforeEach, describe, expect, it, vi } from 'vitest'
55

66
import MobileDownloadEmailForm from './MobileDownloadEmailForm.vue'
77

@@ -35,10 +35,6 @@ describe('MobileDownloadEmailForm', () => {
3535
hoisted.isMobileUa = true
3636
})
3737

38-
afterEach(() => {
39-
cleanup()
40-
})
41-
4238
it('renders nothing when the write key is not configured', () => {
4339
hoisted.isEnabled = false
4440
render(MobileDownloadEmailForm)

apps/website/src/templates/model-launch/ModelLaunchHeroCtaButtons.test.ts

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,9 @@
11
// @vitest-environment happy-dom
2-
import { cleanup, render, screen } from '@testing-library/vue'
3-
import { afterEach, describe, expect, it } from 'vitest'
2+
import { render, screen } from '@testing-library/vue'
3+
import { describe, expect, it } from 'vitest'
44

55
import ModelLaunchHeroCtaButtons from './ModelLaunchHeroCtaButtons.vue'
66

7-
afterEach(() => {
8-
cleanup()
9-
})
10-
117
describe('ModelLaunchHeroCtaButtons', () => {
128
it('renders only the primary CTA when no secondary CTA is given', () => {
139
render(ModelLaunchHeroCtaButtons, {

apps/website/src/templates/model-launch/ModelLaunchPricingSection.test.ts

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,10 @@
11
// @vitest-environment happy-dom
2-
import { cleanup, render, screen } from '@testing-library/vue'
3-
import { afterEach, describe, expect, it } from 'vitest'
2+
import { render, screen } from '@testing-library/vue'
3+
import { describe, expect, it } from 'vitest'
44

55
import { minimaxPage } from '../../data/minimax'
66
import ModelLaunchPricingSection from './ModelLaunchPricingSection.vue'
77

8-
afterEach(() => {
9-
cleanup()
10-
})
11-
128
// The live /minimax config, so a refactor of the shared banner cannot quietly
139
// change what that page ships. `pricing` is optional on a launch page, so fail
1410
// loudly here rather than silently testing an empty section.

apps/website/src/test/setup.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
import { cleanup } from '@testing-library/vue'
2+
import { afterEach } from 'vitest'
3+
4+
afterEach(cleanup)

apps/website/src/utils/cloudNodes.build.test.ts

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -35,8 +35,6 @@ describe('loadPacksForBuild', () => {
3535
const savedVercelEnv = process.env.VERCEL_ENV
3636

3737
beforeEach(() => {
38-
fetchCloudNodesMock.mockReset()
39-
reportCloudNodesOutcomeMock.mockReset()
4038
delete process.env.VERCEL_ENV
4139
})
4240

apps/website/src/utils/cloudNodes.test.ts

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -94,9 +94,7 @@ describe('fetchCloudNodesForBuild', () => {
9494

9595
beforeEach(() => {
9696
resetCloudNodesFetcherForTests()
97-
fetchRegistryPacksWithNodesMock.mockReset()
9897
fetchRegistryPacksWithNodesMock.mockResolvedValue(new Map())
99-
sanitizeCallSpy.mockReset()
10098
delete process.env.WEBSITE_CLOUD_API_KEY
10199
})
102100

apps/website/vitest.config.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,6 @@ export default defineConfig({
1818
environment: 'node',
1919
include: ['src/**/*.{test,spec}.ts'],
2020
globals: false,
21-
setupFiles: ['../../vitest.timer.setup.ts']
21+
setupFiles: ['../../vitest.timer.setup.ts', './src/test/setup.ts']
2222
}
2323
})

knip.config.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,7 @@ const config: KnipConfig = {
7070
config: ['vitest?(.*).config.ts'],
7171
entry: [
7272
'**/*.{bench,test,test-d,spec}.?(c|m)[jt]s?(x)',
73-
'**/__mocks__/**/*.[jt]s?(x)'
73+
'**/__mocks__/**/*.{js,ts,vue}'
7474
]
7575
},
7676
playwright: {

0 commit comments

Comments
 (0)