Search code examples
testingvisual-studio-codepathtestcafevisual-studio-test-runner

VS Code - TestCafe - Change "node" path (Windows)


We have some front automated tests in TypeScript and use TestCafe TestRunner extension in VS Code.

To run them, we simply right clic on a file and click "TestCafe: Run Test(s) in Firefox".

If Windows path contains the right path to "node", it works well. But... We have several versions of nodes installed for different applications and want to use a local (relative) path, not coming from env variables.

I searched here and in Google and can't state how to set it.

When running tests, the terminal opens and the following very long command runs:

${env:NODE_OPTIONS}='--require "c:/Program Files/Microsoft VS Code/resources/app/extensions/ms-vscode.js-debug/src/bootloader.bundle.js" --inspect-publish-uid=http'; ${env:VSCODE_INSPECTOR_OPTIONS}='{"inspectorIpc":"\\\\.\\pipe\\node-cdp.12008-1.sock","deferredMode":false,"waitForDebugger":"","execPath":"<nodePathFromWindowsEnv>\node.exe","onlyEntrypoint":false,"autoAttachMode":"always","fileCallback":"C:\\Users\\<ME>\\AppData\\Local\\Temp\\node-debug-callback-948a46317a826eb1"}'; & '<nodePathFromWindowsEnv>\node.exe' '--no-deprecation' '.\node_modules\testcafe\lib\cli\index.js' 'firefox' '<dirPath>\<file>.e2e.ts' '--skip-js-errors'

So... I "just" want to set a relative (or absolute) path to the 2 node paths (nodePathFromWindowsEnv)


Solution

  • You can use the Node version manager to switch different Node.js versions before running TestCafe tests in VS Code. In that case, it is not needed to specify the different patches for Node.js:

    C:\testcafe\support\node_path>nvm use 12.22.0
    Now using node v12.22.0 (64-bit)
    
    C:\testcafe\support\node_path>"C:\Program Files\nodejs\node.exe" -v
    v12.22.0
    
    C:\testcafe\support\node_path>nvm use 14.17.6
    Now using node v14.17.6 (64-bit)
    
    C:\testcafe\support\node_path>"C:\Program Files\nodejs\node.exe" -v
    v14.17.6
    

    You can also refer to TestCafe TestRunner extension source code to learn how it runs tests and contribute to the advanced functionality.