From 8baaf380dc06d0360cf12ce3483ca871be5b6f3f Mon Sep 17 00:00:00 2001 From: Chenlei Hu Date: Fri, 1 Nov 2024 22:39:42 -0400 Subject: [PATCH] Split jest tests into fast and slow groups (#1401) --- jest.config.ts => jest.config.base.ts | 11 +++++----- jest.config.fast.ts | 12 ++++++++++ jest.config.slow.ts | 11 ++++++++++ package.json | 4 +++- tests-ui/{ => tests}/afterSetup.ts | 4 ++-- tests-ui/tests/{ => fast}/apiTypes.test.ts | 0 tests-ui/tests/{ => fast}/colorUtil.test.ts | 0 .../tests/{ => fast}/comfyWorkflow.test.ts | 4 ++-- tests-ui/tests/fast/globalSetup.ts | 22 +++++++++++++++++++ tests-ui/tests/{ => fast}/litegraph.test.ts | 0 tests-ui/tests/{ => fast}/nodeDef.test.ts | 0 .../{ => fast}/nodeSearchService.test.ts | 0 .../tests/{ => fast}/store/modelStore.test.ts | 2 ++ .../{ => fast}/store/userFileStore.test.ts | 0 .../{ => fast}/utils/treeUtilTest.test.ts | 0 tests-ui/{ => tests}/globalSetup.ts | 2 +- .../tests/{ => slow}/exampleWorkflows.test.ts | 4 ++-- tests-ui/tests/{ => slow}/extensions.test.ts | 4 ++-- tests-ui/tests/{ => slow}/groupNode.test.ts | 9 ++++---- .../{ => slow}/store/keybindingStore.test.ts | 5 +---- tests-ui/tests/{ => slow}/users.test.ts | 18 +++++++-------- .../tests/{ => slow}/widgetInputs.test.ts | 4 ++-- 22 files changed, 80 insertions(+), 36 deletions(-) rename jest.config.ts => jest.config.base.ts (83%) create mode 100644 jest.config.fast.ts create mode 100644 jest.config.slow.ts rename tests-ui/{ => tests}/afterSetup.ts (90%) rename tests-ui/tests/{ => fast}/apiTypes.test.ts (100%) rename tests-ui/tests/{ => fast}/colorUtil.test.ts (100%) rename tests-ui/tests/{ => fast}/comfyWorkflow.test.ts (96%) create mode 100644 tests-ui/tests/fast/globalSetup.ts rename tests-ui/tests/{ => fast}/litegraph.test.ts (100%) rename tests-ui/tests/{ => fast}/nodeDef.test.ts (100%) rename tests-ui/tests/{ => fast}/nodeSearchService.test.ts (100%) rename tests-ui/tests/{ => fast}/store/modelStore.test.ts (96%) rename tests-ui/tests/{ => fast}/store/userFileStore.test.ts (100%) rename tests-ui/tests/{ => fast}/utils/treeUtilTest.test.ts (100%) rename tests-ui/{ => tests}/globalSetup.ts (97%) rename tests-ui/tests/{ => slow}/exampleWorkflows.test.ts (96%) rename tests-ui/tests/{ => slow}/extensions.test.ts (98%) rename tests-ui/tests/{ => slow}/groupNode.test.ts (99%) rename tests-ui/tests/{ => slow}/store/keybindingStore.test.ts (98%) rename tests-ui/tests/{ => slow}/users.test.ts (94%) rename tests-ui/tests/{ => slow}/widgetInputs.test.ts (99%) diff --git a/jest.config.ts b/jest.config.base.ts similarity index 83% rename from jest.config.ts rename to jest.config.base.ts index 65935392e..7f2ca5b62 100644 --- a/jest.config.ts +++ b/jest.config.base.ts @@ -14,15 +14,14 @@ const jestConfig: JestConfigWithTsJest = { } ] }, - setupFiles: ['./tests-ui/globalSetup.ts'], - setupFilesAfterEnv: ['./tests-ui/afterSetup.ts'], - clearMocks: true, - resetModules: true, - testTimeout: 10000, moduleNameMapper: { '^@/(.*)$': '/src/$1', '\\.(css|less|scss|sass)$': 'identity-obj-proxy' - } + }, + clearMocks: true, + resetModules: true, + setupFiles: ['./tests-ui/tests/globalSetup.ts'], + setupFilesAfterEnv: ['./tests-ui/tests/afterSetup.ts'] } export default jestConfig diff --git a/jest.config.fast.ts b/jest.config.fast.ts new file mode 100644 index 000000000..a75d0a63a --- /dev/null +++ b/jest.config.fast.ts @@ -0,0 +1,12 @@ +import type { JestConfigWithTsJest } from 'ts-jest' +import baseConfig from './jest.config.base' + +const jestConfig: JestConfigWithTsJest = { + ...baseConfig, + displayName: 'fast', + setupFiles: ['./tests-ui/tests/fast/globalSetup.ts'], + setupFilesAfterEnv: undefined, + testMatch: ['**/tests-ui/tests/fast/**/*.test.ts'] +} + +export default jestConfig diff --git a/jest.config.slow.ts b/jest.config.slow.ts new file mode 100644 index 000000000..169d594f5 --- /dev/null +++ b/jest.config.slow.ts @@ -0,0 +1,11 @@ +import type { JestConfigWithTsJest } from 'ts-jest' +import baseConfig from './jest.config.base' + +const jestConfig: JestConfigWithTsJest = { + ...baseConfig, + displayName: 'slow (DOM)', + testTimeout: 10000, + testMatch: ['**/tests-ui/tests/slow/**/*.test.ts'] +} + +export default jestConfig diff --git a/package.json b/package.json index b5f370e92..793844134 100644 --- a/package.json +++ b/package.json @@ -11,7 +11,9 @@ "zipdist": "node scripts/zipdist.js", "typecheck": "tsc --noEmit && tsc-strict", "format": "prettier --write './**/*.{js,ts,tsx,vue}'", - "test": "npm run build && jest", + "test": "jest --config jest.config.base.ts", + "test:jest:fast": "jest --config jest.config.fast.ts", + "test:jest:slow": "jest --config jest.config.slow.ts", "test:generate:examples": "npx tsx tests-ui/extractExamples", "test:generate": "npx tsx tests-ui/setup", "test:browser": "npx playwright test", diff --git a/tests-ui/afterSetup.ts b/tests-ui/tests/afterSetup.ts similarity index 90% rename from tests-ui/afterSetup.ts rename to tests-ui/tests/afterSetup.ts index 279f19e0c..e58966b12 100644 --- a/tests-ui/afterSetup.ts +++ b/tests-ui/tests/afterSetup.ts @@ -1,5 +1,5 @@ -import { start } from './utils' -import lg from './utils/litegraph' +import { start } from '../utils' +import lg from '../utils/litegraph' // Load things once per test file before to ensure its all warmed up for the tests beforeAll(async () => { diff --git a/tests-ui/tests/apiTypes.test.ts b/tests-ui/tests/fast/apiTypes.test.ts similarity index 100% rename from tests-ui/tests/apiTypes.test.ts rename to tests-ui/tests/fast/apiTypes.test.ts diff --git a/tests-ui/tests/colorUtil.test.ts b/tests-ui/tests/fast/colorUtil.test.ts similarity index 100% rename from tests-ui/tests/colorUtil.test.ts rename to tests-ui/tests/fast/colorUtil.test.ts diff --git a/tests-ui/tests/comfyWorkflow.test.ts b/tests-ui/tests/fast/comfyWorkflow.test.ts similarity index 96% rename from tests-ui/tests/comfyWorkflow.test.ts rename to tests-ui/tests/fast/comfyWorkflow.test.ts index 456caec14..4b8666347 100644 --- a/tests-ui/tests/comfyWorkflow.test.ts +++ b/tests-ui/tests/fast/comfyWorkflow.test.ts @@ -1,6 +1,6 @@ // @ts-strict-ignore -import { validateComfyWorkflow } from '../../src/types/comfyWorkflow' -import { defaultGraph } from '../../src/scripts/defaultGraph' +import { validateComfyWorkflow } from '@/types/comfyWorkflow' +import { defaultGraph } from '@/scripts/defaultGraph' import fs from 'fs' const WORKFLOW_DIR = 'tests-ui/workflows' diff --git a/tests-ui/tests/fast/globalSetup.ts b/tests-ui/tests/fast/globalSetup.ts new file mode 100644 index 000000000..c5d89ee96 --- /dev/null +++ b/tests-ui/tests/fast/globalSetup.ts @@ -0,0 +1,22 @@ +module.exports = async function () { + jest.mock('@/services/dialogService', () => { + return { + showLoadWorkflowWarning: jest.fn(), + showMissingModelsWarning: jest.fn(), + showSettingsDialog: jest.fn(), + showExecutionErrorDialog: jest.fn(), + showTemplateWorkflowsDialog: jest.fn(), + showPromptDialog: jest + .fn() + .mockImplementation((message, defaultValue) => { + return Promise.resolve(defaultValue) + }) + } + }) + + jest.mock('vue-i18n', () => { + return { + useI18n: jest.fn() + } + }) +} diff --git a/tests-ui/tests/litegraph.test.ts b/tests-ui/tests/fast/litegraph.test.ts similarity index 100% rename from tests-ui/tests/litegraph.test.ts rename to tests-ui/tests/fast/litegraph.test.ts diff --git a/tests-ui/tests/nodeDef.test.ts b/tests-ui/tests/fast/nodeDef.test.ts similarity index 100% rename from tests-ui/tests/nodeDef.test.ts rename to tests-ui/tests/fast/nodeDef.test.ts diff --git a/tests-ui/tests/nodeSearchService.test.ts b/tests-ui/tests/fast/nodeSearchService.test.ts similarity index 100% rename from tests-ui/tests/nodeSearchService.test.ts rename to tests-ui/tests/fast/nodeSearchService.test.ts diff --git a/tests-ui/tests/store/modelStore.test.ts b/tests-ui/tests/fast/store/modelStore.test.ts similarity index 96% rename from tests-ui/tests/store/modelStore.test.ts rename to tests-ui/tests/fast/store/modelStore.test.ts index db05ad31b..345ba0a39 100644 --- a/tests-ui/tests/store/modelStore.test.ts +++ b/tests-ui/tests/fast/store/modelStore.test.ts @@ -90,7 +90,9 @@ describe('useModelStore', () => { it('should cache model information', async () => { enableMocks() await store.loadModelFolders() + expect(api.getModels).toHaveBeenCalledTimes(0) await store.getLoadedModelFolder('checkpoints') + expect(api.getModels).toHaveBeenCalledTimes(1) await store.getLoadedModelFolder('checkpoints') expect(api.getModels).toHaveBeenCalledTimes(1) }) diff --git a/tests-ui/tests/store/userFileStore.test.ts b/tests-ui/tests/fast/store/userFileStore.test.ts similarity index 100% rename from tests-ui/tests/store/userFileStore.test.ts rename to tests-ui/tests/fast/store/userFileStore.test.ts diff --git a/tests-ui/tests/utils/treeUtilTest.test.ts b/tests-ui/tests/fast/utils/treeUtilTest.test.ts similarity index 100% rename from tests-ui/tests/utils/treeUtilTest.test.ts rename to tests-ui/tests/fast/utils/treeUtilTest.test.ts diff --git a/tests-ui/globalSetup.ts b/tests-ui/tests/globalSetup.ts similarity index 97% rename from tests-ui/globalSetup.ts rename to tests-ui/tests/globalSetup.ts index 9d9c75e9c..5c3f5eb6f 100644 --- a/tests-ui/globalSetup.ts +++ b/tests-ui/tests/globalSetup.ts @@ -6,7 +6,7 @@ module.exports = async function () { disconnect() {} } - const { nop } = require('./utils/nopProxy') + const { nop } = require('../utils/nopProxy') global.enableWebGLCanvas = nop HTMLCanvasElement.prototype.getContext = nop diff --git a/tests-ui/tests/exampleWorkflows.test.ts b/tests-ui/tests/slow/exampleWorkflows.test.ts similarity index 96% rename from tests-ui/tests/exampleWorkflows.test.ts rename to tests-ui/tests/slow/exampleWorkflows.test.ts index 0d1d6a701..b18ad27ff 100644 --- a/tests-ui/tests/exampleWorkflows.test.ts +++ b/tests-ui/tests/slow/exampleWorkflows.test.ts @@ -1,7 +1,7 @@ import { readdirSync, readFileSync } from 'fs' -import lg from '../utils/litegraph' +import lg from '../../utils/litegraph' import path from 'path' -import { start } from '../utils' +import { start } from '../../utils' const WORKFLOW_DIR = 'tests-ui/workflows/examples' diff --git a/tests-ui/tests/extensions.test.ts b/tests-ui/tests/slow/extensions.test.ts similarity index 98% rename from tests-ui/tests/extensions.test.ts rename to tests-ui/tests/slow/extensions.test.ts index 501b10b16..7fdc7b64f 100644 --- a/tests-ui/tests/extensions.test.ts +++ b/tests-ui/tests/slow/extensions.test.ts @@ -1,6 +1,6 @@ // @ts-strict-ignore -import { start } from '../utils' -import lg from '../utils/litegraph' +import { start } from '../../utils' +import lg from '../../utils/litegraph' describe('extensions', () => { beforeEach(() => { diff --git a/tests-ui/tests/groupNode.test.ts b/tests-ui/tests/slow/groupNode.test.ts similarity index 99% rename from tests-ui/tests/groupNode.test.ts rename to tests-ui/tests/slow/groupNode.test.ts index 227d1e1e2..b056406a4 100644 --- a/tests-ui/tests/groupNode.test.ts +++ b/tests-ui/tests/slow/groupNode.test.ts @@ -1,13 +1,12 @@ // @ts-strict-ignore -import { createPinia, setActivePinia } from 'pinia' import { start, createDefaultWorkflow, getNodeDef, checkBeforeAndAfterReload -} from '../utils' -import { EzNode } from '../utils/ezgraph' -import lg from '../utils/litegraph' +} from '../../utils' +import { EzNode } from '../../utils/ezgraph' +import lg from '../../utils/litegraph' describe('group node', () => { beforeEach(() => { @@ -567,7 +566,7 @@ describe('group node', () => { nodes.save ]) - const { api } = await import('../../src/scripts/api') + const { api } = await import('../../../src/scripts/api') api.dispatchEvent(new CustomEvent('execution_start', {})) api.dispatchEvent( diff --git a/tests-ui/tests/store/keybindingStore.test.ts b/tests-ui/tests/slow/store/keybindingStore.test.ts similarity index 98% rename from tests-ui/tests/store/keybindingStore.test.ts rename to tests-ui/tests/slow/store/keybindingStore.test.ts index c54005423..f34985464 100644 --- a/tests-ui/tests/store/keybindingStore.test.ts +++ b/tests-ui/tests/slow/store/keybindingStore.test.ts @@ -1,8 +1,5 @@ import { setActivePinia, createPinia } from 'pinia' -import { - useKeybindingStore, - KeybindingImpl -} from '../../../src/stores/keybindingStore' +import { useKeybindingStore, KeybindingImpl } from '@/stores/keybindingStore' describe('useKeybindingStore', () => { beforeEach(() => { diff --git a/tests-ui/tests/users.test.ts b/tests-ui/tests/slow/users.test.ts similarity index 94% rename from tests-ui/tests/users.test.ts rename to tests-ui/tests/slow/users.test.ts index 0b6f454ea..0a4c5315d 100644 --- a/tests-ui/tests/users.test.ts +++ b/tests-ui/tests/slow/users.test.ts @@ -1,6 +1,6 @@ // @ts-strict-ignore -import { start } from '../utils' -import lg from '../utils/litegraph' +import { start } from '../../utils' +import lg from '../../utils/litegraph' describe('users', () => { beforeEach(() => { @@ -21,14 +21,14 @@ describe('users', () => { describe('multi-user', () => { async function mockAddStylesheet() { - const utils = await import('../../src/scripts/utils') + const utils = await import('../../../src/scripts/utils') utils.addStylesheet = jest.fn().mockReturnValue(Promise.resolve()) } async function waitForUserScreenShow() { // Wait for "show" to be called const { UserSelectionScreen } = await import( - '../../src/scripts/ui/userSelection' + '../../../src/scripts/ui/userSelection' ) let resolve, reject const fn = UserSelectionScreen.prototype.show @@ -91,7 +91,7 @@ describe('users', () => { expect(window.getComputedStyle(menu)?.display).not.toBe('none') // Ensure settings + templates are saved - const { api } = await import('../../src/scripts/api') + const { api } = await import('../../../src/scripts/api') expect(api.createUser).toHaveBeenCalledTimes(+isCreate) expect(api.storeSettings).toHaveBeenCalledTimes(+isCreate) expect(api.storeUserData).toHaveBeenCalledTimes(+isCreate) @@ -234,7 +234,7 @@ describe('users', () => { expectNoUserScreen() // It should store the settings - const { api } = await import('../../src/scripts/api') + const { api } = await import('../../../src/scripts/api') expect(api.storeSettings).toHaveBeenCalledTimes(1) expect(api.storeUserData).toHaveBeenCalledTimes(1) expect(api.storeUserData).toHaveBeenCalledWith( @@ -252,7 +252,7 @@ describe('users', () => { expectNoUserScreen() // It should store the settings - const { api } = await import('../../src/scripts/api') + const { api } = await import('../../../src/scripts/api') expect(api.storeSettings).toHaveBeenCalledTimes(0) expect(api.storeUserData).toHaveBeenCalledTimes(0) expect(app.isNewUserSession).toBeFalsy() @@ -276,7 +276,7 @@ describe('users', () => { expectNoUserScreen() // It should store the settings - const { api } = await import('../../src/scripts/api') + const { api } = await import('../../../src/scripts/api') expect(api.storeSettings).toHaveBeenCalledTimes(0) expect(api.storeUserData).toHaveBeenCalledTimes(0) expect(app.isNewUserSession).toBeFalsy() @@ -289,7 +289,7 @@ describe('users', () => { expectNoUserScreen() // It should store the settings - const { api } = await import('../../src/scripts/api') + const { api } = await import('../../../src/scripts/api') expect(api.storeSettings).toHaveBeenCalledTimes(0) expect(api.storeUserData).toHaveBeenCalledTimes(0) expect(app.isNewUserSession).toBeFalsy() diff --git a/tests-ui/tests/widgetInputs.test.ts b/tests-ui/tests/slow/widgetInputs.test.ts similarity index 99% rename from tests-ui/tests/widgetInputs.test.ts rename to tests-ui/tests/slow/widgetInputs.test.ts index 4ddcae034..be76d221e 100644 --- a/tests-ui/tests/widgetInputs.test.ts +++ b/tests-ui/tests/slow/widgetInputs.test.ts @@ -5,8 +5,8 @@ import { checkBeforeAndAfterReload, assertNotNullOrUndefined, createDefaultWorkflow -} from '../utils' -import lg from '../utils/litegraph' +} from '../../utils' +import lg from '../../utils/litegraph' /** * @typedef { import("../utils/ezgraph") } Ez