Skip to content

Commit d5c583e

Browse files
committed
test: stub provider and environment detection in dev output tests
1 parent 682c773 commit d5c583e

1 file changed

Lines changed: 22 additions & 1 deletion

File tree

packages/nuxt-cli/test/unit/terminal-output.spec.ts

Lines changed: 22 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,17 @@ import { colourOf, render, screen as visibleScreen } from '../utils/terminal'
1212
// under test are loaded dynamically below.
1313
process.env.FORCE_COLOR = '3'
1414

15-
vi.mock('std-env', () => ({ isCI: false, isTest: false }))
15+
vi.mock('std-env', () => ({ isCI: false, isTest: false, provider: undefined }))
16+
17+
// The suite may itself run inside a container, so the environment the URL block
18+
// describes is stubbed rather than detected.
19+
const isolatedEnvironment = vi.hoisted(() => ({ current: undefined as string | undefined }))
20+
21+
vi.mock('../../src/dev/environment', () => ({
22+
isDocker: () => false,
23+
isWsl: () => false,
24+
detectIsolatedEnvironment: () => isolatedEnvironment.current,
25+
}))
1626

1727
const { listen, openBrowser, printQRCode } = await import('../../src/dev/listen')
1828
const { setupShortcuts } = await import('../../src/dev/shortcuts')
@@ -53,6 +63,7 @@ describe('dev server terminal output', () => {
5363

5464
afterEach(async () => {
5565
await Promise.all(listeners.splice(0).map(listener => listener.close()))
66+
isolatedEnvironment.current = undefined
5667
vi.restoreAllMocks()
5768
})
5869

@@ -94,6 +105,16 @@ describe('dev server terminal output', () => {
94105
`)
95106
})
96107

108+
it('should say how to reach a loopback server from outside a container', async () => {
109+
isolatedEnvironment.current = 'the container'
110+
const renderer = await render(() => start())
111+
112+
expect(screen(renderer)).toMatchInlineSnapshot(`
113+
" ➜ Local: http://localhost:<port>/
114+
➜ Network: use --host to reach this server from outside the container"
115+
`)
116+
})
117+
97118
it('should colour each url type differently', async () => {
98119
const renderer = await render(() => start())
99120
renderer.goToFrame(renderer.frames.length - 1)

0 commit comments

Comments
 (0)