|
| 1 | +local Result = require "mason-core.result" |
| 2 | +local installer = require "mason-core.installer" |
| 3 | +local match = require "luassert.match" |
| 4 | +local pnpm = require "mason-core.installer.managers.pnpm" |
| 5 | +local spawn = require "mason-core.spawn" |
| 6 | +local spy = require "luassert.spy" |
| 7 | +local stub = require "luassert.stub" |
| 8 | + |
| 9 | +describe("pnpm manager", function() |
| 10 | + it("should init package.json", function() |
| 11 | + local ctx = create_dummy_context() |
| 12 | + stub(ctx.fs, "read_file") |
| 13 | + stub(ctx.fs, "write_file") |
| 14 | + stub(spawn, "pnpm") |
| 15 | + ctx.fs.read_file.returns '{"name": "my-package", "version": "1.0.0"}' |
| 16 | + spawn.pnpm.returns(Result.success {}) |
| 17 | + installer.exec_in_context(ctx, function() |
| 18 | + pnpm.init() |
| 19 | + end) |
| 20 | + |
| 21 | + assert.spy(ctx.spawn.pnpm).was_called(1) |
| 22 | + assert.spy(ctx.spawn.pnpm).was_called_with { "init" } |
| 23 | + assert.spy(ctx.fs.read_file).was_called(1) |
| 24 | + assert.spy(ctx.fs.read_file).was_called_with(match.is_ref(ctx.fs), "package.json") |
| 25 | + assert.spy(ctx.fs.write_file).was_called(1) |
| 26 | + assert |
| 27 | + .spy(ctx.fs.write_file) |
| 28 | + .was_called_with(match.is_ref(ctx.fs), "package.json", match.has_match '"name":"@mason/my--package"') |
| 29 | + end) |
| 30 | + |
| 31 | + it("should install extra packages", function() |
| 32 | + local ctx = create_dummy_context() |
| 33 | + installer.exec_in_context(ctx, function() |
| 34 | + pnpm.install("my-package", "1.0.0", { |
| 35 | + extra_packages = { "extra-package" }, |
| 36 | + }) |
| 37 | + end) |
| 38 | + |
| 39 | + assert.spy(ctx.spawn.pnpm).was_called(1) |
| 40 | + assert.spy(ctx.spawn.pnpm).was_called_with { |
| 41 | + "add", |
| 42 | + |
| 43 | + { "extra-package" }, |
| 44 | + } |
| 45 | + end) |
| 46 | +end) |
0 commit comments