Skip to content
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

Environment variables and PATH not passing through in 1.2.3 #52

Closed
disposedtrolley opened this issue Nov 21, 2019 · 4 comments
Closed
Labels
question Question instead of bug/feature-request

Comments

@disposedtrolley
Copy link

Hello! I'm trying to test my VS Code extension which starts a language server by executing a command on the PATH, but none of the system's environment variables seem to be passing through to the test runner. This is causing my tests to fail with an ENOENT error as the executable is not able to be located on the PATH.

Despite passing in the entirety of process.env to runTests(), no environment variables are available in the test runner script specified by extensionTestsPath:

await runTests({
  extensionDevelopmentPath,
  extensionTestsPath,
  extensionTestsEnv: process.env,
  launchArgs: [extensionWorkspacePath, "--disable-extensions"]
});

In the extensionTestsPath file:

export function run(): Promise<void> {
	console.log(process.env)  // prints nothing
}

#20

@disposedtrolley
Copy link
Author

Update: it may have something to do with nvm and how it alters the PATH when a shell is started.

Somehow I had a global installation of node in addition to an nvm one, which was conflicting with VS Code's shell (see this Stackoverflow answer)

Removing the global installations allowed me to get the production build of the extension to call the language server executable properly, but it still fails under test.

Does the Extension Development Host have its own set of shell parameters?

@disposedtrolley
Copy link
Author

Update: a little more digging and it looks like nvm is indeed broken when running the Extension Development Host.

I get this error on startup:

nvm is not compatible with the "npm_config_prefix" environment variable: currently set to "[...]/.nvm/versions/node/v12.13.1"

Run `unset npm_config_prefix` to unset it.

which is detailed in this issue - microsoft/vscode#36987

The fix is to apply this setting:

"terminal.integrated.shellArgs.osx": []

but I'm unsure how to do it when testing.

@disposedtrolley
Copy link
Author

disposedtrolley commented Nov 22, 2019

Ok this appears to have fixed the issue:

await runTests({
  extensionDevelopmentPath,
  extensionTestsPath,
  extensionTestsEnv: {
    ...process.env,
    "npm_config_prefix": ""
  },
  launchArgs: [extensionWorkspacePath, "--disable-extensions"]
});

I needed to unset the npm_config_prefix env var before running tests, because I assume nvm is trying to set it on startup within the Extension Development Host.

@octref octref added the question Question instead of bug/feature-request label Dec 11, 2019
@octref
Copy link
Contributor

octref commented Dec 11, 2019

Glad you found a solution. I'm not very familiar with what nvm is doing.

@octref octref closed this as completed Dec 11, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
question Question instead of bug/feature-request
Projects
None yet
Development

No branches or pull requests

2 participants