Skip to content

Commit

Permalink
fix: clean up birthday command
Browse files Browse the repository at this point in the history
Clean up tests too

PR-URL: #4033
Credit: @wraithgar
Close: #4033
Reviewed-by: @lukekarrys
  • Loading branch information
wraithgar committed Nov 10, 2021
1 parent cd6d3a9 commit 5cf6068
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 25 deletions.
4 changes: 1 addition & 3 deletions lib/commands/birthday.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,8 @@ const BaseCommand = require('../base-command.js')

class Birthday extends BaseCommand {
async exec () {
this.npm.config.set('package', ['@npmcli/npm-birthday'])
this.npm.config.set('yes', true)
const exec = await this.npm.cmd('exec')
return exec.exec(['npm-birthday'])
return this.npm.exec('exec', ['@npmcli/npm-birthday'])
}
}

Expand Down
30 changes: 8 additions & 22 deletions test/lib/commands/birthday.js
Original file line number Diff line number Diff line change
@@ -1,28 +1,14 @@
const t = require('tap')
const { fake: mockNpm } = require('../../fixtures/mock-npm')
const { real: mockNpm } = require('../../fixtures/mock-npm')

t.test('birthday', async t => {
t.plan(4)
const config = {
yes: false,
package: [],
}
const npm = mockNpm({
config,
cmd: async (cmd) => {
t.ok(cmd, 'exec', 'calls out to exec command')
return {
exec: async (args) => {
t.equal(npm.config.get('yes'), true, 'should say yes')
t.strictSame(npm.config.get('package'), ['@npmcli/npm-birthday'],
'uses correct package')
t.strictSame(args, ['npm-birthday'], 'called with correct args')
},
}
t.plan(2)
const { Npm } = mockNpm(t, {
libnpmexec: ({ args, yes }) => {
t.ok(yes)
t.match(args, ['@npmcli/npm-birthday'])
},
})
const Birthday = require('../../../lib/commands/birthday.js')
const birthday = new Birthday(npm)

await birthday.exec([])
const npm = new Npm()
await npm.exec('birthday', [])
})

0 comments on commit 5cf6068

Please sign in to comment.