projects/guix·blob master · refs

108 lines · 3.7 KiB

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