From 8ffeb71dfb248b4a76744bd06cd4d6100f17c8ae Mon Sep 17 00:00:00 2001 From: Gar Date: Thu, 7 Oct 2021 18:40:03 -0700 Subject: chore: refactor commands This is the first phase of refactoring the internal structure of the npm commands to set us up for future changes. This iteration changes the function signature of `exec` for all the commands to be a async (no more callbacks), and also groups all the commands into their own subdirectory. It also removes the Proxy `npm.commands` object, in favor of an `npm.cmd` and `npm.exec` function that breaks up the two things that proxy was doing. Namely, getting to the attributes of a given command (`npm.cmd` now does this), and actually running the command `npm.exec` does this. PR-URL: https://github.com/npm/cli/pull/3959 Credit: @wraithgar Close: #3959 Reviewed-by: @lukekarrys --- test/lib/commands/birthday.js | 28 ++++++++++++++++++++++++++++ 1 file changed, 28 insertions(+) create mode 100644 test/lib/commands/birthday.js (limited to 'test/lib/commands/birthday.js') diff --git a/test/lib/commands/birthday.js b/test/lib/commands/birthday.js new file mode 100644 index 000000000..c92f197c5 --- /dev/null +++ b/test/lib/commands/birthday.js @@ -0,0 +1,28 @@ +const t = require('tap') +const { fake: 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') + }, + } + }, + }) + const Birthday = require('../../../lib/commands/birthday.js') + const birthday = new Birthday(npm) + + await birthday.exec([]) +}) -- cgit v1.2.3