Skip to content

Commit 862fade

Browse files
tests: Adds test for skip-empty functionality (#4)
* Adds test for skip-empty functionality Adds a test case to verify that the `skip-empty` option correctly prevents playlist file creation when no tests match the specified outcome filters. This ensures that the action doesn't produce empty playlist files, avoiding potential issues in downstream processes. * Adds skip-empty option for playlist generation Allows skipping playlist generation if no matching tests are found when using the `skip-empty` option. This prevents errors and provides informative messages instead. * Update * update * update
1 parent 263ed17 commit 862fade

File tree

2 files changed

+35
-3
lines changed

2 files changed

+35
-3
lines changed

.github/workflows/test.yml

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -370,6 +370,25 @@ jobs:
370370
exit 1
371371
fi
372372
373+
# Test skip-empty: should NOT create a playlist file if no tests match
374+
- name: Test Action - skip-empty prevents empty playlist
375+
uses: ./
376+
with:
377+
trx-file-path: './TestResults/comprehensive.trx'
378+
output-directory: './skip-empty-test'
379+
test-outcomes: 'Pending' # No test in the TRX has this outcome
380+
skip-empty: true
381+
artifact-name: 'test-playlist-skipempty'
382+
383+
- name: Verify skip-empty prevents empty playlist
384+
run: |
385+
if [ -f "./skip-empty-test/comprehensive.playlist" ]; then
386+
echo "❌ Playlist file should NOT have been created when skip-empty is true and no tests match."
387+
exit 1
388+
else
389+
echo "✅ No playlist file created as expected with skip-empty enabled and no matching tests."
390+
fi
391+
373392
test-error-conditions:
374393
runs-on: ubuntu-latest
375394
steps:
@@ -386,6 +405,7 @@ jobs:
386405

387406
- name: Verify missing TRX file error handling
388407
run: |
408+
echo "status: ${{ steps.missing-trx-test.outcome }}"
389409
if [ "${{ steps.missing-trx-test.outcome }}" = "failure" ]; then
390410
echo "✅ Action correctly failed for missing TRX file"
391411
else

action.yml

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -80,12 +80,14 @@ runs:
8080
8181
PLAYLIST_PATHS=()
8282
ARTIFACT_BASENAMES=()
83+
PROCESSED_TRX_COUNT=0
8384
8485
for ACTUAL_TRX_FILE in "${TRX_FILES[@]}"; do
8586
if [ ! -f "$ACTUAL_TRX_FILE" ]; then
8687
echo "Warning: $ACTUAL_TRX_FILE is not a file, skipping."
8788
continue
8889
fi
90+
PROCESSED_TRX_COUNT=$((PROCESSED_TRX_COUNT+1))
8991
echo "Using TRX file: $ACTUAL_TRX_FILE"
9092
9193
TRX_BASENAME=$(basename "$ACTUAL_TRX_FILE" .trx)
@@ -111,15 +113,25 @@ runs:
111113
trx-to-vsplaylist "${ARGS[@]}"
112114
113115
if [ ! -f "$FINAL_OUTPUT" ]; then
114-
echo "Error: Playlist file was not created at: $FINAL_OUTPUT"
115-
exit 1
116+
if [ "$SKIP_EMPTY" = "false" ]; then
117+
echo "Error: Playlist file was not created at: $FINAL_OUTPUT"
118+
exit 1
119+
else
120+
echo "Info: Playlist file was not created at: $FINAL_OUTPUT (likely due to --skip-empty and no matching tests)"
121+
continue
122+
fi
116123
fi
117124
118125
echo "Successfully created playlist file: $FINAL_OUTPUT"
119126
PLAYLIST_PATHS+=("$FINAL_OUTPUT")
120127
ARTIFACT_BASENAMES+=("$(basename "$FINAL_OUTPUT" .playlist)")
121128
done
122129
130+
if [ "$PROCESSED_TRX_COUNT" -eq 0 ]; then
131+
echo "Error: No valid TRX files were found to process."
132+
exit 1
133+
fi
134+
123135
# Output all playlist paths as a colon-separated list
124136
echo "playlist-paths=${PLAYLIST_PATHS[*]}" | tr ' ' ':' >> $GITHUB_OUTPUT
125137
echo "artifact-basenames=${ARTIFACT_BASENAMES[*]}" | tr ' ' ':' >> $GITHUB_OUTPUT
@@ -130,4 +142,4 @@ runs:
130142
with:
131143
name: ${{ inputs.artifact-name || 'playlists' }}
132144
path: ${{ steps.convert.outputs.artifact-dir }}/*.playlist
133-
if-no-files-found: 'error'
145+
if-no-files-found: 'warn'

0 commit comments

Comments
 (0)