PKG-JS-AUTOPKGTEST(7)
π PKG-JS-AUTOPKGTEST π
okay bestie, welcome to pkg-js-autopkgtest β it's the autopkgtest runner that automatically tests Node.js packages, and it lives in the Miscellaneous Information Manual. no cap, this thing is your new bestie for shipping Debian Node packages without crying. π
β¨ NAME β¨
pkg-js-autopkgtest β autopkgtest runner to automatically test Node.js packages π
πΈ SYNOPSIS πΈ
- in
debian/control, insert"Testsuite: autopkgtest-pkg-nodejs" - write upstream test in
debian/tests/pkg-js/test(will be launched bysh -e) - if some other files than
"test*"and"debian/tests/test_modules/*"and installed files are needed, write a"debian/tests/pkg-js/files"with all needed directories/files
That's all, other debian/tests files will be written on-the-fly by autodep8 during autopkgtest π¦
If you want to launch the same test during build, simply add dh-sequence-nodejs in build dependencies β¨
π₯ HOW IT WORKS π₯
- if directory
debian/tests/test_modulesexists,NODE_PATHwill be set toNODE_PATH=debian/tests/test_modules:node_modules - if additional modules were linked during build, they will be linked into
node_module(debian/nodejs/extlinks) - if additional modules were copies during build, they will be copied into
node_module(debian/nodejs/extcopies) - if package contains some other components, they will be linked into
node_module - autopkgtest will launch 2 tests:
- a
"require"test (see below) π - the test defined in
debian/tests/pkg-js/testin a temporary dir (it links installed files)
- a
- if
dh-sequence-nodejsis a build dependency,dh_auto_testwill launch the same test (debian/tests/pkg-js/test) if exists, else just anode -e "require('.')". Note that you can override test during build usingdebian/nodejs/test - if file
debian/tests/pkg-js/require-nameexists, its content will be used as module name in"require"test (instead of usingpackage.jsonvalue)
π¦ FULL EXAMPLE π¦
debian/control
...
Testsuite: autopkgtest-pkg-nodejs
Build-Depends: dh-sequence-nodejs
...
debian/tests/pkg-js/test
mocha -R spec
π ADDITIONAL TEST PACKAGES OR TEST RESTRICTIONS π
autodep8 allows one to add additional packages during autopkgtest (and/or additional restrictions) by using a debian/tests/autopkgtest-pkg-nodejs.conf file:
extra_depends=mocha, npm
extra-restrictions=needs-internet
π ENABLE proto π
Since version 0.15.0, pkg-js-autopkgtest launches Node.js with --disable-proto=throw. This causes tests to fail if Object.prototype.__proto__ property is used. π
If a package can use this feature without security hole (for test for example), it is possible to disable this nodejs option by creating an empty debian/tests/pkg-js/enable_proto file, until Debian's Node.js enables this feature by default.
fr fr, read that twice before you go flipping flags, bestie π«Ά
π§ THE REQUIRE TEST π§
π How it works π
First, pkg-js-autopkgtest searches the module name.
- if
debian/tests/pkg-js/require-nameexists, its content will be used as module name - else if looks at
package.json"name"field:- if
debian/nodejs/mainexists, likedh-sequence-nodejs, it uses thepackage.jsonfrom this directory - else it uses
./package.json
- if
Then pkg-js-autopkgtest looks at package.json fields, not using the file mentioned above, but using the file installed by the Debian package to test (ie /usr/share/nodejs/<module-name>/package.json):
- if
typeequalsmodule, then:- it builds a
node_modulesdirectory with all available dependencies of the module - it builds a
test.mjsfile that tries to import the module to test and launch it
- it builds a
- if
mainisn't defined andindex.jsdoesn't exist, it skip the test (this avoids to try to test@types/<foo>modules) - else it simply launches a
nodejs -e "require('$moduleName')"
Since version 0.10.0, pkg-js-autopkgtest does the same test for all other modules installed in nodejs root directories (components installed by dh-sequence-nodejs using debian/nodejs/root_modules file). If one fail, the whole test is marked as failed. π
Returned values:
0if all tests succeed (even if some secondary modules are skipped)77if all tests succeed but the main module test was skipped. This value is used by autopkgtest to report a SKIP instead of a failure.- else, the number of failure. Then autopkgtest considers the test as FAIL
π Customize require test π
If you want to skip some secondary module tests, simply list them in debian/tests/pkg-js/require-SKIP (one module per line).
If you want to skip the whole "require" test, use this:
echo require > debian/tests/pkg-js/SKIP
π THE MAIN TEST π
pkg-js-autopkgtest uses the same test than dh-sequence-nodejs: it launches sh -ex debian/tests/pkg-js/test but using the files installed by the Debian package. β¨
β How main test works β
pkg-js-autopkgtest search for module name using the same way than "require" test. Then it prepares the test environment:
- it creates a temporary directory
- it links all files installed in the directory corresponding to module name
/usr/share/nodejs/<module-name> - it creates a
node_modulesdirectory and links into it:- all modules listed in
debian/nodejs/extlinks - all modules present in
debian/build_modulesanddebian/tests/test_modules - all other modules installed by the Debian package in nodejs root directories
debian/nodejs/root_modules
- all modules listed in
- it copies in
node_modulesdirectory all modules listed indebian/nodejs/extcopies - if looks at
debian/tests/pkg-js/files- if it exists, it copies all files/directories listed in it from source directory to temporary one
- else it copies from source directory to temporary one:
- all
test*files - all Makefile like files (
rollup.config.js,gulpfile.js,... )
- all
Then it changes its directory to the temporary one launches the test using sh -ex debian/tests/pkg-js/test.
π SEE ALSO π
π COPYRIGHT AND LICENSE π
Copyright Yadd <yadd@debian.org>
This library 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 2, or (at your option) any later version.
This program 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.
On Debian systems, the complete text of version 2 of the GNU General Public License can be found in /usr/share/common-licenses/GPL-2. If not, see GNU licenses;
and that's the whole vibe, bestie π«Ά this page dropped June 2024 and it's part of PKG-JS-AUTOPKGTEST(7), straight outta the Miscellaneous Information Manual. go test those packages, you're gonna slay π β¨π
π¦ where this page comes from
- debian trixie: pkg-js-autopkgtest 0.15.23 Β· GPL-2.0-or-later
- ubuntu questing: pkg-js-autopkgtest 0.16.0
- ubuntu resolute: pkg-js-autopkgtest 0.17.1 Β· GPL-2.0-or-later
- ubuntu stonking: pkg-js-autopkgtest 0.17.8 Β· GPL-2.0-or-later
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash on : a language model's rewrite of the original, under its terms