From 5cf6068037af608c3254fba1035f238a944ddc64 Mon Sep 17 00:00:00 2001 From: Gar Date: Wed, 10 Nov 2021 12:02:11 -0800 Subject: [PATCH] fix: clean up birthday command Clean up tests too PR-URL: https://github.com/npm/cli/pull/4033 Credit: @wraithgar Close: #4033 Reviewed-by: @lukekarrys --- lib/commands/birthday.js | 4 +--- test/lib/commands/birthday.js | 30 ++++++++---------------------- 2 files changed, 9 insertions(+), 25 deletions(-) diff --git a/lib/commands/birthday.js b/lib/commands/birthday.js index 4fa0268f8bcfa..5dd9331d836c8 100644 --- a/lib/commands/birthday.js +++ b/lib/commands/birthday.js @@ -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']) } } diff --git a/test/lib/commands/birthday.js b/test/lib/commands/birthday.js index c92f197c5f3f1..8c95dd57b2e3a 100644 --- a/test/lib/commands/birthday.js +++ b/test/lib/commands/birthday.js @@ -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', []) })