mirror of
https://github.com/facebook/docusaurus.git
synced 2025-05-16 18:46:57 +02:00
migrate useful helper functions to docusaurus-utils
This commit is contained in:
parent
c964a1e3b6
commit
6b507630e3
7 changed files with 77 additions and 95 deletions
|
@ -19,6 +19,10 @@ import {
|
|||
aliasedSitePath,
|
||||
createExcerpt,
|
||||
isValidPathname,
|
||||
addTrailingSlash,
|
||||
removeTrailingSlash,
|
||||
removeSuffix,
|
||||
getFilePathForRoutePath,
|
||||
} from '../index';
|
||||
|
||||
describe('load utils', () => {
|
||||
|
@ -381,3 +385,52 @@ describe('load utils', () => {
|
|||
expect(isValidPathname('//hey')).toBe(false);
|
||||
});
|
||||
});
|
||||
|
||||
describe('addTrailingSlash', () => {
|
||||
test('should no-op', () => {
|
||||
expect(addTrailingSlash('/abcd/')).toEqual('/abcd/');
|
||||
});
|
||||
test('should add /', () => {
|
||||
expect(addTrailingSlash('/abcd')).toEqual('/abcd/');
|
||||
});
|
||||
});
|
||||
|
||||
describe('removeTrailingSlash', () => {
|
||||
test('should no-op', () => {
|
||||
expect(removeTrailingSlash('/abcd')).toEqual('/abcd');
|
||||
});
|
||||
test('should remove /', () => {
|
||||
expect(removeTrailingSlash('/abcd/')).toEqual('/abcd');
|
||||
});
|
||||
});
|
||||
|
||||
describe('removeSuffix', () => {
|
||||
test('should no-op 1', () => {
|
||||
expect(removeSuffix('abcdef', 'ijk')).toEqual('abcdef');
|
||||
});
|
||||
test('should no-op 2', () => {
|
||||
expect(removeSuffix('abcdef', 'abc')).toEqual('abcdef');
|
||||
});
|
||||
test('should no-op 3', () => {
|
||||
expect(removeSuffix('abcdef', '')).toEqual('abcdef');
|
||||
});
|
||||
test('should remove suffix', () => {
|
||||
expect(removeSuffix('abcdef', 'ef')).toEqual('abcd');
|
||||
});
|
||||
});
|
||||
|
||||
describe('getFilePathForRoutePath', () => {
|
||||
test('works for /', () => {
|
||||
expect(getFilePathForRoutePath('/')).toEqual('/index.html');
|
||||
});
|
||||
test('works for /somePath', () => {
|
||||
expect(getFilePathForRoutePath('/somePath')).toEqual(
|
||||
'/somePath/index.html',
|
||||
);
|
||||
});
|
||||
test('works for /somePath/', () => {
|
||||
expect(getFilePathForRoutePath('/somePath/')).toEqual(
|
||||
'/somePath/index.html',
|
||||
);
|
||||
});
|
||||
});
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue