-
Notifications
You must be signed in to change notification settings - Fork 1.4k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
process.env.PATH missing in tests on Windows #3014
Comments
https://nodejs.org/api/process.html#processenv This implies some magic that would not survive the copying, though presumably at least one version of the variable is copied. That said, I'd think within the tests Node.js should again make the variables case-insensitive. What Node.js version are you using? And could you share your AVA config? Could you try disabling AVA's use of worker threads to see if that helps? What does |
I am using Node.js v14.19.1 on Windows. Turning off I created a small repository to test the issue: https://github.com/emilis-ideait/ava-process-env-path-on-windows
I should be able to test with Node.js v16 on Windows in a couple of weeks. |
My impression is that somehow in worker threads |
Update the implementation of `resolveExecutable` to accept the environment variables so that they can explicitly be provided to which [1]. All internal code and tests have been updated accordingly, no external changes. This is in an effort to fix a problem (bug?) where environment variables aren't always passed on correctly to subprocesses. The problem is described in [2], though if Shescape is used in a forked process on Windows it would face the same problem. Funny to see that `getShellName` name unit tests for both Unix and Windows already generated and provided environment variables (: -- 1. https://www.npmjs.com/package/which 2. avajs/ava#3014
Update the implementation of `resolveExecutable` to accept the environment variables so that they can explicitly be provided to which [1]. All internal code and tests have been updated accordingly, no external changes. This is in an effort to fix a problem where environment variables aren't always passed on correctly to subprocesses. The problem is described in [2], though if Shescape is used in a forked process on Windows it would face the same problem. (As a problem found through the test runner, use of which [1] in tests has been updated similarly. As a result of this change, the integration and e2e test on Windows are quite a bit slower (because now they actually look up the executable). Hence, both of these suites have been updated to use separated test files in order to better leverage AVA's concurrency - speeding up individual files and avoiding timeouts as well as running tests quicker if cores are available. This change also allowed for including executables without a file extension in the integration and e2e tests, further improving coverage. (This replaced the `.EXE` coverage as extensionless executables are resolved to `.EXE`, thus reducing test count without reducing coverage.) As a side note, it was funny to see that `getShellName` name unit tests for both Unix and Windows already generated and provided environment variables (: -- 1. https://www.npmjs.com/package/which 2. avajs/ava#3014
TL;DR:
{ ...process.env }.PATH
isundefined
on Windows. Probably need to fix lib/fork.js.Tried to do:
I upgraded Ava from 2.4.0 to 4.2.0 in our internal project and tests started failing on our Windows build server with this message:
The failing code was trying to execute
process.env['PATH'].split()
.I added some
console.log()
statements to our tests and found thatprocess.env.PATH
is missing, butprocess.env.Path
is available instead.Expected:
process.env.PATH
available in tests on Windows.Investigation:
process.env.PATH
is problematic in Node.js on Windows. See related issues: https://github.com/nodejs/node/issues?q=is%3Aissue+process.env.PATH+I suspect this code (I'm not familiar with Ava codebase) in lib/fork.js:
env: {NODE_ENV: 'test', ...process.env, ...options.environmentVariables},
This minimal code in Node.js on windows shows what's happening with
...process.env
:Temporary workaround for other users
I renamed
Path
toPATH
in Windows System Variables.(Settings -> System -> About -> Advanced system settings -> Environment Variables...)
This fixed the issue with the tests failing, but now the tests get both
process.env.PATH
ANDprocess.env.Path
, which is different to how it works in Node.js (you only seePath
when printing outprocess.env
).The text was updated successfully, but these errors were encountered: