Skip to content

Commit

Permalink
test: more tests
Browse files Browse the repository at this point in the history
  • Loading branch information
sheremet-va committed Jan 5, 2024
1 parent fd1abab commit e4d4998
Show file tree
Hide file tree
Showing 6 changed files with 359 additions and 284 deletions.
14 changes: 14 additions & 0 deletions packages/vite/src/node/server/ws.ts
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,8 @@ export interface WebSocketServer {
off: WebSocketTypes.Server['off'] & {
(event: string, listener: Function): void
}

emit(...args: any[]): void
}

export interface WebSocketClient {
Expand Down Expand Up @@ -280,6 +282,18 @@ export function createWebSocketServer(
})
},

// TODO: remove when multiple hmr cliens are merged
emit(event, payload) {
customListeners.get(event)?.forEach((fn) =>
fn(payload.data, {
socket: {} as any,
send: () => {
//
},
}),
)
},

close() {
// should remove listener if hmr.server is set
// otherwise the old listener swallows all WebSocket connections
Expand Down
16 changes: 16 additions & 0 deletions packages/vite/src/node/ssr/runtime/runtime.ts
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,22 @@ export class ViteRuntime {
this.hmrClient?.clear()
}

// TODO - what if it's a virtual module(?)
public resolveIdToFilepath(id: string): string {
if (this.moduleCache.has(id)) {
return id
}
const file = this.idToFileMap.get(id)
if (file && this.moduleCache.has(file)) {
return file
}
const resolved = posixResolve(
this.options.root,
id[0] === '/' ? id.slice(1) : id,
)
return resolved
}

private async cachedRequest(
id: string,
fetchedModule: FetchResult,
Expand Down
Loading

0 comments on commit e4d4998

Please sign in to comment.