@@ -39,9 +39,7 @@ type UploadFuncArgs = {
3939 "strip-common-prefix" ?: boolean ;
4040 "no-rewrite" ?: boolean ;
4141 "allow-empty" ?: boolean ;
42- /** Parsed `--wait` limit in milliseconds. */
43- wait ?: number ;
44- "no-wait" ?: boolean ;
42+ wait ?: boolean ;
4543} ;
4644type CmdFunc < A > = ( this : unknown , flags : A , dir : string ) => Promise < unknown > ;
4745
@@ -401,40 +399,34 @@ describe("sourcemap upload command — --allow-empty behavior", () => {
401399 }
402400 } ) ;
403401
404- test . each < [ string , NodeJS . ProcessEnv , UploadFuncArgs , boolean , number ] > ( [
405- [ "outside CI" , { } , { } , false , 300_000 ] ,
406- [ "in CI" , { CI : "true" } , { } , true , 300_000 ] ,
402+ test . each < [ string , NodeJS . ProcessEnv , UploadFuncArgs , boolean ] > ( [
403+ [ "outside CI" , { } , { } , false ] ,
404+ [ "in CI" , { CI : "true" } , { } , true ] ,
407405 [
408406 "in CI with --no-wait" ,
409407 { GITHUB_ACTIONS : "true" } ,
410- { "no- wait" : true } ,
408+ { wait : false } ,
411409 false ,
412- 300_000 ,
413410 ] ,
414- [ "outside CI with --wait" , { } , { wait : 300_000 } , true , 300_000 ] ,
415- [ "outside CI with --wait 30" , { } , { wait : 30_000 } , true , 30_000 ] ,
416- ] ) (
417- "waits for processing %s" ,
418- async ( _name , env , flags , expectedWait , expectedMaxWaitMs ) => {
419- await writeFile ( join ( dir , "app.js" ) , "console.log(1)\n" ) ;
420- await writeFile (
421- join ( dir , "app.js.map" ) ,
422- JSON . stringify ( { version : 3 , sources : [ ] , names : [ ] , mappings : "" } ) ,
423- ) ;
424- const uploadSpy = vi
425- . spyOn ( sourcemapsApi , "uploadSourcemaps" )
426- . mockResolvedValue ( undefined ) ;
427- try {
428- await func . call ( makeContext ( env ) , flags , dir ) ;
429- expect ( uploadSpy . mock . calls [ 0 ] ?. [ 0 ] ) . toMatchObject ( {
430- wait : expectedWait ,
431- maxWaitMs : expectedMaxWaitMs ,
432- } ) ;
433- } finally {
434- uploadSpy . mockRestore ( ) ;
435- }
436- } ,
437- ) ;
411+ [ "outside CI with --wait" , { } , { wait : true } , true ] ,
412+ ] ) ( "waits for processing %s" , async ( _name , env , flags , expectedWait ) => {
413+ await writeFile ( join ( dir , "app.js" ) , "console.log(1)\n" ) ;
414+ await writeFile (
415+ join ( dir , "app.js.map" ) ,
416+ JSON . stringify ( { version : 3 , sources : [ ] , names : [ ] , mappings : "" } ) ,
417+ ) ;
418+ const uploadSpy = vi
419+ . spyOn ( sourcemapsApi , "uploadSourcemaps" )
420+ . mockResolvedValue ( undefined ) ;
421+ try {
422+ await func . call ( makeContext ( env ) , flags , dir ) ;
423+ expect ( uploadSpy . mock . calls [ 0 ] ?. [ 0 ] ) . toMatchObject ( {
424+ wait : expectedWait ,
425+ } ) ;
426+ } finally {
427+ uploadSpy . mockRestore ( ) ;
428+ }
429+ } ) ;
438430
439431 test ( "inline sourcemap: uploads decoded map as a source_map with content" , async ( ) => {
440432 const jsPath = join ( dir , "inline.js" ) ;
@@ -1158,75 +1150,41 @@ describe("sourcemap upload command — waiting for processing", () => {
11581150 expect ( assembleCalls ( ) ) . toBe ( 1 ) ;
11591151 } ) ;
11601152
1161- test ( "rejects --wait with --no-wait" , async ( ) => {
1162- const assembleCalls = serveAssembleStates ( [ { state : "ok" } ] ) ;
1163-
1164- await expect (
1165- func . call ( makeContext ( ) , { wait : 30_000 , "no-wait" : true } , dir ) ,
1166- ) . rejects . toThrow ( "--wait cannot be combined with --no-wait" ) ;
1167- expect ( assembleCalls ( ) ) . toBe ( 0 ) ;
1168- } ) ;
1169-
1170- describe ( "--wait argument" , ( ) => {
1153+ describe ( "flag parsing" , ( ) => {
11711154 const app = buildApplication (
11721155 buildRouteMap ( {
11731156 routes : { upload : uploadCommand } ,
11741157 docs : { brief : "Test app" } ,
11751158 } ) ,
1176- { name : "test" } ,
1159+ // The CLI's scanner style, which `--no-wait` needs.
1160+ { name : "test" , scanner : { caseStyle : "allow-kebab-for-camel" } } ,
11771161 ) ;
11781162
1179- /** Run `upload <argv>` and return the options passed to the uploader. */
1180- async function uploadWith ( argv : string [ ] , env : NodeJS . ProcessEnv = { } ) {
1181- const stderr : string [ ] = [ ] ;
1163+ test . each < [ string [ ] , NodeJS . ProcessEnv , boolean ] > ( [
1164+ [ [ "--wait" ] , { } , true ] ,
1165+ [ [ "--no-wait" ] , { CI : "true" } , false ] ,
1166+ [ [ "--wait" ] , { CI : "true" } , true ] ,
1167+ ] ) ( "%o with env %o waits: %s" , async ( flags , env , expectedWait ) => {
11821168 const uploadSpy = vi
11831169 . spyOn ( sourcemapsApi , "uploadSourcemaps" )
11841170 . mockResolvedValue ( undefined ) ;
11851171 try {
1186- const write = ( s : string ) => {
1187- stderr . push ( s ) ;
1188- return true ;
1189- } ;
1172+ const writer = { write : ( ) => true } ;
11901173 const ctx = {
1191- process : { stdout : { write : ( ) => true } , stderr : { write } } ,
1192- stdout : { write : ( ) => true } ,
1193- stderr : { write } ,
1174+ process : { stdout : writer , stderr : writer } ,
1175+ stdout : writer ,
1176+ stderr : writer ,
11941177 cwd : dir ,
11951178 env,
11961179 } ;
1197- await run ( app , [ "upload" , ... argv ] , ctx as never ) ;
1198- return {
1199- options : uploadSpy . mock . calls [ 0 ] ?. [ 0 ] ,
1200- stderr : stderr . join ( "" ) ,
1201- } ;
1180+ // `--wait` before the directory must not consume it as a value.
1181+ await run ( app , [ "upload" , ... flags , dir ] , ctx as never ) ;
1182+ expect ( uploadSpy . mock . calls [ 0 ] ?. [ 0 ] ) . toMatchObject ( {
1183+ wait : expectedWait ,
1184+ } ) ;
12021185 } finally {
12031186 uploadSpy . mockRestore ( ) ;
12041187 }
1205- }
1206-
1207- test . each < [ string [ ] , number ] > ( [
1208- [ [ "--wait" ] , 300_000 ] ,
1209- [ [ "--wait" , "30" ] , 30_000 ] ,
1210- [ [ "--wait=0" ] , Number . POSITIVE_INFINITY ] ,
1211- ] ) ( "%o waits with limit %d ms" , async ( flags , maxWaitMs ) => {
1212- const { options } = await uploadWith ( [ dir , ...flags ] ) ;
1213- expect ( options ) . toMatchObject ( { wait : true , maxWaitMs } ) ;
1214- } ) ;
1215-
1216- test ( "bare --wait before another flag keeps the default limit" , async ( ) => {
1217- const { options } = await uploadWith ( [ dir , "--wait" , "--allow-empty" ] ) ;
1218- expect ( options ) . toMatchObject ( { wait : true , maxWaitMs : 300_000 } ) ;
1219- } ) ;
1220-
1221- test ( "--no-wait skips waiting in CI" , async ( ) => {
1222- const { options } = await uploadWith ( [ dir , "--no-wait" ] , { CI : "true" } ) ;
1223- expect ( options ) . toMatchObject ( { wait : false } ) ;
1224- } ) ;
1225-
1226- test ( "--wait followed by the directory explains the mix-up" , async ( ) => {
1227- const { options, stderr } = await uploadWith ( [ "--wait" , dir ] ) ;
1228- expect ( options ) . toBeUndefined ( ) ;
1229- expect ( stderr ) . toContain ( "--wait takes a number of seconds" ) ;
12301188 } ) ;
12311189 } ) ;
12321190} ) ;
0 commit comments