Skip to content

Commit

Permalink
fix(browser): dedupe @vitest/browser/client (#6081)
Browse files Browse the repository at this point in the history
  • Loading branch information
sheremet-va authored Jul 10, 2024
1 parent 756ac2b commit ee72518
Show file tree
Hide file tree
Showing 6 changed files with 8 additions and 9 deletions.
2 changes: 1 addition & 1 deletion packages/browser/src/client/orchestrator.ts
Original file line number Diff line number Diff line change
Expand Up @@ -245,7 +245,7 @@ async function getContainer(config: ResolvedConfig): Promise<HTMLDivElement> {
return document.querySelector('#vitest-tester') as HTMLDivElement
}

client.ws.addEventListener('open', async () => {
client.waitForConnection().then(async () => {
const testFiles = getBrowserState().files

await orchestrator.init()
Expand Down
2 changes: 1 addition & 1 deletion packages/browser/src/client/public/error-catcher.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { channel, client } from '/@id/@vitest/browser/client'
import { channel, client } from '@vitest/browser/client'

function on(event, listener) {
window.addEventListener(event, listener)
Expand Down
2 changes: 2 additions & 0 deletions packages/browser/src/node/plugin.ts
Original file line number Diff line number Diff line change
Expand Up @@ -166,6 +166,8 @@ export default (browserServer: BrowserServer, base = '/'): Plugin[] => {
'vitest/utils',
'vitest/browser',
'vitest/runners',
'@vitest/browser',
'@vitest/browser/client',
'@vitest/utils',
'@vitest/utils/source-map',
'@vitest/runner',
Expand Down
7 changes: 2 additions & 5 deletions packages/browser/src/node/server.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ export class BrowserServer implements IBrowserServer {
public testerHtml: Promise<string> | string
public orchestratorHtml: Promise<string> | string
public injectorJs: Promise<string> | string
public errorCatcherJs: Promise<string> | string
public errorCatcherPath: Promise<string> | string
public stateJs: Promise<string> | string

public state: BrowserServerState
Expand Down Expand Up @@ -87,10 +87,7 @@ export class BrowserServer implements IBrowserServer {
resolve(distRoot, 'client/esm-client-injector.js'),
'utf8',
).then(js => (this.injectorJs = js))
this.errorCatcherJs = readFile(
resolve(distRoot, 'client/error-catcher.js'),
'utf8',
).then(js => (this.errorCatcherJs = js))
this.errorCatcherPath = resolve(distRoot, 'client/error-catcher.js')
this.stateJs = readFile(
resolve(distRoot, 'state.js'),
'utf-8',
Expand Down
2 changes: 1 addition & 1 deletion packages/browser/src/node/serverOrchestrator.ts
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ export async function resolveOrchestrator(
__VITEST_TITLE__: 'Vitest Browser Runner',
__VITEST_SCRIPTS__: server.orchestratorScripts,
__VITEST_INJECTOR__: `<script type="module">${injector}</script>`,
__VITEST_ERROR_CATCHER__: `<script type="module">${server.errorCatcherJs}</script>`,
__VITEST_ERROR_CATCHER__: `<script type="module" src="${server.errorCatcherPath}"></script>`,
__VITEST_CONTEXT_ID__: JSON.stringify(contextId),
})
}
2 changes: 1 addition & 1 deletion packages/browser/src/node/serverTester.ts
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ export async function resolveTester(
__VITEST_TITLE__: 'Vitest Browser Tester',
__VITEST_SCRIPTS__: server.testerScripts,
__VITEST_INJECTOR__: `<script type="module">${injector}</script>`,
__VITEST_ERROR_CATCHER__: `<script type="module">${server.errorCatcherJs}</script>`,
__VITEST_ERROR_CATCHER__: `<script type="module" src="${server.errorCatcherPath}"></script>`,
__VITEST_APPEND__:
`<script type="module">
__vitest_browser_runner__.runningFiles = ${tests}
Expand Down

0 comments on commit ee72518

Please # to comment.