Skip to content

Commit

Permalink
chore: cleanup tests
Browse files Browse the repository at this point in the history
  • Loading branch information
3cp committed Aug 10, 2024
1 parent cafdcca commit 4cb5367
Show file tree
Hide file tree
Showing 4 changed files with 26 additions and 34 deletions.
16 changes: 4 additions & 12 deletions app-min/test__if_not_no-unit-tests/my-app.spec.ext
Original file line number Diff line number Diff line change
Expand Up @@ -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(
'<my-app></my-app>',
{},
[MyApp],
);

try {
await startPromise;
assertText('Hello World!', { compact: true });
} finally {
await stop(true);
}
await startPromise;
assertText('Hello World!', { compact: true });
});
});
27 changes: 18 additions & 9 deletions common/test__if_not_no-unit-tests/setup.ext
Original file line number Diff line number Diff line change
@@ -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<object>[]/* @endif */ = [];
beforeAll(() => {
bootstrapTextEnv();
onFixtureCreated(fixture => {
fixtures.push(fixture);
});
});

afterEach(() => {
fixtures.forEach(f => f.stop(true));
fixtures.length = 0;
});
16 changes: 4 additions & 12 deletions plugin-min/test__if_not_no-unit-tests/hello-world.spec.ext
Original file line number Diff line number Diff line change
Expand Up @@ -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(
'<hello-world message="message"></hello-world>',
{ message: "foo" },
[HelloWorld],
);

try {
await startPromise;
assertText('Hello World! foo', { compact: true });
} finally {
await stop(true);
}
await startPromise;
assertText('Hello World! foo', { compact: true });
});
});
1 change: 0 additions & 1 deletion vite/vitest.config.ext__if_vitest
Original file line number Diff line number Diff line change
Expand Up @@ -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 */']
},
}),
);

0 comments on commit 4cb5367

Please sign in to comment.