Skip to content

Commit

Permalink
fix: npm birthday
Browse files Browse the repository at this point in the history
Replaces usage of flatOptions with npm.config.
  • Loading branch information
ruyadorno committed Mar 22, 2021
1 parent b7b4491 commit 4fb6e2f
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 19 deletions.
15 changes: 4 additions & 11 deletions lib/birthday.js
Original file line number Diff line number Diff line change
@@ -1,16 +1,9 @@
class Birthday {
constructor (npm) {
this.npm = npm
Object.defineProperty(this.npm, 'flatOptions', {
value: {
...npm.flatOptions,
package: ['@npmcli/npm-birthday'],
yes: true,
},
})
}
const BaseCommand = require('./base-command.js')

class Birthday extends BaseCommand {
exec (args, cb) {
this.npm.config.set('package', ['@npmcli/npm-birthday'])
this.npm.config.set('yes', true)
return this.npm.commands.exec(['npm-birthday'], cb)
}
}
Expand Down
19 changes: 11 additions & 8 deletions test/lib/birthday.js
Original file line number Diff line number Diff line change
@@ -1,20 +1,23 @@
const t = require('tap')
const npm = {
flatOptions: {
yes: false,
package: [],
},
const mockNpm = require('../fixtures/mock-npm')

const config = {
yes: false,
package: [],
}
const npm = mockNpm({
config,
commands: {
exec: (args, cb) => {
t.equal(npm.flatOptions.yes, true, 'should say yes')
t.strictSame(npm.flatOptions.package, ['@npmcli/npm-birthday'],
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.match(cb, Function, 'callback is a function')
cb()
},
},
}
})

const Birthday = require('../../lib/birthday.js')
const birthday = new Birthday(npm)
Expand Down

0 comments on commit 4fb6e2f

Please sign in to comment.