Skip to content

Commit

Permalink
fix: remove unused npm.setCmd method
Browse files Browse the repository at this point in the history
  • Loading branch information
lukekarrys committed Apr 25, 2024
1 parent 0708b3b commit 180b919
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 19 deletions.
9 changes: 2 additions & 7 deletions lib/npm.js
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,8 @@ class Npm {
return this.constructor.version
}

setCmd (cmd) {
// Call an npm command
async exec (cmd, args = this.argv) {
const Command = Npm.cmd(cmd)
const command = new Command(this)

Expand All @@ -88,12 +89,6 @@ class Npm {
process.env.npm_command = this.command
}

return command
}

// Call an npm command
async exec (cmd, args = this.argv) {
const command = this.setCmd(cmd)
return time.start(`command:${cmd}`, () => command.cmdExec(args))
}

Expand Down
11 changes: 0 additions & 11 deletions test/fixtures/mock-npm.js
Original file line number Diff line number Diff line change
Expand Up @@ -120,7 +120,6 @@ const setupMockNpm = async (t, {
// preload a command
command = null, // string name of the command
exec = null, // optionally exec the command before returning
setCmd = false,
// test dirs
prefixDir = {},
homeDir = {},
Expand Down Expand Up @@ -267,16 +266,6 @@ const setupMockNpm = async (t, {
const mockCommand = {}
if (command) {
const Cmd = mockNpm.Npm.cmd(command)
if (setCmd) {
// XXX(hack): This is a hack to allow fake-ish tests to set the currently
// running npm command without running exec. Generally, we should rely on
// actually exec-ing the command to asserting the state of the world
// through what is printed/on disk/etc. This is a stop-gap to allow tests
// that are time intensive to convert to continue setting the npm command
// this way. TODO: remove setCmd from all tests and remove the setCmd
// method from `lib/npm.js`
npm.setCmd(command)
}
mockCommand.cmd = new Cmd(npm)
mockCommand[command] = {
usage: Cmd.describeUsage,
Expand Down
13 changes: 12 additions & 1 deletion test/lib/utils/reify-output.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,18 @@ const mockReify = async (t, reify, { command, ...config } = {}) => {
const mock = await mockNpm(t, {
command,
config,
setCmd: true,
})

// Hack to adapt existing fake test. Make npm.command
// return whatever was passed in to this function.
// What it should be doing is npm.exec(command) but that
// breaks most of these tests because they dont expect
// a command to actually run.
Object.defineProperty(mock.npm, 'command', {
get () {
return command
},
enumerable: true,
})

reifyOutput(mock.npm, reify)
Expand Down

0 comments on commit 180b919

Please sign in to comment.