Skip to content

Commit c697544

Browse files
committed
add windows test + clear test separation between node.js and bun + shebang
1 parent 99eff7f commit c697544

11 files changed

Lines changed: 255 additions & 27 deletions

File tree

.github/workflows/node.js.yml

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ jobs:
1010

1111
strategy:
1212
matrix:
13-
node-version: [20, latest]
13+
node-version: [20, 24]
1414

1515
steps:
1616
- uses: actions/checkout@v4
@@ -25,3 +25,21 @@ jobs:
2525
- uses: actions/checkout@v4
2626
- name: Run parallel tests in Docker (Bun)
2727
run: RUNTIME=bun MAX_JOBS=6 npm run test:parallel
28+
29+
test-windows:
30+
runs-on: windows-latest
31+
timeout-minutes: 30
32+
33+
strategy:
34+
matrix:
35+
node-version: [20, latest]
36+
37+
steps:
38+
- uses: actions/checkout@v4
39+
- uses: actions/setup-node@v4
40+
with:
41+
node-version: ${{ matrix.node-version }}
42+
- run: npm install
43+
- name: Run tests (Node.js ${{ matrix.node-version }})
44+
shell: bash
45+
run: bash test/windows.sh

README.md

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ PM2 is constantly assailed by [more than 1800 tests](https://github.com/Unitech/
3838

3939
Official website: [https://pm2.keymetrics.io/](https://pm2.keymetrics.io/)
4040

41-
Works on Linux (stable) & macOS (stable) & Windows (stable). All Node.js versions are supported starting Node.js 12.X and Bun since v1
41+
Works on Linux (stable) & macOS (stable) & Windows (stable). All Node.js versions are supported starting Node.js 20.X and Bun since v1
4242

4343

4444
## Installing PM2
@@ -54,7 +54,10 @@ $ npm install pm2 -g
5454
```bash
5555
$ bun install pm2 -g
5656
```
57-
**Please note that you might need to symlink node to bun if you only want to use bun via `sudo ln -s /home/$USER/.bun/bin/bun /usr/bin/node`**
57+
**If Node.js is not installed**, PM2 binaries use `#!/usr/bin/env node` as shebang, so you need to symlink `node` to `bun`:
58+
```bash
59+
$ sudo ln -s $(which bun) /usr/local/bin/node
60+
```
5861

5962
___
6063

bin/pm2

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1-
#!/usr/bin/env node
1+
#!/bin/sh
2+
':' //; exec "$(command -v node || command -v bun)" "$0" "$@"
23

34
require('../lib/binaries/CLI.js');

bin/pm2-dev

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1-
#!/usr/bin/env node
1+
#!/bin/sh
2+
':' //; exec "$(command -v node || command -v bun)" "$0" "$@"
23

34
require('../lib/binaries/DevCLI.js');

bin/pm2-docker

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1-
#!/usr/bin/env node
1+
#!/bin/sh
2+
':' //; exec "$(command -v node || command -v bun)" "$0" "$@"
23

34
require('../lib/binaries/Runtime4Docker.js');

bin/pm2-runtime

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1-
#!/usr/bin/env node
1+
#!/bin/sh
2+
':' //; exec "$(command -v node || command -v bun)" "$0" "$@"
23

34
require('../lib/binaries/Runtime4Docker.js');

modules/pm2-io-agent/test/units/InteractorDaemon.mocha.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -424,7 +424,8 @@ describe('InteractorDaemon', () => {
424424
daemon.exit = _ => {
425425
assert(_startRPCCalled === 1)
426426
assert(daemon.opts.ROOT_URL === cst.KEYMETRICS_ROOT_URL)
427-
assert(_processSendCalled === 1)
427+
// Bun: sendToParent skips process.send when IS_BUN is true
428+
if (typeof Bun === 'undefined') assert(_processSendCalled === 1)
428429
process.send = sendTmp
429430
axonMock.reset()
430431
cb()

package.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -106,7 +106,8 @@
106106
"test:bpm": "mocha 'modules/pm2-io-bpm/test/**/*.spec.js' --exit --timeout 10000",
107107
"test:axon-rpc": "mocha 'modules/pm2-axon-rpc/test/' --reporter spec --exit",
108108
"test:axon": "bash modules/pm2-axon/test/run modules/pm2-axon/test/test.*.js",
109-
"test:io-agent": "mocha 'modules/pm2-io-agent/test/units/*.mocha.js' --reporter spec --exit"
109+
"test:io-agent": "mocha 'modules/pm2-io-agent/test/units/*.mocha.js' --reporter spec --exit",
110+
"test:windows": "bash test/windows.sh"
110111
},
111112
"keywords": [
112113
"cli",

test/Dockerfile

Lines changed: 21 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -24,31 +24,39 @@ RUN apt-get update && apt-get install -y \
2424
gcc \
2525
&& rm -rf /var/lib/apt/lists/*
2626

27-
# Always install Node.js (required for PM2 daemon and tests)
28-
RUN mkdir -p /etc/apt/keyrings && \
29-
curl -fsSL https://deb.nodesource.com/gpgkey/nodesource-repo.gpg.key | gpg --dearmor -o /etc/apt/keyrings/nodesource.gpg && \
30-
echo "deb [signed-by=/etc/apt/keyrings/nodesource.gpg] https://deb.nodesource.com/node_${NODE_VERSION}.x nodistro main" | tee /etc/apt/sources.list.d/nodesource.list && \
31-
apt-get update && \
32-
apt-get install -y nodejs && \
33-
rm -rf /var/lib/apt/lists/*
34-
35-
# Additionally install Bun if RUNTIME=bun
27+
# Install Node.js when RUNTIME=node
28+
RUN if [ "$RUNTIME" = "node" ]; then \
29+
mkdir -p /etc/apt/keyrings && \
30+
curl -fsSL https://deb.nodesource.com/gpgkey/nodesource-repo.gpg.key | gpg --dearmor -o /etc/apt/keyrings/nodesource.gpg && \
31+
echo "deb [signed-by=/etc/apt/keyrings/nodesource.gpg] https://deb.nodesource.com/node_${NODE_VERSION}.x nodistro main" | tee /etc/apt/sources.list.d/nodesource.list && \
32+
apt-get update && \
33+
apt-get install -y nodejs && \
34+
rm -rf /var/lib/apt/lists/*; \
35+
fi
36+
37+
# Install Bun when RUNTIME=bun
3638
RUN if [ "$RUNTIME" = "bun" ]; then \
3739
curl -fsSL https://bun.sh/install | bash && \
3840
ln -s /root/.bun/bin/bun /usr/local/bin/bun && \
3941
ln -s /root/.bun/bin/bunx /usr/local/bin/bunx; \
4042
fi
4143

42-
# Install mocha globally
43-
RUN npm install -g mocha
44+
# Install mocha globally (only needed for Node runtime)
45+
RUN if [ "$RUNTIME" = "node" ]; then \
46+
npm install -g mocha; \
47+
fi
4448

4549
WORKDIR /var/pm2
4650

4751
# Copy package files first (for layer caching)
4852
COPY package*.json ./
4953

50-
# Install dependencies (always use npm for consistency)
51-
RUN npm install
54+
# Install dependencies
55+
RUN if [ "$RUNTIME" = "bun" ]; then \
56+
bun install; \
57+
else \
58+
npm install; \
59+
fi
5260

5361
# Environment
5462
ENV PM2_DISCRETE_MODE=true

test/docker-parallel.sh

Lines changed: 14 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -214,6 +214,15 @@ echo "[*] Found $TOTAL tests, running with $MAX_JOBS parallel jobs"
214214
[[ $SKIPPED -gt 0 ]] && echo "[*] Skipped $SKIPPED tests (require host features)"
215215
echo ""
216216

217+
# Runtime commands (bunx mocha for Bun, mocha for Node)
218+
if [[ "$RUNTIME" == "bun" ]]; then
219+
MOCHA="bunx mocha"
220+
JSRUN="bun"
221+
else
222+
MOCHA="mocha"
223+
JSRUN="node"
224+
fi
225+
217226
# Run a single test in a container (with isolated codebase copy)
218227
run_test() {
219228
local test_spec=$1
@@ -235,28 +244,28 @@ run_test() {
235244
cat "$CODEBASE_TAR" | docker run --rm -i \
236245
--mount type=tmpfs,destination=/root/.pm2 \
237246
"$IMAGE_NAME" \
238-
bash -c "tar -xf - && mocha --exit --timeout 10000 --bail $test_path" \
247+
bash -c "tar -xf - && $MOCHA --exit --timeout 10000 --bail $test_path" \
239248
> "$log_file" 2>&1
240249
elif [[ "$test_type" == "axon" ]]; then
241-
# Axon: custom runner (runs test file with node directly)
250+
# Axon: custom runner (runs test file directly)
242251
cat "$CODEBASE_TAR" | docker run --rm -i \
243252
"$IMAGE_NAME" \
244-
bash -c "tar -xf - && node $test_path" \
253+
bash -c "tar -xf - && $JSRUN $test_path" \
245254
> "$log_file" 2>&1
246255
elif [[ "$test_type" == "io-agent" ]] || [[ "$test_type" == "axon-rpc" ]]; then
247256
# IO Agent / Axon-RPC: mocha with spec reporter
248257
cat "$CODEBASE_TAR" | docker run --rm -i \
249258
--mount type=tmpfs,destination=/root/.pm2 \
250259
"$IMAGE_NAME" \
251-
bash -c "tar -xf - && mocha --reporter spec --exit --bail $test_path" \
260+
bash -c "tar -xf - && $MOCHA --reporter spec --exit --bail $test_path" \
252261
> "$log_file" 2>&1
253262
else
254263
# Unit: extract codebase, run with mocha
255264
# Use tmpfs for ~/.pm2 to speed up PM2 file I/O
256265
cat "$CODEBASE_TAR" | docker run --rm -i \
257266
--mount type=tmpfs,destination=/root/.pm2 \
258267
"$IMAGE_NAME" \
259-
bash -c "tar -xf - && mocha --exit --bail $test_path" \
268+
bash -c "tar -xf - && $MOCHA --exit --bail $test_path" \
260269
> "$log_file" 2>&1
261270
fi
262271
}

0 commit comments

Comments
 (0)