Skip to content

Commit 4d03c01

Browse files
committed
Set up integration tests over webpack extension bundle
1 parent 7e7bbd1 commit 4d03c01

File tree

10 files changed

+48
-21
lines changed

10 files changed

+48
-21
lines changed

client/.vscode/launch.json

+8-5
Original file line numberDiff line numberDiff line change
@@ -7,24 +7,27 @@
77
"type": "extensionHost",
88
"request": "launch",
99
"runtimeExecutable": "${execPath}",
10-
"args": ["--extensionDevelopmentPath=${workspaceRoot}"],
10+
"args": ["--extensionDevelopmentPath=${workspaceFolder}"],
1111
"stopOnEntry": false,
1212
"sourceMaps": true,
13-
"outFiles": ["${workspaceRoot}/dist/**/*.js"],
13+
"outFiles": ["${workspaceFolder}/dist/**/*.js"],
1414
"preLaunchTask": "npm: compile:dev"
1515
},
1616
{
1717
"name": "Extension Tests",
1818
"type": "extensionHost",
1919
"request": "launch",
2020
"runtimeExecutable": "${execPath}",
21+
"env": {
22+
"TEST_WORKSPACES_DIR": "${workspaceFolder}/dist/test-workspaces"
23+
},
2124
"args": [
22-
"--extensionDevelopmentPath=${workspaceRoot}/out",
23-
"--extensionTestsPath=${workspaceRoot}/out/tests"
25+
"--extensionDevelopmentPath=${workspaceFolder}",
26+
"--extensionTestsPath=${workspaceFolder}/tests/runtime"
2427
],
2528
"stopOnEntry": false,
2629
"sourceMaps": true,
27-
"outFiles": ["${workspaceRoot}/out/**/*.js"],
30+
"outFiles": ["${workspaceFolder}/dist/**/*.js"],
2831
"preLaunchTask": "npm: compile:test"
2932
}
3033
]

client/.vscode/tasks.json

+10-7
Original file line numberDiff line numberDiff line change
@@ -5,15 +5,18 @@
55
"tasks": [
66
{
77
"type": "npm",
8-
"script": "compile:watch",
9-
"problemMatcher": "$tsc-watch",
10-
"isBackground": true,
8+
"script": "compile:dev",
9+
"problemMatcher": "$tsc",
10+
"presentation": {
11+
"reveal": "never"
12+
}
13+
},
14+
{
15+
"type": "npm",
16+
"script": "compile:test",
17+
"problemMatcher": "$tsc",
1118
"presentation": {
1219
"reveal": "never"
13-
},
14-
"group": {
15-
"kind": "build",
16-
"isDefault": true
1720
}
1821
}
1922
]

client/package.json

+4-5
Original file line numberDiff line numberDiff line change
@@ -31,11 +31,10 @@
3131
"scripts": {
3232
"postinstall": "node ./node_modules/vscode/bin/install",
3333
"clean": "rimraf out && rimraf dist",
34-
"compile:dev": "webpack --mode none && cpx ./tests/__simple-workspace__/**/* ./dist/tests/__simple-workspace__",
35-
"compile:prod": "webpack --mode production && cpx ./tests/__simple-workspace__/**/* ./dist/tests/__simple-workspace__",
36-
"compile:watch": "webpack --mode none --watch",
37-
"compile:test": "tsc -p ./ && cpx ./tests/__simple-workspace__/**/* ./out/tests/__simple-workspace__",
38-
"test": "CODE_TESTS_PATH=${PWD}/out/tests node ./node_modules/vscode/bin/test"
34+
"compile:dev": "webpack --mode none",
35+
"compile:test": "webpack --mode none && cpx ./tests/__simple-workspace__/**/* ./dist/test-workspaces/__simple-workspace__",
36+
"compile:prod": "webpack --mode production",
37+
"test": "npm run compile:test && TEST_WORKSPACES_DIR=${PWD}/dist/test-workspaces CODE_TESTS_PATH=${PWD}/tests/runtime CODE_EXTENSIONS_PATH=${PWD} node ./node_modules/vscode/bin/test"
3938
},
4039
"main": "./dist/extension",
4140
"activationEvents": [

client/src/extension.ts

+9
Original file line numberDiff line numberDiff line change
@@ -23,3 +23,12 @@ export async function activate(context: ExtensionContext) {
2323
}
2424

2525
export function deactivate() {}
26+
27+
if (process.env.NODE_ENV !== 'production') {
28+
// tslint:disable-next-line:no-var-requires
29+
const testRunnerExports = require('../tests/index');
30+
module.exports.testRunnerExports = testRunnerExports;
31+
module.exports.defineIntegrationTests = function defineTests() {
32+
require('../tests/integration.test');
33+
};
34+
}

client/tests/integration.test.ts

+5-1
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,11 @@ import { executeCodeActionCommand } from '../src/executeCodeActionCommand';
66
import langService from '../src/services/langService';
77

88
function getWorkspaceFilePath(workspaceName: string, relativeFilePath: string) {
9-
return path.join(__dirname, `__${workspaceName}__`, relativeFilePath);
9+
const testWorkspacesDir = process.env.TEST_WORKSPACES_DIR;
10+
if (!testWorkspacesDir) {
11+
throw new Error('TEST_WORSPACES_DIR variable is not set.');
12+
}
13+
return path.join(testWorkspacesDir, `__${workspaceName}__`, relativeFilePath);
1014
}
1115

1216
function createDiagnosticsMock(): vscode.CodeActionContext {

client/tests/runtime/index.js

+3
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
const extension = require('../../dist/extension.js');
2+
3+
module.exports = extension.testRunnerExports;
+3
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
const extension = require('../../dist/extension.js');
2+
3+
extension.defineIntegrationTests();

client/webpack.config.js

-1
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,6 @@ const config = {
1010

1111
entry: {
1212
extension: './src/extension.ts'
13-
//tests: './tests/index.ts'
1413
},
1514
output: {
1615
path: path.resolve(__dirname, 'dist'),

server/.vscode/tasks.json

+5
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,11 @@
1515
"kind": "build",
1616
"isDefault": true
1717
}
18+
},
19+
{
20+
"type": "npm",
21+
"script": "compile:dev",
22+
"problemMatcher": "$tsc"
1823
}
1924
]
2025
}

server/src/services/codeModService.ts

+1-2
Original file line numberDiff line numberDiff line change
@@ -22,10 +22,9 @@ function parseCodeMod(id: string, modFn: CodeModExports): CodeModDefinition {
2222
}
2323

2424
export function requireFiles() {
25-
debugger;
2625
let result: CodeModDefinition[];
2726
if (typeof __webpack_require__ === 'function') {
28-
let context = (require as any).context('../codemods');
27+
let context = (require as any).context('../codemods', true, /\.ts$/);
2928
result = context.keys().map((k: any) => parseCodeMod(k, context(k)));
3029
} else {
3130
const embeddedCodeModDir = path.join(__dirname, '..', 'codemods');

0 commit comments

Comments
 (0)