Files
guix-mirror/tests/node.scm
Maxim Cournoyer 728408c2b0 build/node: Clean-up deprecation.
(guix build json-utils): should not be deprecating things that are to be
deprecated in (guix build node-build-system).  For things now defined in (guix
build json-utils), opt to re-export rather than define a deprecation, as this
would otherwise cause warnings that cannot be resolved (due to the conflicting
definitions).

* guix/build/json-utils.scm: Export with-atomic-json-file-replacement*. Do not
define/export delete-fields, replace-fields and add-fields.  Avoid double
definition of with-atomic-json-file-replacement and modify-json.
* guix/build/node-build-system.scm: Streamline imports/re-exports.  Do not
deprecate things that were newly added to (guix build json-utils).
* tests/node.scm: Add (guix build json-utils) import.
2026-08-27 10:59:22 +09:00

124 lines
4.7 KiB
Scheme

;;; 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 json-utils)
(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"
(list '(("domelementtype" . "^3.0.0"))
;; Ensure development dependencies are unaffected.
'(("typescript-eslint" . "^8.61.0") ;devDependencies
("typescript" . "^5.9.3")
("typedoc" . "^0.28.19")
("htmlparser2" . "^10.1.0")
("eslint" . "^10.4.1")
("@types/node" . "^25.9.2"))
'(("mkdirp" . ">=1.0.0") ;peerDependencies
("react" . "^16.8.0")))
(let ((result (modify-json* (delete-dependencies
'("boolbase")))))
(list (assoc-ref result "dependencies")
(assoc-ref result "devDependencies")
(assoc-ref result "peerDependencies"))))
(test-equal "delete-dependencies/except"
(list '(("boolbase" . ">=2.0.0")) ;in 'dependencies'
;; Ensure development dependencies are not affected (as boolbase is
;; not in their set).
'() ;devDependencies
'()) ;peerDependencies
(let ((result (modify-json* (delete-dependencies/except
'("boolbase")))))
(list (assoc-ref result "dependencies")
(assoc-ref result "devDependencies")
(assoc-ref result "peerDependencies"))))
(test-equal "delete-dev-dependencies/except"
(list '(("typescript" . "^5.9.3") ;devDependencies
("@types/node" . "^25.9.2"))
'(("react" . "^16.8.0")) ;peerDependencies
;; Ensure normal dependencies are unaffected.
'(("domelementtype" . "^3.0.0")
("boolbase" . ">=2.0.0")))
(let ((result (modify-json* (delete-dev-dependencies/except
'("typescript" "@types/node" ;devDependencies
"react"))))) ;peerDependencies
(list (assoc-ref result "devDependencies")
(assoc-ref result "peerDependencies")
(assoc-ref result "dependencies"))))
(test-end)