Skip to content

Commit c880e6b

Browse files
committed
Move razor integration tests to their own thing
1 parent 32f67db commit c880e6b

14 files changed

+263
-34
lines changed

.vscode/launch.json

Lines changed: 11 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -43,34 +43,6 @@
4343
],
4444
"preLaunchTask": "buildDev"
4545
},
46-
{
47-
"name": "Launch Current File BasicRazorApp Integration Tests",
48-
"type": "extensionHost",
49-
"request": "launch",
50-
"runtimeExecutable": "${execPath}",
51-
"args": [
52-
// Create a temp profile that has no extensions / user settings.
53-
// This allows us to only have the C# extension + the dotnet runtime installer extension dependency.
54-
"--profile-temp",
55-
"${workspaceRoot}/test/integrationTests/testAssets/BasicRazorApp2_1/.vscode/lsp_tools_host_BasicRazorApp2_1.code-workspace",
56-
"--extensionDevelopmentPath=${workspaceRoot}",
57-
"--extensionTestsPath=${workspaceRoot}/out/test/integrationTests",
58-
],
59-
"env": {
60-
"CODE_EXTENSIONS_PATH": "${workspaceRoot}",
61-
"TEST_FILE_FILTER": "${file}"
62-
},
63-
"sourceMaps": true,
64-
"outFiles": [
65-
"${workspaceRoot}/dist/*.js",
66-
"${workspaceRoot}/out/test/**/*.js"
67-
],
68-
"resolveSourceMapLocations": [
69-
"${workspaceFolder}/**",
70-
"!**/node_modules/**"
71-
],
72-
"preLaunchTask": "buildDev"
73-
},
7446
{
7547
"type": "node",
7648
"request": "launch",
@@ -351,6 +323,17 @@
351323
"generateOptionsSchema"
352324
],
353325
"cwd": "${workspaceFolder}"
326+
},
327+
{
328+
"type": "node",
329+
"request": "launch",
330+
"name": "Razor integration tests",
331+
"preLaunchTask": "build",
332+
"program": "${workspaceFolder}/node_modules/gulp/bin/gulp.js",
333+
"args": [
334+
"test:razorintegration"
335+
],
336+
"cwd": "${workspaceFolder}"
354337
}
355338
]
356339
}

jest.config.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ const config: Config = {
88
projects: [
99
'<rootDir>/test/unitTests/jest.config.ts',
1010
'<rootDir>/test/integrationTests/jest.config.ts',
11+
'<rootDir>/test/razorIntegrationTests/jest.config.ts',
1112
'<rootDir>/test/razorTests/jest.config.ts',
1213
'<rootDir>/omnisharptest/omnisharpJestTests/jest.config.ts',
1314
],

package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,7 @@
6363
"test": "tsc -p ./ && gulp test",
6464
"test:integration": "tsc -p ./ && gulp test:integration",
6565
"test:razor": "tsc -p ./ && npm run compile:razorTextMate && gulp test:razor",
66+
"test:razorintegration": "tsc -p ./ && gulp test:razorintegration",
6667
"omnisharptest": "tsc -p ./ && gulp omnisharptest",
6768
"omnisharptest:unit": "tsc -p ./ && gulp omnisharptest:unit",
6869
"omnisharptest:feature": "tsc -p ./ && gulp omnisharptest:feature",

tasks/projectPaths.ts

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,8 +23,14 @@ export const omnisharpTestRootPath = path.join(rootPath, 'out', 'omnisharptest')
2323
export const omnisharpFeatureTestRunnerPath = path.join(omnisharpTestRootPath, 'runFeatureTests.js');
2424

2525
export const integrationTestAssetsRootPath = path.join(rootPath, 'test', 'integrationTests', 'testAssets');
26+
export const razorIntegrationTestAssetsRootPath = path.join(rootPath, 'test', 'razorIntegrationTests', 'testAssets');
2627

2728
export const testRootPath = path.join(rootPath, 'out', 'test');
2829
export const integrationTestRunnerPath = path.join(testRootPath, 'integrationTests', 'runIntegrationTests.js');
30+
export const razorIntegrationTestRunnerPath = path.join(
31+
testRootPath,
32+
'razorIntegrationTests',
33+
'runIntegrationTests.js'
34+
);
2935

3036
export const nodePath = path.join(process.env.NVM_BIN ? `${process.env.NVM_BIN}${path.sep}` : '', 'node');

tasks/testTasks.ts

Lines changed: 18 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,8 @@ import {
1414
omnisharpTestRootPath,
1515
testRootPath,
1616
integrationTestRunnerPath,
17+
razorIntegrationTestAssetsRootPath,
18+
razorIntegrationTestRunnerPath,
1719
} from './projectPaths';
1820
import spawnNode from './spawnNode';
1921
import * as jest from 'jest';
@@ -45,6 +47,16 @@ gulp.task('test:razor', async () => {
4547
runJestTest(razorTestProjectName);
4648
});
4749

50+
const razorIntegrationTestProjects = ['BasicRazorApp2_1'];
51+
for (const projectName of razorIntegrationTestProjects) {
52+
gulp.task(`test:razorintegration:${projectName}`, async () => runIntegrationTest(projectName, /* razor */ true));
53+
}
54+
55+
gulp.task(
56+
'test:razorintegration',
57+
gulp.series(razorIntegrationTestProjects.map((projectName) => `test:razorintegration:${projectName}`))
58+
);
59+
4860
gulp.task('omnisharptest:unit', async () => {
4961
const result = await spawnNode([
5062
mochaPath,
@@ -113,7 +125,7 @@ gulp.task(
113125
gulp.series(integrationTestProjects.map((projectName) => `test:integration:${projectName}`))
114126
);
115127

116-
gulp.task('test', gulp.series('test:unit', 'test:integration', 'test:razor'));
128+
gulp.task('test', gulp.series('test:unit', 'test:integration', 'test:razor', 'test:razorintegration'));
117129

118130
async function runOmnisharpIntegrationTest(testAssetName: string, engine: 'stdio' | 'lsp') {
119131
const workspaceFile = `omnisharp${engine === 'lsp' ? '_lsp' : ''}_${testAssetName}.code-workspace`;
@@ -145,22 +157,23 @@ async function runOmnisharpIntegrationTest(testAssetName: string, engine: 'stdio
145157
return result;
146158
}
147159

148-
async function runIntegrationTest(testAssetName: string) {
160+
async function runIntegrationTest(testAssetName: string, razor = false) {
149161
const workspacePath = path.join(
150-
integrationTestAssetsRootPath,
162+
razor ? razorIntegrationTestAssetsRootPath : integrationTestAssetsRootPath,
151163
testAssetName,
152164
'.vscode',
153165
`lsp_tools_host_${testAssetName}.code-workspace`
154166
);
155-
const codeTestsPath = path.join(testRootPath, 'integrationTests');
167+
const codeTestsPath = path.join(testRootPath, razor ? 'razorIntegrationTests' : 'integrationTests');
156168

157169
const env = {
158170
CODE_TESTS_WORKSPACE: workspacePath,
159171
CODE_EXTENSIONS_PATH: rootPath,
160172
EXTENSIONS_TESTS_PATH: path.join(codeTestsPath, 'index.js'),
161173
};
162174

163-
const result = await spawnNode([integrationTestRunnerPath, '--enable-source-maps'], { env, cwd: rootPath });
175+
const runnerPath = razor ? razorIntegrationTestRunnerPath : integrationTestRunnerPath;
176+
const result = await spawnNode([runnerPath, '--enable-source-maps'], { env, cwd: rootPath });
164177

165178
if (result.code === null || result.code > 0) {
166179
// Ensure that gulp fails when tests fail

test/razorIntegrationTests/index.ts

Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
/*---------------------------------------------------------------------------------------------
2+
* Copyright (c) Microsoft Corporation. All rights reserved.
3+
* Licensed under the MIT License. See License.txt in the project root for license information.
4+
*--------------------------------------------------------------------------------------------*/
5+
6+
import * as jest from 'jest';
7+
import { Config } from '@jest/types';
8+
import * as path from 'path';
9+
import { jestIntegrationTestProjectName } from './jest.config';
10+
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+
45+
export async function run() {
46+
process.env.RUNNING_INTEGRATION_TESTS = 'true';
47+
48+
return runIntegrationTests();
49+
}
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
/*---------------------------------------------------------------------------------------------
2+
* Copyright (c) Microsoft Corporation. All rights reserved.
3+
* Licensed under the MIT License. See License.txt in the project root for license information.
4+
*--------------------------------------------------------------------------------------------*/
5+
import type { Config } from 'jest';
6+
import { baseProjectConfig } from '../../baseJestConfig';
7+
8+
export const jestIntegrationTestProjectName = 'Razor Integration Tests';
9+
10+
/**
11+
* Defines a project configuration for jest integration tests.
12+
*/
13+
const integrationTestConfig: Config = {
14+
...baseProjectConfig,
15+
displayName: jestIntegrationTestProjectName,
16+
roots: ['<rootDir>'],
17+
testEnvironment: '<rootDir>/jestSetup/vsCodeEnvironment.ts',
18+
setupFilesAfterEnv: ['<rootDir>/jestSetup/vsCodeFramework.ts'],
19+
};
20+
21+
export default integrationTestConfig;
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
/*---------------------------------------------------------------------------------------------
2+
* Copyright (c) Microsoft Corporation. All rights reserved.
3+
* Licensed under the MIT License. See License.txt in the project root for license information.
4+
*--------------------------------------------------------------------------------------------*/
5+
6+
import * as vscode from 'vscode';
7+
import { JestEnvironmentConfig, EnvironmentContext } from '@jest/environment';
8+
import { TestEnvironment } from 'jest-environment-node';
9+
10+
/**
11+
* Defines a custom jest environment that allows us to replace vscode module imports with the
12+
* instance from the vscode extension in the test runner.
13+
*/
14+
class VsCodeEnvironment extends TestEnvironment {
15+
constructor(config: JestEnvironmentConfig, context: EnvironmentContext) {
16+
super(config, context);
17+
}
18+
19+
public async setup() {
20+
await super.setup();
21+
this.global.vscode = vscode;
22+
}
23+
24+
public async teardown() {
25+
this.global.vscode = {};
26+
return await super.teardown();
27+
}
28+
}
29+
30+
module.exports = VsCodeEnvironment;
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
/*---------------------------------------------------------------------------------------------
2+
* Copyright (c) Microsoft Corporation. All rights reserved.
3+
* Licensed under the MIT License. See License.txt in the project root for license information.
4+
*--------------------------------------------------------------------------------------------*/
5+
6+
import { jest } from '@jest/globals';
7+
8+
// Defines a virtual mock for the vscode library since it doesn't exist until it gets loaded in by the vscode extension process.
9+
jest.mock('vscode', () => (global as any).vscode, { virtual: true });

test/integrationTests/razorFormatting.integration.test.ts renamed to test/razorIntegrationTests/razorFormatting.integration.test.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ import * as path from 'path';
77
import * as vscode from 'vscode';
88
import * as jestLib from '@jest/globals';
99
import testAssetWorkspace from './testAssets/testAssetWorkspace';
10-
import * as integrationHelpers from './integrationHelpers';
10+
import * as integrationHelpers from '../integrationTests/integrationHelpers';
1111

1212
jestLib.describe(`Razor Formatting ${testAssetWorkspace.description}`, function () {
1313
jestLib.beforeAll(async function () {

0 commit comments

Comments
 (0)