Skip to content

Commit 2c6be1d

Browse files
committed
test: add integration tests and fixtures for script-file input
1 parent c01c5a1 commit 2c6be1d

7 files changed

Lines changed: 181 additions & 0 deletions

File tree

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
module.exports = async ({github, octokit, getOctokit, context, core, exec, glob, io, require}) => {
2+
return [github, octokit, getOctokit, context, core, exec, glob, io, require]
3+
.map(arg => typeof arg)
4+
.every(t => t === 'function' || t === 'object')
5+
}
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
module.exports = async () => 'hello from script-file'
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
module.exports = async ({context}) => ({repo: context.repo.repo, owner: context.repo.owner})
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
module.exports = 42
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
module.exports = async ({require}) => require('./sibling-module').value
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
module.exports = {value: 'loaded-by-require'}

.github/workflows/integration.yml

Lines changed: 171 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -361,3 +361,174 @@ jobs:
361361
echo $'::error::\u274C' "Expected base-url to equal '$expected', got $actual"
362362
exit 1
363363
fi
364+
365+
test-script-file-basic:
366+
name: 'Integration test: script-file - relative path, string return'
367+
runs-on: ubuntu-latest
368+
steps:
369+
- uses: actions/checkout@v4
370+
- id: act
371+
uses: ./
372+
with:
373+
script-file: .github/fixtures/script-file/basic.js
374+
result-encoding: string
375+
- run: |
376+
expected="hello from script-file"
377+
if [[ "${{ steps.act.outputs.result }}" != "$expected" ]]; then
378+
echo $'::error::❌' "Expected '$expected', got ${{ steps.act.outputs.result }}"
379+
exit 1
380+
fi
381+
echo $'✅ Test passed' | tee -a $GITHUB_STEP_SUMMARY
382+
383+
test-script-file-absolute-path:
384+
name: 'Integration test: script-file - absolute path'
385+
runs-on: ubuntu-latest
386+
steps:
387+
- uses: actions/checkout@v4
388+
- id: act
389+
uses: ./
390+
with:
391+
script-file: ${{ github.workspace }}/.github/fixtures/script-file/basic.js
392+
result-encoding: string
393+
- run: |
394+
expected="hello from script-file"
395+
if [[ "${{ steps.act.outputs.result }}" != "$expected" ]]; then
396+
echo $'::error::❌' "Expected '$expected', got ${{ steps.act.outputs.result }}"
397+
exit 1
398+
fi
399+
echo $'✅ Test passed' | tee -a $GITHUB_STEP_SUMMARY
400+
401+
test-script-file-all-ioc-args:
402+
name: 'Integration test: script-file - all IoC args available'
403+
runs-on: ubuntu-latest
404+
steps:
405+
- uses: actions/checkout@v4
406+
- id: act
407+
uses: ./
408+
with:
409+
script-file: .github/fixtures/script-file/all-args.js
410+
- run: |
411+
if [[ "${{ steps.act.outputs.result }}" != "true" ]]; then
412+
echo $'::error::❌' "Expected all IoC args to be present, got ${{ steps.act.outputs.result }}"
413+
exit 1
414+
fi
415+
echo $'✅ Test passed' | tee -a $GITHUB_STEP_SUMMARY
416+
417+
test-script-file-result-encoding-json:
418+
name: 'Integration test: script-file - result-encoding json'
419+
runs-on: ubuntu-latest
420+
steps:
421+
- uses: actions/checkout@v4
422+
- id: act
423+
uses: ./
424+
with:
425+
script-file: .github/fixtures/script-file/json-return.js
426+
- run: |
427+
expected='{"repo":"${{ github.event.repository.name }}","owner":"${{ github.repository_owner }}"}'
428+
if [[ "${{ steps.act.outputs.result }}" != "$expected" ]]; then
429+
echo $'::error::❌' "Expected '$expected', got ${{ steps.act.outputs.result }}"
430+
exit 1
431+
fi
432+
echo $'✅ Test passed' | tee -a $GITHUB_STEP_SUMMARY
433+
434+
test-script-file-require-in-file:
435+
name: 'Integration test: script-file - require inside script file'
436+
runs-on: ubuntu-latest
437+
steps:
438+
- uses: actions/checkout@v4
439+
- id: act
440+
uses: ./
441+
with:
442+
script-file: .github/fixtures/script-file/sibling-caller.js
443+
result-encoding: string
444+
- run: |
445+
expected="loaded-by-require"
446+
if [[ "${{ steps.act.outputs.result }}" != "$expected" ]]; then
447+
echo $'::error::❌' "Expected '$expected', got ${{ steps.act.outputs.result }}"
448+
exit 1
449+
fi
450+
echo $'✅ Test passed' | tee -a $GITHUB_STEP_SUMMARY
451+
452+
test-script-file-conflict-both:
453+
name: 'Integration test: script-file - fails when both script and script-file are set'
454+
runs-on: ubuntu-latest
455+
steps:
456+
- uses: actions/checkout@v4
457+
- id: act
458+
continue-on-error: true
459+
uses: ./
460+
with:
461+
script: return 1
462+
script-file: .github/fixtures/script-file/basic.js
463+
- run: |
464+
if [[ "${{ steps.act.outcome }}" != "failure" ]]; then
465+
echo $'::error::❌' "Expected step to fail when both inputs are set"
466+
exit 1
467+
fi
468+
echo $'✅ Test passed' | tee -a $GITHUB_STEP_SUMMARY
469+
470+
test-script-file-conflict-neither:
471+
name: 'Integration test: script-file - fails when neither script nor script-file is set'
472+
runs-on: ubuntu-latest
473+
steps:
474+
- uses: actions/checkout@v4
475+
- id: act
476+
continue-on-error: true
477+
uses: ./
478+
- run: |
479+
if [[ "${{ steps.act.outcome }}" != "failure" ]]; then
480+
echo $'::error::❌' "Expected step to fail when no input is set"
481+
exit 1
482+
fi
483+
echo $'✅ Test passed' | tee -a $GITHUB_STEP_SUMMARY
484+
485+
test-script-file-nonexistent-file:
486+
name: 'Integration test: script-file - fails on nonexistent file'
487+
runs-on: ubuntu-latest
488+
steps:
489+
- uses: actions/checkout@v4
490+
- id: act
491+
continue-on-error: true
492+
uses: ./
493+
with:
494+
script-file: .github/fixtures/script-file/does-not-exist.js
495+
- run: |
496+
if [[ "${{ steps.act.outcome }}" != "failure" ]]; then
497+
echo $'::error::❌' "Expected step to fail for nonexistent file"
498+
exit 1
499+
fi
500+
echo $'✅ Test passed' | tee -a $GITHUB_STEP_SUMMARY
501+
502+
test-script-file-non-function-export:
503+
name: 'Integration test: script-file - fails when file does not export a function'
504+
runs-on: ubuntu-latest
505+
steps:
506+
- uses: actions/checkout@v4
507+
- id: act
508+
continue-on-error: true
509+
uses: ./
510+
with:
511+
script-file: .github/fixtures/script-file/not-a-function.js
512+
- run: |
513+
if [[ "${{ steps.act.outcome }}" != "failure" ]]; then
514+
echo $'::error::❌' "Expected step to fail for non-function export"
515+
exit 1
516+
fi
517+
echo $'✅ Test passed' | tee -a $GITHUB_STEP_SUMMARY
518+
519+
test-script-file-file-protocol-rejected:
520+
name: 'Integration test: script-file - fails for file:// protocol'
521+
runs-on: ubuntu-latest
522+
steps:
523+
- uses: actions/checkout@v4
524+
- id: act
525+
continue-on-error: true
526+
uses: ./
527+
with:
528+
script-file: file://${{ github.workspace }}/.github/fixtures/script-file/basic.js
529+
- run: |
530+
if [[ "${{ steps.act.outcome }}" != "failure" ]]; then
531+
echo $'::error::❌' "Expected step to fail for file:// protocol"
532+
exit 1
533+
fi
534+
echo $'✅ Test passed' | tee -a $GITHUB_STEP_SUMMARY

0 commit comments

Comments
 (0)