Skip to content

Commit

Permalink
Merge pull request #24 from KristjanESPERANTO/testsWithNode16
Browse files Browse the repository at this point in the history
Tests with node16
  • Loading branch information
KID-joker authored Nov 23, 2024
2 parents 9ee6adc + 7ecd5a3 commit ef96c3d
Show file tree
Hide file tree
Showing 2 changed files with 70 additions and 28 deletions.
57 changes: 49 additions & 8 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,55 @@ jobs:
check-latest: true
cache: npm

- name: Install dependencies
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]

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: Install pnpm
run: npm install -g pnpm
run: |
if [[ ${{ matrix.node-version }} == 16 ]]; then
npm install -g pnpm@8
else
npm install -g pnpm
fi
- name: Install dependencies
run: pnpm --silent install
- name: Pnpm version
run: pnpm --version

- name: Check linting
run: pnpm run lint
- name: Install dependencies
run: pnpm install --prod

- name: Run tests
run: pnpm run test
run: pnpm test
41 changes: 21 additions & 20 deletions test.js
Original file line number Diff line number Diff line change
@@ -1,52 +1,53 @@
/* eslint-disable no-console */
import assert from 'node:assert/strict'
import { exec } from 'node:child_process'
import { test } from 'node:test'

console.log('Running tests...')

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.')
await t.test('check if no deprecation warning is shown', (_t, done) => {
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()
})
})

await t.test('check if no deprecation warning is shown', (_t, done) => {
exec('npm run dev current', (_error, _stdout, stderr) => {
assert.ok(!/has been deprecated/.test(stderr), 'Not expected "has been deprecated" to be mentioned in deprecation warning.')
await t.test('check if deprecation warning is shown if deprecated package is installed', (_t, done) => {
exec('pnpm i request --force && node ./dist/cli.mjs current', { timeout: 160000 }, (_error, _stdout, stderr) => {
assert.ok(/request has been deprecated/.test(stderr), 'Expected "has been deprecated" to be mentioned in deprecation warning.')
// Cleanup: Undo the installation
exec('pnpm remove request')
done()
})
})
})

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.')
test('node tests', async (t) => {
await t.test('test node version deprecation check', (_t, done) => {
exec('node ./dist/cli.mjs node', (_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()
})
})
})

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) => {
await t.test('check if deprecated package gets detected', (_t, done) => {
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) => {
await t.test('check if not deprecated package does not get detected as deprecated', (_t, done) => {
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 +56,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

0 comments on commit ef96c3d

Please sign in to comment.