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.
27import * as path from 'path' ;
38import * as vscode from 'vscode' ;
4- import glob from 'glob' ;
59import Mocha from 'mocha' ;
610import { mockWebviewEnvironment } from './mocks/mockWebviewEnvironment' ;
711import { 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-
2413async 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 , / \. t e s t $ / ) ) ;
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' , {
0 commit comments