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

Example for Testing extensions does not work on Windows. #7328

Open
sdedic opened this issue May 24, 2024 · 3 comments
Open

Example for Testing extensions does not work on Windows. #7328

sdedic opened this issue May 24, 2024 · 3 comments
Assignees

Comments

@sdedic
Copy link

sdedic commented May 24, 2024

Does this issue occur when all extensions are disabled?: Yes

  • VS Code Version: 1.84.0
  • OS Version: Windows 11

Steps to Reproduce:

  1. Execute code similar to the one exhibited at https://code.visualstudio.com/api/working-with-extensions/testing-extension#custom-setup-with-vscodetestelectron:
async function main() {
  try {
    const extensionDevelopmentPath = path.resolve(__dirname, '../../../');
    const extensionTestsPath = path.resolve(__dirname, './suite/index');
    const vscodeExecutablePath = await downloadAndUnzipVSCode('1.40.1');
    const [cliPath, ...args] = resolveCliArgsFromVSCodeExecutablePath(vscodeExecutablePath);

    // Use cp.spawn / cp.exec for custom setup
    cp.spawnSync(
      cliPath,
      [...args, '--install-extension', '<EXTENSION-ID-OR-PATH-TO-VSIX>'],
      {
        encoding: 'utf-8',
        stdio: 'inherit'
// --- BUG: MISSING shell: true option here 
      }
    );

    // Run the extension test
    await runTests({
      // Use the specified `code` executable
      vscodeExecutablePath,
      extensionDevelopmentPath,
      extensionTestsPath
    });
  } catch (err) {
    console.error('Failed to run tests');
    process.exit(1);
  }
}

The problem is that on Windows, the cli evaluates to %vscodeTestDir%\bin\Code that is not a Windows executable, but a bash shell script, so direct invocation using spanwSync fails. There must be shell: true option for the spawnSync that launches the command using windows command shell, that properly recognizes presence of Code.cmd and uses that.

Please correct the example in the extension development guide.

@vscodenpa
Copy link
Collaborator

Thanks for creating this issue! It looks like you may be using an old version of VS Code, the latest stable release is 1.89.1. Please try upgrading to the latest version and checking whether this issue remains.

Happy Coding!

@lramos15 lramos15 assigned connor4312 and unassigned lramos15 May 29, 2024
@connor4312 connor4312 transferred this issue from microsoft/vscode May 29, 2024
@headerjson
Copy link

headerjson commented May 29, 2024

I started experiencing the same issue during vscode testing. For a long time, I had no issues, but my agent pool image updated and cp.spawnSync silently stopped installing the extension required.

Reproduces the error (agent pool vm):
OS Build: 22631.3593
Version of VSCode installed by runtest.js: 1.89.1
Powershell version: 5.1.22621.2506
Node version: v20.13.1

Does not reproduce the error (dev machine):
OS Build: 22631.3593
Version of VSCode installed by runtest.js: 1.89.1
Powershell version: 5.1.22621.2506
Node version: v20.11.0

Using the cp.spawnSync shell: true option works as a workaround for me.

@connor4312
Copy link
Member

Modern versions of test-electron include a helper you can use, e.g.

await runVSCodeCommand(['--install-extension', 'ms-python.python']);

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

No branches or pull requests

5 participants