mirror of
https://github.com/facebook/docusaurus.git
synced 2025-08-06 10:20:09 +02:00
test: enable a few jest eslint rules (#6900)
* test: enable a few jest eslint rules * more
This commit is contained in:
parent
1efc6c6091
commit
aa5a2d4c04
155 changed files with 3644 additions and 3478 deletions
|
@ -5,6 +5,7 @@
|
|||
* LICENSE file in the root directory of this source tree.
|
||||
*/
|
||||
|
||||
import {jest} from '@jest/globals';
|
||||
import {
|
||||
isNameTooLong,
|
||||
shortName,
|
||||
|
@ -17,7 +18,7 @@ import {
|
|||
import path from 'path';
|
||||
|
||||
describe('isNameTooLong', () => {
|
||||
test('behaves correctly', () => {
|
||||
it('works', () => {
|
||||
const asserts = {
|
||||
'': false,
|
||||
'foo-bar-096': false,
|
||||
|
@ -58,7 +59,7 @@ describe('isNameTooLong', () => {
|
|||
});
|
||||
|
||||
describe('shortName', () => {
|
||||
test('works', () => {
|
||||
it('works', () => {
|
||||
const asserts = {
|
||||
'': '',
|
||||
'foo-bar': 'foo-bar',
|
||||
|
@ -104,76 +105,87 @@ describe('shortName', () => {
|
|||
const VERY_LONG_PATH = `/${`x`.repeat(256)}/`;
|
||||
const VERY_LONG_PATH_NON_LATIN = `/${`あ`.repeat(255)}/`;
|
||||
|
||||
test('Truncates long paths correctly', () => {
|
||||
it('truncates long paths correctly', () => {
|
||||
const truncatedPathLatin = shortName(VERY_LONG_PATH);
|
||||
const truncatedPathNonLatin = shortName(VERY_LONG_PATH_NON_LATIN);
|
||||
expect(truncatedPathLatin.length).toBeLessThanOrEqual(255);
|
||||
expect(truncatedPathNonLatin.length).toBeLessThanOrEqual(255);
|
||||
});
|
||||
|
||||
test('Does not truncate short paths', () => {
|
||||
it('does not truncate short paths', () => {
|
||||
const truncatedPath = shortName(SHORT_PATH);
|
||||
expect(truncatedPath).toEqual(SHORT_PATH);
|
||||
});
|
||||
});
|
||||
|
||||
test('toMessageRelativeFilePath', () => {
|
||||
jest
|
||||
.spyOn(process, 'cwd')
|
||||
.mockImplementationOnce(() => path.join(__dirname, '..'));
|
||||
expect(toMessageRelativeFilePath(path.join(__dirname, 'foo/bar.js'))).toEqual(
|
||||
'__tests__/foo/bar.js',
|
||||
);
|
||||
});
|
||||
|
||||
test('escapePath', () => {
|
||||
const asserts: Record<string, string> = {
|
||||
'c:/aaaa\\bbbb': 'c:/aaaa\\\\bbbb',
|
||||
'c:\\aaaa\\bbbb\\★': 'c:\\\\aaaa\\\\bbbb\\\\★',
|
||||
'\\\\?\\c:\\aaaa\\bbbb': '\\\\\\\\?\\\\c:\\\\aaaa\\\\bbbb',
|
||||
'c:\\aaaa\\bbbb': 'c:\\\\aaaa\\\\bbbb',
|
||||
'foo\\bar': 'foo\\\\bar',
|
||||
'foo\\bar/lol': 'foo\\\\bar/lol',
|
||||
'website\\docs/**/*.{md,mdx}': 'website\\\\docs/**/*.{md,mdx}',
|
||||
};
|
||||
Object.keys(asserts).forEach((file) => {
|
||||
expect(escapePath(file)).toBe(asserts[file]);
|
||||
describe('toMessageRelativeFilePath', () => {
|
||||
it('works', () => {
|
||||
jest
|
||||
.spyOn(process, 'cwd')
|
||||
.mockImplementationOnce(() => path.join(__dirname, '..'));
|
||||
expect(
|
||||
toMessageRelativeFilePath(path.join(__dirname, 'foo/bar.js')),
|
||||
).toEqual('__tests__/foo/bar.js');
|
||||
});
|
||||
});
|
||||
|
||||
test('posixPath', () => {
|
||||
const asserts: Record<string, string> = {
|
||||
'c:/aaaa\\bbbb': 'c:/aaaa/bbbb',
|
||||
'c:\\aaaa\\bbbb\\★': 'c:\\aaaa\\bbbb\\★',
|
||||
'\\\\?\\c:\\aaaa\\bbbb': '\\\\?\\c:\\aaaa\\bbbb',
|
||||
'c:\\aaaa\\bbbb': 'c:/aaaa/bbbb',
|
||||
'foo\\bar': 'foo/bar',
|
||||
'foo\\bar/lol': 'foo/bar/lol',
|
||||
'website\\docs/**/*.{md,mdx}': 'website/docs/**/*.{md,mdx}',
|
||||
};
|
||||
Object.keys(asserts).forEach((file) => {
|
||||
expect(posixPath(file)).toBe(asserts[file]);
|
||||
describe('escapePath', () => {
|
||||
it('works', () => {
|
||||
const asserts: Record<string, string> = {
|
||||
'c:/aaaa\\bbbb': 'c:/aaaa\\\\bbbb',
|
||||
'c:\\aaaa\\bbbb\\★': 'c:\\\\aaaa\\\\bbbb\\\\★',
|
||||
'\\\\?\\c:\\aaaa\\bbbb': '\\\\\\\\?\\\\c:\\\\aaaa\\\\bbbb',
|
||||
'c:\\aaaa\\bbbb': 'c:\\\\aaaa\\\\bbbb',
|
||||
'foo\\bar': 'foo\\\\bar',
|
||||
'foo\\bar/lol': 'foo\\\\bar/lol',
|
||||
'website\\docs/**/*.{md,mdx}': 'website\\\\docs/**/*.{md,mdx}',
|
||||
};
|
||||
Object.keys(asserts).forEach((file) => {
|
||||
expect(escapePath(file)).toBe(asserts[file]);
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
test('aliasedSitePath', () => {
|
||||
const asserts: Record<string, string> = {
|
||||
'user/website/docs/asd.md': '@site/docs/asd.md',
|
||||
'user/website/versioned_docs/foo/bar.md': '@site/versioned_docs/foo/bar.md',
|
||||
'user/docs/test.md': '@site/../docs/test.md',
|
||||
};
|
||||
Object.keys(asserts).forEach((file) => {
|
||||
expect(posixPath(aliasedSitePath(file, 'user/website'))).toBe(
|
||||
asserts[file],
|
||||
describe('posixPath', () => {
|
||||
it('works', () => {
|
||||
const asserts: Record<string, string> = {
|
||||
'c:/aaaa\\bbbb': 'c:/aaaa/bbbb',
|
||||
'c:\\aaaa\\bbbb\\★': 'c:\\aaaa\\bbbb\\★',
|
||||
'\\\\?\\c:\\aaaa\\bbbb': '\\\\?\\c:\\aaaa\\bbbb',
|
||||
'c:\\aaaa\\bbbb': 'c:/aaaa/bbbb',
|
||||
'foo\\bar': 'foo/bar',
|
||||
'foo\\bar/lol': 'foo/bar/lol',
|
||||
'website\\docs/**/*.{md,mdx}': 'website/docs/**/*.{md,mdx}',
|
||||
};
|
||||
Object.keys(asserts).forEach((file) => {
|
||||
expect(posixPath(file)).toBe(asserts[file]);
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
describe('aliasedSitePath', () => {
|
||||
it('works', () => {
|
||||
const asserts: Record<string, string> = {
|
||||
'user/website/docs/asd.md': '@site/docs/asd.md',
|
||||
'user/website/versioned_docs/foo/bar.md':
|
||||
'@site/versioned_docs/foo/bar.md',
|
||||
'user/docs/test.md': '@site/../docs/test.md',
|
||||
};
|
||||
Object.keys(asserts).forEach((file) => {
|
||||
expect(posixPath(aliasedSitePath(file, 'user/website'))).toBe(
|
||||
asserts[file],
|
||||
);
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
describe('addTrailingPathSeparator', () => {
|
||||
it('works', () => {
|
||||
expect(addTrailingPathSeparator('foo')).toEqual(
|
||||
process.platform === 'win32' ? 'foo\\' : 'foo/',
|
||||
);
|
||||
expect(addTrailingPathSeparator('foo/')).toEqual(
|
||||
process.platform === 'win32' ? 'foo\\' : 'foo/',
|
||||
);
|
||||
});
|
||||
});
|
||||
|
||||
test('addTrailingPathSeparator', () => {
|
||||
expect(addTrailingPathSeparator('foo')).toEqual(
|
||||
process.platform === 'win32' ? 'foo\\' : 'foo/',
|
||||
);
|
||||
expect(addTrailingPathSeparator('foo/')).toEqual(
|
||||
process.platform === 'win32' ? 'foo\\' : 'foo/',
|
||||
);
|
||||
});
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue