Skip to content

Commit f87bcf0

Browse files
committed
Fix: Include tests in webpack compilation for node target
1 parent 73cf083 commit f87bcf0

File tree

2 files changed

+23
-19
lines changed

2 files changed

+23
-19
lines changed

src/test/index.ts

Lines changed: 21 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1,26 +1,15 @@
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+
16
// This file is providing the test runner to use when running extension tests.
27
import * as path from 'path';
38
import * as vscode from 'vscode';
4-
import glob from 'glob';
59
import Mocha from 'mocha';
610
import { mockWebviewEnvironment } from './mocks/mockWebviewEnvironment';
711
import { EXTENSION_ID } from '../constants';
812

9-
function addTests(mocha: Mocha, root: string): Promise<void> {
10-
return new Promise((resolve, reject) => {
11-
glob('**/**.test.js', { cwd: root }, (error, files) => {
12-
if (error) {
13-
return reject(error);
14-
}
15-
16-
for (const testFile of files) {
17-
mocha.addFile(path.join(root, testFile));
18-
}
19-
resolve();
20-
});
21-
});
22-
}
23-
2413
async function runAllExtensionTests(testsRoot: string, clb: (error: Error | null, failures?: number) => void): Promise<any> {
2514
// Ensure the dev-mode extension is activated
2615
await vscode.extensions.getExtension(EXTENSION_ID)!.activate();
@@ -31,10 +20,23 @@ async function runAllExtensionTests(testsRoot: string, clb: (error: Error | null
3120
ui: 'bdd',
3221
color: true
3322
});
34-
mocha.addFile(path.resolve(testsRoot, 'globalHooks.js'));
3523

36-
await addTests(mocha, testsRoot);
37-
await addTests(mocha, path.resolve(testsRoot, '../../../webviews/'));
24+
// Load globalHooks if it exists
25+
try {
26+
mocha.addFile(path.resolve(testsRoot, 'globalHooks.js'));
27+
} catch (e) {
28+
// globalHooks might not exist in webpack bundle, ignore
29+
}
30+
31+
// Import all test files using webpack's require.context
32+
try {
33+
// Load tests from src/test directory only
34+
// Webview tests are compiled separately with the webview configuration
35+
const importAll = (r: __WebpackModuleApi.RequireContext) => r.keys().forEach(r);
36+
importAll(require.context('./', true, /\.test$/));
37+
} catch (e) {
38+
console.log('Error loading tests:', e);
39+
}
3840

3941
if (process.env.TEST_JUNIT_XML_PATH) {
4042
mocha.reporter('mocha-multi-reporters', {

webpack.config.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -192,6 +192,8 @@ async function getExtensionConfig(target, mode, env) {
192192
};
193193
if (target === 'webworker') {
194194
entry['test/index'] = './src/test/browser/index.ts';
195+
} else if (target === 'node') {
196+
entry['test/index'] = './src/test/index.ts';
195197
}
196198

197199
return {

0 commit comments

Comments
 (0)