Skip to content

Commit

Permalink
Integration Tests - Add gulp tasks for lsp integration tests (#6188)
Browse files Browse the repository at this point in the history
* wip

* explicitly use workspace path

* fix

* remove settings

* feedback

* fix
  • Loading branch information
akhera99 authored Aug 25, 2023
1 parent b5f8db1 commit ea7aa46
Show file tree
Hide file tree
Showing 15 changed files with 149 additions and 38 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
{
"folders": [
{
"path": ".."
}
],
"settings": {
"dotnet.server.useOmnisharp": true,
"omnisharp.enableLspDriver": false
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
{
"folders": [
{
"path": ".."
}
],
"settings": {
"dotnet.server.useOmnisharp": true,
"omnisharp.enableLspDriver": true
}
}

This file was deleted.

Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
{
"folders": [
{
"path": ".."
}
],
"settings": {
"omnisharp.path": "latest",
"omnisharp.enableRoslynAnalyzers": true,
"omnisharp.enableLspDriver": true,
"dotnet.server.useOmnisharp": true
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
{
"folders": [
{
"path": ".."
}
],
"settings": {
"omnisharp.path": "latest",
"omnisharp.enableRoslynAnalyzers": true,
"omnisharp.enableLspDriver": false,
"dotnet.server.useOmnisharp": true
}
}

This file was deleted.

Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
{
"folders": [
{
"path": ".."
}
],
"settings": {
"omnisharp.defaultLaunchSolution": "SolutionFilter.slnf",
"omnisharp.path": "latest",
"omnisharp.enableRoslynAnalyzers": true,
"dotnet.server.useOmnisharp": true,
"omnisharp.enableLspDriver": true,
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
{
"folders": [
{
"path": ".."
}
],
"settings": {
"omnisharp.defaultLaunchSolution": "SolutionFilter.slnf",
"omnisharp.path": "latest",
"omnisharp.enableRoslynAnalyzers": true,
"dotnet.server.useOmnisharp": true,
"omnisharp.enableLspDriver": false
}
}

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,6 @@
"omnisharp.enableRoslynAnalyzers": true,
"dotnet.server.useOmnisharp": true,
"omnisharp.enableLspDriver": true,
"dotnet.defaultSolution": "b_SecondInOrder_SlnFile.sln",
"dotnet.defaultSolution": "b_SecondInOrder_SlnFile.sln"
}
}

This file was deleted.

1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,7 @@
"omnisharptest:integration:slnWithCsproj": "tsc -p ./ && gulp omnisharptest:integration:slnWithCsproj",
"omnisharptest:integration:slnFilterWithCsproj": "tsc -p ./ && gulp omnisharptest:integration:slnFilterWithCsproj",
"omnisharptest:artifacts": "tsc -p ./ && mocha out/omnisharptest/omnisharpArtifactTests/**/*.test.js",
"test:integration:slnWithCsproj": "tsc -p ./ && gulp test:integration:slnWithCsproj",
"unpackage:vsix": "gulp vsix:release:unpackage",
"updatePackageDependencies": "gulp updatePackageDependencies",
"l10nDevGenerateXlf": "npx @vscode/l10n-dev generate-xlf ./package.nls.json ./l10n/bundle.l10n.json --outFile ./loc/vscode-csharp.xlf",
Expand Down
13 changes: 10 additions & 3 deletions tasks/projectPaths.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,16 @@ export const languageServerDirectory = path.join(rootPath, '.roslyn');

export const codeExtensionPath = commandLineOptions.codeExtensionPath || rootPath;

export const testRootPath = path.join(rootPath, 'out', 'omnisharptest');
export const featureTestRunnerPath = path.join(testRootPath, 'runFeatureTests.js');
export const omnisharpTestRootPath = path.join(rootPath, 'out', 'omnisharptest');
export const omnisharpFeatureTestRunnerPath = path.join(omnisharpTestRootPath, 'runFeatureTests.js');
export const omnisharpTestAssetsRootPath = path.join(
rootPath,
'omnisharptest',
'omnisharpIntegrationTests',
'testAssets'
);

export const testRootPath = path.join(rootPath, 'out', 'test');
export const integrationTestRunnerPath = path.join(testRootPath, 'runIntegrationTests.js');
export const testAssetsRootPath = path.join(rootPath, 'omnisharptest', 'omnisharpIntegrationTests', 'testAssets');

export const nodePath = path.join(process.env.NVM_BIN ? `${process.env.NVM_BIN}${path.sep}` : '', 'node');
66 changes: 55 additions & 11 deletions tasks/testTasks.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,26 +7,27 @@ import * as gulp from 'gulp';
import * as path from 'path';
import {
codeExtensionPath,
featureTestRunnerPath,
integrationTestRunnerPath,
jestPath,
omnisharpFeatureTestRunnerPath,
mochaPath,
rootPath,
testAssetsRootPath,
omnisharpTestAssetsRootPath,
omnisharpTestRootPath,
testRootPath,
integrationTestRunnerPath,
jestPath,
} from './projectPaths';
import spawnNode from './spawnNode';

gulp.task('omnisharptest:feature', async () => {
const env = {
OSVC_SUITE: 'omnisharpFeatureTests',
CODE_EXTENSIONS_PATH: codeExtensionPath,
CODE_TESTS_PATH: path.join(testRootPath, 'omnisharpFeatureTests'),
CODE_TESTS_PATH: path.join(omnisharpTestRootPath, 'omnisharpFeatureTests'),
CODE_WORKSPACE_ROOT: rootPath,
CODE_DISABLE_EXTENSIONS: 'true',
};

const result = await spawnNode([featureTestRunnerPath], { env });
const result = await spawnNode([omnisharpFeatureTestRunnerPath], { env });

if (result.code === null || result.code > 0) {
// Ensure that gulp fails when tests fail
Expand Down Expand Up @@ -60,8 +61,12 @@ gulp.task('omnisharp:jest:test', async () => {
const projectNames = ['singleCsproj', 'slnWithCsproj', 'slnFilterWithCsproj', 'BasicRazorApp2_1'];

for (const projectName of projectNames) {
gulp.task(`omnisharptest:integration:${projectName}:stdio`, async () => runIntegrationTest(projectName, 'stdio'));
gulp.task(`omnisharptest:integration:${projectName}:lsp`, async () => runIntegrationTest(projectName, 'lsp'));
gulp.task(`omnisharptest:integration:${projectName}:stdio`, async () =>
runOmnisharpIntegrationTest(projectName, 'stdio')
);
gulp.task(`omnisharptest:integration:${projectName}:lsp`, async () =>
runOmnisharpIntegrationTest(projectName, 'lsp')
);
gulp.task(
`omnisharptest:integration:${projectName}`,
gulp.series(`omnisharptest:integration:${projectName}:stdio`, `omnisharptest:integration:${projectName}:lsp`)
Expand All @@ -86,24 +91,63 @@ gulp.task(
gulp.series('omnisharp:jest:test', 'omnisharptest:feature', 'omnisharptest:unit', 'omnisharptest:integration:stdio')
);

gulp.task('test:integration:slnWithCsproj', async () => runIntegrationTest('slnWithCsproj'));

gulp.task('test:unit', async () => {
runJestTest(/unitTests.*\.ts/);
});

gulp.task('test', gulp.series('test:unit'));

async function runIntegrationTest(testAssetName: string, engine: 'stdio' | 'lsp') {
async function runOmnisharpIntegrationTest(testAssetName: string, engine: 'stdio' | 'lsp') {
const workspaceFile = `omnisharp${engine === 'lsp' ? '_lsp' : ''}_${testAssetName}.code-workspace`;
const workspacePath = path.join(omnisharpTestAssetsRootPath, testAssetName, '.vscode', workspaceFile);
const codeTestsPath = path.join(omnisharpTestRootPath, 'omnisharpIntegrationTests');

const env = {
OSVC_SUITE: testAssetName,
CODE_TESTS_PATH: path.join(testRootPath, 'omnisharpIntegrationTests'),
CODE_TESTS_PATH: codeTestsPath,
CODE_EXTENSIONS_PATH: codeExtensionPath,
CODE_TESTS_WORKSPACE: path.join(testAssetsRootPath, testAssetName),
CODE_TESTS_WORKSPACE: workspacePath,
CODE_WORKSPACE_ROOT: rootPath,
EXTENSIONS_TESTS_PATH: path.join(codeTestsPath, 'index.js'),
OMNISHARP_ENGINE: engine,
OMNISHARP_LOCATION: process.env.OMNISHARP_LOCATION,
CODE_DISABLE_EXTENSIONS: 'true',
};

const result = await spawnNode([integrationTestRunnerPath, '--enable-source-maps'], {
env,
cwd: rootPath,
});

if (result.code === null || result.code > 0) {
// Ensure that gulp fails when tests fail
throw new Error(`Exit code: ${result.code} Signal: ${result.signal}`);
}

return result;
}

async function runIntegrationTest(testAssetName: string) {
const workspacePath = path.join(
omnisharpTestAssetsRootPath,
testAssetName,
'.vscode',
`lsp_tools_host_${testAssetName}.code-workspace`
);
const codeTestsPath = path.join(testRootPath, 'integrationTests');

const env = {
OSVC_SUITE: testAssetName,
CODE_TESTS_PATH: codeTestsPath,
CODE_EXTENSIONS_PATH: codeExtensionPath,
CODE_TESTS_WORKSPACE: workspacePath,
CODE_WORKSPACE_ROOT: rootPath,
EXTENSIONS_TESTS_PATH: path.join(codeTestsPath, 'index.js'),
CODE_DISABLE_EXTENSIONS: 'true',
};

const result = await spawnNode([integrationTestRunnerPath, '--enable-source-maps'], { env, cwd: rootPath });

if (result.code === null || result.code > 0) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,12 @@ async function main() {

// The path to the extension test runner script
// Passed to --extensionTestsPath
const extensionTestsPath = path.resolve(__dirname, './omnisharpIntegrationTests/index');
const extensionTestsPath = process.env.EXTENSIONS_TESTS_PATH;

if (!extensionTestsPath) {
console.error('Empty extension tests path');
process.exit(-1);
}

// The integration tests expect that the workspace to run the
// tests against is set in an environment variable.
Expand Down

0 comments on commit ea7aa46

Please sign in to comment.