diff --git a/packages/electron-commons/test/electron-node.unit.ts b/packages/electron-commons/test/electron-node.unit.ts index 3d943f486..048cd09a9 100644 --- a/packages/electron-commons/test/electron-node.unit.ts +++ b/packages/electron-commons/test/electron-node.unit.ts @@ -5,7 +5,7 @@ import path from 'node:path'; import type { TopLevelConfig } from '@wixc3/engine-core'; import testFeature, { serverEnv } from '@fixture/disconnecting-env/dist/disconnecting-env.feature.js'; import { setupRunningNodeEnv } from '../test-kit/setup-running-node-env.js'; -import { disposeAfter } from '@wixc3/testing'; +import { Disposables } from '@wixc3/patterns'; const { expect } = chai; chai.use(chaiAsPromised); @@ -28,6 +28,8 @@ const setupRunningEnv = ({ featuresConfig, stdio }: SetupRunningFeatureOptions) }); describe('onDisconnectHandler for node environment initializer', () => { + const disposables = new Disposables(); + afterEach(() => disposables.dispose()); describe('without own uncaughtException handling', () => { it('should catch on dispose of env', async () => { const { dispose, exitPromise } = await setupRunningEnv({ @@ -42,7 +44,8 @@ describe('onDisconnectHandler for node environment initializer', () => { const { exitPromise, dispose } = await setupRunningEnv({ featuresConfig: [testFeature.use({ errorsConfig: { throwError: 'exit' } })], }); - disposeAfter(dispose, { + + disposables.add(dispose, { timeout, name: `env ${testFeature.id}`, }); @@ -53,7 +56,8 @@ describe('onDisconnectHandler for node environment initializer', () => { const { exitPromise, dispose } = await setupRunningEnv({ featuresConfig: [testFeature.use({ errorsConfig: { throwError: 'exception' } })], }); - disposeAfter(dispose, { + + disposables.add(dispose, { timeout, name: `env ${testFeature.id}`, }); @@ -64,7 +68,7 @@ describe('onDisconnectHandler for node environment initializer', () => { const { exitPromise, dispose } = await setupRunningEnv({ featuresConfig: [testFeature.use({ errorsConfig: { throwError: 'promise-reject' } })], }); - disposeAfter(dispose, { + disposables.add(dispose, { timeout, name: `env ${testFeature.id}`, }); @@ -76,7 +80,7 @@ describe('onDisconnectHandler for node environment initializer', () => { featuresConfig: [testFeature.use({ errorsConfig: { throwError: 'exception' } })], stdio: 'pipe', }); - disposeAfter(dispose, { + disposables.add(dispose, { timeout, name: `env ${testFeature.id}`, }); @@ -100,7 +104,7 @@ describe('onDisconnectHandler for node environment initializer', () => { const { exitPromise, dispose } = await setupRunningEnv({ featuresConfig: [testFeature.use({ errorsConfig: { throwError: 'exit', handleUncaught } })], }); - disposeAfter(dispose, { + disposables.add(dispose, { timeout, name: `env ${testFeature.id}`, }); @@ -110,18 +114,17 @@ describe('onDisconnectHandler for node environment initializer', () => { const { exitPromise, dispose } = await setupRunningEnv({ featuresConfig: [testFeature.use({ errorsConfig: { throwError: 'exception', handleUncaught } })], }); - disposeAfter(dispose, { + disposables.add(dispose, { timeout, name: `env ${testFeature.id}`, }); - await expect(exitPromise).to.eventually.deep.eq({ exitCode: 1 }); }); it('should catch on env unhandled promise rejection', async () => { const { exitPromise, dispose } = await setupRunningEnv({ featuresConfig: [testFeature.use({ errorsConfig: { throwError: 'promise-reject', handleUncaught } })], }); - disposeAfter(dispose, { + disposables.add(dispose, { timeout, name: `env ${testFeature.id}`, }); diff --git a/packages/electron-commons/test/worker-thread.unit.ts b/packages/electron-commons/test/worker-thread.unit.ts index 24e5dccb8..4cf42e415 100644 --- a/packages/electron-commons/test/worker-thread.unit.ts +++ b/packages/electron-commons/test/worker-thread.unit.ts @@ -8,7 +8,7 @@ import workerThreadFeature, { serverEnv, type WorkerService, } from '@fixture/worker-thread/dist/worker-thread.feature.js'; -import { disposeAfter } from '@wixc3/testing'; +import { Disposables } from '@wixc3/patterns'; import { expect } from 'chai'; import { setupRunningNodeEnv } from '../test-kit/setup-running-node-env.js'; @@ -24,9 +24,12 @@ const setupRunningEnv = (featureId: string) => const timeout = 3000; describe('workerthread environment type', () => { + const disposables = new Disposables(); + afterEach(() => disposables.dispose()); it('initializes worker, calls API and disposes', async () => { const { dispose, communication } = await setupRunningEnv(workerThreadFeature.id); - disposeAfter(dispose, { + + disposables.add(dispose, { timeout, name: `worker thread ${workerThreadFeature.id}`, }); @@ -42,7 +45,7 @@ describe('workerthread environment type', () => { it('initializes multiple workers, calls API and disposes', async () => { const { dispose, communication } = await setupRunningEnv(`${workerThreadFeature.id}/${multiFeature.id}`); - disposeAfter(dispose, { + disposables.add(dispose, { timeout, name: `worker thread ${workerThreadFeature.id}/${multiFeature.id}`, }); @@ -60,7 +63,7 @@ describe('workerthread environment type', () => { const { dispose, communication } = await setupRunningEnv( `${workerThreadFeature.id}/${contextualMultiPreloadFeature.id}`, ); - disposeAfter(dispose, { + disposables.add(dispose, { timeout, name: `worker thread ${workerThreadFeature.id}/${contextualMultiPreloadFeature.id}`, }); diff --git a/packages/test-kit/src/run-environment.ts b/packages/test-kit/src/run-environment.ts index ee855ee1f..bdf55b8b5 100644 --- a/packages/test-kit/src/run-environment.ts +++ b/packages/test-kit/src/run-environment.ts @@ -1,14 +1,13 @@ import { RuntimeEngine, type AnyEnvironment, type FeatureClass, type Running } from '@wixc3/engine-core'; import { getRunningFeature as originalGetRunningFeature, type RunningFeatureOptions } from '@wixc3/engine-scripts'; -import { disposeAfter } from '@wixc3/testing'; /** * get a running feature with no browser environment - * @param disposeAfterTestTimeout if false, will not dispose the engine after the test + * @param autoDisposeTimeout if false, will not dispose the engine after the test */ export async function getRunningFeature( options: RunningFeatureOptions, - disposeAfterTestTimeout: false | number = 10_000, + autoDisposeTimeout: false | number = 10_000, ): Promise<{ runningApi: Running; engine: RuntimeEngine; @@ -16,10 +15,10 @@ export async function getRunningFeature Promise; }> { const runningFeature = await originalGetRunningFeature(options); - if (disposeAfterTestTimeout) { - disposeAfter(runningFeature.engine.shutdown, { - name: `engine shutdown for ${options.featureName}`, - timeout: disposeAfterTestTimeout, + if (autoDisposeTimeout) { + afterEach(`engine shutdown for ${options.featureName}`, function () { + this.timeout(autoDisposeTimeout); + return runningFeature.engine.shutdown(); }); } diff --git a/packages/test-kit/src/with-local-fixture.ts b/packages/test-kit/src/with-local-fixture.ts index 8ad2d3519..1ad83fcdf 100644 --- a/packages/test-kit/src/with-local-fixture.ts +++ b/packages/test-kit/src/with-local-fixture.ts @@ -18,7 +18,7 @@ export function withLocalFixture(suiteOptions: IWithLocalFixtureOptions) { const { fixturePath = suiteOptions.fixturePath, runOptions = suiteOptions.runOptions } = testOptions; if (runOptions && runOptions.projectPath) { throw new Error( - `runOptions["projectPath"] shouldn't be provided. It will get overriden by returned projectPath.`, + `runOptions["projectPath"] shouldn't be provided. It will get overridden by returned projectPath.`, ); }