From 4fb6e2fd7fbbdb8791b4ccefe0433bd3cb62f0d5 Mon Sep 17 00:00:00 2001 From: Ruy Adorno Date: Mon, 22 Mar 2021 18:25:28 -0400 Subject: [PATCH] fix: npm birthday Replaces usage of flatOptions with npm.config. --- lib/birthday.js | 15 ++++----------- test/lib/birthday.js | 19 +++++++++++-------- 2 files changed, 15 insertions(+), 19 deletions(-) diff --git a/lib/birthday.js b/lib/birthday.js index 5ea855512f9f6..92b1dd1c2e5fe 100644 --- a/lib/birthday.js +++ b/lib/birthday.js @@ -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) } } diff --git a/test/lib/birthday.js b/test/lib/birthday.js index c818223fb51e5..0589be7a8eedb 100644 --- a/test/lib/birthday.js +++ b/test/lib/birthday.js @@ -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)