Skip to content

Commit

Permalink
fix: use resolvedUrls from devserver as in #4855
Browse files Browse the repository at this point in the history
  • Loading branch information
saitonakamura committed Feb 28, 2024
1 parent 9a64e6c commit d63f098
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 6 deletions.
10 changes: 7 additions & 3 deletions packages/vitest/src/node/logger.ts
Original file line number Diff line number Diff line change
Expand Up @@ -171,10 +171,14 @@ export class Logger {
this.log(c.dim(c.green(` ${output} Browser runner started at ${new URL('/', origin)}`)))
})

if (this.ctx.config.ui)
if (this.ctx.config.ui) {
this.log(c.dim(c.green(` UI started at http://${this.ctx.config.api?.host || 'localhost'}:${c.bold(`${this.ctx.server.config.server.port}`)}${this.ctx.config.uiBase}`)))
else if (this.ctx.config.api?.port)
this.log(c.dim(c.green(` API started at http://${this.ctx.config.api?.host || 'localhost'}:${c.bold(`${this.ctx.config.api.port}`)}`)))
}
else if (this.ctx.config.api?.port) {
const resolvedUrls = this.ctx.server.resolvedUrls
const origin = resolvedUrls?.local[0] ?? resolvedUrls?.network[0]
this.log(c.dim(c.green(` API started at ${new URL('/', origin)}`)))
}

if (this.ctx.coverageProvider)
this.log(c.dim(' Coverage enabled with ') + c.yellow(this.ctx.coverageProvider.name))
Expand Down
6 changes: 3 additions & 3 deletions test/ws-api/tests/server-url.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,13 @@ import { runVitestCli } from '../../test-utils'
it('api server-url http', async () => {
delete process.env.TEST_HTTPS
const { stdout } = await runVitestCli('run', '--root', join(process.cwd(), './fixtures/server-url'), '--api')
expect(stdout).toContain('API started at http://localhost:51204')
expect(stdout).toContain('API started at http://localhost:51204/')
expect(stdout).toContain('Test Files 1 passed')
})

it.fails('api server-url https', async () => {
it('api server-url https', async () => {
process.env.TEST_HTTPS = '1'
const { stdout } = await runVitestCli('run', '--root', join(process.cwd(), './fixtures/server-url'), '--api')
expect(stdout).toContain('API started at https://localhost:51204')
expect(stdout).toContain('API started at https://localhost:51204/')
expect(stdout).toContain('Test Files 1 passed')
})

0 comments on commit d63f098

Please sign in to comment.