diff --git a/app-min/test__if_not_no-unit-tests/my-app.spec.ext b/app-min/test__if_not_no-unit-tests/my-app.spec.ext index 8bb0597..b0b42cd 100644 --- a/app-min/test__if_not_no-unit-tests/my-app.spec.ext +++ b/app-min/test__if_not_no-unit-tests/my-app.spec.ext @@ -3,25 +3,17 @@ import { describe, it } from 'vitest'; // @endif import { MyApp } from '../src/my-app'; import { createFixture } from '@aurelia/testing'; -// @if jest -import { bootstrapTestEnvironment } from './setup'; - -beforeAll(bootstrapTestEnvironment); -// @endif +import './setup'; describe('my-app', () => { it('should render message', async () => { - const { assertText, startPromise, stop } = createFixture( + const { assertText, startPromise } = createFixture( '', {}, [MyApp], ); - try { - await startPromise; - assertText('Hello World!', { compact: true }); - } finally { - await stop(true); - } + await startPromise; + assertText('Hello World!', { compact: true }); }); }); diff --git a/common/test__if_not_no-unit-tests/setup.ext b/common/test__if_not_no-unit-tests/setup.ext index d4f84d2..20b533f 100644 --- a/common/test__if_not_no-unit-tests/setup.ext +++ b/common/test__if_not_no-unit-tests/setup.ext @@ -1,16 +1,25 @@ import { BrowserPlatform } from '@aurelia/platform-browser'; -import { setPlatform } from '@aurelia/testing'; - -// Sets up the Aurelia environment for testing +import { setPlatform, onFixtureCreated/* @if typescript */, type IFixture/* @endif */ } from '@aurelia/testing'; // @if vitest -const platform = new BrowserPlatform(window); -setPlatform(platform); -BrowserPlatform.set(globalThis, platform); +import { beforeAll, afterEach } from 'vitest'; // @endif -// @if jest -export function bootstrapTestEnvironment() { + +// Sets up the Aurelia environment for testing +function bootstrapTextEnv() { const platform = new BrowserPlatform(window); setPlatform(platform); BrowserPlatform.set(globalThis, platform); } -// @endif + +const fixtures/* @if typescript */: IFixture[]/* @endif */ = []; +beforeAll(() => { + bootstrapTextEnv(); + onFixtureCreated(fixture => { + fixtures.push(fixture); + }); +}); + +afterEach(() => { + fixtures.forEach(f => f.stop(true)); + fixtures.length = 0; +}); diff --git a/plugin-min/test__if_not_no-unit-tests/hello-world.spec.ext b/plugin-min/test__if_not_no-unit-tests/hello-world.spec.ext index ebf63a2..a6e8ce4 100644 --- a/plugin-min/test__if_not_no-unit-tests/hello-world.spec.ext +++ b/plugin-min/test__if_not_no-unit-tests/hello-world.spec.ext @@ -3,25 +3,17 @@ import { describe, it } from 'vitest'; // @endif import { HelloWorld } from '../src/hello-world'; import { createFixture } from '@aurelia/testing'; -// @if jest -import { bootstrapTestEnvironment } from './setup'; - -beforeAll(bootstrapTestEnvironment); -// @endif +import './setup'; describe('my-app', () => { it('should render message', async () => { - const { assertText, startPromise, stop } = createFixture( + const { assertText, startPromise } = createFixture( '', { message: "foo" }, [HelloWorld], ); - try { - await startPromise; - assertText('Hello World! foo', { compact: true }); - } finally { - await stop(true); - } + await startPromise; + assertText('Hello World! foo', { compact: true }); }); }); diff --git a/vite/vitest.config.ext__if_vitest b/vite/vitest.config.ext__if_vitest index 4639a1d..1261649 100644 --- a/vite/vitest.config.ext__if_vitest +++ b/vite/vitest.config.ext__if_vitest @@ -12,7 +12,6 @@ export default mergeConfig( exclude: [...configDefaults.exclude, "e2e/*"], // @endif root: fileURLToPath(new URL("./", import.meta.url)), - setupFiles: ['./test/setup./* @if babel */js/* @endif *//* @if typescript */ts/* @endif */'] }, }), ); \ No newline at end of file