microsoft / microsoft/vscode-test
unable to import vscode in test using jest
Nobody has claimed this yet.
- Dominant language
- TypeScript
- Stars
- 316
- Forks
- 73
- Avg merge
- 1d 6h
- Merged PRs (30d)
- 3
Description
Hi, I'm trying to run some integration tests for my vscode extension using jest. Unit tests work fine since I'm able to mock vscode however, when I'm trying to run an integration test I'm getting Cannot find module 'vscode' in the files when i'm using vscode api (import * as vscode from 'vscode')
jest config looks like this:
module.exports = {
moduleFileExtensions: ['js'],
testMatch: ['<rootDir>/out/test/**/*.int.test.js'],
verbose: true,
};
runTest.ts
import * as path from 'path';
import { runTests } from 'vscode-test';
async function main() {
try {
// The folder containing the Extension Manifest package.json
// Passed to `--extensionDevelopmentPath`
const extensionDevelopmentPath = path.resolve(__dirname, '../../');
// The path to the extension test script
// Passed to --extensionTestsPath
const extensionTestsPath = path.resolve(__dirname, './suite/index');
// Download VS Code, unzip it and run the integration test
console.log(`running tests... ext path: ${extensionTestsPath}`);
await runTests({
extensionDevelopmentPath,
extensionTestsPath,
launchArgs: ['--disable-extensions']
});
} catch (err) {
console.error('Failed to run tests', err);
process.exit(1);
}
}
main();
index.ts
import * as path from 'path';
import { runCLI } from 'jest-cli';
import * as vscode from 'vscode';
export function run(): Promise<void> {
return new Promise((resolve, reject) => {
const projectRootPath = path.join(__dirname, '../../../');
const config = path.join(projectRootPath, 'jest.e2e.config.js');
vscode.window.showInformationMessage('Run suite');
runCLI({ config } as any, [projectRootPath])
.then(jestCliCallResult => {
console.log(`complete: ${JSON.stringify(jestCliCallResult)}`);
console.log('print results');
jestCliCallResult.results.testResults
.forEach(testResult => {
testResult.testResults
.filter(assertionResult => assertionResult.status === 'passed')
.forEach(({ ancestorTitles, title, status }) => {
console.info(` ● ${ancestorTitles} › ${title} (${status})`);
});
});
console.log('check results');
jestCliCallResult.results.testResults
.forEach(testResult => {
if (testResult.failureMessage) {
console.error(testResult.failureMessage);
}
});
resolve();
})
.catch(errorCaughtByJestRunner => {
console.error('error in test runner', errorCaughtByJestRunner);
reject(errorCaughtByJestRunner);
});
});
}
I installed both vscode-test and @types/vscode as dev dependencies. I'm not sure why my tests are unable to find the 'vscode' dependency. Vscode is the only dependency that has this issue, other modules work fine. Can anyone help?
Thanks!
Contributor guide
No contributing guide indexed for this repository
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start with runTest.ts and index.ts, then inspect the referenced jest.e2e.config.js and the integration test entry point under out/test. Run the vscode-test integration command and trace how the Jest process resolves the vscode import. Done means the integration tests can import vscode and execute in the launched VS Code instance.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- typescript, vscode
- Domain
- devtools, testing-qa
- Issue type
- Bug
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 35/100