diff options
| author | William Boman <william@redwill.se> | 2022-07-08 18:34:38 +0200 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2022-07-08 18:34:38 +0200 |
| commit | 976aa4fbee8a070f362cab6f6ec84e9251a90cf9 (patch) | |
| tree | 5e8d9c9c59444a25c7801b8f39763c4ba6e1f76d /tests/core/managers/npm_spec.lua | |
| parent | feat: add gotests, gomodifytags, impl (#28) (diff) | |
| download | mason-976aa4fbee8a070f362cab6f6ec84e9251a90cf9.tar mason-976aa4fbee8a070f362cab6f6ec84e9251a90cf9.tar.gz mason-976aa4fbee8a070f362cab6f6ec84e9251a90cf9.tar.bz2 mason-976aa4fbee8a070f362cab6f6ec84e9251a90cf9.tar.lz mason-976aa4fbee8a070f362cab6f6ec84e9251a90cf9.tar.xz mason-976aa4fbee8a070f362cab6f6ec84e9251a90cf9.tar.zst mason-976aa4fbee8a070f362cab6f6ec84e9251a90cf9.zip | |
refactor: add mason-schemas and mason-core modules (#29)
* refactor: add mason-schemas and move generated filetype map to mason-lspconfig
* refactor: add mason-core module
Diffstat (limited to 'tests/core/managers/npm_spec.lua')
| -rw-r--r-- | tests/core/managers/npm_spec.lua | 194 |
1 files changed, 0 insertions, 194 deletions
diff --git a/tests/core/managers/npm_spec.lua b/tests/core/managers/npm_spec.lua deleted file mode 100644 index a2170a63..00000000 --- a/tests/core/managers/npm_spec.lua +++ /dev/null @@ -1,194 +0,0 @@ -local spy = require "luassert.spy" -local match = require "luassert.match" -local mock = require "luassert.mock" -local installer = require "mason.core.installer" -local npm = require "mason.core.managers.npm" -local Result = require "mason.core.result" -local spawn = require "mason.core.spawn" -local path = require "mason.core.path" - -describe("npm manager", function() - it( - "should call npm install", - async_test(function() - local handle = InstallHandleGenerator "dummy" - local ctx = InstallContextGenerator(handle, { requested_version = "42.13.37" }) - installer.run_installer(ctx, npm.packages { "main-package", "supporting-package", "supporting-package2" }) - assert.spy(ctx.spawn.npm).was_called_with(match.tbl_containing { - "install", - match.tbl_containing { - "main-package@42.13.37", - "supporting-package", - "supporting-package2", - }, - }) - end) - ) - - it( - "should call npm init if node_modules and package.json doesnt exist", - async_test(function() - local handle = InstallHandleGenerator "dummy" - local ctx = InstallContextGenerator(handle) - ctx.fs.file_exists = mockx.returns(false) - ctx.fs.dir_exists = mockx.returns(false) - installer.run_installer(ctx, function() - npm.install { "main-package", "supporting-package", "supporting-package2" } - end) - assert.spy(ctx.spawn.npm).was_called_with { - "init", - "--yes", - "--scope=mason", - } - end) - ) - - it( - "should append .npmrc file", - async_test(function() - local handle = InstallHandleGenerator "dummy" - local ctx = InstallContextGenerator(handle, { requested_version = "42.13.37" }) - ctx.fs.append_file = spy.new(mockx.just_runs()) - installer.run_installer(ctx, npm.packages { "main-package", "supporting-package", "supporting-package2" }) - assert.spy(ctx.fs.append_file).was_called(1) - assert.spy(ctx.fs.append_file).was_called_with(ctx.fs, ".npmrc", "global-style=true") - end) - ) - - it( - "should provide receipt information", - async_test(function() - local handle = InstallHandleGenerator "dummy" - local ctx = InstallContextGenerator(handle, { requested_version = "42.13.37" }) - installer.run_installer(ctx, npm.packages { "main-package", "supporting-package", "supporting-package2" }) - assert.same({ - type = "npm", - package = "main-package", - }, ctx.receipt.primary_source) - assert.same({ - { - type = "npm", - package = "supporting-package", - }, - { - type = "npm", - package = "supporting-package2", - }, - }, ctx.receipt.secondary_sources) - end) - ) -end) - -describe("npm version check", function() - it( - "should return current version", - async_test(function() - spawn.npm = spy.new(function() - return Result.success { - stdout = [[ - { - "name": "bash", - "dependencies": { - "bash-language-server": { - "version": "2.0.0", - "resolved": "https://registry.npmjs.org/bash-language-server/-/bash-language-server-2.0.0.tgz" - } - } - } - ]], - } - end) - - local result = npm.get_installed_primary_package_version( - mock.new { - primary_source = mock.new { - type = "npm", - package = "bash-language-server", - }, - }, - path.package_prefix "dummy" - ) - - assert.spy(spawn.npm).was_called(1) - assert.spy(spawn.npm).was_called_with { "ls", "--json", cwd = path.package_prefix "dummy" } - assert.is_true(result:is_success()) - assert.equals("2.0.0", result:get_or_nil()) - - spawn.npm = nil - end) - ) - - it( - "should return outdated primary package", - async_test(function() - spawn.npm = spy.new(function() - -- npm outdated returns with exit code 1 if outdated packages are found! - return Result.failure { - exit_code = 1, - stdout = [[ - { - "bash-language-server": { - "current": "1.17.0", - "wanted": "1.17.0", - "latest": "2.0.0", - "dependent": "bash", - "location": "/tmp/install/dir" - } - } - ]], - } - end) - - local result = npm.check_outdated_primary_package( - mock.new { - primary_source = mock.new { - type = "npm", - package = "bash-language-server", - }, - }, - path.package_prefix "dummy" - ) - - assert.spy(spawn.npm).was_called(1) - assert.spy(spawn.npm).was_called_with { - "outdated", - "--json", - "bash-language-server", - cwd = path.package_prefix "dummy", - } - assert.is_true(result:is_success()) - assert.same({ - name = "bash-language-server", - current_version = "1.17.0", - latest_version = "2.0.0", - }, result:get_or_nil()) - - spawn.npm = nil - end) - ) - - it( - "should return failure if primary package is not outdated", - async_test(function() - spawn.npm = spy.new(function() - return Result.success { - stdout = "{}", - } - end) - - local result = npm.check_outdated_primary_package( - mock.new { - primary_source = mock.new { - type = "npm", - package = "bash-language-server", - }, - }, - path.package_prefix "dummy" - ) - - assert.is_true(result:is_failure()) - assert.equals("Primary package is not outdated.", result:err_or_nil()) - spawn.npm = nil - end) - ) -end) |
