@@ -35,7 +35,7 @@ function getProjectPathFromTestItem(test: TestItem): string | undefined {
3535 if ( isTestFunctionItem ( test ) ) {
3636 // Extract from test ID: test:${projectPath}:${fileName}:${functionName}
3737 const parts = test . id . split ( ':' ) ;
38- if ( parts . length >= 2 ) {
38+ if ( parts . length >= 2 && parts [ 0 ] === 'test' ) {
3939 return parts [ 1 ] ;
4040 }
4141 } else if ( isProjectGroupItem ( test ) ) {
@@ -170,7 +170,7 @@ export async function runHandler(request: TestRunRequest, token: CancellationTok
170170 const workingDirectory = projectName ? StateMachine . context ( ) . workspacePath || projectPath : projectPath ;
171171 runCommand ( command , workingDirectory ) . then ( ( ) => {
172172 const endTime = Date . now ( ) ;
173- const timeElapsed = testItems . length > 0 ? ( endTime - startTime ) / testItems . length : ( endTime - startTime ) ;
173+ const timeElapsed = calculateTimeElapsed ( startTime , endTime , testItems ) ;
174174
175175 reportTestResults ( run , testItems , timeElapsed , projectPath ) . then ( ( ) => {
176176 endGroup ( test , true , run ) ;
@@ -179,7 +179,7 @@ export async function runHandler(request: TestRunRequest, token: CancellationTok
179179 } ) ;
180180 } ) . catch ( ( ) => {
181181 const endTime = Date . now ( ) ;
182- const timeElapsed = testItems . length > 0 ? ( endTime - startTime ) / testItems . length : ( endTime - startTime ) ;
182+ const timeElapsed = calculateTimeElapsed ( startTime , endTime , testItems ) ;
183183
184184 reportTestResults ( run , testItems , timeElapsed , projectPath ) . then ( ( ) => {
185185 endGroup ( test , true , run ) ;
@@ -210,7 +210,7 @@ export async function runHandler(request: TestRunRequest, token: CancellationTok
210210 const workingDirectory = projectName ? StateMachine . context ( ) . workspacePath || projectPath : projectPath ;
211211 runCommand ( command , workingDirectory ) . then ( ( ) => {
212212 const endTime = Date . now ( ) ;
213- const timeElapsed = ( endTime - startTime ) / testItems . length ;
213+ const timeElapsed = calculateTimeElapsed ( startTime , endTime , testItems ) ;
214214
215215 reportTestResults ( run , testItems , timeElapsed , projectPath ) . then ( ( ) => {
216216 endGroup ( test , true , run ) ;
@@ -219,7 +219,7 @@ export async function runHandler(request: TestRunRequest, token: CancellationTok
219219 } ) ;
220220 } ) . catch ( ( ) => {
221221 const endTime = Date . now ( ) ;
222- const timeElapsed = ( endTime - startTime ) / testItems . length ;
222+ const timeElapsed = calculateTimeElapsed ( startTime , endTime , testItems ) ;
223223
224224 reportTestResults ( run , testItems , timeElapsed , projectPath ) . then ( ( ) => {
225225 endGroup ( test , true , run ) ;
@@ -251,7 +251,7 @@ export async function runHandler(request: TestRunRequest, token: CancellationTok
251251 const workingDirectory = projectName ? StateMachine . context ( ) . workspacePath || projectPath : projectPath ;
252252 runCommand ( command , workingDirectory ) . then ( ( ) => {
253253 const endTime = Date . now ( ) ;
254- const timeElapsed = ( endTime - startTime ) / testItems . length ;
254+ const timeElapsed = calculateTimeElapsed ( startTime , endTime , testItems ) ;
255255
256256 reportTestResults ( run , testItems , timeElapsed , projectPath , true ) . then ( ( ) => {
257257 endGroup ( test , true , run ) ;
@@ -260,7 +260,7 @@ export async function runHandler(request: TestRunRequest, token: CancellationTok
260260 } ) ;
261261 } ) . catch ( ( ) => {
262262 const endTime = Date . now ( ) ;
263- const timeElapsed = ( endTime - startTime ) / testItems . length ;
263+ const timeElapsed = calculateTimeElapsed ( startTime , endTime , testItems ) ;
264264
265265 reportTestResults ( run , testItems , timeElapsed , projectPath , true ) . then ( ( ) => {
266266 endGroup ( test , true , run ) ;
@@ -273,6 +273,17 @@ export async function runHandler(request: TestRunRequest, token: CancellationTok
273273 }
274274 } ) ;
275275}
276+ /**
277+ * Calculate time elapsed per test item
278+ * @param startTime - Start time in milliseconds
279+ * @param endTime - End time in milliseconds
280+ * @param testItems - Array of test items
281+ * @returns Time elapsed per test item in milliseconds
282+ */
283+ function calculateTimeElapsed ( startTime : number , endTime : number , testItems : TestItem [ ] ) : number {
284+ return testItems . length > 0 ? ( endTime - startTime ) / testItems . length : ( endTime - startTime ) ;
285+ }
286+
276287const TEST_RESULTS_PATH = path . join ( "target" , "report" , "test_results.json" ) . toString ( ) ;
277288
278289enum TEST_STATUS {
0 commit comments