blob: 5159d530a12f228c0dcf94e81c3dd027f0c81cdd (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
|
;;; GNU Guix --- Tests for the node-build-system procedures.
;;; Copyright © 2026 Maxim Cournoyer <maxim@guixotic.coop>
;;;
;;; This file is part of GNU Guix.
;;;
;;; GNU Guix is free software; you can redistribute it and/or modify it
;;; under the terms of the GNU General Public License as published by
;;; the Free Software Foundation; either version 3 of the License, or (at
;;; your option) any later version.
;;;
;;; GNU Guix is distributed in the hope that it will be useful, but
;;; WITHOUT ANY WARRANTY; without even the implied warranty of
;;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
;;; GNU General Public License for more details.
;;;
;;; You should have received a copy of the GNU General Public License
;;; along with GNU Guix. If not, see <http://www.gnu.org/licenses/>.
(use-modules (json)
(guix build node-build-system)
(guix tests)
(srfi srfi-64))
(define (package.json)
"Sample package.json file."
(call-with-output-string
(lambda (out)
(scm->json
'(("devDependencies"
("typescript-eslint" . "^8.61.0")
("typescript" . "^5.9.3")
("typedoc" . "^0.28.19")
("htmlparser2" . "^10.1.0")
("eslint" . "^10.4.1")
("@types/node" . "^25.9.2"))
("dependencies"
("domelementtype" . "^3.0.0")
("boolbase" . ">=2.0.0"))
("peerDependencies"
("mkdirp" . ">=1.0.0")
("react" . "^16.8.0"))
("engines" ("node" . ">=20.19.0"))
("repository"
("url" . "https://example.com/dummy/dummy.git")
("type" . "git"))
("scripts"
("test" . "npm run test")
("lint" . "eslint .")
("build" . "tsc"))
("files" . #("dist" "src" "!**/*.spec.ts"))
("sideEffects" . #f)
("exports"
("." ("default" . "./dist/index.js") ("types" . "./dist/index.d.ts")))
("types" . "dist/index.d.ts")
("main" . "dist/index.js")
("license" . "GPL-3.0")
("description" . "Dummy package.json")
("version" . "6.0.1")
("name" . "dummy")
("type" . "module"))
out #:pretty #t))))
(define* (modify-json* #:rest all-arguments)
"Wrap modify-json to use our package.json test sample and avoid file I/O.
It also returns the data as an alist directly."
(mock ((guix build utils) with-atomic-file-replacement
(lambda (_ proc)
(call-with-input-string (package.json)
(lambda (in)
(call-with-output-string
(lambda (out)
(proc in out)))))))
(json-string->scm (apply modify-json all-arguments)
#:ordered #t)))
(test-begin "node related tests")
(test-equal "delete-dependencies"
'(("domelementtype" . "^3.0.0"))
(assoc-ref (modify-json*
(delete-dependencies '("boolbase")))
"dependencies"))
(test-equal "delete-dependencies/except"
'(("boolbase" . ">=2.0.0"))
(assoc-ref (modify-json*
(delete-dependencies/except '("boolbase")))
"dependencies"))
(test-equal "delete-dev-dependencies/except"
'(("@types/node" . "^25.9.2")
("typescript" . "^5.9.3"))
(assoc-ref (modify-json*
(delete-dev-dependencies/except
'("typescript" "@types/node")))
"devDependencies"))
(test-end)
|