Contribution issue : failing test after fork "lifecycle-path.js"

What I Wanted to Do

After discussing an idea in the forum, I decided to try to make my first PR to the CLI.

I forked npm/cli to olivr70/cli, cloned it, npm install and the npm test before exploring the code base.

What Happened Instead

The tests ran for a while, lifecycle-path.js failed :

test/broken-under-nyc-and-travis/lifecycle-path.js … 25/26 8s
make sure the path is correct, with directory of current node and warn-only detection
not ok informs user that there is no node binary in PATH
found: >
npm WARN lifecycle The node binary used for scripts is /usr/bin/node but npm
is using
/home/olivr70/repos/github/olivr70/cli/test/broken-under-nyc-and-travis/lifecycle-path/node-bin/my_bundled_node/node
itself. Use the --scripts-prepend-node-path option to include the path for
the node binary npm was executed with.
pattern: /there is no node binary in the current PATH/
at:
line: 187
column: 13
file: test/broken-under-nyc-and-travis/lifecycle-path.js
type: global
stack: |
test/broken-under-nyc-and-travis/lifecycle-path.js:187:13
f (node_modules/once/once.js:25:25)
ChildProcess. (test/common-tap.js:167:5)

or from the tap file:

    # Subtest: make sure the path is correct, with directory of current node and warn-only detection
        ok 1 - exit code
        ok 2 - spit out a warning
        ok 3 - mention the path of the binary npm itself is using.
        not ok 4 - informs user that there is no node binary in PATH
          ---
          found: >
            npm WARN lifecycle The node binary used for scripts is /usr/bin/node but npm
            is using
            /home/olivr70/repos/github/olivr70/cli/test/broken-under-nyc-and-travis/lifecycle-path/node-bin/my_bundled_node/node
            itself. Use the `--scripts-prepend-node-path` option to include the path for
            the node binary npm was executed with.
          pattern: /there is no node binary in the current PATH/
          at:
            line: 241
            column: 15
            file: test/broken-under-nyc-and-travis/lifecycle-path.js
            type: global
          stack: |
            test/broken-under-nyc-and-travis/lifecycle-path.js:241:15
            f (node_modules/once/once.js:25:25)
            ChildProcess.<anonymous> (test/common-tap.js:167:5)
          ...
        
        ok 5 - should be equivalent
        1..5
        # failed 1 of 5 tests

Reproduction Steps

  1. git clone git@github.com:olivr70/cli.git cli
  2. cd cli
  3. npm install
  4. npm test
    5.1 also happens when running the test standalone with ./node_modules/.bin/tap test/broken-under-nyc-and-travis/lifecycle-path.js

It also happens when running the specific test from VS Code using the recipe Debugging node-tap tests in VS Code

Details

When stepping through the test using VSCode, the common.npm() callback on line 181 is invoked with :

  • er = null
  • code = 0
  • stderr = "npm WARN lifecycle The node binary used for scripts is /usr/bin/node but npm is using /home/olivr70/repos/github/olivr70/cli/test/broken-under-nyc-and-travis/lifecycle-path/node-bin/my_bundled_node/node itself. Use the --scripts-prepend-node-path option to include the path for the node binary npm was executed with.
    "
  • stdout = "

@ env /home/olivr70/repos/github/olivr70/cli/test/broken-under-nyc-and-travis/lifecycle-path
env

npm_config_cache_lock_stale=60000
npm_config_ham_it_up=
npm_config_legacy_bundling=
npm_config_sign_git_tag=
npm_config_user_agent=npm/6.10.2 node/v12.5.0 linux x64
npm_config_always_auth=
npm_config_bin_links=true
npm_config_key=
npm_config_allow_same_version=
npm_config_description=true
npm_config_fetch_retries=2
npm_config_heading=npm
npm_config_if_present=
npm_config_init_version=1.0.0
npm_config_user=1000
npm_node_execpath=/home/olivr70/repos/github/olivr70/cli/test/broken-under-nyc-and-travis/lifecycle-path/node-bin/my_bundled_node/node
npm_config_prefer_online=
npm_config_noproxy=
HOME=/home/olivr70
npm_config_force=
npm_config_only=
npm_config_read_only=
npm_config__olivr70_registry=https://registry.npmjs.org/
npm_config_cache_min=10
npm_config_init_license=ISC
npm_config_editor=vi
npm_config_rollback=true
npm_config_tag_version_prefix=v
npm_config_cache_max=Infinity
npm_config_timing=
npm_config_userconfig=/home/olivr70/.npmrc
npm_config_init_author_name=
npm_config_engine_strict=
npm_config_init_author_url=
npm_config_preid=
npm_config_tmp=/tmp
npm_config_depth=Infinity
npm_config_package_lock_only=
npm_config_save_dev=
npm_config_usage=
npm_config_metrics_registry=https://registry.npmjs.org/
npm_config_cafile=
npm_config_otp=
npm_config_package_lock=true
npm_config_progress=true
npm_config_https_proxy=
npm_config_save_prod=
npm_config_audit=
npm_config_cidr=
npm_config_onload_script=
npm_config_sso_type=oauth
npm_config_rebuild_bundle=true
npm_config_save_bundle=
npm_config_shell=bash
npm_config_dry_run=
npm_config_prefix=/home/olivr70/repos/github/olivr70/cli/test/broken-under-nyc-and-travis/lifecycle-path/node-bin
npm_config_scope=
npm_config_browser=
npm_config_cache_lock_wait=10000
npm_config_ignore_prepublish=
npm_config_registry=https://registry.npmjs.org/
npm_config_save_optional=
npm_config_searchopts=
npm_config_versions=
npm_config_cache=/home/olivr70/repos/github/olivr70/cli/test/npm_cache_lifecycle-path
npm_config_send_metrics=
npm_config_proxy=
npm_config__bit_registry=https://node.bit.dev/
npm_config_global_style=
npm_config_ignore_scripts=
npm_config_version=
npm_config_local_address=
npm_config_viewer=man
npm_config_node_gyp=/home/olivr70/repos/github/olivr70/cli/node_modules/node-gyp/bin/node-gyp.js
PATH=/home/olivr70/repos/github/olivr70/cli/node_modules/npm-lifecycle/node-gyp-bin:/home/olivr70/repos/github/olivr70/cli/test/broken-under-nyc-and-travis/lifecycle-path/node_modules/.bin:/bin:/usr/bin
npm_package_name=
npm_config_audit_level=low
npm_config_prefer_offline=
NODE=/home/olivr70/repos/github/olivr70/cli/test/broken-under-nyc-and-travis/lifecycle-path/node-bin/my_bundled_node/node
npm_config_color=true
npm_config_sign_git_commit=
npm_config_fetch_retry_mintimeout=10000
npm_config_maxsockets=50
npm_config_offline=
npm_config_sso_poll_frequency=500
npm_package_scripts_env=env
npm_config_umask=0002
npm_config_fetch_retry_maxtimeout=60000
npm_config_loglevel=notice
npm_config_logs_max=10
npm_config_message=%s
npm_lifecycle_script=env
npm_config_ca=
npm_config_cert=
npm_config_global=
npm_config_link=
npm_package_version=
npm_config_access=
npm_config_also=
npm_config_save=true
npm_config_unicode=
npm_lifecycle_event=env
npm_config_argv={“remain”:,“cooked”:[“run-script”,“env”],“original”:[“run-script”,“env”]}
npm_config_unsafe_perm=true
npm_config_before=
npm_config_long=
npm_config_production=
npm_config_searchlimit=20
npm_config_update_notifier=true
npm_config_auth_type=legacy
npm_config_node_version=12.5.0
npm_config_tag=latest
npm_config_pid=17812
npm_config_git_tag_version=true
npm_config_commit_hooks=true
npm_config_script_shell=
npm_config_shrinkwrap=true
npm_config_init_licence=
npm_config_fetch_retry_factor=10
npm_config_save_exact=
npm_config_strict_ssl=true
npm_config_dev=
npm_config_globalconfig=/home/olivr70/repos/github/olivr70/cli/test/broken-under-nyc-and-travis/lifecycle-path/node-bin/etc/npmrc
npm_config_init_module=/home/olivr70/.npm-init.js
npm_config_parseable=
npm_config_globalignorefile=/home/olivr70/repos/github/olivr70/cli/test/broken-under-nyc-and-travis/lifecycle-path/node-bin/etc/npmignore
npm_execpath=/home/olivr70/repos/github/olivr70/cli/bin/npm-cli.js
PWD=/home/olivr70/repos/github/olivr70/cli/test/broken-under-nyc-and-travis/lifecycle-path
npm_config_cache_lock_retries=10
npm_config_searchstaleness=900
npm_config_scripts_prepend_node_path=warn-only
npm_config_node_options=
npm_config_save_prefix=^
npm_config_init_author_email=
npm_config_group=1000
npm_config_searchexclude=
npm_config_foo=bar
npm_config_git=git
npm_config_optional=true
npm_config_json=
INIT_CWD=/home/olivr70/repos/github/olivr70/cli/test/broken-under-nyc-and-travis/lifecycle-path
"

I have been using npm for years on this machine (Ubuntu 18.04) without a problem

I I use n to manage node version

$ n --version
4.1.0
$ which -a node
/home/olivr70/n/bin/node
/usr/bin/node
$ node --version
v12.5.0
$ /usr/bin/node --version
v9.11.2

Platform Info

$ npm --versions
{
  npm: '6.10.0',
  ares: '1.15.0',
  brotli: '1.0.7',
  cldr: '35.1',
  http_parser: '2.8.0',
  icu: '64.2',
  llhttp: '1.1.4',
  modules: '72',
  napi: '4',
  nghttp2: '1.38.0',
  node: '12.5.0',
  openssl: '1.1.1c',
  tz: '2019a',
  unicode: '12.1',
  uv: '1.29.1',
  v8: '7.5.288.22-node.14',
  zlib: '1.2.11'
}
# From the project directory
$ node ./lib/npm.js --versions
{
  npm: '6.10.2',
  ares: '1.15.0',
  brotli: '1.0.7',
  cldr: '35.1',
  http_parser: '2.8.0',
  icu: '64.2',
  llhttp: '1.1.4',
  modules: '72',
  napi: '4',
  nghttp2: '1.38.0',
  node: '12.5.0',
  openssl: '1.1.1c',
  tz: '2019a',
  unicode: '12.1',
  uv: '1.29.1',
  v8: '7.5.288.22-node.14',
  zlib: '1.2.11'
}

$ node -p process.platform
linux

I made a PR to solve this : Corrected test/lifecycle-path.js by olivr70 · Pull Request #228 · npm/cli