'Cannot run vscode extension starter project tests twice in a row on macos

I am implementing a VSCode extension and I have set up the project following this link.

It creates a starter project and with it a src/test/runTest.ts:

import * as path from 'path';

import { runTests } from '@vscode/test-electron';

async function main() {
    try {
        // The folder containing the Extension Manifest package.json
        // Passed to `--extensionDevelopmentPath`
        const extensionDevelopmentPath = path.resolve(__dirname, '../../');

        // The path to test runner
        // Passed to --extensionTestsPath
        const extensionTestsPath = path.resolve(__dirname, './suite/index');

        // Download VS Code, unzip it and run the integration test
        await runTests({ extensionDevelopmentPath, extensionTestsPath });
    } catch (err) {
        console.error('Failed to run tests');
        process.exit(1);
    }
}

main();

and a package.json:

{
    "compile": "tsc -p ./",
    "pretest": "npm run compile && npm run lint",
    "lint": "eslint src --ext ts",
    "test": "node ./out/test/runTest.js"
}

I cannot run

npm test

twice in a row.


The first time, everything goes well, and it looks like it is downloading VSCode in the folder .vscode-test.

Downloading VS Code 1.65.2 from https://update.code.visualstudio.com/1.65.2/darwin/stable
Downloading VS Code [==============================] 100%Downloaded VS Code 1.65.2 into /my-path/my-project/.vscode-test/vscode-darwin-1.65.2

However, I get a warning:

WARNING: IPC handle "/my-path/my-project/.vscode-test/user-data/1.65.2-main.sock" is longer than 103 chars, try a shorter --user-data-dir

When I run the tests a second time, if fails:

Found existing install in /my-path/my-project/.vscode-test/vscode-darwin-1.65.2. Skipping download
WARNING: IPC handle "/my-path/my-project/.vscode-test/user-data/1.65.2-main.sock" is longer than 103 chars, try a shorter --user-data-dir
[main 2022-03-29T14:44:22.271Z] Could not delete obsolete instance handle Error: ENOENT: no such file or directory, unlink '/my-path/my-project/.vscode-test/user-data/1.65.2-main.sock'
    at unlinkSync (original-fs.js:1210:3)
    at ne.claimInstance (/my-path/my-project/.vscode-test/vscode-darwin-1.65.2/Visual Studio Code.app/Contents/Resources/app/out/vs/code/electron-main/main.js:77:5083)
    at processTicksAndRejections (internal/process/task_queues.js:93:5)
    at async /my-path/my-project/.vscode-test/vscode-darwin-1.65.2/Visual Studio Code.app/Contents/Resources/app/out/vs/code/electron-main/main.js:77:2282
    at async ne.startup (/my-path/my-project/.vscode-test/vscode-darwin-1.65.2/Visual Studio Code.app/Contents/Resources/app/out/vs/code/electron-main/main.js:77:2151) {
  errno: -2,
  syscall: 'unlink',
  code: 'ENOENT',
  path: '/my-path/my-project/.vscode-test/user-data/1.65.2-main.sock'
}
[main 2022-03-29T14:44:22.274Z] Error: ENOENT: no such file or directory, unlink '/my-path/my-project/.vscode-test/user-data/1.65.2-main.sock'
    at unlinkSync (original-fs.js:1210:3)
    at ne.claimInstance (/my-path/my-project/.vscode-test/vscode-darwin-1.65.2/Visual Studio Code.app/Contents/Resources/app/out/vs/code/electron-main/main.js:77:5083)
    at processTicksAndRejections (internal/process/task_queues.js:93:5)
    at async /my-path/my-project/.vscode-test/vscode-darwin-1.65.2/Visual Studio Code.app/Contents/Resources/app/out/vs/code/electron-main/main.js:77:2282
    at async ne.startup (/my-path/my-project/.vscode-test/vscode-darwin-1.65.2/Visual Studio Code.app/Contents/Resources/app/out/vs/code/electron-main/main.js:77:2151)
Exit code:   1
Failed to run tests

But it works fine if I delete the folder .vscode-test.

What is happening and what can I do?



Solution 1:[1]

try to make your work directory shorter or use the os temporary directory

for example:

await runTests({ 
  extensionDevelopmentPath, 
  extensionTestsPath,
  launchArgs: ['--user-data-dir', `${os.tmpdir()}`]
});

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 songwave