@@ -163,7 +163,7 @@ describe("wrangler", () => {
163
163
const packageJson = JSON . parse (
164
164
fs . readFileSync ( "./package.json" , "utf-8" )
165
165
) ;
166
- expect ( packageJson . name ) . toEqual ( "worker ") ; // TODO: should we infer the name from the directory?
166
+ expect ( packageJson . name ) . toContain ( "wrangler-tests ") ;
167
167
expect ( packageJson . version ) . toEqual ( "0.0.0" ) ;
168
168
expect ( packageJson . devDependencies ) . toEqual ( {
169
169
wrangler : expect . any ( String ) ,
@@ -329,6 +329,76 @@ describe("wrangler", () => {
329
329
expect ( fs . existsSync ( "./src/index.ts" ) ) . toBe ( true ) ;
330
330
} ) ;
331
331
332
+ it ( "should add scripts for a typescript project with .ts extension" , async ( ) => {
333
+ mockConfirm (
334
+ {
335
+ text : "No package.json found. Would you like to create one?" ,
336
+ result : true ,
337
+ } ,
338
+ {
339
+ text : "Would you like to install wrangler into your package.json?" ,
340
+ result : false ,
341
+ } ,
342
+ {
343
+ text : "Would you like to use TypeScript?" ,
344
+ result : true ,
345
+ } ,
346
+ {
347
+ text : "Would you like to create a Worker at src/index.ts?" ,
348
+ result : true ,
349
+ }
350
+ ) ;
351
+ await runWrangler ( "init" ) ;
352
+
353
+ expect ( fs . existsSync ( "./package.json" ) ) . toBe ( true ) ;
354
+ const packageJson = JSON . parse (
355
+ fs . readFileSync ( "./package.json" , "utf-8" )
356
+ ) ;
357
+
358
+ expect ( fs . existsSync ( "./src/index.js" ) ) . toBe ( false ) ;
359
+ expect ( fs . existsSync ( "./src/index.ts" ) ) . toBe ( true ) ;
360
+
361
+ expect ( packageJson . scripts . start ) . toBe ( "wrangler dev src/index.ts" ) ;
362
+ expect ( packageJson . scripts . deploy ) . toBe ( "wrangler publish src/index.ts" ) ;
363
+ expect ( packageJson . name ) . toContain ( "wrangler-tests" ) ;
364
+ expect ( packageJson . version ) . toEqual ( "0.0.0" ) ;
365
+ } ) ;
366
+
367
+ it ( "should add scripts for a non-ts project with .js extension" , async ( ) => {
368
+ mockConfirm (
369
+ {
370
+ text : "No package.json found. Would you like to create one?" ,
371
+ result : true ,
372
+ } ,
373
+ {
374
+ text : "Would you like to install wrangler into your package.json?" ,
375
+ result : false ,
376
+ } ,
377
+ {
378
+ text : "Would you like to use TypeScript?" ,
379
+ result : false ,
380
+ } ,
381
+ {
382
+ text : "Would you like to create a Worker at src/index.js?" ,
383
+ result : true ,
384
+ }
385
+ ) ;
386
+ await runWrangler ( "init" ) ;
387
+
388
+ expect ( fs . existsSync ( "./package.json" ) ) . toBe ( true ) ;
389
+ const packageJson = JSON . parse (
390
+ fs . readFileSync ( "./package.json" , "utf-8" )
391
+ ) ;
392
+
393
+ expect ( fs . existsSync ( "./src/index.js" ) ) . toBe ( true ) ;
394
+ expect ( fs . existsSync ( "./src/index.ts" ) ) . toBe ( false ) ;
395
+
396
+ expect ( packageJson . scripts . start ) . toBe ( "wrangler dev src/index.js" ) ;
397
+ expect ( packageJson . scripts . deploy ) . toBe ( "wrangler publish src/index.js" ) ;
398
+ expect ( packageJson . name ) . toContain ( "wrangler-tests" ) ;
399
+ expect ( packageJson . version ) . toEqual ( "0.0.0" ) ;
400
+ } ) ;
401
+
332
402
it ( "should not offer to create a worker in a non-ts project if a file already exists at the location" , async ( ) => {
333
403
mockConfirm (
334
404
{
0 commit comments