-
Notifications
You must be signed in to change notification settings - Fork 923
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
15 changed files
with
1,831 additions
and
1,870 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | ||
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) | ||
}) | ||
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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: [], | ||
}) | ||
}) |
Oops, something went wrong.