From b468cf40cc8b575037f4fee5d5e80e50137c18b1 Mon Sep 17 00:00:00 2001 From: Julian Waller Date: Fri, 11 Oct 2024 14:49:46 +0100 Subject: [PATCH] fix: tests --- apps/app/{jest.config.js => jest.config.cjs} | 2 +- apps/app/package.json | 2 +- apps/app/src/ipc/IPCAPI.ts | 52 ++++++++++---------- apps/app/src/ipc/__tests__/IPCAPI.test.ts | 21 +++++--- apps/app/tsconfig.jest.json | 8 +++ jest.config.base.js => jest.config.base.cjs | 8 ++- package.json | 2 +- yarn.lock | 26 ++-------- 8 files changed, 61 insertions(+), 60 deletions(-) rename apps/app/{jest.config.js => jest.config.cjs} (75%) create mode 100644 apps/app/tsconfig.jest.json rename jest.config.base.js => jest.config.base.cjs (70%) diff --git a/apps/app/jest.config.js b/apps/app/jest.config.cjs similarity index 75% rename from apps/app/jest.config.js rename to apps/app/jest.config.cjs index a192bf3e..81d0c323 100644 --- a/apps/app/jest.config.js +++ b/apps/app/jest.config.cjs @@ -1,5 +1,5 @@ // eslint-disable-next-line n/no-unpublished-require -const base = require('../../jest.config.base') +const base = require('../../jest.config.base.cjs') const packageJson = require('./package') module.exports = { diff --git a/apps/app/package.json b/apps/app/package.json index a5ff4dbc..16b19fb3 100644 --- a/apps/app/package.json +++ b/apps/app/package.json @@ -16,7 +16,7 @@ "react:dev": "vite", "electron:dev": "nodemon", "dev": "concurrently --kill-others \"yarn react:dev\" \"yarn electron:dev\"", - "test": "jest" + "test": "node --experimental-vm-modules ../../node_modules/jest/bin/jest.js" }, "repository": { "type": "git", diff --git a/apps/app/src/ipc/IPCAPI.ts b/apps/app/src/ipc/IPCAPI.ts index 650a2a82..e573f56c 100644 --- a/apps/app/src/ipc/IPCAPI.ts +++ b/apps/app/src/ipc/IPCAPI.ts @@ -1,29 +1,29 @@ -import { PartialDeep } from 'type-fest' -import { BridgeStatus } from '../models/project/Bridge.js' -import { Project, SerializableLedger } from '../models/project/Project.js' -import { ResourceAny, ResourceId, MetadataAny, SerializedProtectedMap, TSRDeviceId } from '@shared/models' -import { Rundown } from '../models/rundown/Rundown.js' -import { TimelineObj } from '../models/rundown/TimelineObj.js' -import { Part } from '../models/rundown/Part.js' -import { Group } from '../models/rundown/Group.js' -import { AppData } from '../models/App/AppData.js' -import { PeripheralArea, PeripheralStatus } from '../models/project/Peripheral.js' -import { ActiveTrigger, ActiveTriggers, ApplicationTrigger, RundownTrigger } from '../models/rundown/Trigger.js' -import { BridgeId, LogLevel, PeripheralId } from '@shared/api' -import { MoveTarget } from '../lib/util.js' -import { CurrentSelectionAny } from '../lib/GUI.js' -import { ActiveAnalog } from '../models/rundown/Analog.js' -import { AnalogInput } from '../models/project/AnalogInput.js' -import { ValidatorCache } from 'graphics-data-definition' -import { BridgePeripheralId } from '@shared/lib' -import { DefiningArea } from '../lib/triggers/keyDisplay/keyDisplay.js' -import { type EverythingService } from '../electron/EverythingService.js' -import { type PartService } from '../electron/api/PartService.js' -import { type ProjectService } from '../electron/api/ProjectService.js' -import { type ReportingService } from '../electron/api/ReportingService.js' -import { type RundownService } from '../electron/api/RundownService.js' -import { type GroupService } from '../electron/api/GroupService.js' -import { type SpecialLedgers } from '../models/project/Project.js' +import type { PartialDeep } from 'type-fest' +import type { BridgeStatus } from '../models/project/Bridge.js' +import type { Project, SerializableLedger } from '../models/project/Project.js' +import type { ResourceAny, ResourceId, MetadataAny, SerializedProtectedMap, TSRDeviceId } from '@shared/models' +import type { Rundown } from '../models/rundown/Rundown.js' +import type { TimelineObj } from '../models/rundown/TimelineObj.js' +import type { Part } from '../models/rundown/Part.js' +import type { Group } from '../models/rundown/Group.js' +import type { AppData } from '../models/App/AppData.js' +import type { PeripheralArea, PeripheralStatus } from '../models/project/Peripheral.js' +import type { ActiveTrigger, ActiveTriggers, ApplicationTrigger, RundownTrigger } from '../models/rundown/Trigger.js' +import type { BridgeId, LogLevel, PeripheralId } from '@shared/api' +import type { MoveTarget } from '../lib/util.js' +import type { CurrentSelectionAny } from '../lib/GUI.js' +import type { ActiveAnalog } from '../models/rundown/Analog.js' +import type { AnalogInput } from '../models/project/AnalogInput.js' +import type { ValidatorCache } from 'graphics-data-definition' +import type { BridgePeripheralId } from '@shared/lib' +import type { DefiningArea } from '../lib/triggers/keyDisplay/keyDisplay.js' +import type { EverythingService } from '../electron/EverythingService.js' +import type { PartService } from '../electron/api/PartService.js' +import type { ProjectService } from '../electron/api/ProjectService.js' +import type { ReportingService } from '../electron/api/ReportingService.js' +import type { RundownService } from '../electron/api/RundownService.js' +import type { GroupService } from '../electron/api/GroupService.js' +import type { SpecialLedgers } from '../models/project/Project.js' export enum ServiceName { GROUPS = 'groups', diff --git a/apps/app/src/ipc/__tests__/IPCAPI.test.ts b/apps/app/src/ipc/__tests__/IPCAPI.test.ts index 864346e6..80440b8e 100644 --- a/apps/app/src/ipc/__tests__/IPCAPI.test.ts +++ b/apps/app/src/ipc/__tests__/IPCAPI.test.ts @@ -1,11 +1,18 @@ import { ClientMethods, ServiceName, ServiceTypes } from '../IPCAPI' +import { jest } from '@jest/globals' -import { EverythingService } from '../../electron/EverythingService' -import { PartService } from '../../electron/api/PartService' -import { ProjectService } from '../../electron/api/ProjectService' -import { ReportingService } from '../../electron/api/ReportingService' -import { RundownService } from '../../electron/api/RundownService' -import { GroupService } from '../../electron/api/GroupService' +// Mock electron as it doesn't provide sensible exports during tests +jest.unstable_mockModule('electron', () => ({ + dialog: null, +})) + +// Delay import after the mock ahs been setup +const { EverythingService } = await import('../../electron/EverythingService') +const { PartService } = await import('../../electron/api/PartService') +const { ProjectService } = await import('../../electron/api/ProjectService') +const { ReportingService } = await import('../../electron/api/ReportingService') +const { RundownService } = await import('../../electron/api/RundownService') +const { GroupService } = await import('../../electron/api/GroupService') describe('ClientMethods', () => { const services: ServiceTypes = { @@ -47,7 +54,7 @@ describe('ClientMethods', () => { for (const method of clientMethods) { if (typeof serviceMethods[method] !== 'function') { - nonexistantMethods.push(`${serviceType}.${method}`) + nonexistantMethods.push(`${serviceType}.${String(method)}`) } } } diff --git a/apps/app/tsconfig.jest.json b/apps/app/tsconfig.jest.json new file mode 100644 index 00000000..a435ca25 --- /dev/null +++ b/apps/app/tsconfig.jest.json @@ -0,0 +1,8 @@ +{ + "extends": "./tsconfig.json", + "compilerOptions": { + "types": ["node", "jest"] + }, + "include": ["src/**/*"], + "exclude": ["dist"] +} diff --git a/jest.config.base.js b/jest.config.base.cjs similarity index 70% rename from jest.config.base.js rename to jest.config.base.cjs index 017f5337..5de840d9 100644 --- a/jest.config.base.js +++ b/jest.config.base.cjs @@ -1,13 +1,19 @@ +/** @type {import('ts-jest').JestConfigWithTsJest} */ module.exports = { roots: ['/src'], projects: [''], preset: 'ts-jest', moduleFileExtensions: ['js', 'ts'], + extensionsToTreatAsEsm: ['.ts'], + moduleNameMapper: { + '^(\\.{1,2}/.*)\\.js$': '$1', + }, transform: { '^.+\\.(ts|tsx)$': [ 'ts-jest', { - tsconfig: 'tsconfig.json', + tsconfig: 'tsconfig.jest.json', + useESM: true, }, ], }, diff --git a/package.json b/package.json index 90a9351a..e0f124d8 100644 --- a/package.json +++ b/package.json @@ -67,7 +67,7 @@ "rimraf": "^6.0.1", "shelljs": "^0.8.5", "ts-jest": "^29.2.5", - "typescript": "~5.1" + "typescript": "~5.6.3" }, "lint-staged": { "*.{css,json,md,scss}": [ diff --git a/yarn.lock b/yarn.lock index 0e218c1f..04d0c347 100644 --- a/yarn.lock +++ b/yarn.lock @@ -14159,7 +14159,7 @@ asn1@evs-broadcast/node-asn1: rimraf: "npm:^6.0.1" shelljs: "npm:^0.8.5" ts-jest: "npm:^29.2.5" - typescript: "npm:~5.1" + typescript: "npm:~5.6.3" languageName: unknown linkType: soft @@ -14948,7 +14948,7 @@ asn1@evs-broadcast/node-asn1: languageName: node linkType: hard -"typescript@npm:>=3 < 6, typescript@npm:^5.3.3": +"typescript@npm:>=3 < 6, typescript@npm:^5.3.3, typescript@npm:~5.6.3": version: 5.6.3 resolution: "typescript@npm:5.6.3" bin: @@ -14958,17 +14958,7 @@ asn1@evs-broadcast/node-asn1: languageName: node linkType: hard -"typescript@npm:~5.1": - version: 5.1.6 - resolution: "typescript@npm:5.1.6" - bin: - tsc: bin/tsc - tsserver: bin/tsserver - checksum: 10c0/45ac28e2df8365fd28dac42f5d62edfe69a7203d5ec646732cadc04065331f34f9078f81f150fde42ed9754eed6fa3b06a8f3523c40b821e557b727f1992e025 - languageName: node - linkType: hard - -"typescript@patch:typescript@npm%3A>=3 < 6#optional!builtin, typescript@patch:typescript@npm%3A^5.3.3#optional!builtin": +"typescript@patch:typescript@npm%3A>=3 < 6#optional!builtin, typescript@patch:typescript@npm%3A^5.3.3#optional!builtin, typescript@patch:typescript@npm%3A~5.6.3#optional!builtin": version: 5.6.3 resolution: "typescript@patch:typescript@npm%3A5.6.3#optional!builtin::version=5.6.3&hash=8c6c40" bin: @@ -14978,16 +14968,6 @@ asn1@evs-broadcast/node-asn1: languageName: node linkType: hard -"typescript@patch:typescript@npm%3A~5.1#optional!builtin": - version: 5.1.6 - resolution: "typescript@patch:typescript@npm%3A5.1.6#optional!builtin::version=5.1.6&hash=5da071" - bin: - tsc: bin/tsc - tsserver: bin/tsserver - checksum: 10c0/c2bded58ab897a8341fdbb0c1d92ea2362f498cfffebdc8a529d03e15ea2454142dfbf122dabbd9a5cb79b7123790d27def16e11844887d20636226773ed329a - languageName: node - linkType: hard - "uglify-js@npm:^3.1.4": version: 3.14.5 resolution: "uglify-js@npm:3.14.5"