Skip to content

Commit

Permalink
test: remove redundant describe
Browse files Browse the repository at this point in the history
  • Loading branch information
meteorlxy committed Sep 12, 2024
1 parent be249ec commit 017abb3
Show file tree
Hide file tree
Showing 15 changed files with 1,831 additions and 1,870 deletions.
36 changes: 17 additions & 19 deletions packages/cli/tests/config/loadUserConfig.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -47,31 +47,29 @@ const MJS_CASES: [string, unknown][] = [
],
]

describe('cli > config > loadUserConfig', () => {
describe('should load ts config file correctly', () => {
TS_CASES.forEach(([source, expected]) => {
it(JSON.stringify(source), async () => {
const { userConfig } = await loadUserConfig(source)
expect(userConfig).toEqual(expected)
})
describe('should load ts config file correctly', () => {
TS_CASES.forEach(([source, expected]) => {
it(JSON.stringify(source), async () => {
const { userConfig } = await loadUserConfig(source)
expect(userConfig).toEqual(expected)
})
})
})

describe('should load js config file correctly', () => {
JS_CASES.forEach(([source, expected]) => {
it(JSON.stringify(source), async () => {
const { userConfig } = await loadUserConfig(source)
expect(userConfig).toEqual(expected)
})
describe('should load js config file correctly', () => {
JS_CASES.forEach(([source, expected]) => {
it(JSON.stringify(source), async () => {
const { userConfig } = await loadUserConfig(source)
expect(userConfig).toEqual(expected)
})
})
})

describe('should load mjs config file correctly', () => {
MJS_CASES.forEach(([source, expected]) => {
it(JSON.stringify(source), async () => {
const { userConfig } = await loadUserConfig(source)
expect(userConfig).toEqual(expected)
})
describe('should load mjs config file correctly', () => {
MJS_CASES.forEach(([source, expected]) => {
it(JSON.stringify(source), async () => {
const { userConfig } = await loadUserConfig(source)
expect(userConfig).toEqual(expected)
})
})
})
Original file line number Diff line number Diff line change
Expand Up @@ -14,13 +14,11 @@ const TEST_CASES: [string, string][] = [
[resolveFixtures('case6'), '.vuepress/config.mjs'],
]

describe('cli > config > resolveUserConfigConventionalPath', () => {
describe('should resolve conventional config file correctly', () => {
TEST_CASES.forEach(([source, expected]) => {
it(expected, () => {
const configFile = resolveUserConfigConventionalPath(source, source)
expect(configFile).toEqual(path.resolve(source, expected))
})
describe('should resolve conventional config file correctly', () => {
TEST_CASES.forEach(([source, expected]) => {
it(expected, () => {
const configFile = resolveUserConfigConventionalPath(source, source)
expect(configFile).toEqual(path.resolve(source, expected))
})
})
})
40 changes: 19 additions & 21 deletions packages/cli/tests/config/resolveUserConfigPath.spec.ts
Original file line number Diff line number Diff line change
@@ -1,32 +1,30 @@
import { path } from '@vuepress/utils'
import { describe, expect, it, vi } from 'vitest'
import { expect, it, vi } from 'vitest'
import { resolveUserConfigPath } from '../../src/index.js'

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

describe('cli > config > resolveUserConfigPath', () => {
it('should resolve absolute file path correctly', () => {
const absolutePath = resolveFixtures('custom-config.ts')
const configFile = resolveUserConfigPath(absolutePath)
expect(configFile).toEqual(absolutePath)
})
it('should resolve absolute file path correctly', () => {
const absolutePath = resolveFixtures('custom-config.ts')
const configFile = resolveUserConfigPath(absolutePath)
expect(configFile).toEqual(absolutePath)
})

it('should resolve relative file path correctly', () => {
const relativePath = 'custom-config.ts'
const configFile = resolveUserConfigPath(relativePath, resolveFixtures(''))
expect(configFile).toEqual(resolveFixtures(relativePath))
})
it('should resolve relative file path correctly', () => {
const relativePath = 'custom-config.ts'
const configFile = resolveUserConfigPath(relativePath, resolveFixtures(''))
expect(configFile).toEqual(resolveFixtures(relativePath))
})

it('should throw an error if file does not exist', () => {
const consoleError = console.error
console.error = vi.fn()
it('should throw an error if file does not exist', () => {
const consoleError = console.error
console.error = vi.fn()

expect(() => {
resolveUserConfigPath('4-0-4')
}).toThrow()
expect(console.error).toHaveBeenCalled()
expect(() => {
resolveUserConfigPath('4-0-4')
}).toThrow()
expect(console.error).toHaveBeenCalled()

console.error = consoleError
})
console.error = consoleError
})
57 changes: 24 additions & 33 deletions packages/core/tests/app/resolveAppEnv.spec.ts
Original file line number Diff line number Diff line change
@@ -1,48 +1,39 @@
import { describe, expect, it } from 'vitest'
import { expect, it } from 'vitest'
import type { Bundler } from '../../src/index.js'
import { resolveAppEnv, resolveAppOptions } from '../../src/index.js'

const TEST_CASES: [
Parameters<typeof resolveAppEnv>,
ReturnType<typeof resolveAppEnv>,
][] = [
[
[
resolveAppOptions({
source: '/foo',
theme: { name: 'test' },
bundler: {} as Bundler,
}),
],
{
const TEST_CASES = [
{
name: 'should resolve app env correctly without debug flag',
options: resolveAppOptions({
source: '/foo',
theme: { name: 'test' },
bundler: {} as Bundler,
}),
expected: {
isBuild: false,
isDev: false,
isDebug: false,
},
],
[
[
resolveAppOptions({
source: '/foo',
theme: { name: 'test' },
bundler: {} as Bundler,
debug: true,
}),
],
{
},
{
name: 'should resolve app env correctly with debug flag',
options: resolveAppOptions({
source: '/foo',
theme: { name: 'test' },
bundler: {} as Bundler,
debug: true,
}),
expected: {
isBuild: false,
isDev: false,
isDebug: true,
},
],
},
]

describe('core > app > resolveAppEnv', () => {
describe('should create app env correctly', () => {
TEST_CASES.forEach(([params, expected], i) => {
it(`case ${i}`, () => {
expect(resolveAppEnv(...params)).toEqual(expected)
})
})
TEST_CASES.forEach(({ name, options, expected }) => {
it(name, () => {
expect(resolveAppEnv(options)).toEqual(expected)
})
})
80 changes: 39 additions & 41 deletions packages/core/tests/app/resolveAppOptions.spec.ts
Original file line number Diff line number Diff line change
@@ -1,49 +1,47 @@
import { path, templateRenderer } from '@vuepress/utils'
import { describe, expect, it } from 'vitest'
import { expect, it } from 'vitest'
import type { Bundler } from '../../src/index.js'
import { resolveAppOptions } from '../../src/index.js'

describe('core > app > resolveAppOptions', () => {
it('should create app options with default values', () => {
const source = '/foo'
it('should create app options with default values', () => {
const source = '/foo'

expect(
resolveAppOptions({
source,
theme: { name: 'theme' },
bundler: { name: 'bundler' } as Bundler,
}),
).toEqual({
base: '/',
lang: 'en-US',
title: '',
description: '',
head: [],
locales: {},
theme: { name: 'theme' },
bundler: { name: 'bundler' },
expect(
resolveAppOptions({
source,
dest: path.resolve(source, '.vuepress/dist'),
temp: path.resolve(source, '.vuepress/.temp'),
cache: path.resolve(source, '.vuepress/.cache'),
public: path.resolve(source, '.vuepress/public'),
debug: false,
host: '0.0.0.0',
port: 8080,
open: false,
pagePatterns: ['**/*.md', '!.vuepress', '!node_modules'],
permalinkPattern: null,
templateDev: path.normalize(
require.resolve('@vuepress/client/templates/dev.html'),
),
templateBuild: path.normalize(
require.resolve('@vuepress/client/templates/build.html'),
),
templateBuildRenderer: templateRenderer,
shouldPreload: true,
shouldPrefetch: true,
markdown: {},
plugins: [],
})
theme: { name: 'theme' },
bundler: { name: 'bundler' } as Bundler,
}),
).toEqual({
base: '/',
lang: 'en-US',
title: '',
description: '',
head: [],
locales: {},
theme: { name: 'theme' },
bundler: { name: 'bundler' },
source,
dest: path.resolve(source, '.vuepress/dist'),
temp: path.resolve(source, '.vuepress/.temp'),
cache: path.resolve(source, '.vuepress/.cache'),
public: path.resolve(source, '.vuepress/public'),
debug: false,
host: '0.0.0.0',
port: 8080,
open: false,
pagePatterns: ['**/*.md', '!.vuepress', '!node_modules'],
permalinkPattern: null,
templateDev: path.normalize(
require.resolve('@vuepress/client/templates/dev.html'),
),
templateBuild: path.normalize(
require.resolve('@vuepress/client/templates/build.html'),
),
templateBuildRenderer: templateRenderer,
shouldPreload: true,
shouldPrefetch: true,
markdown: {},
plugins: [],
})
})
Loading

0 comments on commit 017abb3

Please sign in to comment.