@@ -14,6 +14,7 @@ import {
1414 runC3 ,
1515 spawnWithLogging ,
1616 test ,
17+ waitForExit ,
1718} from "./helpers" ;
1819import type { RunnerConfig } from "./helpers" ;
1920import type { Writable } from "stream" ;
@@ -30,12 +31,71 @@ type WorkerTestConfig = RunnerConfig & {
3031
3132function getWorkerTests ( opts : { experimental : boolean } ) : WorkerTestConfig [ ] {
3233 if ( opts . experimental ) {
33- return [ ] ;
34+ return [
35+ {
36+ template : "hello-world-with-assets" ,
37+ variants : [ "ts" , "js" ] ,
38+ verifyDeploy : {
39+ route : "/message" ,
40+ expectedText : "Hello, World!" ,
41+ } ,
42+ // There is no preview script
43+ verifyPreview : null ,
44+ verifyTest : true ,
45+ argv : [ "--category" , "hello-world" ] ,
46+ } ,
47+ {
48+ template : "hello-world-with-assets" ,
49+ variants : [ "python" ] ,
50+ verifyDeploy : {
51+ route : "/message" ,
52+ expectedText : "Hello, World!" ,
53+ } ,
54+ // There is no preview script
55+ verifyPreview : null ,
56+ argv : [ "--category" , "hello-world" ] ,
57+ } ,
58+ {
59+ template : "hello-world-durable-object-with-assets" ,
60+ variants : [ "ts" , "js" ] ,
61+ verifyDeploy : {
62+ route : "/" ,
63+ expectedText : "Hello, World!" ,
64+ } ,
65+ // There is no preview script
66+ verifyPreview : null ,
67+ argv : [ "--category" , "hello-world" ] ,
68+ } ,
69+ {
70+ template : "hello-world-assets-only" ,
71+ variants : [ ] ,
72+ verifyDeploy : {
73+ route : "/" ,
74+ expectedText : "Hello, World!" ,
75+ } ,
76+ // There is no preview script
77+ verifyPreview : null ,
78+ argv : [ "--category" , "hello-world" ] ,
79+ } ,
80+ ] ;
3481 } else {
3582 return [
3683 {
3784 template : "hello-world" ,
38- variants : [ "TypeScript" , "JavaScript" , "Python" ] ,
85+ variants : [ "ts" , "js" ] ,
86+ verifyDeploy : {
87+ route : "/" ,
88+ expectedText : "Hello World!" ,
89+ } ,
90+ verifyPreview : {
91+ route : "/" ,
92+ expectedText : "Hello World!" ,
93+ } ,
94+ verifyTest : true ,
95+ } ,
96+ {
97+ template : "hello-world" ,
98+ variants : [ "python" ] ,
3999 verifyDeploy : {
40100 route : "/" ,
41101 expectedText : "Hello World!" ,
@@ -47,7 +107,7 @@ function getWorkerTests(opts: { experimental: boolean }): WorkerTestConfig[] {
47107 } ,
48108 {
49109 template : "common" ,
50- variants : [ "TypeScript " , "JavaScript " ] ,
110+ variants : [ "ts " , "js " ] ,
51111 verifyDeploy : {
52112 route : "/" ,
53113 expectedText : "Try making requests to:" ,
@@ -59,14 +119,14 @@ function getWorkerTests(opts: { experimental: boolean }): WorkerTestConfig[] {
59119 } ,
60120 {
61121 template : "queues" ,
62- variants : [ "TypeScript " , "JavaScript " ] ,
122+ variants : [ "ts " , "js " ] ,
63123 // Skipped for now, since C3 does not yet support resource creation
64124 verifyDeploy : null ,
65125 verifyPreview : null ,
66126 } ,
67127 {
68128 template : "scheduled" ,
69- variants : [ "TypeScript " , "JavaScript " ] ,
129+ variants : [ "ts " , "js " ] ,
70130 // Skipped for now, since it's not possible to test scheduled events on deployed Workers
71131 verifyDeploy : null ,
72132 verifyPreview : null ,
@@ -92,8 +152,7 @@ const workerTests = getWorkerTests({ experimental });
92152
93153describe
94154 . skipIf (
95- experimental || // skip until we add tests for experimental workers templates
96- getFrameworkToTest ( { experimental } ) ||
155+ getFrameworkToTest ( { experimental } ) ||
97156 isQuarantineMode ( ) ||
98157 process . platform === "win32" ,
99158 )
@@ -109,15 +168,7 @@ describe
109168 return {
110169 ...testConfig ,
111170 name : `${ testConfig . name ?? testConfig . template } -${ variant . toLowerCase ( ) } ` ,
112- promptHandlers : [
113- {
114- matcher : / W h i c h l a n g u a g e d o y o u w a n t t o u s e \? / ,
115- input : {
116- type : "select" ,
117- target : variant ,
118- } ,
119- } ,
120- ] ,
171+ argv : ( testConfig . argv ?? [ ] ) . concat ( "--lang" , variant ) ,
121172 } ;
122173 } )
123174 : [ testConfig ] ,
@@ -137,9 +188,6 @@ describe
137188 // Relevant project files should have been created
138189 expect ( project . path ) . toExist ( ) ;
139190
140- const gitignorePath = join ( project . path , ".gitignore" ) ;
141- expect ( gitignorePath ) . toExist ( ) ;
142-
143191 const pkgJsonPath = join ( project . path , "package.json" ) ;
144192 expect ( pkgJsonPath ) . toExist ( ) ;
145193
@@ -151,22 +199,30 @@ describe
151199
152200 try {
153201 expect ( jsonPath ) . toExist ( ) ;
154- const config = readJSON ( jsonPath ) as { main : string } ;
155- expect ( join ( project . path , config . main ) ) . toExist ( ) ;
156- } catch {
202+ const config = readJSON ( jsonPath ) as { main ?: string } ;
203+ if ( config . main ) {
204+ expect ( join ( project . path , config . main ) ) . toExist ( ) ;
205+ }
206+ } catch ( e ) {
157207 expect ( tomlPath ) . toExist ( ) ;
158- const config = readToml ( tomlPath ) as { main : string } ;
159- expect ( join ( project . path , config . main ) ) . toExist ( ) ;
208+ const config = readToml ( tomlPath ) as { main ?: string } ;
209+ if ( config . main ) {
210+ expect ( join ( project . path , config . main ) ) . toExist ( ) ;
211+ }
160212 }
161213
162- const { verifyDeploy } = testConfig ;
214+ const { verifyDeploy, verifyTest } = testConfig ;
163215 if ( verifyDeploy ) {
164216 if ( deployedUrl ) {
165217 await verifyDeployment ( deployedUrl , verifyDeploy ) ;
166218 } else {
167219 await verifyLocalDev ( testConfig , project . path , logStream ) ;
168220 }
169221 }
222+
223+ if ( verifyTest ) {
224+ await verifyTestScript ( project . path , logStream ) ;
225+ }
170226 } finally {
171227 await deleteWorker ( project . name ) ;
172228 }
@@ -185,6 +241,7 @@ const runCli = async (
185241 projectPath ,
186242 "--type" ,
187243 template ,
244+ ...( experimental ? [ "--experimental" ] : [ ] ) ,
188245 "--no-open" ,
189246 "--no-git" ,
190247 NO_DEPLOY ? "--no-deploy" : "--deploy" ,
@@ -279,3 +336,18 @@ const verifyLocalDev = async (
279336 await sleep ( 1000 ) ;
280337 }
281338} ;
339+
340+ async function verifyTestScript ( projectPath : string , logStream : Writable ) {
341+ const proc = spawnWithLogging (
342+ [ pm , "run" , "test" ] ,
343+ {
344+ cwd : projectPath ,
345+ env : {
346+ VITEST : undefined ,
347+ } ,
348+ } ,
349+ logStream ,
350+ ) ;
351+
352+ return await waitForExit ( proc ) ;
353+ }
0 commit comments