From 88f374fcb5e423c0fe238f72d592ec2e8ad18c21 Mon Sep 17 00:00:00 2001 From: Chunpeng Huo Date: Sun, 11 Aug 2024 08:18:14 +1000 Subject: [PATCH] chore: cleanup tests --- app-min/test__if_not_no-unit-tests/my-app.spec.ext | 6 ++---- common/test__if_not_no-unit-tests/setup.ext | 8 +++++++- jest/package.json | 1 + parcel/test__if_jasmine_or_mocha/all-spec.ext | 5 ----- .../test__if_not_no-unit-tests/hello-world.spec.ext | 6 ++---- vite/vitest.config.ext__if_vitest | 1 + webpack/test__if_jasmine_or_mocha/all-spec.ext | 8 -------- 7 files changed, 13 insertions(+), 22 deletions(-) delete mode 100644 parcel/test__if_jasmine_or_mocha/all-spec.ext delete mode 100644 webpack/test__if_jasmine_or_mocha/all-spec.ext 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 b0b42cd..4aa5b78 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,17 +3,15 @@ import { describe, it } from 'vitest'; // @endif import { MyApp } from '../src/my-app'; import { createFixture } from '@aurelia/testing'; -import './setup'; describe('my-app', () => { it('should render message', async () => { - const { assertText, startPromise } = createFixture( + const { assertText } = await createFixture( '', {}, [MyApp], - ); + ).started; - 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 20b533f..3748416 100644 --- a/common/test__if_not_no-unit-tests/setup.ext +++ b/common/test__if_not_no-unit-tests/setup.ext @@ -20,6 +20,12 @@ beforeAll(() => { }); afterEach(() => { - fixtures.forEach(f => f.stop(true)); + fixtures.forEach(async f => { + try { + await f.stop(true); + } catch { + // ignore + } + }); fixtures.length = 0; }); diff --git a/jest/package.json b/jest/package.json index 9431f7f..504c1f2 100644 --- a/jest/package.json +++ b/jest/package.json @@ -19,6 +19,7 @@ "/test/**/*.spec./* @if babel */js/* @endif *//* @if typescript */ts/* @endif */" ], "testEnvironment": "jsdom", + "setupFilesAfterEnv": ["./test/setup./* @if babel */js/* @endif *//* @if typescript */ts/* @endif */"], "transform": { "\\.(css|sass|scss|styl|jpg|jpeg|png|gif|eot|otf|webp|svg|ttf|woff|woff2|mp4|webm|wav|mp3|m4a|aac|oga)$": "jest-transform-stub", // @if babel diff --git a/parcel/test__if_jasmine_or_mocha/all-spec.ext b/parcel/test__if_jasmine_or_mocha/all-spec.ext deleted file mode 100644 index 45a143f..0000000 --- a/parcel/test__if_jasmine_or_mocha/all-spec.ext +++ /dev/null @@ -1,5 +0,0 @@ -// @if typescript -// eslint-disable-next-line @typescript-eslint/ban-ts-comment -// @ts-nocheck -// @endif -import './**/*.spec./* @if babel */js/* @endif *//* @if typescript */ts/* @endif */'; 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 a6e8ce4..c2022ac 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,17 +3,15 @@ import { describe, it } from 'vitest'; // @endif import { HelloWorld } from '../src/hello-world'; import { createFixture } from '@aurelia/testing'; -import './setup'; describe('my-app', () => { it('should render message', async () => { - const { assertText, startPromise } = createFixture( + const { assertText } = await createFixture( '', { message: "foo" }, [HelloWorld], - ); + ).started; - 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 1261649..d1c4d0a 100644 --- a/vite/vitest.config.ext__if_vitest +++ b/vite/vitest.config.ext__if_vitest @@ -12,6 +12,7 @@ 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 diff --git a/webpack/test__if_jasmine_or_mocha/all-spec.ext b/webpack/test__if_jasmine_or_mocha/all-spec.ext deleted file mode 100644 index 1e9dbf2..0000000 --- a/webpack/test__if_jasmine_or_mocha/all-spec.ext +++ /dev/null @@ -1,8 +0,0 @@ -// @if typescript -// eslint-disable-next-line @typescript-eslint/ban-ts-comment -// @ts-nocheck -// @endif -function requireAll(requireContext)/* @if typescript */: void/* @endif */ { - requireContext.keys().map(requireContext); -} -requireAll(require.context('./', true, /\.spec\.(js|ts)$/));