Skip to content

Some tests are not fully CWD-agnostic #61303

@LiviaMedeiros

Description

@LiviaMedeiros

Version

v26.0.0-pre

Platform

Linux tumba 6.18.3-gentoo-yuran #1 SMP Sun Jan  4 21:50:21 +08 2026 x86_64 Intel(R) Core(TM)2 Quad CPU Q8200 @ 2.33GHz GenuineIntel GNU/Linux

Subsystem

test

What steps will reproduce the bug?

# cd /
# git clone --depth=1 https://github.com/nodejs/node.git
# cd node
# ./configure && make test-only

In realistic scenarios, cd / is implicit: for example, right after chroot or pivot_root into disposable environment.

How often does it reproduce? Is there a required condition?

Always.

What is the expected behavior? Why is that the expected behavior?

All tests are expected to pass.

What do you see instead?

A bunch of failing tests. Assertions are failing with something like:

+   '(node:*) UnhandledPromiseRejectionWarning: Unhandled promise rejection. This error originated either by throwing inside of an async function without a catch block, or by rejecting a promise which was not handled with .catch(). To terminate the node process on unhandled promise rejection, use the CLI flag `--unhandled-rejections=strict` (see https:*js.org*api*cli.html#cli_unhandled_rejections_mode). (rejection id: 1)\n'
-   '(node:*) UnhandledPromiseRejectionWarning: Unhandled promise rejection. This error originated either by throwing inside of an async function without a catch block, or by rejecting a promise which was not handled with .catch(). To terminate the node process on unhandled promise rejection, use the CLI flag `--unhandled-rejections=strict` (see https:*nodejs.org*api*cli.html#cli_unhandled_rejections_mode). (rejection id: 1)\n'
   'Error: an error!\n' +
+   '    at functionD (*/test/fixtures/source-map*_modules/error-stack/enclosing-call-site.js:16:17)\n' +
+   '    at functionC (*/test/fixtures/source-map*_modules/error-stack/enclosing-call-site.js:10:3)\n' +
+   '    at functionB (*/test/fixtures/source-map*_modules/error-stack/enclosing-call-site.js:6:3)\n' +
+   '    at functionA (*/test/fixtures/source-map*_modules/error-stack/enclosing-call-site.js:2:3)\n' +
+   '    at Object.<anonymous> (*/test/fixtures/source-map*_modules/error-stack/enclosing-call-site.js:24:3)\n' +
-   '    at functionD (*/test/fixtures/source-map/node_modules/error-stack/enclosing-call-site.js:16:17)\n' +
-   '    at functionC (*/test/fixtures/source-map/node_modules/error-stack/enclosing-call-site.js:10:3)\n' +
-   '    at functionB (*/test/fixtures/source-map/node_modules/error-stack/enclosing-call-site.js:6:3)\n' +
-   '    at functionA (*/test/fixtures/source-map/node_modules/error-stack/enclosing-call-site.js:2:3)\n' +
-   '    at Object.<anonymous> (*/test/fixtures/source-map/node_modules/error-stack/enclosing-call-site.js:24:3)\n' +
    'Error: an error!\n' +
+   '    at functionD (*/test/fixtures/source-map*_modules/error-stack/enclosing-call-site-min.js:1:156)\n' +
+   '    at functionC (*/test/fixtures/source-map*_modules/error-stack/enclosing-call-site-min.js:1:97)\n' +
+   '    at functionB (*/test/fixtures/source-map*_modules/error-stack/enclosing-call-site-min.js:1:60)\n' +
+   '    at functionA (*/test/fixtures/source-map*_modules/error-stack/enclosing-call-site-min.js:1:26)\n' +
+   '    at Object.<anonymous> (*/test/fixtures/source-map*_modules/error-stack/enclosing-call-site-min.js:1:199)\n'
-   '    at functionD (*/test/fixtures/source-map/node_modules/error-stack/enclosing-call-site-min.js:1:156)\n' +
-   '    at functionC (*/test/fixtures/source-map/node_modules/error-stack/enclosing-call-site-min.js:1:97)\n' +
-   '    at functionB (*/test/fixtures/source-map/node_modules/error-stack/enclosing-call-site-min.js:1:60)\n' +
-   '    at functionA (*/test/fixtures/source-map/node_modules/error-stack/enclosing-call-site-min.js:1:26)\n' +
-   '    at Object.<anonymous> (*/test/fixtures/source-map/node_modules/error-stack/enclosing-call-site-min.js:1:199)\n'

Additional information

The reason is that the tests simply remove matches to process.cwd(). In the examples above, CWD being /node corrupts http://nodejs.org and /node_modules.
Obviously there are other directories that may break tests, e.g. /test.

List of tests :

  • test/parallel/test-node-output-v8-warning.mjs
  • test/parallel/test-node-output-vm.mjs
  • test/parallel/test-node-output-console.mjs
  • test/parallel/test-node-output-sourcemaps.mjs
  • test/parallel/test-node-output-errors.mjs

Also the most edge case is CWD being /, assuming no conflict with /lib. In this case, additional failing tests are:

  • test/parallel/test-cli-permission-deny-fs.js - has skips if founds itself in /etc but doesn't check if it's even worse.
  • test/es-module/test-esm-import-meta.mjs - uses regexps that assume that leading / and /test... are not overlapped.

All of the above might be a valid good first issue Issues that are suitable for first-time contributors. material.


And then there are at least these tests in test-runner that validate test output, using common/assertSnapshot.js to normalize it:

  • test/test-runner/test-output-abort-runs-after-hook.mjs
  • test/test-runner/test-output-abort-hooks.mjs
  • test/test-runner/test-output-abort-suite.mjs
  • test/test-runner/test-output-abort.mjs
  • test/test-runner/test-output-filtered-suite-throws.mjs
  • test/test-runner/test-output-default-output.mjs
  • test/test-runner/test-output-global-after-should-fail-the-test.mjs
  • test/test-runner/test-output-source-mapped-locations.mjs
  • test/test-runner/test-output-describe-it.mjs
  • test/test-runner/test-output-test-runner-plan.mjs
  • test/test-runner/test-output-hooks.mjs
  • test/test-runner/test-output-test-timeout-flag.mjs
  • test/test-runner/test-output-output.mjs
  • test/test-runner/test-output-unfinished-suite-async-error.mjs
  • test/test-runner/test-output-test-timeout-flag-with-test.mjs
  • test/test-runner/test-output-timeout-in-before-each.mjs
  • test/test-runner/test-output-test-runner-plan-timeout.mjs
  • test/test-runner/test-output-lcov-reporter.mjs
  • test/test-runner/test-output-output-cli.mjs

Adjusting them individually would be an exercise in futility, so it's just an extra in case of bright ideas on making transformations from assertSnapshot more strict&robust and unify test-node-output-* as well.

Metadata

Metadata

Assignees

No one assigned

    Labels

    good first issueIssues that are suitable for first-time contributors.testIssues and PRs related to the tests.

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions