summaryrefslogtreecommitdiff
path: root/tests
diff options
context:
space:
mode:
Diffstat (limited to 'tests')
-rw-r--r--tests/node.scm99
1 files changed, 99 insertions, 0 deletions
diff --git a/tests/node.scm b/tests/node.scm
new file mode 100644
index 00000000000..5159d530a12
--- /dev/null
+++ b/tests/node.scm
@@ -0,0 +1,99 @@
1;;; GNU Guix --- Tests for the node-build-system procedures.
2;;; Copyright © 2026 Maxim Cournoyer <maxim@guixotic.coop>
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 "delete-dependencies"
80 '(("domelementtype" . "^3.0.0"))
81 (assoc-ref (modify-json*
82 (delete-dependencies '("boolbase")))
83 "dependencies"))
84
85(test-equal "delete-dependencies/except"
86 '(("boolbase" . ">=2.0.0"))
87 (assoc-ref (modify-json*
88 (delete-dependencies/except '("boolbase")))
89 "dependencies"))
90
91(test-equal "delete-dev-dependencies/except"
92 '(("@types/node" . "^25.9.2")
93 ("typescript" . "^5.9.3"))
94 (assoc-ref (modify-json*
95 (delete-dev-dependencies/except
96 '("typescript" "@types/node")))
97 "devDependencies"))
98
99(test-end)