@@ -57,6 +57,54 @@ describe("publish", () => {
57
57
expect ( stderr ) . toMatchInlineSnapshot ( `""` ) ;
58
58
expect ( error ) . toMatchInlineSnapshot ( `undefined` ) ;
59
59
} ) ;
60
+
61
+ it ( "should be able to transpile TypeScript" , async ( ) => {
62
+ writeWranglerToml ( ) ;
63
+ writeEsmWorkerSource ( { format : "ts" } ) ;
64
+ mockUploadWorkerRequest ( { expectedBody : "var foo = 100;" } ) ;
65
+ mockSubDomainRequest ( ) ;
66
+
67
+ const { stdout, stderr, error } = await runWrangler (
68
+ "publish " + fs . realpathSync ( "./index.ts" )
69
+ ) ;
70
+
71
+ expect ( stripTimings ( stdout ) ) . toMatchInlineSnapshot ( `
72
+ "Uploaded
73
+ test-name
74
+ (TIMINGS)
75
+ Deployed
76
+ test-name
77
+ (TIMINGS)
78
+
79
+ test-name.test-sub-domain.workers.dev"
80
+ ` ) ;
81
+ expect ( stderr ) . toMatchInlineSnapshot ( `""` ) ;
82
+ expect ( error ) . toMatchInlineSnapshot ( `undefined` ) ;
83
+ } ) ;
84
+
85
+ it ( "should be able to transpile entry-points in sub-directories" , async ( ) => {
86
+ writeWranglerToml ( ) ;
87
+ writeEsmWorkerSource ( { basePath : "./src" } ) ;
88
+ mockUploadWorkerRequest ( { expectedBody : "var foo = 100;" } ) ;
89
+ mockSubDomainRequest ( ) ;
90
+
91
+ const { stdout, stderr, error } = await runWrangler (
92
+ "publish ./src/index.js"
93
+ ) ;
94
+
95
+ expect ( stripTimings ( stdout ) ) . toMatchInlineSnapshot ( `
96
+ "Uploaded
97
+ test-name
98
+ (TIMINGS)
99
+ Deployed
100
+ test-name
101
+ (TIMINGS)
102
+
103
+ test-name.test-sub-domain.workers.dev"
104
+ ` ) ;
105
+ expect ( stderr ) . toMatchInlineSnapshot ( `""` ) ;
106
+ expect ( error ) . toMatchInlineSnapshot ( `undefined` ) ;
107
+ } ) ;
60
108
} ) ;
61
109
62
110
describe ( "asset upload" , ( ) => {
@@ -572,9 +620,15 @@ function writeWranglerToml(
572
620
}
573
621
574
622
/** Write a mock Worker script to disk. */
575
- function writeEsmWorkerSource ( ) {
623
+ function writeEsmWorkerSource ( {
624
+ basePath = "." ,
625
+ format = "js" ,
626
+ } : { basePath ?: string ; format ?: "js" | "ts" } = { } ) {
627
+ if ( basePath !== "." ) {
628
+ fs . mkdirSync ( basePath , { recursive : true } ) ;
629
+ }
576
630
fs . writeFileSync (
577
- " index.js" ,
631
+ ` ${ basePath } / index.${ format } ` ,
578
632
[
579
633
`import { foo } from "./another";` ,
580
634
`export default {` ,
@@ -584,7 +638,7 @@ function writeEsmWorkerSource() {
584
638
`};` ,
585
639
] . join ( "\n" )
586
640
) ;
587
- fs . writeFileSync ( " another.js" , `export const foo = 100;` ) ;
641
+ fs . writeFileSync ( ` ${ basePath } / another.${ format } ` , `export const foo = 100;` ) ;
588
642
}
589
643
590
644
/** Write mock assets to the file system so they can be uploaded. */
@@ -596,14 +650,25 @@ function writeAssets(assets: { filePath: string; content: string }[]) {
596
650
}
597
651
598
652
/** Create a mock handler for the request to upload a worker script. */
599
- function mockUploadWorkerRequest ( available_on_subdomain = true ) {
653
+ function mockUploadWorkerRequest ( {
654
+ available_on_subdomain = true ,
655
+ expectedBody,
656
+ } : {
657
+ available_on_subdomain ?: boolean ;
658
+ expectedBody ?: string ;
659
+ } = { } ) {
600
660
setMockResponse (
601
661
"/accounts/:accountId/workers/scripts/:scriptName" ,
602
662
"PUT" ,
603
- ( [ _url , accountId , scriptName ] , _init , queryParams ) => {
663
+ async ( [ _url , accountId , scriptName ] , { body } , queryParams ) => {
604
664
expect ( accountId ) . toEqual ( "some-account-id" ) ;
605
665
expect ( scriptName ) . toEqual ( "test-name" ) ;
606
666
expect ( queryParams . get ( "available_on_subdomains" ) ) . toEqual ( "true" ) ;
667
+ if ( expectedBody !== undefined ) {
668
+ expect (
669
+ await ( ( body as FormData ) . get ( "index.js" ) as File ) . text ( )
670
+ ) . toMatch ( expectedBody ) ;
671
+ }
607
672
return { available_on_subdomain } ;
608
673
}
609
674
) ;
0 commit comments