@@ -41,7 +41,9 @@ const testEnvVars = {
4141
4242 // File Commands
4343 GITHUB_PATH : '' ,
44- GITHUB_ENV : ''
44+ GITHUB_ENV : '' ,
45+ GITHUB_OUTPUT : '' ,
46+ GITHUB_STATE : ''
4547}
4648
4749const UUID = '9b1deb4d-3b7d-4bad-9bdd-2b0d7b3dcb6d'
@@ -283,24 +285,82 @@ describe('@actions/core', () => {
283285 ) . toEqual ( [ ' val1 ' , ' val2 ' , ' ' ] )
284286 } )
285287
286- it ( 'setOutput produces the correct command' , ( ) => {
288+ it ( 'legacy setOutput produces the correct command' , ( ) => {
287289 core . setOutput ( 'some output' , 'some value' )
288290 assertWriteCalls ( [
289291 os . EOL ,
290292 `::set-output name=some output::some value${ os . EOL } `
291293 ] )
292294 } )
293295
294- it ( 'setOutput handles bools' , ( ) => {
296+ it ( 'legacy setOutput handles bools' , ( ) => {
295297 core . setOutput ( 'some output' , false )
296298 assertWriteCalls ( [ os . EOL , `::set-output name=some output::false${ os . EOL } ` ] )
297299 } )
298300
299- it ( 'setOutput handles numbers' , ( ) => {
301+ it ( 'legacy setOutput handles numbers' , ( ) => {
300302 core . setOutput ( 'some output' , 1.01 )
301303 assertWriteCalls ( [ os . EOL , `::set-output name=some output::1.01${ os . EOL } ` ] )
302304 } )
303305
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+
304364 it ( 'setFailed sets the correct exit code and failure message' , ( ) => {
305365 core . setFailed ( 'Failure message' )
306366 expect ( process . exitCode ) . toBe ( core . ExitCode . Failure )
@@ -466,21 +526,79 @@ describe('@actions/core', () => {
466526 assertWriteCalls ( [ `::debug::%0D%0Adebug%0A${ os . EOL } ` ] )
467527 } )
468528
469- it ( 'saveState produces the correct command' , ( ) => {
529+ it ( 'legacy saveState produces the correct command' , ( ) => {
470530 core . saveState ( 'state_1' , 'some value' )
471531 assertWriteCalls ( [ `::save-state name=state_1::some value${ os . EOL } ` ] )
472532 } )
473533
474- it ( 'saveState handles numbers' , ( ) => {
534+ it ( 'legacy saveState handles numbers' , ( ) => {
475535 core . saveState ( 'state_1' , 1 )
476536 assertWriteCalls ( [ `::save-state name=state_1::1${ os . EOL } ` ] )
477537 } )
478538
479- it ( 'saveState handles bools' , ( ) => {
539+ it ( 'legacy saveState handles bools' , ( ) => {
480540 core . saveState ( 'state_1' , true )
481541 assertWriteCalls ( [ `::save-state name=state_1::true${ os . EOL } ` ] )
482542 } )
483543
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+
484602 it ( 'getState gets wrapper action state' , ( ) => {
485603 expect ( core . getState ( 'TEST_1' ) ) . toBe ( 'state_val' )
486604 } )
0 commit comments