|
1 | 1 | import type { UserConfig } from 'vitest'
|
2 | 2 | import type { UserConfig as ViteUserConfig } from 'vite'
|
3 |
| -import { describe, expect, it } from 'vitest' |
4 |
| -import { createVitest } from 'vitest/node' |
| 3 | +import { describe, expect, it, onTestFinished, vi } from 'vitest' |
| 4 | +import { createVitest, parseCLI } from 'vitest/node' |
5 | 5 | import { extraInlineDeps } from 'vitest/config'
|
6 | 6 |
|
7 | 7 | async function vitest(cliOptions: UserConfig, configValue: UserConfig = {}, viteConfig: ViteUserConfig = {}) {
|
@@ -263,3 +263,50 @@ describe('correctly defines api flag', () => {
|
263 | 263 | })
|
264 | 264 | })
|
265 | 265 | })
|
| 266 | + |
| 267 | +describe.each([ |
| 268 | + '--inspect', |
| 269 | + '--inspect-brk', |
| 270 | +])('correctly parses %s flags', (inspectFlagName) => { |
| 271 | + it.each([ |
| 272 | + ['', { enabled: true }], |
| 273 | + ['true', { enabled: true }], |
| 274 | + ['yes', { enabled: true }], |
| 275 | + ['false', { enabled: false }], |
| 276 | + ['no', { enabled: false }], |
| 277 | + |
| 278 | + ['1002', { enabled: true, port: 1002 }], |
| 279 | + ['www.remote.com:1002', { enabled: true, port: 1002, host: 'www.remote.com' }], |
| 280 | + ['www.remote.com', { enabled: true, host: 'www.remote.com' }], |
| 281 | + ])(`parses "vitest ${inspectFlagName} %s" value`, async (cliValue, inspect) => { |
| 282 | + const rawConfig = parseCLI( |
| 283 | + `vitest --no-file-parallelism ${inspectFlagName} ${cliValue}`, |
| 284 | + ) |
| 285 | + const c = await config(rawConfig.options) |
| 286 | + expect(c.inspector).toEqual({ |
| 287 | + ...inspect, |
| 288 | + waitForDebugger: inspectFlagName === '--inspect-brk' && inspect.enabled, |
| 289 | + }) |
| 290 | + }) |
| 291 | + it('cannot use a URL', async () => { |
| 292 | + const url = 'https://www.remote.com:1002' |
| 293 | + const rawConfig = parseCLI([ |
| 294 | + 'vitest', |
| 295 | + '--no-file-parallelism', |
| 296 | + inspectFlagName, |
| 297 | + url, |
| 298 | + ]) |
| 299 | + const error = vi.fn() |
| 300 | + const originalError = console.error |
| 301 | + console.error = error |
| 302 | + onTestFinished(() => { |
| 303 | + console.error = originalError |
| 304 | + }) |
| 305 | + await expect(async () => { |
| 306 | + await config(rawConfig.options) |
| 307 | + }).rejects.toThrowError() |
| 308 | + expect(error.mock.lastCall[0]).toEqual( |
| 309 | + expect.stringContaining(`Inspector host cannot be a URL. Use "host:port" instead of "${url}"`), |
| 310 | + ) |
| 311 | + }) |
| 312 | +}) |
0 commit comments