Skip to content

Commit 017abb3

Browse files
committed
test: remove redundant describe
1 parent be249ec commit 017abb3

15 files changed

+1831
-1870
lines changed

packages/cli/tests/config/loadUserConfig.spec.ts

+17-19
Original file line numberDiff line numberDiff line change
@@ -47,31 +47,29 @@ const MJS_CASES: [string, unknown][] = [
4747
],
4848
]
4949

50-
describe('cli > config > loadUserConfig', () => {
51-
describe('should load ts config file correctly', () => {
52-
TS_CASES.forEach(([source, expected]) => {
53-
it(JSON.stringify(source), async () => {
54-
const { userConfig } = await loadUserConfig(source)
55-
expect(userConfig).toEqual(expected)
56-
})
50+
describe('should load ts config file correctly', () => {
51+
TS_CASES.forEach(([source, expected]) => {
52+
it(JSON.stringify(source), async () => {
53+
const { userConfig } = await loadUserConfig(source)
54+
expect(userConfig).toEqual(expected)
5755
})
5856
})
57+
})
5958

60-
describe('should load js config file correctly', () => {
61-
JS_CASES.forEach(([source, expected]) => {
62-
it(JSON.stringify(source), async () => {
63-
const { userConfig } = await loadUserConfig(source)
64-
expect(userConfig).toEqual(expected)
65-
})
59+
describe('should load js config file correctly', () => {
60+
JS_CASES.forEach(([source, expected]) => {
61+
it(JSON.stringify(source), async () => {
62+
const { userConfig } = await loadUserConfig(source)
63+
expect(userConfig).toEqual(expected)
6664
})
6765
})
66+
})
6867

69-
describe('should load mjs config file correctly', () => {
70-
MJS_CASES.forEach(([source, expected]) => {
71-
it(JSON.stringify(source), async () => {
72-
const { userConfig } = await loadUserConfig(source)
73-
expect(userConfig).toEqual(expected)
74-
})
68+
describe('should load mjs config file correctly', () => {
69+
MJS_CASES.forEach(([source, expected]) => {
70+
it(JSON.stringify(source), async () => {
71+
const { userConfig } = await loadUserConfig(source)
72+
expect(userConfig).toEqual(expected)
7573
})
7674
})
7775
})

packages/cli/tests/config/resolveUserConfigConventionalPath.spec.ts

+5-7
Original file line numberDiff line numberDiff line change
@@ -14,13 +14,11 @@ const TEST_CASES: [string, string][] = [
1414
[resolveFixtures('case6'), '.vuepress/config.mjs'],
1515
]
1616

17-
describe('cli > config > resolveUserConfigConventionalPath', () => {
18-
describe('should resolve conventional config file correctly', () => {
19-
TEST_CASES.forEach(([source, expected]) => {
20-
it(expected, () => {
21-
const configFile = resolveUserConfigConventionalPath(source, source)
22-
expect(configFile).toEqual(path.resolve(source, expected))
23-
})
17+
describe('should resolve conventional config file correctly', () => {
18+
TEST_CASES.forEach(([source, expected]) => {
19+
it(expected, () => {
20+
const configFile = resolveUserConfigConventionalPath(source, source)
21+
expect(configFile).toEqual(path.resolve(source, expected))
2422
})
2523
})
2624
})
Original file line numberDiff line numberDiff line change
@@ -1,32 +1,30 @@
11
import { path } from '@vuepress/utils'
2-
import { describe, expect, it, vi } from 'vitest'
2+
import { expect, it, vi } from 'vitest'
33
import { resolveUserConfigPath } from '../../src/index.js'
44

55
const resolveFixtures = (str: string): string =>
66
path.resolve(__dirname, '../__fixtures__/config', str)
77

8-
describe('cli > config > resolveUserConfigPath', () => {
9-
it('should resolve absolute file path correctly', () => {
10-
const absolutePath = resolveFixtures('custom-config.ts')
11-
const configFile = resolveUserConfigPath(absolutePath)
12-
expect(configFile).toEqual(absolutePath)
13-
})
8+
it('should resolve absolute file path correctly', () => {
9+
const absolutePath = resolveFixtures('custom-config.ts')
10+
const configFile = resolveUserConfigPath(absolutePath)
11+
expect(configFile).toEqual(absolutePath)
12+
})
1413

15-
it('should resolve relative file path correctly', () => {
16-
const relativePath = 'custom-config.ts'
17-
const configFile = resolveUserConfigPath(relativePath, resolveFixtures(''))
18-
expect(configFile).toEqual(resolveFixtures(relativePath))
19-
})
14+
it('should resolve relative file path correctly', () => {
15+
const relativePath = 'custom-config.ts'
16+
const configFile = resolveUserConfigPath(relativePath, resolveFixtures(''))
17+
expect(configFile).toEqual(resolveFixtures(relativePath))
18+
})
2019

21-
it('should throw an error if file does not exist', () => {
22-
const consoleError = console.error
23-
console.error = vi.fn()
20+
it('should throw an error if file does not exist', () => {
21+
const consoleError = console.error
22+
console.error = vi.fn()
2423

25-
expect(() => {
26-
resolveUserConfigPath('4-0-4')
27-
}).toThrow()
28-
expect(console.error).toHaveBeenCalled()
24+
expect(() => {
25+
resolveUserConfigPath('4-0-4')
26+
}).toThrow()
27+
expect(console.error).toHaveBeenCalled()
2928

30-
console.error = consoleError
31-
})
29+
console.error = consoleError
3230
})
+24-33
Original file line numberDiff line numberDiff line change
@@ -1,48 +1,39 @@
1-
import { describe, expect, it } from 'vitest'
1+
import { expect, it } from 'vitest'
22
import type { Bundler } from '../../src/index.js'
33
import { resolveAppEnv, resolveAppOptions } from '../../src/index.js'
44

5-
const TEST_CASES: [
6-
Parameters<typeof resolveAppEnv>,
7-
ReturnType<typeof resolveAppEnv>,
8-
][] = [
9-
[
10-
[
11-
resolveAppOptions({
12-
source: '/foo',
13-
theme: { name: 'test' },
14-
bundler: {} as Bundler,
15-
}),
16-
],
17-
{
5+
const TEST_CASES = [
6+
{
7+
name: 'should resolve app env correctly without debug flag',
8+
options: resolveAppOptions({
9+
source: '/foo',
10+
theme: { name: 'test' },
11+
bundler: {} as Bundler,
12+
}),
13+
expected: {
1814
isBuild: false,
1915
isDev: false,
2016
isDebug: false,
2117
},
22-
],
23-
[
24-
[
25-
resolveAppOptions({
26-
source: '/foo',
27-
theme: { name: 'test' },
28-
bundler: {} as Bundler,
29-
debug: true,
30-
}),
31-
],
32-
{
18+
},
19+
{
20+
name: 'should resolve app env correctly with debug flag',
21+
options: resolveAppOptions({
22+
source: '/foo',
23+
theme: { name: 'test' },
24+
bundler: {} as Bundler,
25+
debug: true,
26+
}),
27+
expected: {
3328
isBuild: false,
3429
isDev: false,
3530
isDebug: true,
3631
},
37-
],
32+
},
3833
]
3934

40-
describe('core > app > resolveAppEnv', () => {
41-
describe('should create app env correctly', () => {
42-
TEST_CASES.forEach(([params, expected], i) => {
43-
it(`case ${i}`, () => {
44-
expect(resolveAppEnv(...params)).toEqual(expected)
45-
})
46-
})
35+
TEST_CASES.forEach(({ name, options, expected }) => {
36+
it(name, () => {
37+
expect(resolveAppEnv(options)).toEqual(expected)
4738
})
4839
})
Original file line numberDiff line numberDiff line change
@@ -1,49 +1,47 @@
11
import { path, templateRenderer } from '@vuepress/utils'
2-
import { describe, expect, it } from 'vitest'
2+
import { expect, it } from 'vitest'
33
import type { Bundler } from '../../src/index.js'
44
import { resolveAppOptions } from '../../src/index.js'
55

6-
describe('core > app > resolveAppOptions', () => {
7-
it('should create app options with default values', () => {
8-
const source = '/foo'
6+
it('should create app options with default values', () => {
7+
const source = '/foo'
98

10-
expect(
11-
resolveAppOptions({
12-
source,
13-
theme: { name: 'theme' },
14-
bundler: { name: 'bundler' } as Bundler,
15-
}),
16-
).toEqual({
17-
base: '/',
18-
lang: 'en-US',
19-
title: '',
20-
description: '',
21-
head: [],
22-
locales: {},
23-
theme: { name: 'theme' },
24-
bundler: { name: 'bundler' },
9+
expect(
10+
resolveAppOptions({
2511
source,
26-
dest: path.resolve(source, '.vuepress/dist'),
27-
temp: path.resolve(source, '.vuepress/.temp'),
28-
cache: path.resolve(source, '.vuepress/.cache'),
29-
public: path.resolve(source, '.vuepress/public'),
30-
debug: false,
31-
host: '0.0.0.0',
32-
port: 8080,
33-
open: false,
34-
pagePatterns: ['**/*.md', '!.vuepress', '!node_modules'],
35-
permalinkPattern: null,
36-
templateDev: path.normalize(
37-
require.resolve('@vuepress/client/templates/dev.html'),
38-
),
39-
templateBuild: path.normalize(
40-
require.resolve('@vuepress/client/templates/build.html'),
41-
),
42-
templateBuildRenderer: templateRenderer,
43-
shouldPreload: true,
44-
shouldPrefetch: true,
45-
markdown: {},
46-
plugins: [],
47-
})
12+
theme: { name: 'theme' },
13+
bundler: { name: 'bundler' } as Bundler,
14+
}),
15+
).toEqual({
16+
base: '/',
17+
lang: 'en-US',
18+
title: '',
19+
description: '',
20+
head: [],
21+
locales: {},
22+
theme: { name: 'theme' },
23+
bundler: { name: 'bundler' },
24+
source,
25+
dest: path.resolve(source, '.vuepress/dist'),
26+
temp: path.resolve(source, '.vuepress/.temp'),
27+
cache: path.resolve(source, '.vuepress/.cache'),
28+
public: path.resolve(source, '.vuepress/public'),
29+
debug: false,
30+
host: '0.0.0.0',
31+
port: 8080,
32+
open: false,
33+
pagePatterns: ['**/*.md', '!.vuepress', '!node_modules'],
34+
permalinkPattern: null,
35+
templateDev: path.normalize(
36+
require.resolve('@vuepress/client/templates/dev.html'),
37+
),
38+
templateBuild: path.normalize(
39+
require.resolve('@vuepress/client/templates/build.html'),
40+
),
41+
templateBuildRenderer: templateRenderer,
42+
shouldPreload: true,
43+
shouldPrefetch: true,
44+
markdown: {},
45+
plugins: [],
4846
})
4947
})

0 commit comments

Comments
 (0)