返回 slidev
config.test.ts
根目录 / packages / parser / src / config.test.ts
1 import { describe, expect, it } from 'vitest'
2 import { resolveConfig, verifyConfig } from './config'
3
4 describe('resolveConfig colorSchema', () => {
5 it.each(['light dark', 'dark light'] as const)('accepts "%s"', (colorSchema) => {
6 expect(resolveConfig({ colorSchema }).colorSchema).toBe(colorSchema)
7 })
8
9 it.each(['auto', 'light', 'dark'] as const)('preserves "%s"', (colorSchema) => {
10 expect(resolveConfig({ colorSchema }).colorSchema).toBe(colorSchema)
11 })
12
13 it('defaults to auto', () => {
14 expect(resolveConfig({}).colorSchema).toBe('auto')
15 })
16
17 it('continues to use a single-scheme theme default when the configured scheme is auto', () => {
18 expect(resolveConfig({ colorSchema: 'auto' }, { colorSchema: 'dark' }).colorSchema).toBe('dark')
19 })
20 })
21
22 describe('verifyConfig colorSchema', () => {
23 it.each([
24 ['light', 'dark'],
25 ['dark', 'light'],
26 ['light dark', 'dark'],
27 ['dark light', 'light'],
28 ] as const)('warns when "%s" is used with a %s-only theme', (colorSchema, themeColorSchema) => {
29 const config = resolveConfig({ colorSchema })
30 const warnings: string[] = []
31
32 verifyConfig(config, { colorSchema: themeColorSchema }, warning => warnings.push(warning))
33
34 expect(warnings).toEqual([
35 `Color schema "${colorSchema}" is not supported by the theme`,
36 ])
37 })
38
39 it.each([
40 ['light', 'light'],
41 ['dark', 'dark'],
42 ['light dark', 'both'],
43 ['dark light', 'both'],
44 ] as const)('does not warn when "%s" is supported by a %s theme', (colorSchema, themeColorSchema) => {
45 const config = resolveConfig({ colorSchema })
46 const warnings: string[] = []
47
48 verifyConfig(config, { colorSchema: themeColorSchema }, warning => warnings.push(warning))
49
50 expect(warnings).toEqual([])
51 })
52 })
53
53 lines TYPESCRIPT