-
Notifications
You must be signed in to change notification settings - Fork 64
Open
Labels
feature-requestRequest for new features or functionalityRequest for new features or functionality
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!
Tom-Bonnike, jsjoeio, mark-wiemer, tobias-tengler, legomushroom and 5 more
Metadata
Metadata
Assignees
Labels
feature-requestRequest for new features or functionalityRequest for new features or functionality