diff options
Diffstat (limited to 'tests')
| -rw-r--r-- | tests/mason-core/installer/managers/npm_spec.lua | 30 |
1 files changed, 29 insertions, 1 deletions
diff --git a/tests/mason-core/installer/managers/npm_spec.lua b/tests/mason-core/installer/managers/npm_spec.lua index 1555b37d..4f81132b 100644 --- a/tests/mason-core/installer/managers/npm_spec.lua +++ b/tests/mason-core/installer/managers/npm_spec.lua @@ -1,12 +1,19 @@ +local Result = require "mason-core.result" local installer = require "mason-core.installer" local match = require "luassert.match" local npm = require "mason-core.installer.managers.npm" +local spawn = require "mason-core.spawn" local stub = require "luassert.stub" describe("npm manager", function() it("should init package.json", function() local ctx = create_dummy_context() stub(ctx.fs, "append_file") + stub(spawn, "npm") + spawn.npm.returns(Result.success {}) + spawn.npm.on_call_with({ "version", "--json" }).returns(Result.success { + stdout = [[ { "npm": "8.1.0" } ]], + }) installer.exec_in_context(ctx, function() npm.init() end) @@ -18,7 +25,28 @@ describe("npm manager", function() "--scope=mason", } assert.spy(ctx.fs.append_file).was_called(1) - assert.spy(ctx.fs.append_file).was_called_with(match.is_ref(ctx.fs), ".npmrc", "global-style=true") + assert.spy(ctx.fs.append_file).was_called_with(match.is_ref(ctx.fs), ".npmrc", "\nglobal-style=true") + end) + + it("should use install-strategy on npm >= 9", function() + local ctx = create_dummy_context() + stub(ctx.fs, "append_file") + stub(spawn, "npm") + spawn.npm.returns(Result.success {}) + spawn.npm.on_call_with({ "version", "--json" }).returns(Result.success { + stdout = [[ { "npm": "9.1.0" } ]], + }) + installer.exec_in_context(ctx, function() + npm.init() + end) + + assert.spy(ctx.spawn.npm).was_called(1) + assert.spy(ctx.spawn.npm).was_called_with { + "init", + "--yes", + "--scope=mason", + } + assert.spy(ctx.fs.append_file).was_called_with(match.is_ref(ctx.fs), ".npmrc", "\ninstall-strategy=shallow") end) it("should install", function() |
