66 * this test, so that the actual module is not imported.
77 */
88import { jest } from '@jest/globals'
9+ import { readFile } from 'fs/promises'
910import * as core from '../__fixtures__/core.js'
1011
1112// Mocks should be declared before the module being tested is imported.
@@ -31,12 +32,15 @@ describe('main.ts', () => {
3132
3233 await run ( )
3334
34- // Verify outputs were set
35+ // Verify outputs were set with file paths
3536 expect ( core . setOutput ) . toHaveBeenCalledWith (
36- 'stdout' ,
37- expect . stringContaining ( 'Hello World' )
37+ 'stdout_file' ,
38+ expect . stringMatching ( / e x e c - .* \. s t d o u t $ / )
39+ )
40+ expect ( core . setOutput ) . toHaveBeenCalledWith (
41+ 'stderr_file' ,
42+ expect . stringMatching ( / e x e c - .* \. s t d e r r $ / )
3843 )
39- expect ( core . setOutput ) . toHaveBeenCalledWith ( 'stderr' , expect . any ( String ) )
4044 expect ( core . setOutput ) . toHaveBeenCalledWith ( 'exit_code' , '0' )
4145
4246 // Verify the action did not fail
@@ -52,9 +56,15 @@ describe('main.ts', () => {
5256
5357 await run ( )
5458
55- // Verify outputs were set
56- expect ( core . setOutput ) . toHaveBeenCalledWith ( 'stdout' , expect . any ( String ) )
57- expect ( core . setOutput ) . toHaveBeenCalledWith ( 'stderr' , expect . any ( String ) )
59+ // Verify outputs were set with file paths
60+ expect ( core . setOutput ) . toHaveBeenCalledWith (
61+ 'stdout_file' ,
62+ expect . stringMatching ( / e x e c - .* \. s t d o u t $ / )
63+ )
64+ expect ( core . setOutput ) . toHaveBeenCalledWith (
65+ 'stderr_file' ,
66+ expect . stringMatching ( / e x e c - .* \. s t d e r r $ / )
67+ )
5868 expect ( core . setOutput ) . toHaveBeenCalledWith ( 'exit_code' , '1' )
5969
6070 // Verify that the action was marked as failed
@@ -72,9 +82,15 @@ describe('main.ts', () => {
7282
7383 await run ( )
7484
75- // Verify outputs were set
76- expect ( core . setOutput ) . toHaveBeenCalledWith ( 'stdout' , expect . any ( String ) )
77- expect ( core . setOutput ) . toHaveBeenCalledWith ( 'stderr' , expect . any ( String ) )
85+ // Verify outputs were set with file paths
86+ expect ( core . setOutput ) . toHaveBeenCalledWith (
87+ 'stdout_file' ,
88+ expect . stringMatching ( / e x e c - .* \. s t d o u t $ / )
89+ )
90+ expect ( core . setOutput ) . toHaveBeenCalledWith (
91+ 'stderr_file' ,
92+ expect . stringMatching ( / e x e c - .* \. s t d e r r $ / )
93+ )
7894 expect ( core . setOutput ) . toHaveBeenCalledWith ( 'exit_code' , '1' )
7995
8096 // Verify the action did not fail
@@ -223,19 +239,28 @@ describe('main.ts', () => {
223239 } )
224240
225241 describe ( 'executeCommand' , ( ) => {
226- it ( 'Captures stdout from a command' , async ( ) => {
242+ it ( 'Captures stdout from a command to file ' , async ( ) => {
227243 const result = await executeCommand ( 'echo "test output"' )
228244
229- expect ( result . stdout ) . toContain ( 'test output' )
245+ expect ( result . stdoutFile ) . toMatch ( / e x e c - .* \. s t d o u t $ / )
246+ expect ( result . stderrFile ) . toMatch ( / e x e c - .* \. s t d e r r $ / )
230247 expect ( result . exitCode ) . toBe ( 0 )
248+
249+ // Verify file contents
250+ const stdoutContent = await readFile ( result . stdoutFile , 'utf-8' )
251+ expect ( stdoutContent ) . toContain ( 'test output' )
231252 } )
232253
233- it ( 'Captures stderr from a command' , async ( ) => {
254+ it ( 'Captures stderr from a command to file ' , async ( ) => {
234255 // Use sh to redirect to stderr since we can't use shell operators directly
235256 const result = await executeCommand ( 'sh -c "echo error output >&2"' )
236257
237- expect ( result . stderr ) . toContain ( 'error output' )
258+ expect ( result . stderrFile ) . toMatch ( / e x e c - . * \. s t d e r r $ / )
238259 expect ( result . exitCode ) . toBe ( 0 )
260+
261+ // Verify file contents
262+ const stderrContent = await readFile ( result . stderrFile , 'utf-8' )
263+ expect ( stderrContent ) . toContain ( 'error output' )
239264 } )
240265
241266 it ( 'Captures exit code from a failed command' , async ( ) => {
@@ -249,25 +274,56 @@ describe('main.ts', () => {
249274 // Use sh to run multiple echo commands
250275 const result = await executeCommand ( 'sh -c "echo line1 && echo line2"' )
251276
252- expect ( result . stdout ) . toContain ( 'line1' )
253- expect ( result . stdout ) . toContain ( 'line2' )
277+ expect ( result . stdoutFile ) . toMatch ( / e x e c - . * \. s t d o u t $ / )
278+ expect ( result . stderrFile ) . toMatch ( / e x e c - . * \. s t d e r r $ / )
254279 expect ( result . exitCode ) . toBe ( 0 )
280+
281+ // Verify file contents
282+ const stdoutContent = await readFile ( result . stdoutFile , 'utf-8' )
283+ expect ( stdoutContent ) . toContain ( 'line1' )
284+ expect ( stdoutContent ) . toContain ( 'line2' )
255285 } )
256286
257287 it ( 'Works with commands in PATH' , async ( ) => {
258288 // Test that we can find executables in PATH without full path
259- const result = await executeCommand ( 'ls -la ' )
289+ const result = await executeCommand ( 'echo testing ' )
260290
261291 expect ( result . exitCode ) . toBe ( 0 )
262- expect ( result . stdout . length ) . toBeGreaterThan ( 0 )
292+ expect ( result . stdoutFile ) . toMatch ( / e x e c - .* \. s t d o u t $ / )
293+
294+ // Verify file has content
295+ const stdoutContent = await readFile ( result . stdoutFile , 'utf-8' )
296+ expect ( stdoutContent ) . toContain ( 'testing' )
263297 } )
264298
265299 it ( 'Works with npm commands' , async ( ) => {
266300 // Test that npm in PATH works
267301 const result = await executeCommand ( 'npm --version' )
268302
269303 expect ( result . exitCode ) . toBe ( 0 )
270- expect ( result . stdout . length ) . toBeGreaterThan ( 0 )
304+ expect ( result . stdoutFile ) . toMatch ( / e x e c - .* \. s t d o u t $ / )
305+
306+ // Verify file has content
307+ const stdoutContent = await readFile ( result . stdoutFile , 'utf-8' )
308+ expect ( stdoutContent . length ) . toBeGreaterThan ( 0 )
309+ } )
310+
311+ it ( 'Captures both stdout and stderr to separate files' , async ( ) => {
312+ const result = await executeCommand (
313+ 'sh -c "echo stdout message && echo stderr message >&2"'
314+ )
315+
316+ expect ( result . exitCode ) . toBe ( 0 )
317+
318+ // Verify stdout file contents
319+ const stdoutContent = await readFile ( result . stdoutFile , 'utf-8' )
320+ expect ( stdoutContent ) . toContain ( 'stdout message' )
321+ expect ( stdoutContent ) . not . toContain ( 'stderr message' )
322+
323+ // Verify stderr file contents
324+ const stderrContent = await readFile ( result . stderrFile , 'utf-8' )
325+ expect ( stderrContent ) . toContain ( 'stderr message' )
326+ expect ( stderrContent ) . not . toContain ( 'stdout message' )
271327 } )
272328 } )
273329} )
0 commit comments