Skip to content

Commit 180b919

Browse files
committed
fix: remove unused npm.setCmd method
1 parent 0708b3b commit 180b919

File tree

3 files changed

+14
-19
lines changed

3 files changed

+14
-19
lines changed

lib/npm.js

+2-7
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,8 @@ class Npm {
7777
return this.constructor.version
7878
}
7979

80-
setCmd (cmd) {
80+
// Call an npm command
81+
async exec (cmd, args = this.argv) {
8182
const Command = Npm.cmd(cmd)
8283
const command = new Command(this)
8384

@@ -88,12 +89,6 @@ class Npm {
8889
process.env.npm_command = this.command
8990
}
9091

91-
return command
92-
}
93-
94-
// Call an npm command
95-
async exec (cmd, args = this.argv) {
96-
const command = this.setCmd(cmd)
9792
return time.start(`command:${cmd}`, () => command.cmdExec(args))
9893
}
9994

test/fixtures/mock-npm.js

-11
Original file line numberDiff line numberDiff line change
@@ -120,7 +120,6 @@ const setupMockNpm = async (t, {
120120
// preload a command
121121
command = null, // string name of the command
122122
exec = null, // optionally exec the command before returning
123-
setCmd = false,
124123
// test dirs
125124
prefixDir = {},
126125
homeDir = {},
@@ -267,16 +266,6 @@ const setupMockNpm = async (t, {
267266
const mockCommand = {}
268267
if (command) {
269268
const Cmd = mockNpm.Npm.cmd(command)
270-
if (setCmd) {
271-
// XXX(hack): This is a hack to allow fake-ish tests to set the currently
272-
// running npm command without running exec. Generally, we should rely on
273-
// actually exec-ing the command to asserting the state of the world
274-
// through what is printed/on disk/etc. This is a stop-gap to allow tests
275-
// that are time intensive to convert to continue setting the npm command
276-
// this way. TODO: remove setCmd from all tests and remove the setCmd
277-
// method from `lib/npm.js`
278-
npm.setCmd(command)
279-
}
280269
mockCommand.cmd = new Cmd(npm)
281270
mockCommand[command] = {
282271
usage: Cmd.describeUsage,

test/lib/utils/reify-output.js

+12-1
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,18 @@ const mockReify = async (t, reify, { command, ...config } = {}) => {
88
const mock = await mockNpm(t, {
99
command,
1010
config,
11-
setCmd: true,
11+
})
12+
13+
// Hack to adapt existing fake test. Make npm.command
14+
// return whatever was passed in to this function.
15+
// What it should be doing is npm.exec(command) but that
16+
// breaks most of these tests because they dont expect
17+
// a command to actually run.
18+
Object.defineProperty(mock.npm, 'command', {
19+
get () {
20+
return command
21+
},
22+
enumerable: true,
1223
})
1324

1425
reifyOutput(mock.npm, reify)

0 commit comments

Comments
 (0)