@@ -41,7 +41,9 @@ const testEnvVars = {
41
41
42
42
// File Commands
43
43
GITHUB_PATH : '' ,
44
- GITHUB_ENV : ''
44
+ GITHUB_ENV : '' ,
45
+ GITHUB_OUTPUT : '' ,
46
+ GITHUB_STATE : ''
45
47
}
46
48
47
49
const UUID = '9b1deb4d-3b7d-4bad-9bdd-2b0d7b3dcb6d'
@@ -283,24 +285,82 @@ describe('@actions/core', () => {
283
285
) . toEqual ( [ ' val1 ' , ' val2 ' , ' ' ] )
284
286
} )
285
287
286
- it ( 'setOutput produces the correct command' , ( ) => {
288
+ it ( 'legacy setOutput produces the correct command' , ( ) => {
287
289
core . setOutput ( 'some output' , 'some value' )
288
290
assertWriteCalls ( [
289
291
os . EOL ,
290
292
`::set-output name=some output::some value${ os . EOL } `
291
293
] )
292
294
} )
293
295
294
- it ( 'setOutput handles bools' , ( ) => {
296
+ it ( 'legacy setOutput handles bools' , ( ) => {
295
297
core . setOutput ( 'some output' , false )
296
298
assertWriteCalls ( [ os . EOL , `::set-output name=some output::false${ os . EOL } ` ] )
297
299
} )
298
300
299
- it ( 'setOutput handles numbers' , ( ) => {
301
+ it ( 'legacy setOutput handles numbers' , ( ) => {
300
302
core . setOutput ( 'some output' , 1.01 )
301
303
assertWriteCalls ( [ os . EOL , `::set-output name=some output::1.01${ os . EOL } ` ] )
302
304
} )
303
305
306
+ it ( 'setOutput produces the correct command and sets the output' , ( ) => {
307
+ const command = 'OUTPUT'
308
+ createFileCommandFile ( command )
309
+ core . setOutput ( 'my out' , 'out val' )
310
+ verifyFileCommand (
311
+ command ,
312
+ `my out<<${ DELIMITER } ${ os . EOL } out val${ os . EOL } ${ DELIMITER } ${ os . EOL } `
313
+ )
314
+ } )
315
+
316
+ it ( 'setOutput handles boolean inputs' , ( ) => {
317
+ const command = 'OUTPUT'
318
+ createFileCommandFile ( command )
319
+ core . setOutput ( 'my out' , true )
320
+ verifyFileCommand (
321
+ command ,
322
+ `my out<<${ DELIMITER } ${ os . EOL } true${ os . EOL } ${ DELIMITER } ${ os . EOL } `
323
+ )
324
+ } )
325
+
326
+ it ( 'setOutput handles number inputs' , ( ) => {
327
+ const command = 'OUTPUT'
328
+ createFileCommandFile ( command )
329
+ core . setOutput ( 'my out' , 5 )
330
+ verifyFileCommand (
331
+ command ,
332
+ `my out<<${ DELIMITER } ${ os . EOL } 5${ os . EOL } ${ DELIMITER } ${ os . EOL } `
333
+ )
334
+ } )
335
+
336
+ it ( 'setOutput does not allow delimiter as value' , ( ) => {
337
+ const command = 'OUTPUT'
338
+ createFileCommandFile ( command )
339
+
340
+ expect ( ( ) => {
341
+ core . setOutput ( 'my out' , `good stuff ${ DELIMITER } bad stuff` )
342
+ } ) . toThrow (
343
+ `Unexpected input: value should not contain the delimiter "${ DELIMITER } "`
344
+ )
345
+
346
+ const filePath = path . join ( __dirname , `test/${ command } ` )
347
+ fs . unlinkSync ( filePath )
348
+ } )
349
+
350
+ it ( 'setOutput does not allow delimiter as name' , ( ) => {
351
+ const command = 'OUTPUT'
352
+ createFileCommandFile ( command )
353
+
354
+ expect ( ( ) => {
355
+ core . setOutput ( `good stuff ${ DELIMITER } bad stuff` , 'test' )
356
+ } ) . toThrow (
357
+ `Unexpected input: name should not contain the delimiter "${ DELIMITER } "`
358
+ )
359
+
360
+ const filePath = path . join ( __dirname , `test/${ command } ` )
361
+ fs . unlinkSync ( filePath )
362
+ } )
363
+
304
364
it ( 'setFailed sets the correct exit code and failure message' , ( ) => {
305
365
core . setFailed ( 'Failure message' )
306
366
expect ( process . exitCode ) . toBe ( core . ExitCode . Failure )
@@ -466,21 +526,79 @@ describe('@actions/core', () => {
466
526
assertWriteCalls ( [ `::debug::%0D%0Adebug%0A${ os . EOL } ` ] )
467
527
} )
468
528
469
- it ( 'saveState produces the correct command' , ( ) => {
529
+ it ( 'legacy saveState produces the correct command' , ( ) => {
470
530
core . saveState ( 'state_1' , 'some value' )
471
531
assertWriteCalls ( [ `::save-state name=state_1::some value${ os . EOL } ` ] )
472
532
} )
473
533
474
- it ( 'saveState handles numbers' , ( ) => {
534
+ it ( 'legacy saveState handles numbers' , ( ) => {
475
535
core . saveState ( 'state_1' , 1 )
476
536
assertWriteCalls ( [ `::save-state name=state_1::1${ os . EOL } ` ] )
477
537
} )
478
538
479
- it ( 'saveState handles bools' , ( ) => {
539
+ it ( 'legacy saveState handles bools' , ( ) => {
480
540
core . saveState ( 'state_1' , true )
481
541
assertWriteCalls ( [ `::save-state name=state_1::true${ os . EOL } ` ] )
482
542
} )
483
543
544
+ it ( 'saveState produces the correct command and saves the state' , ( ) => {
545
+ const command = 'STATE'
546
+ createFileCommandFile ( command )
547
+ core . saveState ( 'my state' , 'out val' )
548
+ verifyFileCommand (
549
+ command ,
550
+ `my state<<${ DELIMITER } ${ os . EOL } out val${ os . EOL } ${ DELIMITER } ${ os . EOL } `
551
+ )
552
+ } )
553
+
554
+ it ( 'saveState handles boolean inputs' , ( ) => {
555
+ const command = 'STATE'
556
+ createFileCommandFile ( command )
557
+ core . saveState ( 'my state' , true )
558
+ verifyFileCommand (
559
+ command ,
560
+ `my state<<${ DELIMITER } ${ os . EOL } true${ os . EOL } ${ DELIMITER } ${ os . EOL } `
561
+ )
562
+ } )
563
+
564
+ it ( 'saveState handles number inputs' , ( ) => {
565
+ const command = 'STATE'
566
+ createFileCommandFile ( command )
567
+ core . saveState ( 'my state' , 5 )
568
+ verifyFileCommand (
569
+ command ,
570
+ `my state<<${ DELIMITER } ${ os . EOL } 5${ os . EOL } ${ DELIMITER } ${ os . EOL } `
571
+ )
572
+ } )
573
+
574
+ it ( 'saveState does not allow delimiter as value' , ( ) => {
575
+ const command = 'STATE'
576
+ createFileCommandFile ( command )
577
+
578
+ expect ( ( ) => {
579
+ core . saveState ( 'my state' , `good stuff ${ DELIMITER } bad stuff` )
580
+ } ) . toThrow (
581
+ `Unexpected input: value should not contain the delimiter "${ DELIMITER } "`
582
+ )
583
+
584
+ const filePath = path . join ( __dirname , `test/${ command } ` )
585
+ fs . unlinkSync ( filePath )
586
+ } )
587
+
588
+ it ( 'saveState does not allow delimiter as name' , ( ) => {
589
+ const command = 'STATE'
590
+ createFileCommandFile ( command )
591
+
592
+ expect ( ( ) => {
593
+ core . saveState ( `good stuff ${ DELIMITER } bad stuff` , 'test' )
594
+ } ) . toThrow (
595
+ `Unexpected input: name should not contain the delimiter "${ DELIMITER } "`
596
+ )
597
+
598
+ const filePath = path . join ( __dirname , `test/${ command } ` )
599
+ fs . unlinkSync ( filePath )
600
+ } )
601
+
484
602
it ( 'getState gets wrapper action state' , ( ) => {
485
603
expect ( core . getState ( 'TEST_1' ) ) . toBe ( 'state_val' )
486
604
} )
0 commit comments