33 * Licensed under the MIT License. See License.txt in the project root for license information.
44 *--------------------------------------------------------------------------------------------*/
55
6+ // @ts -nocheck
67// This file is providing the test runner to use when running extension tests.
78import * as path from 'path' ;
89import * as vscode from 'vscode' ;
@@ -11,20 +12,6 @@ import Mocha from 'mocha';
1112import { mockWebviewEnvironment } from './mocks/mockWebviewEnvironment' ;
1213import { EXTENSION_ID } from '../constants' ;
1314
14- function addTests ( mocha : Mocha , root : string ) : Promise < void > {
15- return new Promise ( ( resolve , reject ) => {
16- glob ( '**/**.test.js' , { cwd : root } , ( error , files ) => {
17- if ( error ) {
18- return reject ( error ) ;
19- }
20-
21- for ( const testFile of files ) {
22- mocha . addFile ( path . join ( root , testFile ) ) ;
23- }
24- resolve ( ) ;
25- } ) ;
26- } ) ;
27- }
2815
2916async function runAllExtensionTests ( testsRoot : string , clb : ( error : Error | null , failures ?: number ) => void ) : Promise < any > {
3017 // Ensure the dev-mode extension is activated
@@ -36,10 +23,22 @@ async function runAllExtensionTests(testsRoot: string, clb: (error: Error | null
3623 ui : 'bdd' ,
3724 color : true
3825 } ) ;
39- mocha . addFile ( path . resolve ( testsRoot , 'globalHooks.js' ) ) ;
26+ // Load globalHooks if it exists
27+ try {
28+ mocha . addFile ( path . resolve ( testsRoot , 'globalHooks.js' ) ) ;
29+ } catch ( e ) {
30+ // globalHooks might not exist in webpack bundle, ignore
31+ }
4032
41- await addTests ( mocha , testsRoot ) ;
42- await addTests ( mocha , path . resolve ( testsRoot , '../../../webviews/' ) ) ;
33+ // Import all test files using webpack's require.context
34+ try {
35+ // Load tests from src/test directory only
36+ // Webview tests are compiled separately with the webview configuration
37+ const importAll = ( r : __WebpackModuleApi . RequireContext ) => r . keys ( ) . forEach ( r ) ;
38+ importAll ( require . context ( './' , true , / \. t e s t $ / ) ) ;
39+ } catch ( e ) {
40+ console . log ( 'Error loading tests:' , e ) ;
41+ }
4342
4443 if ( process . env . TEST_JUNIT_XML_PATH ) {
4544 mocha . reporter ( 'mocha-multi-reporters' , {
0 commit comments