Skip to content

Commit

Permalink
fix: print unhandled errors to tets results tab (#370)
Browse files Browse the repository at this point in the history
* fix: print unhandled errors to tets results tab

* chore: cleanup

* fix: stop debugging if running other profiles

* chore: update types/node and typecheck

* fix: correctly watch folders, and add more debug statements

* chore: files relative

* chore: cleanup
  • Loading branch information
sheremet-va authored May 6, 2024
1 parent 2d34afc commit 7c036fd
Show file tree
Hide file tree
Showing 11 changed files with 247 additions and 155 deletions.
4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -181,7 +181,7 @@
"@types/glob": "^7.2.0",
"@types/micromatch": "^4.0.6",
"@types/mocha": "^10.0.6",
"@types/node": "^18.11.18",
"@types/node": "^20.12.8",
"@types/prompts": "^2.4.9",
"@types/semver": "^7.3.9",
"@types/vscode": "^1.77.0",
Expand Down Expand Up @@ -216,7 +216,7 @@
"tree-kill": "^1.2.2",
"tsup": "^8.0.1",
"tsx": "^4.7.1",
"typescript": "^5.3.3",
"typescript": "^5.4.5",
"vitest": "^1.4.0",
"which": "^4.0.0",
"ws": "^8.16.0"
Expand Down
128 changes: 67 additions & 61 deletions pnpm-lock.yaml

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion src/api/rpc.ts
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ export interface VitestPool extends VitestPoolMethods {
export interface VitestEvents {
onConsoleLog: (log: UserConsoleLog) => void
onTaskUpdate: (task: TaskResultPack[]) => void
onFinished: (files?: File[], errors?: unknown[], collecting?: boolean) => void
onFinished: (files: File[], unhandledError: string, collecting?: boolean) => void
onCollected: (files?: File[], collecting?: boolean) => void
onWatcherStart: (files?: File[], errors?: unknown[], collecting?: boolean) => void
onWatcherRerun: (files: string[], trigger?: string, collecting?: boolean) => void
Expand Down
4 changes: 4 additions & 0 deletions src/debug/debugManager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -138,6 +138,10 @@ export class TestDebugManager extends vscode.Disposable {
public async stopDebugging() {
await Promise.allSettled([...this.sessions].map(([, s]) => vscode.debug.stopDebugging(s)))
}

public get enabled() {
return this.port !== undefined
}
}

interface TestDebugConfiguration {
Expand Down
11 changes: 9 additions & 2 deletions src/extension.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import * as vscode from 'vscode'
import './polyfills'
import { gte } from 'semver'
import { version } from '../package.json'
import { getConfig, testControllerId } from './config'
Expand Down Expand Up @@ -139,7 +140,10 @@ class VitestExtension {
)
}
runProfile.tag = api.tag
runProfile.runHandler = (request, token) => runner.runTests(request, token)
runProfile.runHandler = async (request, token) => {
await runner.stopDebugRun()
await runner.runTests(request, token)
}
this.runProfiles.set(`${api.id}:run`, runProfile)
let debugProfile = previousRunProfiles.get(`${api.id}:debug`)
if (!debugProfile) {
Expand Down Expand Up @@ -179,7 +183,10 @@ class VitestExtension {
)
}
coverageProfile.tag = api.tag
coverageProfile.runHandler = (request, token) => runner.runCoverage(request, token)
coverageProfile.runHandler = async (request, token) => {
await runner.stopDebugRun()
await runner.runCoverage(request, token)
}
coverageProfile.loadDetailedCoverage = coverageContext.loadDetailedCoverage
this.runProfiles.set(`${api.id}:coverage`, coverageProfile)
}
Expand Down
11 changes: 11 additions & 0 deletions src/polyfills.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
if (!Promise.withResolvers) {
Promise.withResolvers = function withResolvers<T>() {
let a: (v: T | PromiseLike<T>) => void
let b: (r?: any) => void
const c = new this<T>((resolve, reject) => {
a = resolve
b = reject
})
return { resolve: a!, reject: b!, promise: c }
}
}
Loading

0 comments on commit 7c036fd

Please sign in to comment.