projects/guix·blob javascript-team · refs

123 lines · 4.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 json-utils)
21 (guix build node-build-system)
22 (guix tests)
23 (srfi srfi-64))
24
25(define (package.json)
26 "Sample package.json file."
27 (call-with-output-string
28 (lambda (out)
29 (scm->json
30 '(("devDependencies"
31 ("typescript-eslint" . "^8.61.0")
32 ("typescript" . "^5.9.3")
33 ("typedoc" . "^0.28.19")
34 ("htmlparser2" . "^10.1.0")
35 ("eslint" . "^10.4.1")
36 ("@types/node" . "^25.9.2"))
37 ("dependencies"
38 ("domelementtype" . "^3.0.0")
39 ("boolbase" . ">=2.0.0"))
40 ("peerDependencies"
41 ("mkdirp" . ">=1.0.0")
42 ("react" . "^16.8.0"))
43 ("engines" ("node" . ">=20.19.0"))
44 ("repository"
45 ("url" . "https://example.com/dummy/dummy.git")
46 ("type" . "git"))
47 ("scripts"
48 ("test" . "npm run test")
49 ("lint" . "eslint .")
50 ("build" . "tsc"))
51 ("files" . #("dist" "src" "!**/*.spec.ts"))
52 ("sideEffects" . #f)
53 ("exports"
54 ("." ("default" . "./dist/index.js") ("types" . "./dist/index.d.ts")))
55 ("types" . "dist/index.d.ts")
56 ("main" . "dist/index.js")
57 ("license" . "GPL-3.0")
58 ("description" . "Dummy package.json")
59 ("version" . "6.0.1")
60 ("name" . "dummy")
61 ("type" . "module"))
62 out #:pretty #t))))
63
64(define* (modify-json* #:rest all-arguments)
65 "Wrap modify-json to use our package.json test sample and avoid file I/O.
66It also returns the data as an alist directly."
67 (mock ((guix build utils) with-atomic-file-replacement
68 (lambda (_ proc)
69 (call-with-input-string (package.json)
70 (lambda (in)
71 (call-with-output-string
72 (lambda (out)
73 (proc in out)))))))
74 (json-string->scm (apply modify-json all-arguments)
75 #:ordered #t)))
76
77
78(test-begin "node related tests")
79
80(test-equal "delete-dependencies"
81 (list '(("domelementtype" . "^3.0.0"))
82 ;; Ensure development dependencies are unaffected.
83 '(("typescript-eslint" . "^8.61.0") ;devDependencies
84 ("typescript" . "^5.9.3")
85 ("typedoc" . "^0.28.19")
86 ("htmlparser2" . "^10.1.0")
87 ("eslint" . "^10.4.1")
88 ("@types/node" . "^25.9.2"))
89 '(("mkdirp" . ">=1.0.0") ;peerDependencies
90 ("react" . "^16.8.0")))
91 (let ((result (modify-json* (delete-dependencies
92 '("boolbase")))))
93 (list (assoc-ref result "dependencies")
94 (assoc-ref result "devDependencies")
95 (assoc-ref result "peerDependencies"))))
96
97(test-equal "delete-dependencies/except"
98 (list '(("boolbase" . ">=2.0.0")) ;in 'dependencies'
99 ;; Ensure development dependencies are not affected (as boolbase is
100 ;; not in their set).
101 '() ;devDependencies
102 '()) ;peerDependencies
103 (let ((result (modify-json* (delete-dependencies/except
104 '("boolbase")))))
105 (list (assoc-ref result "dependencies")
106 (assoc-ref result "devDependencies")
107 (assoc-ref result "peerDependencies"))))
108
109(test-equal "delete-dev-dependencies/except"
110 (list '(("typescript" . "^5.9.3") ;devDependencies
111 ("@types/node" . "^25.9.2"))
112 '(("react" . "^16.8.0")) ;peerDependencies
113 ;; Ensure normal dependencies are unaffected.
114 '(("domelementtype" . "^3.0.0")
115 ("boolbase" . ">=2.0.0")))
116 (let ((result (modify-json* (delete-dev-dependencies/except
117 '("typescript" "@types/node" ;devDependencies
118 "react"))))) ;peerDependencies
119 (list (assoc-ref result "devDependencies")
120 (assoc-ref result "peerDependencies")
121 (assoc-ref result "dependencies"))))
122
123(test-end)