@@ -10,6 +10,7 @@ import { TestWorkflow } from './testWorkflow';
10
10
import { TestWorkspace } from './testWorkspace' ;
11
11
import { isEmptyString } from '@microsoft/utils-logic-apps' ;
12
12
import { type IActionContext , callWithTelemetryAndErrorHandling } from '@microsoft/vscode-azext-utils' ;
13
+ import * as path from 'path' ;
13
14
import {
14
15
RelativePattern ,
15
16
type TestController ,
@@ -30,8 +31,9 @@ export type TestData = TestWorkspace | TestWorkflow | TestFile;
30
31
/**
31
32
* Prepares the test explorer for unit tests.
32
33
* @param {ExtensionContext } context - The extension context.
34
+ * @param {IActionContext } activateContext - Command activate context.
33
35
*/
34
- export const prepareTestExplorer = async ( context : ExtensionContext ) => {
36
+ export const prepareTestExplorer = async ( context : ExtensionContext , activateContext : IActionContext ) => {
35
37
callWithTelemetryAndErrorHandling ( unitTestExplorer , async ( actionContext : IActionContext ) => {
36
38
if ( workspace . workspaceFolders && workspace . workspaceFolders . length > 0 ) {
37
39
const isLogicAppProject = await hasLogicAppProject ( actionContext ) ;
@@ -51,7 +53,7 @@ export const prepareTestExplorer = async (context: ExtensionContext) => {
51
53
unitTestController . createRunProfile (
52
54
'Run logic apps standard unit tests' ,
53
55
TestRunProfileKind . Run ,
54
- ( request , cancellation ) => runHandler ( request , cancellation , unitTestController ) ,
56
+ ( request , cancellation ) => runHandler ( request , cancellation , unitTestController , activateContext ) ,
55
57
true ,
56
58
undefined
57
59
) ;
@@ -91,10 +93,16 @@ export const getWorkspaceTestPatterns = () => {
91
93
* Runs the test handler based on the provided request and cancellation token.
92
94
* @param {TestRunRequest } request - The test run request.
93
95
* @param {CancellationToken } cancellation - The cancellation token.
96
+ * @param {IActionContext } activateContext - Command activate context.
94
97
*/
95
- export const runHandler = ( request : TestRunRequest , cancellation : CancellationToken , unitTestController : TestController ) => {
98
+ export const runHandler = (
99
+ request : TestRunRequest ,
100
+ cancellation : CancellationToken ,
101
+ unitTestController : TestController ,
102
+ activateContext : IActionContext
103
+ ) => {
96
104
cancellation . onCancellationRequested ( ( ) => request . include . forEach ( ( item ) => ext . watchingTests . delete ( item ) ) ) ;
97
- return startTestRun ( request , unitTestController ) ;
105
+ return startTestRun ( request , unitTestController , activateContext ) ;
98
106
} ;
99
107
100
108
/**
@@ -133,10 +141,6 @@ const testsWorkspaceWatcher = (controller: TestController, fileChangedEmitter: E
133
141
fileChangedEmitter . fire ( uri ) ;
134
142
} ) ;
135
143
watcher . onDidChange ( async ( uri ) => {
136
- const { data } = await getOrCreateFile ( controller , uri ) ;
137
- if ( data instanceof TestFile ) {
138
- await data . parseUnitTest ( ) ;
139
- }
140
144
fileChangedEmitter . fire ( uri ) ;
141
145
} ) ;
142
146
watcher . onDidDelete ( ( uri ) => controller . items . delete ( uri . toString ( ) ) ) ;
@@ -156,7 +160,7 @@ const findInitialFiles = async (controller: TestController, pattern: RelativePat
156
160
const unitTestFiles = await workspace . findFiles ( pattern ) ;
157
161
158
162
const workspacesTestFiles = unitTestFiles . reduce ( ( acc , file : Uri ) => {
159
- const workspaceName = file . path . split ( '/' ) . slice ( - 5 ) [ 0 ] ;
163
+ const workspaceName = file . fsPath . split ( '/' ) . slice ( - 5 ) [ 0 ] ;
160
164
161
165
if ( ! acc [ workspaceName ] ) {
162
166
acc [ workspaceName ] = [ ] ;
@@ -182,7 +186,7 @@ const getOrCreateWorkspace = (controller: TestController, workspaceName: string,
182
186
if ( existing ) {
183
187
return { file : existing , data : ext . testData . get ( existing ) as TestWorkspace } ;
184
188
}
185
- const filePath = files . length > 0 ? files [ 0 ] . path : '' ;
189
+ const filePath = files . length > 0 ? files [ 0 ] . fsPath : '' ;
186
190
const workspaceUri = isEmptyString ( filePath ) ? undefined : Uri . file ( filePath . split ( '/' ) . slice ( 0 , - 4 ) . join ( '/' ) ) ;
187
191
188
192
const workspaceTestItem = controller . createTestItem ( workspaceName , workspaceName , workspaceUri ) ;
@@ -202,9 +206,9 @@ const getOrCreateWorkspace = (controller: TestController, workspaceName: string,
202
206
* @returns An object containing the file test and its associated data, if it exists.
203
207
*/
204
208
const getOrCreateFile = async ( controller : TestController , uri : Uri ) => {
205
- const workspaceName = uri . path . split ( '/' ) . slice ( - 5 ) [ 0 ] ;
206
- const testName = uri . path . split ( '/' ) . slice ( - 1 ) [ 0 ] ;
207
- const workflowName = uri . path . split ( '/' ) . slice ( - 2 ) [ 0 ] ;
209
+ const workspaceName = uri . fsPath . split ( '/' ) . slice ( - 5 ) [ 0 ] ;
210
+ const testName = path . basename ( uri . fsPath ) ;
211
+ const workflowName = path . basename ( path . dirname ( uri . fsPath ) ) ;
208
212
209
213
const existingWorkspaceTest = controller . items . get ( workspaceName ) ;
210
214
@@ -225,7 +229,7 @@ const getOrCreateFile = async (controller: TestController, uri: Uri) => {
225
229
existingWorkspaceTest . children . add ( workflowTestItem ) ;
226
230
}
227
231
} else {
228
- const workspaceUri = Uri . file ( uri . path . split ( '/' ) . slice ( 0 , - 4 ) . join ( '/' ) ) ;
232
+ const workspaceUri = Uri . file ( uri . fsPath . split ( '/' ) . slice ( 0 , - 4 ) . join ( '/' ) ) ;
229
233
const workspaceTestItem = controller . createTestItem ( workspaceName , workspaceName , workspaceUri ) ;
230
234
workspaceTestItem . canResolveChildren = true ;
231
235
controller . items . add ( workspaceTestItem ) ;
@@ -242,8 +246,9 @@ const getOrCreateFile = async (controller: TestController, uri: Uri) => {
242
246
* Starts a test run based on the provided request and unit test controller.
243
247
* @param {TestRunRequest } request - The test run request.
244
248
* @param {TestController } unitTestController - The unit test controller.
249
+ * @param {IActionContext } activateContext - Command activate context.
245
250
*/
246
- const startTestRun = ( request : TestRunRequest , unitTestController : TestController ) => {
251
+ const startTestRun = ( request : TestRunRequest , unitTestController : TestController , activateContext : IActionContext ) => {
247
252
const queue : { test : TestItem ; data : TestFile } [ ] = [ ] ;
248
253
const run = unitTestController . createTestRun ( request ) ;
249
254
@@ -278,15 +283,15 @@ const startTestRun = (request: TestRunRequest, unitTestController: TestControlle
278
283
*/
279
284
const runTestQueue = async ( ) => {
280
285
for ( const { test, data } of queue ) {
281
- run . appendOutput ( `Running ${ test . id } \r\n` ) ;
286
+ run . appendOutput ( `Running ${ test . label } \r\n` ) ;
282
287
if ( run . token . isCancellationRequested ) {
283
288
run . skipped ( test ) ;
284
289
} else {
285
290
run . started ( test ) ;
286
- await data . run ( test , run ) ;
291
+ await data . run ( test , run , activateContext ) ;
287
292
}
288
293
289
- run . appendOutput ( `Completed ${ test . id } \r\n` ) ;
294
+ run . appendOutput ( `Completed ${ test . label } \r\n` ) ;
290
295
}
291
296
292
297
run . end ( ) ;
0 commit comments