|
1 | 1 | import { describe, expect, test } from 'vitest'
|
2 | 2 | import type { InlineConfig } from '..'
|
3 |
| -import type { UserConfig, UserConfigExport } from '../config' |
| 3 | +import type { PluginOption, UserConfig, UserConfigExport } from '../config' |
4 | 4 | import { resolveConfig } from '../config'
|
5 | 5 | import { resolveEnvPrefix } from '../env'
|
6 | 6 | import { mergeConfig } from '../publicUtils'
|
@@ -266,3 +266,51 @@ describe('preview config', () => {
|
266 | 266 | })
|
267 | 267 | })
|
268 | 268 | })
|
| 269 | + |
| 270 | +describe('resolveConfig', () => { |
| 271 | + const keepScreenMergePlugin = (): PluginOption => { |
| 272 | + return { |
| 273 | + name: 'vite-plugin-keep-screen-merge', |
| 274 | + config() { |
| 275 | + return { clearScreen: false } |
| 276 | + } |
| 277 | + } |
| 278 | + } |
| 279 | + |
| 280 | + const keepScreenOverridePlugin = (): PluginOption => { |
| 281 | + return { |
| 282 | + name: 'vite-plugin-keep-screen-override', |
| 283 | + config(config) { |
| 284 | + config.clearScreen = false |
| 285 | + } |
| 286 | + } |
| 287 | + } |
| 288 | + |
| 289 | + test('plugin merges `clearScreen` option', async () => { |
| 290 | + const config1: InlineConfig = { plugins: [keepScreenMergePlugin()] } |
| 291 | + const config2: InlineConfig = { |
| 292 | + plugins: [keepScreenMergePlugin()], |
| 293 | + clearScreen: true |
| 294 | + } |
| 295 | + |
| 296 | + const results1 = await resolveConfig(config1, 'build') |
| 297 | + const results2 = await resolveConfig(config2, 'build') |
| 298 | + |
| 299 | + expect(results1.clearScreen).toBe(false) |
| 300 | + expect(results2.clearScreen).toBe(false) |
| 301 | + }) |
| 302 | + |
| 303 | + test('plugin overrides `clearScreen` option', async () => { |
| 304 | + const config1: InlineConfig = { plugins: [keepScreenOverridePlugin()] } |
| 305 | + const config2: InlineConfig = { |
| 306 | + plugins: [keepScreenOverridePlugin()], |
| 307 | + clearScreen: true |
| 308 | + } |
| 309 | + |
| 310 | + const results1 = await resolveConfig(config1, 'build') |
| 311 | + const results2 = await resolveConfig(config2, 'build') |
| 312 | + |
| 313 | + expect(results1.clearScreen).toBe(false) |
| 314 | + expect(results2.clearScreen).toBe(false) |
| 315 | + }) |
| 316 | +}) |
0 commit comments