@@ -4,7 +4,7 @@ type Dependencies = {
4
4
[ key : string ] : {
5
5
version : string ;
6
6
type ?: 'DEV' | 'PEER' ;
7
- reliesOn ?: string ;
7
+ reliesOn ?: string | string [ ] ;
8
8
}
9
9
}
10
10
@@ -126,7 +126,9 @@ abstract class Adder {
126
126
}
127
127
128
128
action . if ( ( ) => dependencyConfig . reliesOn
129
- ? this . getConfiguration ( dependencyConfig . reliesOn )
129
+ ? Array . isArray ( dependencyConfig . reliesOn )
130
+ ? dependencyConfig . reliesOn . every ( Boolean )
131
+ : this . getConfiguration ( dependencyConfig . reliesOn )
130
132
: true
131
133
) ;
132
134
} ) ;
@@ -158,7 +160,8 @@ class SvelteJestAdder extends Adder {
158
160
protected readonly CONFIGURATION : Configuration = {
159
161
'jest-dom' : { message : 'Enable Jest DOM support?' , default : true , question : true } ,
160
162
'ts' : { message : 'Enable TypeScript support?' , default : false , question : true } ,
161
- 'examples' : { message : 'Generate example test file?' , default : true , question : true }
163
+ 'examples' : { message : 'Generate example test file?' , default : true , question : true } ,
164
+ 'jsdom' : { message : 'Enable JSDOM environment by default?' , default : true , question : true }
162
165
} ;
163
166
164
167
protected readonly REQUIRED_DEPENDENCIES : Dependencies = {
@@ -171,7 +174,7 @@ class SvelteJestAdder extends Adder {
171
174
'@testing-library/jest-dom' : { version : '^5.14.0' , type : 'DEV' , reliesOn : 'jest-dom' } ,
172
175
'ts-jest' : { version : '^27.0.0' , type : 'DEV' , reliesOn : 'ts' } ,
173
176
'@types/jest' : { version : '^27.0.0' , type : 'DEV' , reliesOn : 'ts' } ,
174
- '@types/testing-library__jest-dom' : { version : '^5.14.0' , type : 'DEV' , reliesOn : 'ts' }
177
+ '@types/testing-library__jest-dom' : { version : '^5.14.0' , type : 'DEV' , reliesOn : [ 'ts' , 'jest-dom' ] }
175
178
} ;
176
179
177
180
run ( ) : void {
@@ -197,33 +200,50 @@ class SvelteJestAdder extends Adder {
197
200
Preset
198
201
. editJson ( 'jest.config.json' ) . merge ( {
199
202
transform : {
200
- '^.+\\.svelte$' : [ 'svelte-jester' , { preprocess : true } ] ,
203
+ '^.+\\.svelte$' : [ './node_modules/ svelte-jester/dist/transformer.mjs ' , { preprocess : true } ] ,
201
204
'^.+\\.ts$' : 'ts-jest'
202
205
} ,
203
- moduleFileExtensions : [ 'js' , 'ts' , 'svelte' ] ,
206
+ moduleFileExtensions : [ 'ts' ] ,
207
+ extensionsToTreatAsEsm : [ '.ts' ] ,
204
208
globals : {
205
209
'ts-jest' : {
206
- tsconfig : 'tsconfig.spec.json'
210
+ tsconfig : 'tsconfig.spec.json' ,
211
+ 'useESM' : true
207
212
}
208
213
}
209
214
} )
210
215
. withTitle ( 'Modifying Jest config for TypeScript transformation' )
211
216
. if ( ( ) => this . getConfiguration ( 'ts' ) ) ;
212
217
218
+ Preset
219
+ . editJson ( 'jest.config.json' ) . merge ( {
220
+ testEnvironment : 'jsdom'
221
+ } )
222
+ . withTitle ( 'Modifying Jest config to enable JSDOM environment' )
223
+ . if ( ( ) => this . getConfiguration ( 'jsdom' ) ) ;
224
+
213
225
this . safeExtract ( 'Initializing TypeScript config for tests' , 'tsconfig.spec.json' )
214
226
. if ( ( ) => this . getConfiguration ( 'ts' ) ) ;
215
227
228
+ this . safeExtract ( 'Initializing example test file' , 'index.spec.ts' )
229
+ . to ( 'src/routes/' )
230
+ . if ( ( ) => this . getConfiguration ( 'examples' ) && this . getConfiguration ( 'ts' ) && ! this . getConfiguration ( 'jest-dom' ) ) ;
231
+
216
232
this . safeExtract ( 'Initializing example test file' , 'index.spec.js' )
217
233
. to ( 'src/routes/' )
218
- . if ( ( ) => this . getConfiguration ( 'examples' ) && this . getConfiguration ( 'jest-dom ' ) && ! this . getConfiguration ( 'ts ' ) ) ;
234
+ . if ( ( ) => this . getConfiguration ( 'examples' ) && ! this . getConfiguration ( 'ts ' ) && ! this . getConfiguration ( 'jest-dom ' ) ) ;
219
235
220
- this . safeExtract ( 'Initializing example test file' , 'index.spec.ts' )
236
+ this . safeExtract ( 'Initializing example test file' , 'index-dom.spec.ts' )
237
+ . to ( 'src/routes/' )
238
+ . if ( ( ) => this . getConfiguration ( 'examples' ) && this . getConfiguration ( 'ts' ) && this . getConfiguration ( 'jest-dom' ) ) ;
239
+
240
+ this . safeExtract ( 'Initializing example test file' , 'index-dom.spec.js' )
221
241
. to ( 'src/routes/' )
222
- . if ( ( ) => this . getConfiguration ( 'examples' ) && this . getConfiguration ( 'jest-dom ' ) && this . getConfiguration ( 'ts ' ) ) ;
242
+ . if ( ( ) => this . getConfiguration ( 'examples' ) && ! this . getConfiguration ( 'ts ' ) && this . getConfiguration ( 'jest-dom ' ) ) ;
223
243
224
244
Preset
225
245
. editJson ( 'package.json' )
226
- . merge ( { scripts : { 'test' : 'jest src --config jest.config.json' , 'test:watch' : 'npm run test -- --watch' } } )
246
+ . merge ( { scripts : { 'test' : 'NODE_OPTIONS=--experimental-vm-modules jest src --config jest.config.json' , 'test:watch' : 'npm run test -- --watch' } } )
227
247
. withTitle ( 'Adding test scripts to package.json' ) ;
228
248
229
249
Preset
0 commit comments