diff options
author | Gar <gar+gh@danger.computer> | 2021-02-22 20:26:41 +0300 |
---|---|---|
committer | isaacs <i@izs.me> | 2021-02-22 23:30:20 +0300 |
commit | 773ae3e7ee87b96aeb241cdde4c0c6b0f122a375 (patch) | |
tree | 3db8989736f8366f30168abe063f5ed4aebd5d79 /test | |
parent | 4e58274ed0fd2dd29d3c8d6c7c47f37a37dc0f0f (diff) |
chore(refactor): clean up lifecycle-cmds
This is a small incremental step in removing some of the complexity
surrounding the `npm` object in our code.
It moves that object one level up the chain of code, with the end goal
being that we will only require it once in the codebase, ultimately allowing
us to improve our tests.
I also changed the command that it calls to `run-script` because that is the
base command. `run` was an alias, and that is one more layer of hoops a
developer would have to jump through to find what file in `./lib` is even
being referenced here.
PR-URL: https://github.com/npm/cli/pull/2753
Credit: @wraithgar
Close: #2753
Reviewed-by: @isaacs
Diffstat (limited to 'test')
-rw-r--r-- | test/lib/test.js | 6 | ||||
-rw-r--r-- | test/lib/utils/lifecycle-cmd.js | 15 |
2 files changed, 9 insertions, 12 deletions
diff --git a/test/lib/test.js b/test/lib/test.js index 9a44e4760..6f4a7395d 100644 --- a/test/lib/test.js +++ b/test/lib/test.js @@ -3,7 +3,7 @@ const requireInject = require('require-inject') let RUN_ARGS = null const npmock = { commands: { - run: (args, cb) => { + 'run-script': (args, cb) => { RUN_ARGS = args cb() }, @@ -26,12 +26,12 @@ t.test('run a test', t => { }) const otherErr = new Error('should see this') - npmock.commands.run = (args, cb) => cb(lcErr) + npmock.commands['run-script'] = (args, cb) => cb(lcErr) test([], (er) => { t.equal(er, 'Test failed. See above for more details.') }) - npmock.commands.run = (args, cb) => cb(otherErr) + npmock.commands['run-script'] = (args, cb) => cb(otherErr) test([], (er) => { t.match(er, { message: 'should see this' }) }) diff --git a/test/lib/utils/lifecycle-cmd.js b/test/lib/utils/lifecycle-cmd.js index 0eb342cee..9e45b15e4 100644 --- a/test/lib/utils/lifecycle-cmd.js +++ b/test/lib/utils/lifecycle-cmd.js @@ -1,15 +1,12 @@ const t = require('tap') -const requireInject = require('require-inject') -const lifecycleCmd = requireInject('../../../lib/utils/lifecycle-cmd.js', { - '../../../lib/npm.js': { - commands: { - run: (args, cb) => cb(null, 'called npm.commands.run'), - }, +const lifecycleCmd = require('../../../lib/utils/lifecycle-cmd.js') +const npm = { + commands: { + 'run-script': (args, cb) => cb(null, 'called npm.commands.run'), }, -}) - +} t.test('create a lifecycle command', t => { - const cmd = lifecycleCmd('asdf') + const cmd = lifecycleCmd(npm, 'asdf') t.equal(cmd.completion, require('../../../lib/utils/completion/none.js'), 'empty completion') cmd(['some', 'args'], (er, result) => { t.strictSame(result, 'called npm.commands.run') |