@@ -50,7 +50,7 @@ const appTs = `export class MyApp {
50
50
}
51
51
` ;
52
52
53
- const testSetup = ext => `import { BrowserPlatform } from '@aurelia/platform-browser';
53
+ const jasmineSetup = ext => `import { BrowserPlatform } from '@aurelia/platform-browser';
54
54
import { setPlatform, onFixtureCreated${ ext === '.ts' ? ', type IFixture' : '' } } from '@aurelia/testing';
55
55
56
56
// Sets up the Aurelia environment for testing
@@ -80,6 +80,39 @@ afterEach(() => {
80
80
});
81
81
` ;
82
82
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
+
83
116
const jasmineTest = `import { createFixture } from '@aurelia/testing';
84
117
import { MyApp } from '../src/my-app';
85
118
@@ -137,23 +170,26 @@ export default function({transpiler, testFramework}) {
137
170
}
138
171
] ;
139
172
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
+ } , {
148
179
filename : `test/app.spec${ ext } ` ,
149
180
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
+ } , {
153
189
filename : `test/app.spec${ ext } ` ,
154
190
content : mochaTest
155
- } ) ;
156
- }
191
+ }
192
+ ) ;
157
193
}
158
194
159
195
return files ;
0 commit comments