forked from Ikalus1988/MisakaNet
-
Notifications
You must be signed in to change notification settings - Fork 0
76 lines (65 loc) · 2.51 KB
/
Copy pathfatal-guard.yml
File metadata and controls
76 lines (65 loc) · 2.51 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
name: fatal-guard CI
on:
push:
paths:
- 'packages/fatal-guard/**'
pull_request:
paths:
- 'packages/fatal-guard/**'
workflow_dispatch:
permissions:
contents: read
jobs:
test:
strategy:
fail-fast: false
matrix:
os: [ubuntu-latest, windows-latest]
runs-on: ${{ matrix.os }}
# paths filters already gate push/PR; keep workflow_dispatch always runnable.
# Avoid a job-level if that can leave 0 jobs and mark the workflow as failed.
defaults:
run:
working-directory: packages/fatal-guard
steps:
- uses: actions/checkout@v7
- uses: actions/setup-node@v7
with:
node-version: '22'
- name: Check zero dependencies
run: |
node -e "const p=require('./package.json'); const n=Object.keys(p.dependencies||{}).length; console.log('dependencies:', n); if (n !== 0) process.exit(1)"
- name: Test module loads without error
run: |
node -e "require('./register'); console.log('OK: module loaded')"
- name: Test uncaughtException invokes handler
run: |
FATAL_HANDLER=/usr/bin/logger timeout 5 node -r ./register -e "
setTimeout(() => { throw new Error('ci-test'); }, 50);
" 2>&1 | grep -q 'fatal-guard uncaughtException' && echo 'PASS: uncaughtException' || echo 'FAIL'
- name: Test — handler receives payload
run: |
PAYLOAD_FILE=$(mktemp)
cat > /tmp/test-handler.sh << 'HANDLER'
#!/bin/bash
echo "$1" > "$PAYLOAD_FILE"
HANDLER
chmod +x /tmp/test-handler.sh
export PAYLOAD_FILE
FATAL_HANDLER=/tmp/test-handler.sh timeout 5 node -r ./register -e "
setTimeout(() => { throw new Error('ci-payload-test'); }, 50);
" 2>&1 || true
sleep 1
if [ -f "$PAYLOAD_FILE" ] && grep -q 'schemaVersion' "$PAYLOAD_FILE" && grep -q 'uncaught_exception' "$PAYLOAD_FILE"; then
echo 'PASS: handler received payload'
cat "$PAYLOAD_FILE"
else
echo 'FAIL: no payload received'
[ -f "$PAYLOAD_FILE" ] && cat "$PAYLOAD_FILE"
fi
rm -f "$PAYLOAD_FILE" /tmp/test-handler.sh
- name: Test TypeScript declaration exists
run: |
node -e "const fs=require('fs'); if (!fs.existsSync('index.d.ts') || !fs.readFileSync('index.d.ts','utf8').includes('FatalPayload')) process.exit(1); console.log('PASS: index.d.ts')"
- name: Run package tests
run: npm test