@@ -50,7 +50,7 @@ const appTs = `export class MyApp {
5050}
5151` ;
5252
53- const testSetup = ext => `import { BrowserPlatform } from '@aurelia/platform-browser';
53+ const jasmineSetup = ext => `import { BrowserPlatform } from '@aurelia/platform-browser';
5454import { setPlatform, onFixtureCreated${ ext === '.ts' ? ', type IFixture' : '' } } from '@aurelia/testing';
5555
5656// Sets up the Aurelia environment for testing
@@ -80,6 +80,39 @@ afterEach(() => {
8080});
8181` ;
8282
83+ const mochaSetup = ext => `import { BrowserPlatform } from '@aurelia/platform-browser';
84+ import { setPlatform, onFixtureCreated${ ext === '.ts' ? ', type IFixture' : '' } } from '@aurelia/testing';
85+
86+ // Sets up the Aurelia environment for testing
87+ function bootstrapTextEnv() {
88+ const platform = new BrowserPlatform(window);
89+ setPlatform(platform);
90+ BrowserPlatform.set(globalThis, platform);
91+ }
92+
93+ const fixtures${ ext === '.ts' ? ': IFixture<object>[]' : '' } = [];
94+ mocha.setup({
95+ rootHooks: {
96+ beforeAll() {
97+ bootstrapTextEnv();
98+ onFixtureCreated(fixture => {
99+ fixtures.push(fixture);
100+ });
101+ },
102+ afterEach() {
103+ fixtures.forEach(async f => {
104+ try {
105+ await f.stop(true);
106+ } catch {
107+ // ignore
108+ }
109+ });
110+ fixtures.length = 0;
111+ }
112+ }
113+ });
114+ ` ;
115+
83116const jasmineTest = `import { createFixture } from '@aurelia/testing';
84117import { MyApp } from '../src/my-app';
85118
@@ -137,23 +170,26 @@ export default function({transpiler, testFramework}) {
137170 }
138171 ] ;
139172
140- if ( testFramework !== 'none' ) {
141- files . push ( {
142- filename : `test/setup${ ext } ` ,
143- content : testSetup ( ext )
144- } ) ;
145-
146- if ( testFramework === 'jasmine' ) {
147- files . push ( {
173+ if ( testFramework === 'jasmine' ) {
174+ files . push (
175+ {
176+ filename : `test/setup${ ext } ` ,
177+ content : jasmineSetup ( ext )
178+ } , {
148179 filename : `test/app.spec${ ext } ` ,
149180 content : jasmineTest
150- } ) ;
151- } else if ( testFramework === 'mocha' ) {
152- files . push ( {
181+ }
182+ ) ;
183+ } else if ( testFramework === 'mocha' ) {
184+ files . push (
185+ {
186+ filename : `test/setup${ ext } ` ,
187+ content : mochaSetup ( ext )
188+ } , {
153189 filename : `test/app.spec${ ext } ` ,
154190 content : mochaTest
155- } ) ;
156- }
191+ }
192+ ) ;
157193 }
158194
159195 return files ;
0 commit comments