···21362136 specifier: workspace:*
21372137 version: link:../../packages/vitest
2138213821392139+ test/ws-api:
21402140+ devDependencies:
21412141+ '@vitejs/plugin-basic-ssl':
21422142+ specifier: ^1.0.2
21432143+ version: 1.0.2(vite@5.0.12)
21442144+ vitest:
21452145+ specifier: workspace:*
21462146+ version: link:../../packages/vitest
21472147+21392148packages:
2140214921412150 /@aashutoshrathi/word-wrap@1.2.6:
···27570275792757127580 /workbox-google-analytics@7.0.0:
2757227581 resolution: {integrity: sha512-MEYM1JTn/qiC3DbpvP2BVhyIH+dV/5BjHk756u9VbwuAhu0QHyKscTnisQuz21lfRpOwiS9z4XdqeVAKol0bzg==}
2758227582+ deprecated: It is not compatible with newer versions of GA starting with v4, as long as you are using GAv3 it should be ok, but the package is not longer being maintained
2757327583 dependencies:
2757427584 workbox-background-sync: 7.0.0
2757527585 workbox-core: 7.0.0
···11+import { join } from 'node:path'
22+import { expect, it } from 'vitest'
33+44+import { runVitestCli } from '../../test-utils'
55+66+it('api server-url http', async () => {
77+ delete process.env.TEST_HTTPS
88+ const { stdout } = await runVitestCli('run', '--root', join(process.cwd(), './fixtures/server-url'), '--api')
99+ expect(stdout).toContain('API started at http://localhost:51204/')
1010+ expect(stdout).toContain('Test Files 1 passed')
1111+})
1212+1313+it('api server-url https', async () => {
1414+ process.env.TEST_HTTPS = '1'
1515+ const { stdout } = await runVitestCli('run', '--root', join(process.cwd(), './fixtures/server-url'), '--api')
1616+ expect(stdout).toContain('API started at https://localhost:51204/')
1717+ expect(stdout).toContain('Test Files 1 passed')
1818+})
1919+2020+it.todo('api server-url fallback if resolvedUrls is null')
+9-3
packages/vitest/src/node/logger.ts
···171171 this.log(c.dim(c.green(` ${output} Browser runner started at ${new URL('/', origin)}`)))
172172 })
173173174174- if (this.ctx.config.ui)
174174+ if (this.ctx.config.ui) {
175175 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}`)))
176176- else if (this.ctx.config.api?.port)
177177- this.log(c.dim(c.green(` API started at http://${this.ctx.config.api?.host || 'localhost'}:${c.bold(`${this.ctx.config.api.port}`)}`)))
176176+ }
177177+ else if (this.ctx.config.api?.port) {
178178+ const resolvedUrls = this.ctx.server.resolvedUrls
179179+ // workaround for https://github.com/vitejs/vite/issues/15438, it was fixed in vite 5.1
180180+ const fallbackUrl = `http://${this.ctx.config.api.host || 'localhost'}:${this.ctx.config.api.port}`
181181+ const origin = resolvedUrls?.local[0] ?? resolvedUrls?.network[0] ?? fallbackUrl
182182+ this.log(c.dim(c.green(` API started at ${new URL('/', origin)}`)))
183183+ }
178184179185 if (this.ctx.coverageProvider)
180186 this.log(c.dim(' Coverage enabled with ') + c.yellow(this.ctx.coverageProvider.name))
+5
test/ws-api/fixtures/server-url/basic.test.ts
···11+import { expect, test } from "vitest";
22+33+test("basic", () => {
44+ expect(1).toBe(1);
55+})
+11
test/ws-api/fixtures/server-url/vitest.config.ts
···11+import { defineConfig } from 'vitest/config'
22+import basicSsl from '@vitejs/plugin-basic-ssl'
33+44+// test https by
55+// TEST_HTTPS=1 pnpm test --root fixtures/server-url --api
66+77+export default defineConfig({
88+ plugins: [
99+ !!process.env.TEST_HTTPS && basicSsl(),
1010+ ],
1111+})