Update .gitea/workflows/nodejs-test.yml
Some checks failed
CI Demo / build (push) Successful in 4s
Docker Test / docker-ops (push) Successful in 6s
.NET Test / dotnet-test (push) Failing after 17s
Go Test / go-test (push) Failing after 5s
Java Test / java-hello (push) Successful in 32s
Julia Test / julia-test (push) Failing after 5s
Kotlin Test / kotlin-hello (push) Successful in 41s
Node.js Test / nodejs-test (push) Failing after 54s
Notebook Test / nb-test (push) Failing after 8s
Python Test / python-hello (push) Has been cancelled
R Test / r-cmdcheck (push) Has been cancelled
PHP Test / php-test (push) Has been cancelled
Scala Test / scala-test (push) Has been cancelled
Swift Test / swift-hello (push) Has been cancelled
Rust Test / rust-test (push) Failing after 27s

This commit is contained in:
2025-08-07 20:36:52 +00:00
parent f6e7b68fdf
commit 88d835ea6f

View File

@@ -9,12 +9,61 @@ jobs:
uses: actions/checkout@v4
- name: Set up Node.js
uses: actions/setup-node@v3
uses: actions/setup-node@v4
with:
node-version: '18'
node-version: '20' # or '18' if you need older
cache: 'npm'
- name: Install dependencies
run: npm ci
- name: Verify Node & npm
run: |
node -v
npm -v
- name: Run tests
run: npm test
- name: Detect & install deps (lockfile-aware) + run tests
shell: bash
run: |
set -euo pipefail
if [ -f package.json ]; then
echo "package.json found."
if [ -f package-lock.json ]; then
echo "Using npm ci (lockfile present)."
npm ci
else
echo "No lockfile; using npm install."
npm install
fi
# Run tests only if there's a real test script (not the default placeholder)
if node -e "const p=require('./package.json'); const s=p.scripts&&p.scripts.test; process.exit(!(s && !/no test specified/.test(String(s))))"; then
npm test
else
echo "No meaningful test script found; skipping tests."
fi
else
echo "No Node project detected. Creating a tiny smoke-test project..."
npm init -y >/dev/null 2>&1
npm install --save-dev mocha >/dev/null 2>&1
npm pkg set scripts.test="mocha" >/dev/null 2>&1
# Write minimal app and test (note: heredoc terminators aligned under run: |)
cat > sum.js <<'EOF'
function add(a, b) { return a + b; }
module.exports = { add };
EOF
mkdir -p test
cat > test/sum.test.js <<'EOF'
const assert = require('assert');
const { add } = require('../sum');
describe('add', () => {
it('adds numbers', () => {
assert.strictEqual(add(2, 2), 4);
});
});
EOF
npm test
fi