aboutsummaryrefslogtreecommitdiffstats
path: root/tests
diff options
context:
space:
mode:
authorWilliam Boman <william@redwill.se>2023-10-11 15:33:10 +0200
committerWilliam Boman <william@redwill.se>2025-02-16 09:49:17 +0100
commit40bb6ddfa84b91f58a53f9d92ce7a3ce0c57b9aa (patch)
tree1c092b13b2c40c693db87f040410411977990cef /tests
parentfix(package): support older receipt structures (#1520) (diff)
downloadmason-40bb6ddfa84b91f58a53f9d92ce7a3ce0c57b9aa.tar
mason-40bb6ddfa84b91f58a53f9d92ce7a3ce0c57b9aa.tar.gz
mason-40bb6ddfa84b91f58a53f9d92ce7a3ce0c57b9aa.tar.bz2
mason-40bb6ddfa84b91f58a53f9d92ce7a3ce0c57b9aa.tar.lz
mason-40bb6ddfa84b91f58a53f9d92ce7a3ce0c57b9aa.tar.xz
mason-40bb6ddfa84b91f58a53f9d92ce7a3ce0c57b9aa.tar.zst
mason-40bb6ddfa84b91f58a53f9d92ce7a3ce0c57b9aa.zip
refactor(receipt): change receipt structure and remove old builder APIs (#1521)
Diffstat (limited to 'tests')
-rw-r--r--tests/fixtures/receipts/1.0.json23
-rw-r--r--tests/fixtures/receipts/1.1.json27
-rw-r--r--tests/fixtures/receipts/1.2.json19
-rw-r--r--tests/mason-core/installer/installer_spec.lua5
-rw-r--r--tests/mason-core/receipt_spec.lua86
5 files changed, 157 insertions, 3 deletions
diff --git a/tests/fixtures/receipts/1.0.json b/tests/fixtures/receipts/1.0.json
new file mode 100644
index 00000000..e16d68ef
--- /dev/null
+++ b/tests/fixtures/receipts/1.0.json
@@ -0,0 +1,23 @@
+{
+ "schema_version": "1.0",
+ "primary_source": {
+ "type": "npm",
+ "package": "@angular/language-server"
+ },
+ "links": {
+ "bin": {
+ "ngserver": "node_modules/.bin/ngserver"
+ }
+ },
+ "metrics": {
+ "start_time": 1694752057715,
+ "completion_time": 1694752066467
+ },
+ "secondary_sources": [
+ {
+ "type": "npm",
+ "package": "typescript"
+ }
+ ],
+ "name": "angular-language-server"
+}
diff --git a/tests/fixtures/receipts/1.1.json b/tests/fixtures/receipts/1.1.json
new file mode 100644
index 00000000..87d6905a
--- /dev/null
+++ b/tests/fixtures/receipts/1.1.json
@@ -0,0 +1,27 @@
+{
+ "schema_version": "1.1",
+ "metrics": {
+ "start_time": 1694752380220,
+ "completion_time": 1694752386830
+ },
+ "links": {
+ "share": {},
+ "opt": {},
+ "bin": {
+ "ngserver": "node_modules/.bin/ngserver"
+ }
+ },
+ "name": "angular-language-server",
+ "primary_source": {
+ "type": "registry+v1",
+ "id": "pkg:npm/%40angular/language-server@16.1.8",
+ "source": {
+ "extra_packages": [
+ "typescript@5.1.3"
+ ],
+ "version": "16.1.8",
+ "package": "@angular/language-server"
+ }
+ },
+ "secondary_sources": []
+}
diff --git a/tests/fixtures/receipts/1.2.json b/tests/fixtures/receipts/1.2.json
new file mode 100644
index 00000000..75a14f09
--- /dev/null
+++ b/tests/fixtures/receipts/1.2.json
@@ -0,0 +1,19 @@
+{
+ "name": "angular-language-server",
+ "links": {
+ "bin": {
+ "ngserver": "node_modules/.bin/ngserver"
+ },
+ "opt": {},
+ "share": {}
+ },
+ "metrics": {
+ "completion_time": 1694752770559,
+ "start_time": 1694752764840
+ },
+ "schema_version": "1.2",
+ "source": {
+ "type": "registry+v1",
+ "id": "pkg:npm/%40angular/language-server@16.1.8"
+ }
+}
diff --git a/tests/mason-core/installer/installer_spec.lua b/tests/mason-core/installer/installer_spec.lua
index 04de82ba..3e291308 100644
--- a/tests/mason-core/installer/installer_spec.lua
+++ b/tests/mason-core/installer/installer_spec.lua
@@ -87,12 +87,11 @@ describe("installer", function()
local receipt = vim.json.decode(arg)
assert.is_true(match.tbl_containing {
name = "dummy",
- primary_source = match.same {
+ source = match.same {
type = handle.package.spec.schema,
id = handle.package.spec.source.id,
},
- secondary_sources = match.same {},
- schema_version = "1.1",
+ schema_version = "1.2",
metrics = match.is_table(),
links = match.same {
bin = { executable = "target" },
diff --git a/tests/mason-core/receipt_spec.lua b/tests/mason-core/receipt_spec.lua
new file mode 100644
index 00000000..05ce1439
--- /dev/null
+++ b/tests/mason-core/receipt_spec.lua
@@ -0,0 +1,86 @@
+local InstallReceipt = require("mason-core.receipt").InstallReceipt
+local fs = require "mason-core.fs"
+
+local function fixture(file)
+ return vim.json.decode(fs.sync.read_file(("./tests/fixtures/receipts/%s"):format(file)))
+end
+
+describe("receipt ::", function()
+ it("should parse 1.0 structures", function()
+ local receipt = InstallReceipt.new(fixture "1.0.json")
+
+ assert.equals("angular-language-server", receipt:get_name())
+ assert.equals("1.0", receipt:get_schema_version())
+ assert.same({ type = "npm", package = "@angular/language-server" }, receipt:get_source())
+ assert.same({
+ bin = {
+ ngserver = "node_modules/.bin/ngserver",
+ },
+ }, receipt:get_links())
+ assert.is_true(receipt:is_schema_min "1.0")
+ end)
+
+ it("should parse 1.1 structures", function()
+ local receipt = InstallReceipt.new(fixture "1.1.json")
+
+ assert.equals("angular-language-server", receipt:get_name())
+ assert.equals("1.1", receipt:get_schema_version())
+ assert.same({
+ type = "registry+v1",
+ id = "pkg:npm/%40angular/language-server@16.1.8",
+
+ source = {
+ extra_packages = { "typescript@5.1.3" },
+ version = "16.1.8",
+ package = "@angular/language-server",
+ },
+ }, receipt:get_source())
+ assert.same({
+ bin = {
+ ngserver = "node_modules/.bin/ngserver",
+ },
+ opt = {},
+ share = {},
+ }, receipt:get_links())
+ assert.is_true(receipt:is_schema_min "1.1")
+ end)
+
+ it("should parse 1.2 structures", function()
+ local receipt = InstallReceipt.new(fixture "1.2.json")
+
+ assert.equals("angular-language-server", receipt:get_name())
+ assert.equals("1.2", receipt:get_schema_version())
+ assert.same({
+ type = "registry+v1",
+ id = "pkg:npm/%40angular/language-server@16.1.8",
+ }, receipt:get_source())
+ assert.same({
+ bin = {
+ ngserver = "node_modules/.bin/ngserver",
+ },
+ opt = {},
+ share = {},
+ }, receipt:get_links())
+ assert.is_true(receipt:is_schema_min "1.2")
+ end)
+
+ describe("schema versions ::", function()
+ it("should check minimum compatibility", function()
+ local receipt_1_0 = InstallReceipt.new { schema_version = "1.0" }
+ local receipt_1_1 = InstallReceipt.new { schema_version = "1.1" }
+ local receipt_1_2 = InstallReceipt.new { schema_version = "1.2" }
+
+ assert.is_true(receipt_1_0:is_schema_min "1.0")
+ assert.is_true(receipt_1_1:is_schema_min "1.0")
+ assert.is_true(receipt_1_2:is_schema_min "1.0")
+
+ assert.is_false(receipt_1_0:is_schema_min "1.1")
+ assert.is_true(receipt_1_1:is_schema_min "1.1")
+ assert.is_true(receipt_1_2:is_schema_min "1.1")
+
+ assert.is_false(receipt_1_0:is_schema_min "1.2")
+ assert.is_false(receipt_1_1:is_schema_min "1.2")
+ assert.is_true(receipt_1_2:is_schema_min "1.2")
+ end)
+ end)
+end)