|
| 1 | +import type { UserConfig } from 'vitest' |
| 2 | +import { describe, expect, it } from 'vitest' |
| 3 | +import { createVitest } from 'vitest/node' |
| 4 | + |
| 5 | +async function config(cliOptions: UserConfig, configValue: UserConfig = {}) { |
| 6 | + const vitest = await createVitest('test', { ...cliOptions, watch: false }, { test: configValue }) |
| 7 | + return vitest.config |
| 8 | +} |
| 9 | + |
| 10 | +describe('correctly defines isolated flags', async () => { |
| 11 | + it('prefers CLI poolOptions flags over config', async () => { |
| 12 | + const c = await config({ |
| 13 | + isolate: true, |
| 14 | + poolOptions: { |
| 15 | + threads: { |
| 16 | + isolate: false, |
| 17 | + }, |
| 18 | + forks: { |
| 19 | + isolate: false, |
| 20 | + }, |
| 21 | + }, |
| 22 | + }) |
| 23 | + expect(c.poolOptions?.threads?.isolate).toBe(false) |
| 24 | + expect(c.poolOptions?.forks?.isolate).toBe(false) |
| 25 | + expect(c.isolate).toBe(true) |
| 26 | + }) |
| 27 | + |
| 28 | + it('override CLI poolOptions flags over isolate', async () => { |
| 29 | + const c = await config({ |
| 30 | + isolate: false, |
| 31 | + poolOptions: { |
| 32 | + threads: { |
| 33 | + isolate: true, |
| 34 | + }, |
| 35 | + forks: { |
| 36 | + isolate: true, |
| 37 | + }, |
| 38 | + }, |
| 39 | + }, { |
| 40 | + poolOptions: { |
| 41 | + threads: { |
| 42 | + isolate: false, |
| 43 | + }, |
| 44 | + forks: { |
| 45 | + isolate: false, |
| 46 | + }, |
| 47 | + }, |
| 48 | + }) |
| 49 | + expect(c.poolOptions?.threads?.isolate).toBe(true) |
| 50 | + expect(c.poolOptions?.forks?.isolate).toBe(true) |
| 51 | + expect(c.isolate).toBe(false) |
| 52 | + }) |
| 53 | + |
| 54 | + it('override CLI isolate flag if poolOptions is not set via CLI', async () => { |
| 55 | + const c = await config({ |
| 56 | + isolate: true, |
| 57 | + }, { |
| 58 | + poolOptions: { |
| 59 | + threads: { |
| 60 | + isolate: false, |
| 61 | + }, |
| 62 | + forks: { |
| 63 | + isolate: false, |
| 64 | + }, |
| 65 | + }, |
| 66 | + }) |
| 67 | + expect(c.poolOptions?.threads?.isolate).toBe(true) |
| 68 | + expect(c.poolOptions?.forks?.isolate).toBe(true) |
| 69 | + expect(c.isolate).toBe(true) |
| 70 | + }) |
| 71 | + |
| 72 | + it('keeps user configured poolOptions if no CLI flag is provided', async () => { |
| 73 | + const c = await config({}, { |
| 74 | + poolOptions: { |
| 75 | + threads: { |
| 76 | + isolate: false, |
| 77 | + }, |
| 78 | + forks: { |
| 79 | + isolate: false, |
| 80 | + }, |
| 81 | + }, |
| 82 | + }) |
| 83 | + expect(c.poolOptions?.threads?.isolate).toBe(false) |
| 84 | + expect(c.poolOptions?.forks?.isolate).toBe(false) |
| 85 | + expect(c.isolate).toBe(true) |
| 86 | + }) |
| 87 | + |
| 88 | + it('isolate config value overrides poolOptions defaults', async () => { |
| 89 | + const c = await config({}, { |
| 90 | + isolate: false, |
| 91 | + }) |
| 92 | + expect(c.poolOptions?.threads?.isolate).toBe(false) |
| 93 | + expect(c.poolOptions?.forks?.isolate).toBe(false) |
| 94 | + expect(c.isolate).toBe(false) |
| 95 | + }) |
| 96 | + |
| 97 | + it('if no isolation is defined in the config, fallback ot undefined', async () => { |
| 98 | + const c = await config({}, {}) |
| 99 | + expect(c.poolOptions?.threads?.isolate).toBe(undefined) |
| 100 | + expect(c.poolOptions?.forks?.isolate).toBe(undefined) |
| 101 | + // set in configDefaults, so it's always defined |
| 102 | + expect(c.isolate).toBe(true) |
| 103 | + }) |
| 104 | +}) |
0 commit comments