Skip to content

Instantly share code, notes, and snippets.

@bengl
Created January 30, 2025 16:11
Show Gist options
  • Save bengl/41acfeb8ac572e5761c8493673f13180 to your computer and use it in GitHub Desktop.
Save bengl/41acfeb8ac572e5761c8493673f13180 to your computer and use it in GitHub Desktop.
const [MAJOR, MINOR] = process.versions.node.split('.').map(Number)
let testCommand = 'node --test'
if (MAJOR >= 22 || (MAJOR === 20 && MINOR >= 1) || (MAJOR === 18 && MINOR >= 17)) {
testCommand = 'node --experimental-test-coverage --test'
} else if (MAJOR >= 20 || (MAJOR === 18 && MINOR >= 1)) {
testCommand = 'node --test'
} else if (MAJOR >= 18) {
testCommand = 'node_modules/.bin/node--test'
} else {
console.error('Node.js version 18 or higher is required.')
process.exit(1)
}
const { spawn } = require('child_process')
spawn(testCommand, { shell: true, stdio: 'inherit' })
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment