Skip to content

Commit

Permalink
test: migrate to node test runner (#312)
Browse files Browse the repository at this point in the history
  • Loading branch information
ilteoood authored Mar 1, 2025
1 parent 892b120 commit ff11d04
Show file tree
Hide file tree
Showing 9 changed files with 245 additions and 213 deletions.
6 changes: 3 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
"scripts": {
"lint": "eslint",
"lint:fix": "eslint --fix",
"test": "tap"
"test": "c8 --100 node --test"
},
"dependencies": {
"@octokit/rest": "^19.0.3",
Expand All @@ -30,10 +30,10 @@
"yargs-parser": "^21.1.0"
},
"devDependencies": {
"c8": "^10.1.3",
"eslint": "^9.17.0",
"neostandard": "^0.12.0",
"proxyquire": "^2.1.3",
"tap": "^16.0.0"
"proxyquire": "^2.1.3"
},
"repository": {
"type": "git",
Expand Down
194 changes: 93 additions & 101 deletions test/args.test.js
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
'use strict'

const t = require('tap')
const { test } = t
const { test } = require('node:test')

const parseArgs = require('../lib/args')
const proxyquire = require('proxyquire')

test('parse all args', t => {
t.plan(1)
t.plan(24)

const argv = [
'--arg', 'arg',
Expand Down Expand Up @@ -36,64 +36,60 @@ test('parse all args', t => {
]
const parsedArgs = parseArgs(argv)

t.strictSame(parsedArgs, {
_: [],
help: true,
arg: 'arg',
path: 'a/path',
tag: 'vPattern',
verbose: 'info',
semver: 'major',
major: true,
dryRun: true,
remote: 'upstream',
branch: 'v1',
fromCommit: 'commitFrom',
toCommit: 'commitTo',
noVerify: true,
npmOtp: '123123',
silent: true,
npmAccess: 'public',
npmDistTag: 'next',
ghToken: 'MY_KEY',
ghReleaseEdit: true,
ghReleaseDraft: true,
ghReleasePrerelease: true,
ghReleaseBody: true,
ghGroupByLabel: ['bugfix', 'docs']
})
t.assert.deepStrictEqual(parsedArgs._, [])
t.assert.deepStrictEqual(parsedArgs.help, true)
t.assert.deepStrictEqual(parsedArgs.arg, 'arg')
t.assert.deepStrictEqual(parsedArgs.path, 'a/path')
t.assert.deepStrictEqual(parsedArgs.tag, 'vPattern')
t.assert.deepStrictEqual(parsedArgs.verbose, 'info')
t.assert.deepStrictEqual(parsedArgs.semver, 'major')
t.assert.deepStrictEqual(parsedArgs.major, true)
t.assert.deepStrictEqual(parsedArgs.dryRun, true)
t.assert.deepStrictEqual(parsedArgs.remote, 'upstream')
t.assert.deepStrictEqual(parsedArgs.branch, 'v1')
t.assert.deepStrictEqual(parsedArgs.fromCommit, 'commitFrom')
t.assert.deepStrictEqual(parsedArgs.toCommit, 'commitTo')
t.assert.deepStrictEqual(parsedArgs.noVerify, true)
t.assert.deepStrictEqual(parsedArgs.npmOtp, '123123')
t.assert.deepStrictEqual(parsedArgs.silent, true)
t.assert.deepStrictEqual(parsedArgs.npmAccess, 'public')
t.assert.deepStrictEqual(parsedArgs.npmDistTag, 'next')
t.assert.deepStrictEqual(parsedArgs.ghToken, 'MY_KEY')
t.assert.deepStrictEqual(parsedArgs.ghReleaseEdit, true)
t.assert.deepStrictEqual(parsedArgs.ghReleaseDraft, true)
t.assert.deepStrictEqual(parsedArgs.ghReleasePrerelease, true)
t.assert.deepStrictEqual(parsedArgs.ghReleaseBody, true)
t.assert.deepStrictEqual(parsedArgs.ghGroupByLabel, ['bugfix', 'docs'])
})

test('check default values', t => {
t.plan(1)
t.plan(24)
const parsedArgs = parseArgs([])

t.strictSame(parsedArgs, {
_: [],
help: false,
arg: undefined,
path: process.cwd(),
tag: undefined,
verbose: 'warn',
semver: undefined,
major: false,
dryRun: false,
remote: 'origin',
branch: 'main',
fromCommit: 'HEAD',
toCommit: undefined,
noVerify: undefined,
npmOtp: undefined,
silent: false,
npmAccess: undefined,
npmDistTag: undefined,
ghToken: 'GITHUB_OAUTH_TOKEN',
ghReleaseEdit: false,
ghReleaseDraft: false,
ghReleasePrerelease: false,
ghReleaseBody: false,
ghGroupByLabel: []
})
t.assert.deepStrictEqual(parsedArgs._, [])
t.assert.deepStrictEqual(parsedArgs.help, false)
t.assert.deepStrictEqual(parsedArgs.arg, undefined)
t.assert.deepStrictEqual(parsedArgs.path, process.cwd())
t.assert.deepStrictEqual(parsedArgs.tag, undefined)
t.assert.deepStrictEqual(parsedArgs.verbose, 'warn')
t.assert.deepStrictEqual(parsedArgs.semver, undefined)
t.assert.deepStrictEqual(parsedArgs.major, false)
t.assert.deepStrictEqual(parsedArgs.dryRun, false)
t.assert.deepStrictEqual(parsedArgs.remote, 'origin')
t.assert.deepStrictEqual(parsedArgs.branch, 'main')
t.assert.deepStrictEqual(parsedArgs.fromCommit, 'HEAD')
t.assert.deepStrictEqual(parsedArgs.toCommit, undefined)
t.assert.deepStrictEqual(parsedArgs.noVerify, undefined)
t.assert.deepStrictEqual(parsedArgs.npmOtp, undefined)
t.assert.deepStrictEqual(parsedArgs.silent, false)
t.assert.deepStrictEqual(parsedArgs.npmAccess, undefined)
t.assert.deepStrictEqual(parsedArgs.npmDistTag, undefined)
t.assert.deepStrictEqual(parsedArgs.ghToken, 'GITHUB_OAUTH_TOKEN')
t.assert.deepStrictEqual(parsedArgs.ghReleaseEdit, false)
t.assert.deepStrictEqual(parsedArgs.ghReleaseDraft, false)
t.assert.deepStrictEqual(parsedArgs.ghReleasePrerelease, false)
t.assert.deepStrictEqual(parsedArgs.ghReleaseBody, false)
t.assert.deepStrictEqual(parsedArgs.ghGroupByLabel, [])
})

test('parse args with = assignment', t => {
Expand Down Expand Up @@ -127,7 +123,7 @@ test('parse args with = assignment', t => {
]
const parsedArgs = parseArgs(argv)

t.strictSame(parsedArgs, {
t.assert.deepStrictEqual(parsedArgs, {
_: [],
help: false,
arg: 'arg',
Expand Down Expand Up @@ -156,7 +152,7 @@ test('parse args with = assignment', t => {
})

test('parse boolean args', t => {
t.plan(1)
t.plan(8)

const argv = [
'--help',
Expand All @@ -170,20 +166,18 @@ test('parse boolean args', t => {
]
const parsedArgs = parseArgs(argv)

t.match(parsedArgs, {
help: true,
major: true,
dryRun: true,
noVerify: true,
ghReleaseEdit: true,
ghReleaseDraft: true,
ghReleasePrerelease: true,
ghReleaseBody: true
})
t.assert.deepStrictEqual(parsedArgs.help, true)
t.assert.deepStrictEqual(parsedArgs.major, true)
t.assert.deepStrictEqual(parsedArgs.dryRun, true)
t.assert.deepStrictEqual(parsedArgs.noVerify, true)
t.assert.deepStrictEqual(parsedArgs.ghReleaseEdit, true)
t.assert.deepStrictEqual(parsedArgs.ghReleaseDraft, true)
t.assert.deepStrictEqual(parsedArgs.ghReleasePrerelease, true)
t.assert.deepStrictEqual(parsedArgs.ghReleaseBody, true)
})

test('parse args aliases', t => {
t.plan(1)
t.plan(24)

const argv = [
'-h',
Expand All @@ -204,32 +198,30 @@ test('parse args aliases', t => {
]
const parsedArgs = parseArgs(argv)

t.strictSame(parsedArgs, {
_: [],
help: true,
arg: undefined,
path: 'a/path',
tag: 'vPattern',
verbose: 'info',
semver: 'major',
major: true,
dryRun: false,
remote: 'upstream',
branch: 'v1.x',
fromCommit: 'HEAD',
toCommit: undefined,
noVerify: true,
npmOtp: undefined,
silent: false,
npmAccess: 'public',
npmDistTag: undefined,
ghToken: 'MY_KEY',
ghReleaseEdit: true,
ghReleaseDraft: false,
ghReleasePrerelease: false,
ghReleaseBody: true,
ghGroupByLabel: ['bugfix', 'docs']
})
t.assert.deepStrictEqual(parsedArgs._, [])
t.assert.deepStrictEqual(parsedArgs.help, true)
t.assert.deepStrictEqual(parsedArgs.arg, undefined)
t.assert.deepStrictEqual(parsedArgs.path, 'a/path')
t.assert.deepStrictEqual(parsedArgs.tag, 'vPattern')
t.assert.deepStrictEqual(parsedArgs.verbose, 'info')
t.assert.deepStrictEqual(parsedArgs.semver, 'major')
t.assert.deepStrictEqual(parsedArgs.major, true)
t.assert.deepStrictEqual(parsedArgs.dryRun, false)
t.assert.deepStrictEqual(parsedArgs.remote, 'upstream')
t.assert.deepStrictEqual(parsedArgs.branch, 'v1.x')
t.assert.deepStrictEqual(parsedArgs.fromCommit, 'HEAD')
t.assert.deepStrictEqual(parsedArgs.toCommit, undefined)
t.assert.deepStrictEqual(parsedArgs.noVerify, true)
t.assert.deepStrictEqual(parsedArgs.npmOtp, undefined)
t.assert.deepStrictEqual(parsedArgs.silent, false)
t.assert.deepStrictEqual(parsedArgs.npmAccess, 'public')
t.assert.deepStrictEqual(parsedArgs.npmDistTag, undefined)
t.assert.deepStrictEqual(parsedArgs.ghToken, 'MY_KEY')
t.assert.deepStrictEqual(parsedArgs.ghReleaseEdit, true)
t.assert.deepStrictEqual(parsedArgs.ghReleaseDraft, false)
t.assert.deepStrictEqual(parsedArgs.ghReleasePrerelease, false)
t.assert.deepStrictEqual(parsedArgs.ghReleaseBody, true)
t.assert.deepStrictEqual(parsedArgs.ghGroupByLabel, ['bugfix', 'docs'])
})

test('get GitHub Token from env', t => {
Expand All @@ -239,7 +231,7 @@ test('get GitHub Token from env', t => {
const argv = ['-k', 'MY_ENV_KEY']
const parsedArgs = parseArgs(argv)

t.equal(parsedArgs.ghToken, process.env.MY_ENV_KEY)
t.assert.deepStrictEqual(parsedArgs.ghToken, process.env.MY_ENV_KEY)
})

test('autoload config parameters', t => {
Expand All @@ -262,9 +254,9 @@ test('autoload config parameters', t => {
const argv = ['--remote', 'arg-remote']
const parsedArgs = parseArgs(argv)

t.equal(parsedArgs.ghToken, store['gh-token'])
t.equal(parsedArgs.ghReleaseEdit, true)
t.equal(parsedArgs.noVerify, true)
t.equal(parsedArgs.verbose, 'debug')
t.equal(parsedArgs.remote, 'arg-remote')
t.assert.deepStrictEqual(parsedArgs.ghToken, store['gh-token'])
t.assert.deepStrictEqual(parsedArgs.ghReleaseEdit, true)
t.assert.deepStrictEqual(parsedArgs.noVerify, true)
t.assert.deepStrictEqual(parsedArgs.verbose, 'debug')
t.assert.deepStrictEqual(parsedArgs.remote, 'arg-remote')
})
42 changes: 31 additions & 11 deletions test/cli.test.js
Original file line number Diff line number Diff line change
@@ -1,50 +1,70 @@
'use strict'

const t = require('tap')
const { test } = require('node:test')
const h = require('./helper')
const pkg = require('../package.json')

t.test('defaults to help', t => {
test('defaults to help', t => {
t.plan(1)
const cli = h.execute('', [])
cli.stdout.setEncoding('utf8')
const { promise, resolve } = h.withResolvers()
cli.stdout.on('data', output => {
t.match(output, h.readFileHelp('help'))
t.assert.deepStrictEqual(output, h.readFileHelp('help'))
resolve()
})

return promise
})

t.test('version', t => {
test('version', t => {
t.plan(1)
const cli = h.execute('', ['--version'])
cli.stdout.setEncoding('utf8')
const { promise, resolve } = h.withResolvers()
cli.stdout.on('data', output => {
t.match(output, pkg.version)
t.assert.ok(output.includes(pkg.version))
resolve()
})

return promise
})

t.test('version strict', t => {
test('version strict', t => {
t.plan(1)
const cli = h.execute('', ['-v'])
cli.stdout.setEncoding('utf8')
const { promise, resolve } = h.withResolvers()
cli.stdout.on('data', output => {
t.match(output, pkg.version)
t.assert.ok(output.includes(pkg.version))
resolve()
})

return promise
})

t.test('version win over help', t => {
test('version win over help', t => {
t.plan(1)
const cli = h.execute('', ['-h', '-v'])
cli.stdout.setEncoding('utf8')
const { promise, resolve } = h.withResolvers()
cli.stdout.on('data', output => {
t.match(output, pkg.version)
t.assert.ok(output.includes(pkg.version))
resolve()
})

return promise
})

t.test('config error', t => {
test('config error', t => {
t.plan(1)
const cli = h.execute('config', ['--arg', 'wrong'])
cli.stdout.setEncoding('utf8')
const { promise, resolve } = h.withResolvers()
cli.stdout.on('data', output => {
t.match(output, /arg must be equal to one of the allowed values/)
t.assert.match(output, /arg must be equal to one of the allowed values/)
resolve()
})

return promise
})
Loading

0 comments on commit ff11d04

Please sign in to comment.