mirror of
https://github.com/facebook/docusaurus.git
synced 2025-06-02 10:52:35 +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
|
@ -27,8 +27,8 @@ function heading(label, id) {
|
|||
);
|
||||
}
|
||||
|
||||
describe('headings plugin', () => {
|
||||
test('should patch `id`s and `data.hProperties.id', () => {
|
||||
describe('headings remark plugin', () => {
|
||||
it('patches `id`s and `data.hProperties.id', () => {
|
||||
const result = process('# Normal\n\n## Table of Contents\n\n# Baz\n');
|
||||
const expected = u('root', [
|
||||
u(
|
||||
|
@ -55,7 +55,7 @@ describe('headings plugin', () => {
|
|||
expect(result).toEqual(expected);
|
||||
});
|
||||
|
||||
test('should not overwrite `data` on headings', () => {
|
||||
it('does not overwrite `data` on headings', () => {
|
||||
const result = process('# Normal\n', [
|
||||
() => {
|
||||
function transform(tree) {
|
||||
|
@ -78,7 +78,7 @@ describe('headings plugin', () => {
|
|||
expect(result).toEqual(expected);
|
||||
});
|
||||
|
||||
test('should not overwrite `data.hProperties` on headings', () => {
|
||||
it('does not overwrite `data.hProperties` on headings', () => {
|
||||
const result = process('# Normal\n', [
|
||||
() => {
|
||||
function transform(tree) {
|
||||
|
@ -101,7 +101,7 @@ describe('headings plugin', () => {
|
|||
expect(result).toEqual(expected);
|
||||
});
|
||||
|
||||
test('should generate `id`s and `hProperties.id`s, based on `hProperties.id` if they exist', () => {
|
||||
it('generates `id`s and `hProperties.id`s, based on `hProperties.id` if they exist', () => {
|
||||
const result = process(
|
||||
[
|
||||
'## Something',
|
||||
|
@ -157,7 +157,7 @@ describe('headings plugin', () => {
|
|||
expect(result).toEqual(expected);
|
||||
});
|
||||
|
||||
test('should create GitHub-style headings ids', () => {
|
||||
it('creates GitHub-style headings ids', () => {
|
||||
const result = process(
|
||||
[
|
||||
'## I ♥ unicode',
|
||||
|
@ -225,7 +225,7 @@ describe('headings plugin', () => {
|
|||
expect(result).toEqual(expected);
|
||||
});
|
||||
|
||||
test('should generate id from only text contents of headings if they contains HTML tags', () => {
|
||||
it('generates id from only text contents of headings if they contains HTML tags', () => {
|
||||
const result = process('# <span class="normal-header">Normal</span>\n');
|
||||
const expected = u('root', [
|
||||
u(
|
||||
|
@ -245,7 +245,7 @@ describe('headings plugin', () => {
|
|||
expect(result).toEqual(expected);
|
||||
});
|
||||
|
||||
test('should create custom headings ids', () => {
|
||||
it('creates custom headings ids', () => {
|
||||
const result = process(`
|
||||
# Heading One {#custom_h1}
|
||||
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
// Jest Snapshot v1, https://goo.gl/fbAQLP
|
||||
|
||||
exports[`inline code should be escaped 1`] = `
|
||||
exports[`toc remark plugin escapes inline code 1`] = `
|
||||
"export const toc = [
|
||||
{
|
||||
value: '<code><Head /></code>',
|
||||
|
@ -48,7 +48,120 @@ exports[`inline code should be escaped 1`] = `
|
|||
"
|
||||
`;
|
||||
|
||||
exports[`non text phrasing content 1`] = `
|
||||
exports[`toc remark plugin exports even with existing name 1`] = `
|
||||
"export const toc = [
|
||||
{
|
||||
value: 'Thanos',
|
||||
id: 'thanos',
|
||||
level: 2
|
||||
},
|
||||
{
|
||||
value: 'Tony Stark',
|
||||
id: 'tony-stark',
|
||||
level: 2
|
||||
},
|
||||
{
|
||||
value: 'Avengers',
|
||||
id: 'avengers',
|
||||
level: 3
|
||||
}
|
||||
];
|
||||
|
||||
## Thanos
|
||||
|
||||
## Tony Stark
|
||||
|
||||
### Avengers
|
||||
"
|
||||
`;
|
||||
|
||||
exports[`toc remark plugin exports with custom name 1`] = `
|
||||
"export const customName = [
|
||||
{
|
||||
value: 'Endi',
|
||||
id: 'endi',
|
||||
level: 3
|
||||
},
|
||||
{
|
||||
value: 'Endi',
|
||||
id: 'endi-1',
|
||||
level: 2
|
||||
},
|
||||
{
|
||||
value: 'Yangshun',
|
||||
id: 'yangshun',
|
||||
level: 3
|
||||
},
|
||||
{
|
||||
value: 'I ♥ unicode.',
|
||||
id: 'i--unicode',
|
||||
level: 2
|
||||
}
|
||||
];
|
||||
|
||||
### Endi
|
||||
|
||||
\`\`\`md
|
||||
## This is ignored
|
||||
\`\`\`
|
||||
|
||||
## Endi
|
||||
|
||||
Lorem ipsum
|
||||
|
||||
### Yangshun
|
||||
|
||||
Some content here
|
||||
|
||||
## I ♥ unicode.
|
||||
"
|
||||
`;
|
||||
|
||||
exports[`toc remark plugin handles empty headings 1`] = `
|
||||
"export const toc = [];
|
||||
|
||||
# Ignore this
|
||||
|
||||
##
|
||||
|
||||
## 
|
||||
"
|
||||
`;
|
||||
|
||||
exports[`toc remark plugin inserts below imports 1`] = `
|
||||
"import something from 'something';
|
||||
|
||||
import somethingElse from 'something-else';
|
||||
|
||||
export const toc = [
|
||||
{
|
||||
value: 'Title',
|
||||
id: 'title',
|
||||
level: 2
|
||||
},
|
||||
{
|
||||
value: 'Test',
|
||||
id: 'test',
|
||||
level: 2
|
||||
},
|
||||
{
|
||||
value: 'Again',
|
||||
id: 'again',
|
||||
level: 3
|
||||
}
|
||||
];
|
||||
|
||||
## Title
|
||||
|
||||
## Test
|
||||
|
||||
### Again
|
||||
|
||||
Content.
|
||||
"
|
||||
`;
|
||||
|
||||
exports[`toc remark plugin works on non text phrasing content 1`] = `
|
||||
"export const toc = [
|
||||
{
|
||||
value: '<em>Emphasis</em>',
|
||||
|
@ -88,3 +201,45 @@ exports[`non text phrasing content 1`] = `
|
|||
## \`inline.code()\`
|
||||
"
|
||||
`;
|
||||
|
||||
exports[`toc remark plugin works on text content 1`] = `
|
||||
"export const toc = [
|
||||
{
|
||||
value: 'Endi',
|
||||
id: 'endi',
|
||||
level: 3
|
||||
},
|
||||
{
|
||||
value: 'Endi',
|
||||
id: 'endi-1',
|
||||
level: 2
|
||||
},
|
||||
{
|
||||
value: 'Yangshun',
|
||||
id: 'yangshun',
|
||||
level: 3
|
||||
},
|
||||
{
|
||||
value: 'I ♥ unicode.',
|
||||
id: 'i--unicode',
|
||||
level: 2
|
||||
}
|
||||
];
|
||||
|
||||
### Endi
|
||||
|
||||
\`\`\`md
|
||||
## This is ignored
|
||||
\`\`\`
|
||||
|
||||
## Endi
|
||||
|
||||
Lorem ipsum
|
||||
|
||||
### Yangshun
|
||||
|
||||
Some content here
|
||||
|
||||
## I ♥ unicode.
|
||||
"
|
||||
`;
|
||||
|
|
|
@ -24,185 +24,42 @@ const processFixture = async (name, options?) => {
|
|||
return result.toString();
|
||||
};
|
||||
|
||||
test('non text phrasing content', async () => {
|
||||
const result = await processFixture('non-text-content');
|
||||
expect(result).toMatchSnapshot();
|
||||
});
|
||||
|
||||
test('inline code should be escaped', async () => {
|
||||
const result = await processFixture('inline-code');
|
||||
expect(result).toMatchSnapshot();
|
||||
});
|
||||
|
||||
test('text content', async () => {
|
||||
const result = await processFixture('just-content');
|
||||
expect(result).toMatchInlineSnapshot(`
|
||||
"export const toc = [
|
||||
{
|
||||
value: 'Endi',
|
||||
id: 'endi',
|
||||
level: 3
|
||||
},
|
||||
{
|
||||
value: 'Endi',
|
||||
id: 'endi-1',
|
||||
level: 2
|
||||
},
|
||||
{
|
||||
value: 'Yangshun',
|
||||
id: 'yangshun',
|
||||
level: 3
|
||||
},
|
||||
{
|
||||
value: 'I ♥ unicode.',
|
||||
id: 'i--unicode',
|
||||
level: 2
|
||||
}
|
||||
];
|
||||
|
||||
### Endi
|
||||
|
||||
\`\`\`md
|
||||
## This is ignored
|
||||
\`\`\`
|
||||
|
||||
## Endi
|
||||
|
||||
Lorem ipsum
|
||||
|
||||
### Yangshun
|
||||
|
||||
Some content here
|
||||
|
||||
## I ♥ unicode.
|
||||
"
|
||||
`);
|
||||
});
|
||||
|
||||
test('should export even with existing name', async () => {
|
||||
const result = await processFixture('name-exist');
|
||||
expect(result).toMatchInlineSnapshot(`
|
||||
"export const toc = [
|
||||
{
|
||||
value: 'Thanos',
|
||||
id: 'thanos',
|
||||
level: 2
|
||||
},
|
||||
{
|
||||
value: 'Tony Stark',
|
||||
id: 'tony-stark',
|
||||
level: 2
|
||||
},
|
||||
{
|
||||
value: 'Avengers',
|
||||
id: 'avengers',
|
||||
level: 3
|
||||
}
|
||||
];
|
||||
|
||||
## Thanos
|
||||
|
||||
## Tony Stark
|
||||
|
||||
### Avengers
|
||||
"
|
||||
`);
|
||||
});
|
||||
|
||||
test('should export with custom name', async () => {
|
||||
const options = {
|
||||
name: 'customName',
|
||||
};
|
||||
const result = await processFixture('just-content', options);
|
||||
expect(result).toMatchInlineSnapshot(`
|
||||
"export const customName = [
|
||||
{
|
||||
value: 'Endi',
|
||||
id: 'endi',
|
||||
level: 3
|
||||
},
|
||||
{
|
||||
value: 'Endi',
|
||||
id: 'endi-1',
|
||||
level: 2
|
||||
},
|
||||
{
|
||||
value: 'Yangshun',
|
||||
id: 'yangshun',
|
||||
level: 3
|
||||
},
|
||||
{
|
||||
value: 'I ♥ unicode.',
|
||||
id: 'i--unicode',
|
||||
level: 2
|
||||
}
|
||||
];
|
||||
|
||||
### Endi
|
||||
|
||||
\`\`\`md
|
||||
## This is ignored
|
||||
\`\`\`
|
||||
|
||||
## Endi
|
||||
|
||||
Lorem ipsum
|
||||
|
||||
### Yangshun
|
||||
|
||||
Some content here
|
||||
|
||||
## I ♥ unicode.
|
||||
"
|
||||
`);
|
||||
});
|
||||
|
||||
test('should insert below imports', async () => {
|
||||
const result = await processFixture('insert-below-imports');
|
||||
expect(result).toMatchInlineSnapshot(`
|
||||
"import something from 'something';
|
||||
|
||||
import somethingElse from 'something-else';
|
||||
|
||||
export const toc = [
|
||||
{
|
||||
value: 'Title',
|
||||
id: 'title',
|
||||
level: 2
|
||||
},
|
||||
{
|
||||
value: 'Test',
|
||||
id: 'test',
|
||||
level: 2
|
||||
},
|
||||
{
|
||||
value: 'Again',
|
||||
id: 'again',
|
||||
level: 3
|
||||
}
|
||||
];
|
||||
|
||||
## Title
|
||||
|
||||
## Test
|
||||
|
||||
### Again
|
||||
|
||||
Content.
|
||||
"
|
||||
`);
|
||||
});
|
||||
|
||||
test('empty headings', async () => {
|
||||
const result = await processFixture('empty-headings');
|
||||
expect(result).toMatchInlineSnapshot(`
|
||||
"export const toc = [];
|
||||
|
||||
# Ignore this
|
||||
|
||||
##
|
||||
|
||||
## 
|
||||
"
|
||||
`);
|
||||
describe('toc remark plugin', () => {
|
||||
it('works on non text phrasing content', async () => {
|
||||
const result = await processFixture('non-text-content');
|
||||
expect(result).toMatchSnapshot();
|
||||
});
|
||||
|
||||
it('escapes inline code', async () => {
|
||||
const result = await processFixture('inline-code');
|
||||
expect(result).toMatchSnapshot();
|
||||
});
|
||||
|
||||
it('works on text content', async () => {
|
||||
const result = await processFixture('just-content');
|
||||
expect(result).toMatchSnapshot();
|
||||
});
|
||||
|
||||
it('exports even with existing name', async () => {
|
||||
const result = await processFixture('name-exist');
|
||||
expect(result).toMatchSnapshot();
|
||||
});
|
||||
|
||||
it('exports with custom name', async () => {
|
||||
const options = {
|
||||
name: 'customName',
|
||||
};
|
||||
const result = await processFixture('just-content', options);
|
||||
expect(result).toMatchSnapshot();
|
||||
});
|
||||
|
||||
it('inserts below imports', async () => {
|
||||
const result = await processFixture('insert-below-imports');
|
||||
expect(result).toMatchSnapshot();
|
||||
});
|
||||
|
||||
it('handles empty headings', async () => {
|
||||
const result = await processFixture('empty-headings');
|
||||
expect(result).toMatchSnapshot();
|
||||
});
|
||||
});
|
||||
|
|
|
@ -33,34 +33,34 @@ const staticDirs = [
|
|||
const siteDir = path.join(__dirname, '__fixtures__');
|
||||
|
||||
describe('transformImage plugin', () => {
|
||||
test('fail if image does not exist', async () => {
|
||||
it('fail if image does not exist', async () => {
|
||||
await expect(
|
||||
processFixture('fail', {staticDirs}),
|
||||
).rejects.toThrowErrorMatchingSnapshot();
|
||||
});
|
||||
test('fail if image relative path does not exist', async () => {
|
||||
it('fail if image relative path does not exist', async () => {
|
||||
await expect(
|
||||
processFixture('fail2', {staticDirs}),
|
||||
).rejects.toThrowErrorMatchingSnapshot();
|
||||
});
|
||||
test('fail if image url is absent', async () => {
|
||||
it('fail if image url is absent', async () => {
|
||||
await expect(
|
||||
processFixture('noUrl', {staticDirs}),
|
||||
).rejects.toThrowErrorMatchingSnapshot();
|
||||
});
|
||||
|
||||
test('transform md images to <img />', async () => {
|
||||
it('transform md images to <img />', async () => {
|
||||
const result = await processFixture('img', {staticDirs, siteDir});
|
||||
expect(result).toMatchSnapshot();
|
||||
});
|
||||
|
||||
test('pathname protocol', async () => {
|
||||
it('pathname protocol', async () => {
|
||||
const result = await processFixture('pathname', {staticDirs});
|
||||
expect(result).toMatchSnapshot();
|
||||
});
|
||||
|
||||
test('does not choke on invalid image', async () => {
|
||||
const errorMock = jest.spyOn(console, 'warn').mockImplementation();
|
||||
it('does not choke on invalid image', async () => {
|
||||
const errorMock = jest.spyOn(console, 'warn').mockImplementation(() => {});
|
||||
const result = await processFixture('invalid-img', {staticDirs});
|
||||
expect(result).toMatchSnapshot();
|
||||
expect(errorMock).toBeCalledTimes(1);
|
||||
|
|
|
@ -34,24 +34,24 @@ const processFixture = async (name: string, options?) => {
|
|||
};
|
||||
|
||||
describe('transformAsset plugin', () => {
|
||||
test('fail if asset url is absent', async () => {
|
||||
it('fail if asset url is absent', async () => {
|
||||
await expect(
|
||||
processFixture('noUrl'),
|
||||
).rejects.toThrowErrorMatchingSnapshot();
|
||||
});
|
||||
|
||||
test('fail if asset with site alias does not exist', async () => {
|
||||
it('fail if asset with site alias does not exist', async () => {
|
||||
await expect(
|
||||
processFixture('nonexistentSiteAlias'),
|
||||
).rejects.toThrowErrorMatchingSnapshot();
|
||||
});
|
||||
|
||||
test('transform md links to <a />', async () => {
|
||||
it('transform md links to <a />', async () => {
|
||||
const result = await processFixture('asset');
|
||||
expect(result).toMatchSnapshot();
|
||||
});
|
||||
|
||||
test('pathname protocol', async () => {
|
||||
it('pathname protocol', async () => {
|
||||
const result = await processFixture('pathname');
|
||||
expect(result).toMatchSnapshot();
|
||||
});
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
// Jest Snapshot v1, https://goo.gl/fbAQLP
|
||||
|
||||
exports[`unwrapMdxCodeBlocks should unwrap the mdx code blocks 1`] = `
|
||||
exports[`unwrapMdxCodeBlocks remark plugin unwraps the mdx code blocks 1`] = `
|
||||
"# MDX code blocks test document
|
||||
|
||||
## Some basic markdown
|
||||
|
@ -95,7 +95,7 @@ cmd /C 'set \\"GIT_USER=<GITHUB_USERNAME>\\" && yarn deploy'
|
|||
"
|
||||
`;
|
||||
|
||||
exports[`unwrapMdxCodeBlocks should unwrap the mdx code blocks AST 1`] = `
|
||||
exports[`unwrapMdxCodeBlocks remark plugin unwraps the mdx code blocks AST 1`] = `
|
||||
Object {
|
||||
"children": Array [
|
||||
Object {
|
||||
|
|
|
@ -22,14 +22,14 @@ const processFixtureAST = async (name: string) => {
|
|||
return remark().use(mdx).use(plugin).parse(file);
|
||||
};
|
||||
|
||||
describe('unwrapMdxCodeBlocks', () => {
|
||||
test('should unwrap the mdx code blocks', async () => {
|
||||
describe('unwrapMdxCodeBlocks remark plugin', () => {
|
||||
it('unwraps the mdx code blocks', async () => {
|
||||
const result = await processFixture('has-mdx-code-blocks.mdx');
|
||||
expect(result).toMatchSnapshot();
|
||||
});
|
||||
|
||||
// The AST output should be parsed correctly or the MDX loader won't work!
|
||||
test('should unwrap the mdx code blocks AST', async () => {
|
||||
it('unwraps the mdx code blocks AST', async () => {
|
||||
const result = await processFixtureAST('has-mdx-code-blocks.mdx');
|
||||
expect(result).toMatchSnapshot();
|
||||
});
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue