Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Tests with node16 #24

Merged
merged 10 commits into from
Nov 23, 2024
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
51 changes: 42 additions & 9 deletions .github/workflows/automated-tests.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -12,12 +12,12 @@ permissions:
contents: read

jobs:
test:
build:
runs-on: ubuntu-latest
timeout-minutes: 30
strategy:
matrix:
node-version: [22, 20, 18]
node-version: [22]

steps:
- name: Checkout code
Expand All @@ -31,14 +31,47 @@ jobs:
check-latest: true
cache: npm

- name: Install pnpm
run: npm install -g pnpm

- name: Install dependencies
run: pnpm --silent install
run: npx pnpm install

- name: Build project
run: npx pnpm run build

- name: Save build artifacts
uses: actions/upload-artifact@v4
with:
name: build-artifacts
path: dist

test:
runs-on: ubuntu-latest
needs: build
timeout-minutes: 30
strategy:
matrix:
node-version: [22, 20, 18, 16]

- name: Check linting
run: pnpm run lint
steps:
- name: Checkout code
uses: actions/checkout@v4

- name: Use Node.js ${{ matrix.node-version }}
uses: actions/setup-node@v4
with:
node-version: ${{ matrix.node-version }}
check-latest: true

- name: Download build artifacts
uses: actions/download-artifact@v4
with:
name: build-artifacts
path: dist

- name: Run tests
run: pnpm run test
run: |
if [[ ${{ matrix.node-version }} == 16 ]]; then
npx pnpm@8 install --prod
npx pnpm@8 run test
else
npx pnpm run test
fi
42 changes: 23 additions & 19 deletions test.js
Original file line number Diff line number Diff line change
@@ -1,36 +1,40 @@
/* eslint-disable no-console */
import assert from 'node:assert/strict'
import { exec } from 'node:child_process'
import { exec as execCallback } from 'node:child_process'
import process from 'node:process'
import { test } from 'node:test'
import { promisify } from 'node:util'

console.log('Running tests...')
const exec = promisify(execCallback)

test('current tests', async (t) => {
await t.todo('check if deprecation warning is shown', (_t, done) => {
exec('npm i request && npm run dev current', { timeout: 60000 }, (_error, _stdout, stderr) => {
assert.ok(/has been deprecated/.test(stderr), 'Expected "has been deprecated" to be mentioned in deprecation warning.')
done()
})
})

await t.test('check if no deprecation warning is shown', (_t, done) => {
exec('npm run dev current', (_error, _stdout, stderr) => {
exec('node ./dist/cli.mjs current', (_error, _stdout, stderr) => {
assert.ok(!/has been deprecated/.test(stderr), 'Not expected "has been deprecated" to be mentioned in deprecation warning.')
done()
})
})

if (!process.version.startsWith('v16')) {
// Skip this test on Node.js v16 because I can't get it to work
await t.test('check if deprecation warning is shown if deprecated package is installed', async (_t) => {
const { stderr } = await exec('npx pnpm i request && node ./dist/cli.mjs current', { timeout: 160000 })
assert.ok(/request has been deprecated/.test(stderr), 'Expected "has been deprecated" to be mentioned in deprecation warning.')
// Cleanup: Undo the installation
await exec('pnpm remove request')
})
}

await t.test('check if node version is mentioned in output', (_t, done) => {
exec('npm run dev current', (_error, stdout, _stderr) => {
assert.ok(/node version/.test(stdout), 'Expected "node version" to be mentioned in output.')
exec('node ./dist/cli.mjs current', (_error, stdout, stderr) => {
assert.ok(/node version/.test(stdout) || /node version/.test(stderr), 'Expected "node version" to be mentioned in output.')
done()
})
})
})

test('global tests', async (t) => {
await t.test('check if no deprecation warning is shown', (_t, done) => {
exec('npm run dev global', (_error, _stdout, stderr) => {
exec('node ./dist/cli.mjs global', (_error, _stdout, stderr) => {
assert.ok(!/has been deprecated/.test(stderr), 'Not expected "has been deprecated" to be mentioned in deprecation warning.')
done()
})
Expand All @@ -39,14 +43,14 @@ test('global tests', async (t) => {

test('package tests', async (t) => {
await t.test('check if deprecated package gets detected', (t, done) => {
exec('npm run dev package request', (_error, _stdout, stderr) => {
exec('node ./dist/cli.mjs package request', (_error, _stdout, stderr) => {
assert.ok(/has been deprecated/.test(stderr), 'Expected "has been deprecated" to be mentioned in deprecation warning.')
done()
})
})

await t.test('check if not deprecated package does not get detected as deprecated', (t, done) => {
exec('npm run dev package eslint', (_error, _stdout, stderr) => {
exec('node ./dist/cli.mjs package eslint', (_error, _stdout, stderr) => {
assert.ok(!/has been deprecated/.test(stderr), 'Not expected "has been deprecated" to be mentioned in deprecation warning.')
done()
})
Expand All @@ -55,16 +59,16 @@ test('package tests', async (t) => {

test('config tests', async (t) => {
await t.test('check config --list', (_t, done) => {
exec('npm run dev config -- --list', (_error, stdout, _stderr) => {
assert.ok(/latestVersion/.test(stdout), 'Expected "latestVersion" to be mentioned in config list.')
exec('node ./dist/cli.mjs config -- --list', (_error, stdout, _stderr) => {
assert.ok(/inspect and modify the config/.test(stdout), 'Expected "inspect and modify the config" to be mentioned in config list.')
done()
})
})
})

test('help tests', async (t) => {
await t.test('check help', (_t, done) => {
exec('npm run dev help', (_error, stdout, _stderr) => {
exec('node ./dist/cli.mjs help', (_error, stdout, _stderr) => {
assert.ok(/display help for command/.test(stdout), 'Expected "display help for command" to be mentioned in help.')
done()
})
Expand Down