Skip to content

Commit 263f3cb

Browse files
committed
Consolidate index and runIntegrationTests files
1 parent 8754b7a commit 263f3cb

File tree

8 files changed

+136
-261
lines changed

8 files changed

+136
-261
lines changed

test/integrationTests/index.ts

Lines changed: 2 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -3,47 +3,11 @@
33
* Licensed under the MIT License. See License.txt in the project root for license information.
44
*--------------------------------------------------------------------------------------------*/
55

6-
import * as jest from 'jest';
7-
import { Config } from '@jest/types';
8-
import * as path from 'path';
6+
import { runIntegrationTests } from '../runIntegrationTests';
97
import { jestIntegrationTestProjectName } from './jest.config';
108

11-
async function runIntegrationTests() {
12-
const repoRoot = process.env.CODE_EXTENSIONS_PATH;
13-
if (!repoRoot) {
14-
throw new Error('CODE_EXTENSIONS_PATH not set.');
15-
}
16-
17-
const jestConfigPath = path.join(repoRoot, 'jest.config.ts');
18-
const jestConfig = {
19-
config: jestConfigPath,
20-
selectProjects: [jestIntegrationTestProjectName],
21-
// Since we're running tests in the actual vscode process we have to run them serially.
22-
runInBand: true,
23-
// Timeout cannot be overriden in the jest config file, so override here.
24-
testTimeout: 120000,
25-
verbose: true,
26-
} as Config.Argv;
27-
28-
let filter: string;
29-
if (process.env.TEST_FILE_FILTER) {
30-
// If we have just a file, run that with runTestsByPath.
31-
jestConfig.runTestsByPath = true;
32-
jestConfig.testMatch = [process.env.TEST_FILE_FILTER];
33-
filter = process.env.TEST_FILE_FILTER;
34-
} else {
35-
filter = jestIntegrationTestProjectName;
36-
}
37-
38-
const { results } = await jest.runCLI(jestConfig, [filter]);
39-
40-
if (!results.success) {
41-
throw new Error('Tests failed.');
42-
}
43-
}
44-
459
export async function run() {
4610
process.env.RUNNING_INTEGRATION_TESTS = 'true';
4711

48-
return runIntegrationTests();
12+
await runIntegrationTests(jestIntegrationTestProjectName);
4913
}

test/integrationTests/runIntegrationTests.ts

Lines changed: 2 additions & 82 deletions
Original file line numberDiff line numberDiff line change
@@ -3,86 +3,6 @@
33
* Licensed under the MIT License. See License.txt in the project root for license information.
44
*--------------------------------------------------------------------------------------------*/
55

6-
import * as cp from 'child_process';
7-
import * as path from 'path';
8-
import { downloadAndUnzipVSCode, resolveCliArgsFromVSCodeExecutablePath, runTests } from '@vscode/test-electron';
9-
import { execChildProcess } from '../../src/common';
6+
import * as runner from '../runIntegrationTests';
107

11-
function getSln(workspacePath: string): string | undefined {
12-
if (workspacePath.endsWith('slnWithGenerator')) {
13-
return 'slnWithGenerator.sln';
14-
}
15-
return undefined;
16-
}
17-
18-
async function main() {
19-
try {
20-
const vscodeExecutablePath = await downloadAndUnzipVSCode('stable');
21-
const [cli, ...args] = resolveCliArgsFromVSCodeExecutablePath(vscodeExecutablePath);
22-
23-
console.log('Display: ' + process.env.DISPLAY);
24-
25-
const result = cp.spawnSync(cli, [...args, '--install-extension', 'ms-dotnettools.vscode-dotnet-runtime'], {
26-
encoding: 'utf-8',
27-
stdio: 'inherit',
28-
});
29-
if (result.error) {
30-
throw new Error(`Failed to install the runtime extension: ${result.error}`);
31-
}
32-
33-
// The folder containing the Extension Manifest package.json
34-
// Passed to `--extensionDevelopmentPath`
35-
const extensionDevelopmentPath = process.env.CODE_EXTENSIONS_PATH;
36-
if (!extensionDevelopmentPath) {
37-
throw new Error('Environment variable CODE_EXTENSIONS_PATH is empty');
38-
}
39-
40-
// The path to the extension test runner script
41-
// Passed to --extensionTestsPath
42-
const extensionTestsPath = process.env.EXTENSIONS_TESTS_PATH;
43-
44-
if (!extensionTestsPath) {
45-
console.error('Empty extension tests path');
46-
process.exit(-1);
47-
}
48-
49-
// The integration tests expect that the workspace to run the
50-
// tests against is set in an environment variable.
51-
const workspacePath = process.env.CODE_TESTS_WORKSPACE;
52-
53-
if (!workspacePath) {
54-
console.error(`Empty workspace path`);
55-
process.exit(-1);
56-
}
57-
58-
console.log(`workspace path = '${workspacePath}'`);
59-
60-
const sln = getSln(workspacePath);
61-
if (sln) {
62-
// Run a build before the tests, to ensure that source generators are set up correctly
63-
if (!process.env.DOTNET_ROOT) {
64-
throw new Error('Environment variable DOTNET_ROOT is not set');
65-
}
66-
67-
const dotnetPath = path.join(process.env.DOTNET_ROOT, 'dotnet');
68-
await execChildProcess(`${dotnetPath} build ${sln}`, workspacePath);
69-
}
70-
71-
// Download VS Code, unzip it and run the integration test
72-
const exitCode = await runTests({
73-
extensionDevelopmentPath,
74-
extensionTestsPath,
75-
// Launch with info logging as anything else is way too verbose and will hide test results.
76-
launchArgs: [workspacePath, '-n', '--log', 'info'],
77-
extensionTestsEnv: process.env,
78-
});
79-
80-
process.exit(exitCode);
81-
} catch (err) {
82-
console.error(err);
83-
console.error('Failed to run tests');
84-
process.exit(1);
85-
}
86-
}
87-
88-
main();
8+
runner.main();

test/razorIntegrationTests/index.ts

Lines changed: 2 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -3,47 +3,11 @@
33
* Licensed under the MIT License. See License.txt in the project root for license information.
44
*--------------------------------------------------------------------------------------------*/
55

6-
import * as jest from 'jest';
7-
import { Config } from '@jest/types';
8-
import * as path from 'path';
6+
import { runIntegrationTests } from '../runIntegrationTests';
97
import { jestIntegrationTestProjectName } from './jest.config';
108

11-
async function runIntegrationTests() {
12-
const repoRoot = process.env.CODE_EXTENSIONS_PATH;
13-
if (!repoRoot) {
14-
throw new Error('CODE_EXTENSIONS_PATH not set.');
15-
}
16-
17-
const jestConfigPath = path.join(repoRoot, 'jest.config.ts');
18-
const jestConfig = {
19-
config: jestConfigPath,
20-
selectProjects: [jestIntegrationTestProjectName],
21-
// Since we're running tests in the actual vscode process we have to run them serially.
22-
runInBand: true,
23-
// Timeout cannot be overriden in the jest config file, so override here.
24-
testTimeout: 120000,
25-
verbose: true,
26-
} as Config.Argv;
27-
28-
let filter: string;
29-
if (process.env.TEST_FILE_FILTER) {
30-
// If we have just a file, run that with runTestsByPath.
31-
jestConfig.runTestsByPath = true;
32-
jestConfig.testMatch = [process.env.TEST_FILE_FILTER];
33-
filter = process.env.TEST_FILE_FILTER;
34-
} else {
35-
filter = jestIntegrationTestProjectName;
36-
}
37-
38-
const { results } = await jest.runCLI(jestConfig, [filter]);
39-
40-
if (!results.success) {
41-
throw new Error('Tests failed.');
42-
}
43-
}
44-
459
export async function run() {
4610
process.env.RUNNING_INTEGRATION_TESTS = 'true';
4711

48-
return runIntegrationTests();
12+
await runIntegrationTests(jestIntegrationTestProjectName);
4913
}

test/razorIntegrationTests/jest.config.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,8 +14,8 @@ const integrationTestConfig: Config = {
1414
...baseProjectConfig,
1515
displayName: jestIntegrationTestProjectName,
1616
roots: ['<rootDir>'],
17-
testEnvironment: '<rootDir>/jestSetup/vsCodeEnvironment.ts',
18-
setupFilesAfterEnv: ['<rootDir>/jestSetup/vsCodeFramework.ts'],
17+
testEnvironment: '<rootDir>/../integrationTests/jestSetup/vsCodeEnvironment.ts',
18+
setupFilesAfterEnv: ['<rootDir>/../integrationTests/jestSetup/vsCodeFramework.ts'],
1919
};
2020

2121
export default integrationTestConfig;

test/razorIntegrationTests/jestSetup/vsCodeEnvironment.ts

Lines changed: 0 additions & 30 deletions
This file was deleted.

test/razorIntegrationTests/jestSetup/vsCodeFramework.ts

Lines changed: 0 additions & 9 deletions
This file was deleted.

test/razorIntegrationTests/runIntegrationTests.ts

Lines changed: 2 additions & 62 deletions
Original file line numberDiff line numberDiff line change
@@ -3,66 +3,6 @@
33
* Licensed under the MIT License. See License.txt in the project root for license information.
44
*--------------------------------------------------------------------------------------------*/
55

6-
import * as cp from 'child_process';
7-
import { downloadAndUnzipVSCode, resolveCliArgsFromVSCodeExecutablePath, runTests } from '@vscode/test-electron';
6+
import * as runner from '../runIntegrationTests';
87

9-
async function main() {
10-
try {
11-
const vscodeExecutablePath = await downloadAndUnzipVSCode('stable');
12-
const [cli, ...args] = resolveCliArgsFromVSCodeExecutablePath(vscodeExecutablePath);
13-
14-
console.log('Display: ' + process.env.DISPLAY);
15-
16-
const result = cp.spawnSync(cli, [...args, '--install-extension', 'ms-dotnettools.vscode-dotnet-runtime'], {
17-
encoding: 'utf-8',
18-
stdio: 'inherit',
19-
});
20-
if (result.error) {
21-
throw new Error(`Failed to install the runtime extension: ${result.error}`);
22-
}
23-
24-
// The folder containing the Extension Manifest package.json
25-
// Passed to `--extensionDevelopmentPath`
26-
const extensionDevelopmentPath = process.env.CODE_EXTENSIONS_PATH;
27-
if (!extensionDevelopmentPath) {
28-
throw new Error('Environment variable CODE_EXTENSIONS_PATH is empty');
29-
}
30-
31-
// The path to the extension test runner script
32-
// Passed to --extensionTestsPath
33-
const extensionTestsPath = process.env.EXTENSIONS_TESTS_PATH;
34-
35-
if (!extensionTestsPath) {
36-
console.error('Empty extension tests path');
37-
process.exit(-1);
38-
}
39-
40-
// The integration tests expect that the workspace to run the
41-
// tests against is set in an environment variable.
42-
const workspacePath = process.env.CODE_TESTS_WORKSPACE;
43-
44-
if (!workspacePath) {
45-
console.error(`Empty workspace path`);
46-
process.exit(-1);
47-
}
48-
49-
console.log(`workspace path = '${workspacePath}'`);
50-
51-
// Download VS Code, unzip it and run the integration test
52-
const exitCode = await runTests({
53-
extensionDevelopmentPath,
54-
extensionTestsPath,
55-
// Launch with info logging as anything else is way too verbose and will hide test results.
56-
launchArgs: [workspacePath, '-n', '--log', 'info'],
57-
extensionTestsEnv: process.env,
58-
});
59-
60-
process.exit(exitCode);
61-
} catch (err) {
62-
console.error(err);
63-
console.error('Failed to run tests');
64-
process.exit(1);
65-
}
66-
}
67-
68-
main();
8+
runner.main();

0 commit comments

Comments
 (0)