Repository navigation
59 lines (51 loc) · 1.72 KB
/
Copy pathnodejs-tests.yml
File metadata and controls
59 lines (51 loc) · 1.72 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
name: Node.js Tests
permissions: {}
on:
push:
branches: [main]
pull_request:
branches: [main]
jobs:
node-tests:
name: Node.js Tests
runs-on: ubuntu-latest
permissions:
contents: read
actions: write
steps:
- uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1
- name: Use Node.js 20
uses: actions/setup-node@949feb2413d6458794dcd2491c4babbbce0c15c1 # v6
with:
node-version: '20'
- name: Cache node modules
uses: actions/cache@55cc8345863c7cc4c66a329aec7e433d2d1c52a9 # v5
with:
path: ~/.npm
key: ${{ runner.os }}-node-${{ hashFiles('**/package-lock.json') }}
restore-keys: |
${{ runner.os }}-node-
- name: Install dependencies
run: npm ci
- name: Discover packages
id: discover
run: |
echo "Finding packages with tests..."
PACKAGES=$(node -e "const fs=require('fs');const dirs=fs.readdirSync('.').filter(d=>fs.statSync(d).isDirectory() && fs.existsSync(d+'/tests'));console.log(JSON.stringify(dirs))")
echo "PACKAGES=$PACKAGES" >> $GITHUB_OUTPUT
- name: Run tests
env:
PACKAGES: ${{ steps.discover.outputs.PACKAGES }}
run: |
PACKAGES_ENV="$PACKAGES"
PACKAGES=$(node -e "console.log(JSON.parse(process.env.PACKAGES || '[]').join(' '))")
echo "Discovered packages: $PACKAGES"
if [ -z "$PACKAGES" ]; then
echo "No packages found, running root tests"
npm test
exit 0
fi
for p in $PACKAGES; do
echo "Running tests for $p"
npx jest "$p/tests" --colors || exit 1
done