33 * Licensed under the MIT License. See License.txt in the project root for license information.
44 *--------------------------------------------------------------------------------------------*/
55
6- // @ts -nocheck
7-
86// This file is providing the test runner to use when running extension tests.
97import * as path from 'path' ;
108import * as vscode from 'vscode' ;
9+ import glob from 'glob' ;
1110import Mocha from 'mocha' ;
1211import { mockWebviewEnvironment } from './mocks/mockWebviewEnvironment' ;
1312import { EXTENSION_ID } from '../constants' ;
1413
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+ }
28+
1529async function runAllExtensionTests ( testsRoot : string , clb : ( error : Error | null , failures ?: number ) => void ) : Promise < any > {
1630 // Ensure the dev-mode extension is activated
1731 await vscode . extensions . getExtension ( EXTENSION_ID ) ! . activate ( ) ;
@@ -22,23 +36,10 @@ async function runAllExtensionTests(testsRoot: string, clb: (error: Error | null
2236 ui : 'bdd' ,
2337 color : true
2438 } ) ;
39+ mocha . addFile ( path . resolve ( testsRoot , 'globalHooks.js' ) ) ;
2540
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- }
32-
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- }
41+ await addTests ( mocha , testsRoot ) ;
42+ await addTests ( mocha , path . resolve ( testsRoot , '../../../webviews/' ) ) ;
4243
4344 if ( process . env . TEST_JUNIT_XML_PATH ) {
4445 mocha . reporter ( 'mocha-multi-reporters' , {
0 commit comments