Skip to content

Commit

Permalink
fix(vitest): correctly override api with --no-api flag (#5386)
Browse files Browse the repository at this point in the history
  • Loading branch information
sheremet-va authored Mar 14, 2024
1 parent efe441f commit 51d1d47
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 3 deletions.
5 changes: 3 additions & 2 deletions examples/playwright/test/basic.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,9 +20,10 @@ describe.runIf(process.platform !== 'win32')('basic', async () => {
})

afterAll(async () => {
await browser.close()
// hook timed out and we already have another error
await browser?.close()
await new Promise<void>((resolve, reject) => {
server.httpServer.close(error => error ? reject(error) : resolve())
server?.httpServer.close(error => error ? reject(error) : resolve())
})
})

Expand Down
2 changes: 1 addition & 1 deletion packages/vitest/src/node/plugins/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -45,8 +45,8 @@ export async function VitestPlugin(options: UserConfig = {}, ctx = new Vitest('t
const testConfig = deepMerge(
{} as UserConfig,
configDefaults,
options,
removeUndefinedValues(viteConfig.test ?? {}),
options,
)
testConfig.api = resolveApiServerConfig(testConfig)

Expand Down
28 changes: 28 additions & 0 deletions test/config/test/resolution.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -235,3 +235,31 @@ describe('correctly defines inline and noExternal flags', async () => {
])
})
})

describe('correctly defines api flag', () => {
it('CLI overrides disabling api', async () => {
const c = await vitest({ api: false }, {
api: {
port: 1234,
},
watch: true,
})
expect(c.server.config.server.middlewareMode).toBe(true)
expect(c.config.api).toEqual({
middlewareMode: true,
})
})

it('CLI overrides inlined value', async () => {
const c = await vitest({ api: { port: 4321 } }, {
api: {
port: 1234,
},
watch: true,
})
expect(c.server.config.server.port).toBe(4321)
expect(c.config.api).toEqual({
port: 4321,
})
})
})

0 comments on commit 51d1d47

Please sign in to comment.