Skip to content

fix: test should not rely on node being on PATH - #113

Open
richardlau wants to merge 1 commit into
mainfrom
execpath
Open

richardlau wants to merge 1 commit into
mainfrom
execpath

Conversation

@richardlau

Copy link
Copy Markdown
Member

Use process.execPath instead of relying on the shebang for src/dist-indexer.js and node being on the PATH.


Without this, we have this edge condition if the test is run directly when node is not on the PATH.

rlau:~/sandbox/github/nodejs-dist-indexer$ ~/.nvs/node/22.23.4/x64/bin/node test/dist-indexer.test.js
env: ‘node’: No such file or directory
▶ dist-indexer
  ✖ no arguments produces expected error message (40.826214ms)
✖ dist-indexer (41.387342ms)
ℹ tests 1
ℹ suites 1
ℹ pass 0
ℹ fail 1
ℹ cancelled 0
ℹ skipped 0
ℹ todo 0
ℹ duration_ms 45.975528

✖ failing tests:

test at test/dist-indexer.test.js:7:3
✖ no arguments produces expected error message (40.826214ms)
  AssertionError [ERR_ASSERTION]: Expected values to be strictly deep-equal:
  + actual - expected

    Comparison {
  +   message: 'Command failed: /home/rlau/sandbox/github/nodejs-dist-indexer/src/dist-indexer.js\n' +
  +     'env: ‘node’: No such file or directory\n'
  -   message: /Missing --dist <directory> argument/
    }

      at TestContext.<anonymous> (/home/rlau/sandbox/github/nodejs-dist-indexer/test/dist-indexer.test.js:8:12)
      at Test.runInAsyncScope (node:async_hooks:214:14)
      at Test.run (node:internal/test_runner/test:1047:25)
      at Test.start (node:internal/test_runner/test:944:17)
      at node:internal/test_runner/test:1440:71
      at node:internal/per_context/primordials:466:82
      at new Promise (<anonymous>)
      at new SafePromise (node:internal/per_context/primordials:435:3)
      at node:internal/per_context/primordials:466:9
      at Array.map (<anonymous>) {
    generatedMessage: true,
    code: 'ERR_ASSERTION',
    actual: [Error],
    expected: [Object],
    operator: 'throws',
    diff: 'simple'
  }
rlau:~/sandbox/github/nodejs-dist-indexer$

Use `process.execPath` instead of relying on the shebang for
`src/dist-indexer.js` and `node` being on the `PATH`.

Signed-off-by: Richard Lau <richard.lau@ibm.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant