mirror of
https://github.com/facebook/docusaurus.git
synced 2025-06-05 12:22:45 +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
|
@ -8,7 +8,7 @@
|
|||
import flat from '../flat';
|
||||
|
||||
describe('flat', () => {
|
||||
test('nested', () => {
|
||||
it('nested', () => {
|
||||
expect(
|
||||
flat({
|
||||
foo: {
|
||||
|
@ -32,7 +32,7 @@ describe('flat', () => {
|
|||
});
|
||||
});
|
||||
|
||||
test('primitives', () => {
|
||||
it('primitives', () => {
|
||||
const primitives = {
|
||||
String: 'good morning',
|
||||
Number: 1234.99,
|
||||
|
@ -55,7 +55,7 @@ describe('flat', () => {
|
|||
});
|
||||
});
|
||||
|
||||
test('multiple keys', () => {
|
||||
it('multiple keys', () => {
|
||||
expect(
|
||||
flat({
|
||||
foo: {
|
||||
|
@ -69,7 +69,7 @@ describe('flat', () => {
|
|||
});
|
||||
});
|
||||
|
||||
test('empty object', () => {
|
||||
it('empty object', () => {
|
||||
expect(
|
||||
flat({
|
||||
foo: {
|
||||
|
@ -81,7 +81,7 @@ describe('flat', () => {
|
|||
});
|
||||
});
|
||||
|
||||
test('array', () => {
|
||||
it('array', () => {
|
||||
expect(
|
||||
flat({
|
||||
hello: [{world: {again: 'foo'}}, {lorem: 'ipsum'}],
|
||||
|
|
|
@ -9,7 +9,7 @@ import {jest} from '@jest/globals';
|
|||
import normalizeLocation from '../normalizeLocation';
|
||||
|
||||
describe('normalizeLocation', () => {
|
||||
test('rewrite locations with index.html', () => {
|
||||
it('rewrite locations with index.html', () => {
|
||||
expect(
|
||||
normalizeLocation({
|
||||
pathname: '/docs/introduction/index.html',
|
||||
|
@ -35,7 +35,7 @@ describe('normalizeLocation', () => {
|
|||
});
|
||||
});
|
||||
|
||||
test('untouched pathnames', () => {
|
||||
it('untouched pathnames', () => {
|
||||
const replaceMock = jest.spyOn(String.prototype, 'replace');
|
||||
|
||||
expect(
|
||||
|
|
|
@ -13,7 +13,7 @@ import BrowserOnly from '../BrowserOnly';
|
|||
jest.mock('@docusaurus/useIsBrowser', () => () => true);
|
||||
|
||||
describe('BrowserOnly', () => {
|
||||
test('Should reject react element children', () => {
|
||||
it('rejects react element children', () => {
|
||||
process.env.NODE_ENV = 'development';
|
||||
expect(() => {
|
||||
renderer.create(
|
||||
|
@ -27,7 +27,7 @@ describe('BrowserOnly', () => {
|
|||
Current type: React element"
|
||||
`);
|
||||
});
|
||||
test('Should reject string children', () => {
|
||||
it('rejects string children', () => {
|
||||
expect(() => {
|
||||
renderer.create(
|
||||
// @ts-expect-error test
|
||||
|
@ -38,7 +38,7 @@ describe('BrowserOnly', () => {
|
|||
Current type: string"
|
||||
`);
|
||||
});
|
||||
test('Should accept valid children', () => {
|
||||
it('accepts valid children', () => {
|
||||
expect(
|
||||
renderer
|
||||
.create(
|
||||
|
|
|
@ -9,12 +9,12 @@ import React from 'react';
|
|||
import {interpolate} from '../Interpolate';
|
||||
|
||||
describe('Interpolate', () => {
|
||||
test('without placeholders', () => {
|
||||
it('without placeholders', () => {
|
||||
const text = 'Hello how are you?';
|
||||
expect(interpolate(text)).toEqual(text);
|
||||
});
|
||||
|
||||
test('placeholders with string values', () => {
|
||||
it('placeholders with string values', () => {
|
||||
const text = 'Hello {name} how are you {day}?';
|
||||
const values = {name: 'Sébastien', day: 'today'};
|
||||
expect(interpolate(text, values)).toMatchInlineSnapshot(
|
||||
|
@ -22,7 +22,7 @@ describe('Interpolate', () => {
|
|||
);
|
||||
});
|
||||
|
||||
test('placeholders with string values 2', () => {
|
||||
it('placeholders with string values 2', () => {
|
||||
const text = '{number} {string} {object} {array}';
|
||||
const values = {
|
||||
number: 42,
|
||||
|
@ -36,7 +36,7 @@ describe('Interpolate', () => {
|
|||
);
|
||||
});
|
||||
|
||||
test('placeholders with falsy values', () => {
|
||||
it('placeholders with falsy values', () => {
|
||||
const text = '{number} {string} {boolean}';
|
||||
const values = {
|
||||
number: 0,
|
||||
|
@ -47,7 +47,7 @@ describe('Interpolate', () => {
|
|||
expect(interpolate(text, values)).toMatchInlineSnapshot(`"0 false"`);
|
||||
});
|
||||
|
||||
test('placeholders with string values mismatch', () => {
|
||||
it('placeholders with string values mismatch', () => {
|
||||
// Should we emit warnings in such case?
|
||||
const text = 'Hello {name} how are you {unprovidedValue}?';
|
||||
const values = {name: 'Sébastien', extraValue: 'today'};
|
||||
|
@ -56,26 +56,26 @@ describe('Interpolate', () => {
|
|||
);
|
||||
});
|
||||
|
||||
test('placeholders with values not provided', () => {
|
||||
it('placeholders with values not provided', () => {
|
||||
// Should we emit warnings in such case?
|
||||
const text = 'Hello {name} how are you {day}?';
|
||||
expect(interpolate(text)).toEqual(text);
|
||||
expect(interpolate(text, {})).toEqual(text);
|
||||
});
|
||||
|
||||
test('placeholders with JSX values', () => {
|
||||
it('placeholders with JSX values', () => {
|
||||
const text = 'Hello {name} how are you {day}?';
|
||||
const values = {name: <b>Sébastien</b>, day: <span>today</span>};
|
||||
expect(interpolate(text, values)).toMatchSnapshot();
|
||||
});
|
||||
|
||||
test('placeholders with mixed vales', () => {
|
||||
it('placeholders with mixed vales', () => {
|
||||
const text = 'Hello {name} how are you {day}?';
|
||||
const values = {name: 'Sébastien', day: <span>today</span>};
|
||||
expect(interpolate(text, values)).toMatchSnapshot();
|
||||
});
|
||||
|
||||
test('acceptance test', () => {
|
||||
it('acceptance test', () => {
|
||||
const text = 'Hello {name} how are you {day}? Another {unprovidedValue}!';
|
||||
const values = {
|
||||
name: 'Sébastien',
|
||||
|
|
|
@ -8,21 +8,21 @@
|
|||
import {translate} from '../Translate';
|
||||
|
||||
describe('translate', () => {
|
||||
test('accept id and use it as fallback', () => {
|
||||
it('accept id and use it as fallback', () => {
|
||||
expect(translate({id: 'some-id'})).toEqual('some-id');
|
||||
});
|
||||
|
||||
test('accept message and use it as fallback', () => {
|
||||
it('accept message and use it as fallback', () => {
|
||||
expect(translate({message: 'some-message'})).toEqual('some-message');
|
||||
});
|
||||
|
||||
test('accept id+message and use message as fallback', () => {
|
||||
it('accept id+message and use message as fallback', () => {
|
||||
expect(translate({id: 'some-id', message: 'some-message'})).toEqual(
|
||||
'some-message',
|
||||
);
|
||||
});
|
||||
|
||||
test('reject when no id or message', () => {
|
||||
it('reject when no id or message', () => {
|
||||
// TODO tests are not resolving type defs correctly
|
||||
// @ts-expect-error: TS should protect when both id/message are missing
|
||||
expect(() => translate({})).toThrowErrorMatchingInlineSnapshot(
|
||||
|
|
|
@ -8,39 +8,39 @@
|
|||
import isInternalUrl from '../isInternalUrl';
|
||||
|
||||
describe('isInternalUrl', () => {
|
||||
test('should be true for empty links', () => {
|
||||
it('returns true for empty links', () => {
|
||||
expect(isInternalUrl('')).toBeTruthy();
|
||||
});
|
||||
|
||||
test('should be true for root relative links', () => {
|
||||
it('returns true for root relative links', () => {
|
||||
expect(isInternalUrl('/foo/bar')).toBeTruthy();
|
||||
});
|
||||
|
||||
test('should be true for relative links', () => {
|
||||
it('returns true for relative links', () => {
|
||||
expect(isInternalUrl('foo/bar')).toBeTruthy();
|
||||
});
|
||||
|
||||
test('should be false for HTTP links', () => {
|
||||
it('returns false for HTTP links', () => {
|
||||
expect(isInternalUrl('http://foo.com')).toBeFalsy();
|
||||
});
|
||||
|
||||
test('should be false for HTTPS links', () => {
|
||||
it('returns false for HTTPS links', () => {
|
||||
expect(isInternalUrl('https://foo.com')).toBeFalsy();
|
||||
});
|
||||
|
||||
test('should be false for whatever protocol links', () => {
|
||||
it('returns false for whatever protocol links', () => {
|
||||
expect(isInternalUrl('//foo.com')).toBeFalsy();
|
||||
});
|
||||
|
||||
test('should be false for telephone links', () => {
|
||||
it('returns false for telephone links', () => {
|
||||
expect(isInternalUrl('tel:+1234567890')).toBeFalsy();
|
||||
});
|
||||
|
||||
test('should be false for mailto links', () => {
|
||||
it('returns false for mailto links', () => {
|
||||
expect(isInternalUrl('mailto:someone@example.com')).toBeFalsy();
|
||||
});
|
||||
|
||||
test('should be false for undefined links', () => {
|
||||
it('returns false for undefined links', () => {
|
||||
expect(isInternalUrl(undefined)).toBeFalsy();
|
||||
});
|
||||
});
|
||||
|
|
|
@ -16,7 +16,7 @@ const mockedContext = useDocusaurusContext as jest.Mock;
|
|||
const forcePrepend = {forcePrependBaseUrl: true};
|
||||
|
||||
describe('useBaseUrl', () => {
|
||||
test('empty base URL', () => {
|
||||
it('empty base URL', () => {
|
||||
mockedContext.mockImplementation(() => ({
|
||||
siteConfig: {
|
||||
baseUrl: '/',
|
||||
|
@ -44,7 +44,7 @@ describe('useBaseUrl', () => {
|
|||
expect(useBaseUrl('#hello')).toEqual('#hello');
|
||||
});
|
||||
|
||||
test('non-empty base URL', () => {
|
||||
it('non-empty base URL', () => {
|
||||
mockedContext.mockImplementation(() => ({
|
||||
siteConfig: {
|
||||
baseUrl: '/docusaurus/',
|
||||
|
@ -78,7 +78,7 @@ describe('useBaseUrl', () => {
|
|||
});
|
||||
|
||||
describe('useBaseUrlUtils().withBaseUrl()', () => {
|
||||
test('empty base URL', () => {
|
||||
it('empty base URL', () => {
|
||||
mockedContext.mockImplementation(() => ({
|
||||
siteConfig: {
|
||||
baseUrl: '/',
|
||||
|
@ -107,7 +107,7 @@ describe('useBaseUrlUtils().withBaseUrl()', () => {
|
|||
expect(withBaseUrl('#hello')).toEqual('#hello');
|
||||
});
|
||||
|
||||
test('non-empty base URL', () => {
|
||||
it('non-empty base URL', () => {
|
||||
mockedContext.mockImplementation(() => ({
|
||||
siteConfig: {
|
||||
baseUrl: '/docusaurus/',
|
||||
|
|
|
@ -8,15 +8,15 @@
|
|||
import {buildSshUrl, buildHttpsUrl, hasSSHProtocol} from '../deploy';
|
||||
|
||||
describe('remoteBranchUrl', () => {
|
||||
test('should build a normal ssh url', () => {
|
||||
it('builds a normal ssh url', () => {
|
||||
const url = buildSshUrl('github.com', 'facebook', 'docusaurus');
|
||||
expect(url).toEqual('git@github.com:facebook/docusaurus.git');
|
||||
});
|
||||
test('should build a ssh url with port', () => {
|
||||
it('builds a ssh url with port', () => {
|
||||
const url = buildSshUrl('github.com', 'facebook', 'docusaurus', '422');
|
||||
expect(url).toEqual('ssh://git@github.com:422/facebook/docusaurus.git');
|
||||
});
|
||||
test('should build a normal http url', () => {
|
||||
it('builds a normal http url', () => {
|
||||
const url = buildHttpsUrl(
|
||||
'user:pass',
|
||||
'github.com',
|
||||
|
@ -25,7 +25,7 @@ describe('remoteBranchUrl', () => {
|
|||
);
|
||||
expect(url).toEqual('https://user:pass@github.com/facebook/docusaurus.git');
|
||||
});
|
||||
test('should build a normal http url with port', () => {
|
||||
it('builds a normal http url with port', () => {
|
||||
const url = buildHttpsUrl(
|
||||
'user:pass',
|
||||
'github.com',
|
||||
|
@ -40,22 +40,22 @@ describe('remoteBranchUrl', () => {
|
|||
});
|
||||
|
||||
describe('hasSSHProtocol', () => {
|
||||
test('should recognize explicit SSH protocol', () => {
|
||||
it('recognizes explicit SSH protocol', () => {
|
||||
const url = 'ssh://git@github.com:422/facebook/docusaurus.git';
|
||||
expect(hasSSHProtocol(url)).toEqual(true);
|
||||
});
|
||||
|
||||
test('should recognize implied SSH protocol', () => {
|
||||
it('recognizes implied SSH protocol', () => {
|
||||
const url = 'git@github.com:facebook/docusaurus.git';
|
||||
expect(hasSSHProtocol(url)).toEqual(true);
|
||||
});
|
||||
|
||||
test('should not recognize HTTPS with credentials', () => {
|
||||
it('does not recognize HTTPS with credentials', () => {
|
||||
const url = 'https://user:pass@github.com/facebook/docusaurus.git';
|
||||
expect(hasSSHProtocol(url)).toEqual(false);
|
||||
});
|
||||
|
||||
test('should not recognize plain HTTPS URL', () => {
|
||||
it('does not recognize plain HTTPS URL', () => {
|
||||
const url = 'https://github.com:5433/facebook/docusaurus.git';
|
||||
expect(hasSSHProtocol(url)).toEqual(false);
|
||||
});
|
||||
|
|
|
@ -8,45 +8,45 @@
|
|||
import {transformMarkdownContent} from '../writeHeadingIds';
|
||||
|
||||
describe('transformMarkdownContent', () => {
|
||||
test('works for simple level-2 heading', () => {
|
||||
it('works for simple level-2 heading', () => {
|
||||
expect(transformMarkdownContent('## ABC')).toEqual('## ABC {#abc}');
|
||||
});
|
||||
|
||||
test('works for simple level-3 heading', () => {
|
||||
it('works for simple level-3 heading', () => {
|
||||
expect(transformMarkdownContent('### ABC')).toEqual('### ABC {#abc}');
|
||||
});
|
||||
|
||||
test('works for simple level-4 heading', () => {
|
||||
it('works for simple level-4 heading', () => {
|
||||
expect(transformMarkdownContent('#### ABC')).toEqual('#### ABC {#abc}');
|
||||
});
|
||||
|
||||
test('unwraps markdown links', () => {
|
||||
it('unwraps markdown links', () => {
|
||||
const input = `## hello [facebook](https://facebook.com) [crowdin](https://crowdin.com/translate/docusaurus-v2/126/en-fr?filter=basic&value=0)`;
|
||||
expect(transformMarkdownContent(input)).toEqual(
|
||||
`${input} {#hello-facebook-crowdin}`,
|
||||
);
|
||||
});
|
||||
|
||||
test('can slugify complex headings', () => {
|
||||
it('can slugify complex headings', () => {
|
||||
const input = '## abc [Hello] How are you %Sébastien_-_$)( ## -56756';
|
||||
expect(transformMarkdownContent(input)).toEqual(
|
||||
`${input} {#abc-hello-how-are-you-sébastien_-_---56756}`,
|
||||
);
|
||||
});
|
||||
|
||||
test('does not duplicate duplicate id', () => {
|
||||
it('does not duplicate duplicate id', () => {
|
||||
expect(transformMarkdownContent('## hello world {#hello-world}')).toEqual(
|
||||
'## hello world {#hello-world}',
|
||||
);
|
||||
});
|
||||
|
||||
test('respects existing heading', () => {
|
||||
it('respects existing heading', () => {
|
||||
expect(transformMarkdownContent('## New heading {#old-heading}')).toEqual(
|
||||
'## New heading {#old-heading}',
|
||||
);
|
||||
});
|
||||
|
||||
test('overwrites heading ID when asked to', () => {
|
||||
it('overwrites heading ID when asked to', () => {
|
||||
expect(
|
||||
transformMarkdownContent('## New heading {#old-heading}', {
|
||||
overwrite: true,
|
||||
|
@ -54,7 +54,7 @@ describe('transformMarkdownContent', () => {
|
|||
).toEqual('## New heading {#new-heading}');
|
||||
});
|
||||
|
||||
test('maintains casing when asked to', () => {
|
||||
it('maintains casing when asked to', () => {
|
||||
expect(
|
||||
transformMarkdownContent('## getDataFromAPI()', {
|
||||
maintainCase: true,
|
||||
|
@ -62,7 +62,7 @@ describe('transformMarkdownContent', () => {
|
|||
).toEqual('## getDataFromAPI() {#getDataFromAPI}');
|
||||
});
|
||||
|
||||
test('transform the headings', () => {
|
||||
it('transform the headings', () => {
|
||||
const input = `
|
||||
|
||||
# Ignored title
|
||||
|
|
|
@ -0,0 +1,94 @@
|
|||
// Jest Snapshot v1, https://goo.gl/fbAQLP
|
||||
|
||||
exports[`wrap JavaScript wrap ComponentInFolder 2`] = `
|
||||
"import React from 'react';
|
||||
import ComponentInFolder from '@theme-original/ComponentInFolder';
|
||||
|
||||
export default function ComponentInFolderWrapper(props) {
|
||||
return (
|
||||
<>
|
||||
<ComponentInFolder {...props} />
|
||||
</>
|
||||
);
|
||||
}
|
||||
"
|
||||
`;
|
||||
|
||||
exports[`wrap JavaScript wrap ComponentInFolder/ComponentInSubFolder 2`] = `
|
||||
"import React from 'react';
|
||||
import ComponentInSubFolder from '@theme-original/ComponentInFolder/ComponentInSubFolder';
|
||||
|
||||
export default function ComponentInSubFolderWrapper(props) {
|
||||
return (
|
||||
<>
|
||||
<ComponentInSubFolder {...props} />
|
||||
</>
|
||||
);
|
||||
}
|
||||
"
|
||||
`;
|
||||
|
||||
exports[`wrap JavaScript wrap FirstLevelComponent 2`] = `
|
||||
"import React from 'react';
|
||||
import FirstLevelComponent from '@theme-original/FirstLevelComponent';
|
||||
|
||||
export default function FirstLevelComponentWrapper(props) {
|
||||
return (
|
||||
<>
|
||||
<FirstLevelComponent {...props} />
|
||||
</>
|
||||
);
|
||||
}
|
||||
"
|
||||
`;
|
||||
|
||||
exports[`wrap TypeScript wrap ComponentInFolder 2`] = `
|
||||
"import React, {ComponentProps} from 'react';
|
||||
import type ComponentInFolderType from '@theme/ComponentInFolder';
|
||||
import ComponentInFolder from '@theme-original/ComponentInFolder';
|
||||
|
||||
type Props = ComponentProps<typeof ComponentInFolderType>
|
||||
|
||||
export default function ComponentInFolderWrapper(props: Props): JSX.Element {
|
||||
return (
|
||||
<>
|
||||
<ComponentInFolder {...props} />
|
||||
</>
|
||||
);
|
||||
}
|
||||
"
|
||||
`;
|
||||
|
||||
exports[`wrap TypeScript wrap ComponentInFolder/ComponentInSubFolder 2`] = `
|
||||
"import React, {ComponentProps} from 'react';
|
||||
import type ComponentInSubFolderType from '@theme/ComponentInFolder/ComponentInSubFolder';
|
||||
import ComponentInSubFolder from '@theme-original/ComponentInFolder/ComponentInSubFolder';
|
||||
|
||||
type Props = ComponentProps<typeof ComponentInSubFolderType>
|
||||
|
||||
export default function ComponentInSubFolderWrapper(props: Props): JSX.Element {
|
||||
return (
|
||||
<>
|
||||
<ComponentInSubFolder {...props} />
|
||||
</>
|
||||
);
|
||||
}
|
||||
"
|
||||
`;
|
||||
|
||||
exports[`wrap TypeScript wrap FirstLevelComponent 2`] = `
|
||||
"import React, {ComponentProps} from 'react';
|
||||
import type FirstLevelComponentType from '@theme/FirstLevelComponent';
|
||||
import FirstLevelComponent from '@theme-original/FirstLevelComponent';
|
||||
|
||||
type Props = ComponentProps<typeof FirstLevelComponentType>
|
||||
|
||||
export default function FirstLevelComponentWrapper(props: Props): JSX.Element {
|
||||
return (
|
||||
<>
|
||||
<FirstLevelComponent {...props} />
|
||||
</>
|
||||
);
|
||||
}
|
||||
"
|
||||
`;
|
|
@ -0,0 +1,21 @@
|
|||
// Jest Snapshot v1, https://goo.gl/fbAQLP
|
||||
|
||||
exports[`normalizeSwizzleConfig normalize partial config 1`] = `
|
||||
Object {
|
||||
"components": Object {
|
||||
"Other/Component": Object {
|
||||
"actions": Object {
|
||||
"eject": "unsafe",
|
||||
"wrap": "forbidden",
|
||||
},
|
||||
},
|
||||
"SomeComponent": Object {
|
||||
"actions": Object {
|
||||
"eject": "safe",
|
||||
"wrap": "unsafe",
|
||||
},
|
||||
"description": "SomeComponent description",
|
||||
},
|
||||
},
|
||||
}
|
||||
`;
|
|
@ -40,7 +40,7 @@ describe('eject', () => {
|
|||
};
|
||||
}
|
||||
|
||||
test(`eject ${Components.FirstLevelComponent}`, async () => {
|
||||
it(`eject ${Components.FirstLevelComponent}`, async () => {
|
||||
const result = await testEject('eject', Components.FirstLevelComponent);
|
||||
expect(result.createdFiles).toEqual([
|
||||
'FirstLevelComponent.css',
|
||||
|
@ -53,7 +53,7 @@ describe('eject', () => {
|
|||
`);
|
||||
});
|
||||
|
||||
test(`eject ${Components.ComponentInSubFolder}`, async () => {
|
||||
it(`eject ${Components.ComponentInSubFolder}`, async () => {
|
||||
const result = await testEject('eject', Components.ComponentInSubFolder);
|
||||
expect(result.createdFiles).toEqual([
|
||||
'ComponentInFolder/ComponentInSubFolder/index.css',
|
||||
|
@ -72,7 +72,7 @@ describe('eject', () => {
|
|||
`);
|
||||
});
|
||||
|
||||
test(`eject ${Components.ComponentInFolder}`, async () => {
|
||||
it(`eject ${Components.ComponentInFolder}`, async () => {
|
||||
const result = await testEject('eject', Components.ComponentInFolder);
|
||||
expect(result.createdFiles).toEqual([
|
||||
// TODO do we really want to copy those Sibling components?
|
||||
|
@ -124,29 +124,17 @@ describe('wrap', () => {
|
|||
});
|
||||
}
|
||||
|
||||
test(`wrap ${Components.FirstLevelComponent}`, async () => {
|
||||
it(`wrap ${Components.FirstLevelComponent}`, async () => {
|
||||
const result = await doWrap(Components.FirstLevelComponent);
|
||||
expect(result.createdFiles).toEqual(['FirstLevelComponent.js']);
|
||||
expect(result.tree).toMatchInlineSnapshot(`
|
||||
"theme
|
||||
└── FirstLevelComponent.js"
|
||||
`);
|
||||
await expect(result.firstFileContent()).resolves.toMatchInlineSnapshot(`
|
||||
"import React from 'react';
|
||||
import FirstLevelComponent from '@theme-original/FirstLevelComponent';
|
||||
|
||||
export default function FirstLevelComponentWrapper(props) {
|
||||
return (
|
||||
<>
|
||||
<FirstLevelComponent {...props} />
|
||||
</>
|
||||
);
|
||||
}
|
||||
"
|
||||
`);
|
||||
await expect(result.firstFileContent()).resolves.toMatchSnapshot();
|
||||
});
|
||||
|
||||
test(`wrap ${Components.ComponentInSubFolder}`, async () => {
|
||||
it(`wrap ${Components.ComponentInSubFolder}`, async () => {
|
||||
const result = await doWrap(Components.ComponentInSubFolder);
|
||||
expect(result.createdFiles).toEqual([
|
||||
'ComponentInFolder/ComponentInSubFolder/index.js',
|
||||
|
@ -157,22 +145,10 @@ describe('wrap', () => {
|
|||
└── ComponentInSubFolder
|
||||
└── index.js"
|
||||
`);
|
||||
await expect(result.firstFileContent()).resolves.toMatchInlineSnapshot(`
|
||||
"import React from 'react';
|
||||
import ComponentInSubFolder from '@theme-original/ComponentInFolder/ComponentInSubFolder';
|
||||
|
||||
export default function ComponentInSubFolderWrapper(props) {
|
||||
return (
|
||||
<>
|
||||
<ComponentInSubFolder {...props} />
|
||||
</>
|
||||
);
|
||||
}
|
||||
"
|
||||
`);
|
||||
await expect(result.firstFileContent()).resolves.toMatchSnapshot();
|
||||
});
|
||||
|
||||
test(`wrap ${Components.ComponentInFolder}`, async () => {
|
||||
it(`wrap ${Components.ComponentInFolder}`, async () => {
|
||||
const result = await doWrap(Components.ComponentInFolder);
|
||||
expect(result.createdFiles).toEqual(['ComponentInFolder/index.js']);
|
||||
expect(result.tree).toMatchInlineSnapshot(`
|
||||
|
@ -180,19 +156,7 @@ describe('wrap', () => {
|
|||
└── ComponentInFolder
|
||||
└── index.js"
|
||||
`);
|
||||
await expect(result.firstFileContent()).resolves.toMatchInlineSnapshot(`
|
||||
"import React from 'react';
|
||||
import ComponentInFolder from '@theme-original/ComponentInFolder';
|
||||
|
||||
export default function ComponentInFolderWrapper(props) {
|
||||
return (
|
||||
<>
|
||||
<ComponentInFolder {...props} />
|
||||
</>
|
||||
);
|
||||
}
|
||||
"
|
||||
`);
|
||||
await expect(result.firstFileContent()).resolves.toMatchSnapshot();
|
||||
});
|
||||
});
|
||||
|
||||
|
@ -203,32 +167,17 @@ describe('wrap', () => {
|
|||
});
|
||||
}
|
||||
|
||||
test(`wrap ${Components.FirstLevelComponent}`, async () => {
|
||||
it(`wrap ${Components.FirstLevelComponent}`, async () => {
|
||||
const result = await doWrap(Components.FirstLevelComponent);
|
||||
expect(result.createdFiles).toEqual(['FirstLevelComponent.tsx']);
|
||||
expect(result.tree).toMatchInlineSnapshot(`
|
||||
"theme
|
||||
└── FirstLevelComponent.tsx"
|
||||
`);
|
||||
await expect(result.firstFileContent()).resolves.toMatchInlineSnapshot(`
|
||||
"import React, {ComponentProps} from 'react';
|
||||
import type FirstLevelComponentType from '@theme/FirstLevelComponent';
|
||||
import FirstLevelComponent from '@theme-original/FirstLevelComponent';
|
||||
|
||||
type Props = ComponentProps<typeof FirstLevelComponentType>
|
||||
|
||||
export default function FirstLevelComponentWrapper(props: Props): JSX.Element {
|
||||
return (
|
||||
<>
|
||||
<FirstLevelComponent {...props} />
|
||||
</>
|
||||
);
|
||||
}
|
||||
"
|
||||
`);
|
||||
await expect(result.firstFileContent()).resolves.toMatchSnapshot();
|
||||
});
|
||||
|
||||
test(`wrap ${Components.ComponentInSubFolder}`, async () => {
|
||||
it(`wrap ${Components.ComponentInSubFolder}`, async () => {
|
||||
const result = await doWrap(Components.ComponentInSubFolder);
|
||||
expect(result.createdFiles).toEqual([
|
||||
'ComponentInFolder/ComponentInSubFolder/index.tsx',
|
||||
|
@ -239,25 +188,10 @@ describe('wrap', () => {
|
|||
└── ComponentInSubFolder
|
||||
└── index.tsx"
|
||||
`);
|
||||
await expect(result.firstFileContent()).resolves.toMatchInlineSnapshot(`
|
||||
"import React, {ComponentProps} from 'react';
|
||||
import type ComponentInSubFolderType from '@theme/ComponentInFolder/ComponentInSubFolder';
|
||||
import ComponentInSubFolder from '@theme-original/ComponentInFolder/ComponentInSubFolder';
|
||||
|
||||
type Props = ComponentProps<typeof ComponentInSubFolderType>
|
||||
|
||||
export default function ComponentInSubFolderWrapper(props: Props): JSX.Element {
|
||||
return (
|
||||
<>
|
||||
<ComponentInSubFolder {...props} />
|
||||
</>
|
||||
);
|
||||
}
|
||||
"
|
||||
`);
|
||||
await expect(result.firstFileContent()).resolves.toMatchSnapshot();
|
||||
});
|
||||
|
||||
test(`wrap ${Components.ComponentInFolder}`, async () => {
|
||||
it(`wrap ${Components.ComponentInFolder}`, async () => {
|
||||
const result = await doWrap(Components.ComponentInFolder);
|
||||
expect(result.createdFiles).toEqual(['ComponentInFolder/index.tsx']);
|
||||
expect(result.tree).toMatchInlineSnapshot(`
|
||||
|
@ -265,22 +199,7 @@ describe('wrap', () => {
|
|||
└── ComponentInFolder
|
||||
└── index.tsx"
|
||||
`);
|
||||
await expect(result.firstFileContent()).resolves.toMatchInlineSnapshot(`
|
||||
"import React, {ComponentProps} from 'react';
|
||||
import type ComponentInFolderType from '@theme/ComponentInFolder';
|
||||
import ComponentInFolder from '@theme-original/ComponentInFolder';
|
||||
|
||||
type Props = ComponentProps<typeof ComponentInFolderType>
|
||||
|
||||
export default function ComponentInFolderWrapper(props: Props): JSX.Element {
|
||||
return (
|
||||
<>
|
||||
<ComponentInFolder {...props} />
|
||||
</>
|
||||
);
|
||||
}
|
||||
"
|
||||
`);
|
||||
await expect(result.firstFileContent()).resolves.toMatchSnapshot();
|
||||
});
|
||||
});
|
||||
});
|
||||
|
|
|
@ -13,7 +13,7 @@ import {Components} from './testUtils';
|
|||
const FixtureThemePath = path.join(__dirname, '__fixtures__/theme');
|
||||
|
||||
describe('readComponentNames', () => {
|
||||
test('read theme', async () => {
|
||||
it('read theme', async () => {
|
||||
await expect(readComponentNames(FixtureThemePath)).resolves.toEqual([
|
||||
Components.ComponentInFolder,
|
||||
Components.ComponentInSubFolder,
|
||||
|
@ -45,7 +45,7 @@ describe('getThemeComponents', () => {
|
|||
},
|
||||
};
|
||||
|
||||
test('read name', async () => {
|
||||
it('read name', async () => {
|
||||
const themeComponents = await getThemeComponents({
|
||||
themeName,
|
||||
themePath,
|
||||
|
@ -54,7 +54,7 @@ describe('getThemeComponents', () => {
|
|||
expect(themeComponents.themeName).toEqual(themeName);
|
||||
});
|
||||
|
||||
test('read all', async () => {
|
||||
it('read all', async () => {
|
||||
const themeComponents = await getThemeComponents({
|
||||
themeName,
|
||||
themePath,
|
||||
|
@ -69,7 +69,7 @@ describe('getThemeComponents', () => {
|
|||
]);
|
||||
});
|
||||
|
||||
test('getConfig', async () => {
|
||||
it('getConfig', async () => {
|
||||
const themeComponents = await getThemeComponents({
|
||||
themeName,
|
||||
themePath,
|
||||
|
@ -112,7 +112,7 @@ describe('getThemeComponents', () => {
|
|||
);
|
||||
});
|
||||
|
||||
test('getDescription', async () => {
|
||||
it('getDescription', async () => {
|
||||
const themeComponents = await getThemeComponents({
|
||||
themeName,
|
||||
themePath,
|
||||
|
@ -129,7 +129,7 @@ describe('getThemeComponents', () => {
|
|||
).toEqual('N/A');
|
||||
});
|
||||
|
||||
test('getActionStatus', async () => {
|
||||
it('getActionStatus', async () => {
|
||||
const themeComponents = await getThemeComponents({
|
||||
themeName,
|
||||
themePath,
|
||||
|
@ -157,7 +157,7 @@ describe('getThemeComponents', () => {
|
|||
).toEqual('unsafe');
|
||||
});
|
||||
|
||||
test('isSafeAction', async () => {
|
||||
it('isSafeAction', async () => {
|
||||
const themeComponents = await getThemeComponents({
|
||||
themeName,
|
||||
themePath,
|
||||
|
@ -185,7 +185,7 @@ describe('getThemeComponents', () => {
|
|||
).toEqual(false);
|
||||
});
|
||||
|
||||
test('hasAnySafeAction', async () => {
|
||||
it('hasAnySafeAction', async () => {
|
||||
const themeComponents = await getThemeComponents({
|
||||
themeName,
|
||||
themePath,
|
||||
|
|
|
@ -9,14 +9,14 @@ import type {SwizzleConfig} from '@docusaurus/types';
|
|||
import {normalizeSwizzleConfig} from '../config';
|
||||
|
||||
describe('normalizeSwizzleConfig', () => {
|
||||
test(`validate no components config`, async () => {
|
||||
it(`validate no components config`, async () => {
|
||||
const config: SwizzleConfig = {
|
||||
components: {},
|
||||
};
|
||||
expect(normalizeSwizzleConfig(config)).toEqual(config);
|
||||
});
|
||||
|
||||
test(`validate complete config`, async () => {
|
||||
it(`validate complete config`, async () => {
|
||||
const config: SwizzleConfig = {
|
||||
components: {
|
||||
SomeComponent: {
|
||||
|
@ -38,7 +38,7 @@ describe('normalizeSwizzleConfig', () => {
|
|||
expect(normalizeSwizzleConfig(config)).toEqual(config);
|
||||
});
|
||||
|
||||
test(`normalize partial config`, async () => {
|
||||
it(`normalize partial config`, async () => {
|
||||
const config: SwizzleConfig = {
|
||||
components: {
|
||||
SomeComponent: {
|
||||
|
@ -56,28 +56,10 @@ describe('normalizeSwizzleConfig', () => {
|
|||
},
|
||||
},
|
||||
};
|
||||
expect(normalizeSwizzleConfig(config)).toMatchInlineSnapshot(`
|
||||
Object {
|
||||
"components": Object {
|
||||
"Other/Component": Object {
|
||||
"actions": Object {
|
||||
"eject": "unsafe",
|
||||
"wrap": "forbidden",
|
||||
},
|
||||
},
|
||||
"SomeComponent": Object {
|
||||
"actions": Object {
|
||||
"eject": "safe",
|
||||
"wrap": "unsafe",
|
||||
},
|
||||
"description": "SomeComponent description",
|
||||
},
|
||||
},
|
||||
}
|
||||
`);
|
||||
expect(normalizeSwizzleConfig(config)).toMatchSnapshot();
|
||||
});
|
||||
|
||||
test(`reject missing components`, async () => {
|
||||
it(`reject missing components`, async () => {
|
||||
// @ts-expect-error: incomplete actions map
|
||||
const config: SwizzleConfig = {};
|
||||
|
||||
|
@ -88,7 +70,7 @@ describe('normalizeSwizzleConfig', () => {
|
|||
);
|
||||
});
|
||||
|
||||
test(`reject invalid action name`, async () => {
|
||||
it(`reject invalid action name`, async () => {
|
||||
const config: SwizzleConfig = {
|
||||
components: {
|
||||
MyComponent: {
|
||||
|
@ -109,7 +91,7 @@ describe('normalizeSwizzleConfig', () => {
|
|||
);
|
||||
});
|
||||
|
||||
test(`reject invalid action status`, async () => {
|
||||
it(`reject invalid action status`, async () => {
|
||||
const config: SwizzleConfig = {
|
||||
components: {
|
||||
MyComponent: {
|
||||
|
|
|
@ -57,11 +57,13 @@ class MockExitError extends Error {
|
|||
function createExitMock() {
|
||||
let mock: jest.SpyInstance;
|
||||
|
||||
// eslint-disable-next-line jest/require-top-level-describe
|
||||
beforeEach(async () => {
|
||||
mock = jest.spyOn(process, 'exit').mockImplementation((code) => {
|
||||
throw new MockExitError(code as number);
|
||||
throw new MockExitError(code);
|
||||
});
|
||||
});
|
||||
// eslint-disable-next-line jest/require-top-level-describe
|
||||
afterEach(async () => {
|
||||
mock?.mockRestore();
|
||||
});
|
||||
|
@ -142,7 +144,7 @@ async function createTestSite() {
|
|||
describe('swizzle wrap', () => {
|
||||
const exitMock = createExitMock();
|
||||
|
||||
test(`${Components.FirstLevelComponent} JS`, async () => {
|
||||
it(`${Components.FirstLevelComponent} JS`, async () => {
|
||||
const {snapshotThemeDir, testWrap} = await createTestSite();
|
||||
await testWrap({
|
||||
component: Components.FirstLevelComponent,
|
||||
|
@ -151,7 +153,7 @@ describe('swizzle wrap', () => {
|
|||
await snapshotThemeDir();
|
||||
});
|
||||
|
||||
test(`${Components.FirstLevelComponent} TS`, async () => {
|
||||
it(`${Components.FirstLevelComponent} TS`, async () => {
|
||||
const {snapshotThemeDir, testWrap} = await createTestSite();
|
||||
await testWrap({
|
||||
component: Components.FirstLevelComponent,
|
||||
|
@ -160,7 +162,7 @@ describe('swizzle wrap', () => {
|
|||
await snapshotThemeDir();
|
||||
});
|
||||
|
||||
test(`${Components.ComponentInFolder} JS`, async () => {
|
||||
it(`${Components.ComponentInFolder} JS`, async () => {
|
||||
const {snapshotThemeDir, testWrap} = await createTestSite();
|
||||
await testWrap({
|
||||
component: Components.ComponentInFolder,
|
||||
|
@ -169,7 +171,7 @@ describe('swizzle wrap', () => {
|
|||
await snapshotThemeDir();
|
||||
});
|
||||
|
||||
test(`${Components.ComponentInFolder} TS`, async () => {
|
||||
it(`${Components.ComponentInFolder} TS`, async () => {
|
||||
const {snapshotThemeDir, testWrap} = await createTestSite();
|
||||
await testWrap({
|
||||
component: Components.ComponentInFolder,
|
||||
|
@ -179,7 +181,7 @@ describe('swizzle wrap', () => {
|
|||
await snapshotThemeDir();
|
||||
});
|
||||
|
||||
test(`${Components.ComponentInSubFolder} JS`, async () => {
|
||||
it(`${Components.ComponentInSubFolder} JS`, async () => {
|
||||
const {snapshotThemeDir, testWrap} = await createTestSite();
|
||||
await testWrap({
|
||||
component: Components.ComponentInSubFolder,
|
||||
|
@ -188,7 +190,7 @@ describe('swizzle wrap', () => {
|
|||
await snapshotThemeDir();
|
||||
});
|
||||
|
||||
test(`${Components.ComponentInSubFolder} TS`, async () => {
|
||||
it(`${Components.ComponentInSubFolder} TS`, async () => {
|
||||
const {snapshotThemeDir, testWrap} = await createTestSite();
|
||||
await testWrap({
|
||||
component: Components.ComponentInSubFolder,
|
||||
|
@ -198,7 +200,7 @@ describe('swizzle wrap', () => {
|
|||
await snapshotThemeDir();
|
||||
});
|
||||
|
||||
test(`${Components.Sibling} JS`, async () => {
|
||||
it(`${Components.Sibling} JS`, async () => {
|
||||
const {snapshotThemeDir, testWrap} = await createTestSite();
|
||||
await testWrap({
|
||||
component: Components.Sibling,
|
||||
|
@ -207,7 +209,7 @@ describe('swizzle wrap', () => {
|
|||
await snapshotThemeDir();
|
||||
});
|
||||
|
||||
test(`${Components.Sibling} TS`, async () => {
|
||||
it(`${Components.Sibling} TS`, async () => {
|
||||
const {snapshotThemeDir, testWrap} = await createTestSite();
|
||||
await testWrap({
|
||||
component: Components.Sibling,
|
||||
|
@ -221,7 +223,7 @@ describe('swizzle wrap', () => {
|
|||
describe('swizzle eject', () => {
|
||||
const exitMock = createExitMock();
|
||||
|
||||
test(`${Components.FirstLevelComponent} JS`, async () => {
|
||||
it(`${Components.FirstLevelComponent} JS`, async () => {
|
||||
const {snapshotThemeDir, testEject} = await createTestSite();
|
||||
await testEject({
|
||||
component: Components.FirstLevelComponent,
|
||||
|
@ -230,7 +232,7 @@ describe('swizzle eject', () => {
|
|||
await snapshotThemeDir();
|
||||
});
|
||||
|
||||
test(`${Components.FirstLevelComponent} TS`, async () => {
|
||||
it(`${Components.FirstLevelComponent} TS`, async () => {
|
||||
const {snapshotThemeDir, testEject} = await createTestSite();
|
||||
await testEject({
|
||||
component: Components.FirstLevelComponent,
|
||||
|
@ -239,7 +241,7 @@ describe('swizzle eject', () => {
|
|||
await snapshotThemeDir();
|
||||
});
|
||||
|
||||
test(`${Components.ComponentInFolder} JS`, async () => {
|
||||
it(`${Components.ComponentInFolder} JS`, async () => {
|
||||
const {snapshotThemeDir, testEject} = await createTestSite();
|
||||
await testEject({
|
||||
component: Components.ComponentInFolder,
|
||||
|
@ -248,7 +250,7 @@ describe('swizzle eject', () => {
|
|||
await snapshotThemeDir();
|
||||
});
|
||||
|
||||
test(`${Components.ComponentInFolder} TS`, async () => {
|
||||
it(`${Components.ComponentInFolder} TS`, async () => {
|
||||
const {snapshotThemeDir, testEject} = await createTestSite();
|
||||
await testEject({
|
||||
component: Components.ComponentInFolder,
|
||||
|
@ -258,7 +260,7 @@ describe('swizzle eject', () => {
|
|||
await snapshotThemeDir();
|
||||
});
|
||||
|
||||
test(`${Components.ComponentInSubFolder} JS`, async () => {
|
||||
it(`${Components.ComponentInSubFolder} JS`, async () => {
|
||||
const {snapshotThemeDir, testEject} = await createTestSite();
|
||||
await testEject({
|
||||
component: Components.ComponentInSubFolder,
|
||||
|
@ -267,7 +269,7 @@ describe('swizzle eject', () => {
|
|||
await snapshotThemeDir();
|
||||
});
|
||||
|
||||
test(`${Components.ComponentInSubFolder} TS`, async () => {
|
||||
it(`${Components.ComponentInSubFolder} TS`, async () => {
|
||||
const {snapshotThemeDir, testEject} = await createTestSite();
|
||||
await testEject({
|
||||
component: Components.ComponentInSubFolder,
|
||||
|
@ -277,7 +279,7 @@ describe('swizzle eject', () => {
|
|||
await snapshotThemeDir();
|
||||
});
|
||||
|
||||
test(`${Components.Sibling} JS`, async () => {
|
||||
it(`${Components.Sibling} JS`, async () => {
|
||||
const {snapshotThemeDir, testEject} = await createTestSite();
|
||||
await testEject({
|
||||
component: Components.Sibling,
|
||||
|
@ -286,7 +288,7 @@ describe('swizzle eject', () => {
|
|||
await snapshotThemeDir();
|
||||
});
|
||||
|
||||
test(`${Components.Sibling} TS`, async () => {
|
||||
it(`${Components.Sibling} TS`, async () => {
|
||||
const {snapshotThemeDir, testEject} = await createTestSite();
|
||||
await testEject({
|
||||
component: Components.Sibling,
|
||||
|
|
|
@ -1,34 +1,5 @@
|
|||
// Jest Snapshot v1, https://goo.gl/fbAQLP
|
||||
|
||||
exports[`normalizeConfig should throw error for baseUrl without trailing \`/\` 1`] = `
|
||||
"\\"baseUrl\\" must be a string with a trailing slash.
|
||||
"
|
||||
`;
|
||||
|
||||
exports[`normalizeConfig should throw error for required fields 1`] = `
|
||||
"\\"baseUrl\\" is required
|
||||
\\"title\\" is required
|
||||
\\"url\\" is required
|
||||
\\"themes\\" must be an array
|
||||
\\"presets\\" must be an array
|
||||
\\"scripts\\" must be an array
|
||||
\\"stylesheets\\" must be an array
|
||||
These field(s) (\\"invalidField\\",) are not recognized in docusaurus.config.js.
|
||||
If you still want these fields to be in your configuration, put them in the \\"customFields\\" field.
|
||||
See https://docusaurus.io/docs/docusaurus.config.js/#customfields"
|
||||
`;
|
||||
|
||||
exports[`normalizeConfig should throw error for unknown field 1`] = `
|
||||
"These field(s) (\\"invalid\\",) are not recognized in docusaurus.config.js.
|
||||
If you still want these fields to be in your configuration, put them in the \\"customFields\\" field.
|
||||
See https://docusaurus.io/docs/docusaurus.config.js/#customfields"
|
||||
`;
|
||||
|
||||
exports[`normalizeConfig should throw error if css doesn't have href 1`] = `
|
||||
"\\"stylesheets[1]\\" does not match any of the allowed types
|
||||
"
|
||||
`;
|
||||
|
||||
exports[`normalizeConfig should throw error if plugins is not a string and it's not an array #1 for the input of: [123] 1`] = `
|
||||
" => Bad Docusaurus plugin value as path [plugins,0].
|
||||
Example valid plugin config:
|
||||
|
@ -98,16 +69,6 @@ exports[`normalizeConfig should throw error if plugins is not array for the inpu
|
|||
"
|
||||
`;
|
||||
|
||||
exports[`normalizeConfig should throw error if presets is not array 1`] = `
|
||||
"\\"presets\\" must be an array
|
||||
"
|
||||
`;
|
||||
|
||||
exports[`normalizeConfig should throw error if scripts doesn't have src 1`] = `
|
||||
"\\"scripts[1]\\" does not match any of the allowed types
|
||||
"
|
||||
`;
|
||||
|
||||
exports[`normalizeConfig should throw error if themes is not a string and it's not an array #1 for the input of: [123] 1`] = `
|
||||
" => Bad Docusaurus theme value as path [themes,0].
|
||||
Example valid theme config:
|
||||
|
@ -172,12 +133,51 @@ Example valid theme config:
|
|||
"
|
||||
`;
|
||||
|
||||
exports[`normalizeConfig should throw error if themes is not array 1`] = `
|
||||
"\\"themes\\" must be an array
|
||||
"
|
||||
`;
|
||||
|
||||
exports[`normalizeConfig should throw error if themes is not array for the input of: {} 1`] = `
|
||||
"\\"themes\\" must be an array
|
||||
"
|
||||
`;
|
||||
|
||||
exports[`normalizeConfig throws error for baseUrl without trailing \`/\` 1`] = `
|
||||
"\\"baseUrl\\" must be a string with a trailing slash.
|
||||
"
|
||||
`;
|
||||
|
||||
exports[`normalizeConfig throws error for required fields 1`] = `
|
||||
"\\"baseUrl\\" is required
|
||||
\\"title\\" is required
|
||||
\\"url\\" is required
|
||||
\\"themes\\" must be an array
|
||||
\\"presets\\" must be an array
|
||||
\\"scripts\\" must be an array
|
||||
\\"stylesheets\\" must be an array
|
||||
These field(s) (\\"invalidField\\",) are not recognized in docusaurus.config.js.
|
||||
If you still want these fields to be in your configuration, put them in the \\"customFields\\" field.
|
||||
See https://docusaurus.io/docs/docusaurus.config.js/#customfields"
|
||||
`;
|
||||
|
||||
exports[`normalizeConfig throws error for unknown field 1`] = `
|
||||
"These field(s) (\\"invalid\\",) are not recognized in docusaurus.config.js.
|
||||
If you still want these fields to be in your configuration, put them in the \\"customFields\\" field.
|
||||
See https://docusaurus.io/docs/docusaurus.config.js/#customfields"
|
||||
`;
|
||||
|
||||
exports[`normalizeConfig throws error if css doesn't have href 1`] = `
|
||||
"\\"stylesheets[1]\\" does not match any of the allowed types
|
||||
"
|
||||
`;
|
||||
|
||||
exports[`normalizeConfig throws error if presets is not array 1`] = `
|
||||
"\\"presets\\" must be an array
|
||||
"
|
||||
`;
|
||||
|
||||
exports[`normalizeConfig throws error if scripts doesn't have src 1`] = `
|
||||
"\\"scripts[1]\\" does not match any of the allowed types
|
||||
"
|
||||
`;
|
||||
|
||||
exports[`normalizeConfig throws error if themes is not array 1`] = `
|
||||
"\\"themes\\" must be an array
|
||||
"
|
||||
`;
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
// Jest Snapshot v1, https://goo.gl/fbAQLP
|
||||
|
||||
exports[`handleDuplicateRoutes 1`] = `
|
||||
exports[`handleDuplicateRoutes works 1`] = `
|
||||
"Duplicate routes found!
|
||||
- Attempting to create page at /search, but a page already exists at this route.
|
||||
- Attempting to create page at /sameDoc, but a page already exists at this route.
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
// Jest Snapshot v1, https://goo.gl/fbAQLP
|
||||
|
||||
exports[`loadRoutes flat route config 1`] = `
|
||||
exports[`loadRoutes loads flat route config 1`] = `
|
||||
Object {
|
||||
"registry": Object {
|
||||
"component---theme-blog-list-pagea-6-a-7ba": Object {
|
||||
|
@ -58,7 +58,7 @@ export default [
|
|||
}
|
||||
`;
|
||||
|
||||
exports[`loadRoutes nested route config 1`] = `
|
||||
exports[`loadRoutes loads nested route config 1`] = `
|
||||
Object {
|
||||
"registry": Object {
|
||||
"component---theme-doc-item-178-a40": Object {
|
||||
|
@ -142,7 +142,7 @@ export default [
|
|||
}
|
||||
`;
|
||||
|
||||
exports[`loadRoutes route config with empty (but valid) path string 1`] = `
|
||||
exports[`loadRoutes loads route config with empty (but valid) path string 1`] = `
|
||||
Object {
|
||||
"registry": Object {
|
||||
"component---hello-world-jse-0-f-b6c": Object {
|
||||
|
|
|
@ -104,7 +104,7 @@ describe('handleBrokenLinks', () => {
|
|||
|
||||
const outDir = path.resolve(__dirname, '__fixtures__/brokenLinks/outDir');
|
||||
|
||||
test('do not report anything for correct paths', async () => {
|
||||
it('do not report anything for correct paths', async () => {
|
||||
const consoleMock = jest
|
||||
.spyOn(console, 'error')
|
||||
.mockImplementation(() => {});
|
||||
|
@ -143,7 +143,7 @@ describe('handleBrokenLinks', () => {
|
|||
expect(consoleMock).toBeCalledTimes(0);
|
||||
});
|
||||
|
||||
test('reports all broken links', async () => {
|
||||
it('reports all broken links', async () => {
|
||||
await expect(() =>
|
||||
handleBrokenLinks({
|
||||
allCollectedLinks,
|
||||
|
@ -155,7 +155,7 @@ describe('handleBrokenLinks', () => {
|
|||
).rejects.toThrowErrorMatchingSnapshot();
|
||||
});
|
||||
|
||||
test('no-op for ignore', async () => {
|
||||
it('no-op for ignore', async () => {
|
||||
// In any case, _.mapValues will always be called, unless handleBrokenLinks
|
||||
// has already bailed
|
||||
const lodashMock = jest.spyOn(_, 'mapValues');
|
||||
|
@ -170,7 +170,7 @@ describe('handleBrokenLinks', () => {
|
|||
lodashMock.mockRestore();
|
||||
});
|
||||
|
||||
test('reports frequent broken links', async () => {
|
||||
it('reports frequent broken links', async () => {
|
||||
Object.values(allCollectedLinks).forEach((links) =>
|
||||
links.push(
|
||||
'/frequent',
|
||||
|
|
|
@ -9,7 +9,7 @@ import path from 'path';
|
|||
import loadConfig from '../config';
|
||||
|
||||
describe('loadConfig', () => {
|
||||
test('website with valid siteConfig', async () => {
|
||||
it('website with valid siteConfig', async () => {
|
||||
const siteDir = path.join(
|
||||
__dirname,
|
||||
'__fixtures__',
|
||||
|
@ -21,7 +21,7 @@ describe('loadConfig', () => {
|
|||
expect(config).not.toEqual({});
|
||||
});
|
||||
|
||||
test('website with valid config creator function', async () => {
|
||||
it('website with valid config creator function', async () => {
|
||||
const siteDir = path.join(
|
||||
__dirname,
|
||||
'__fixtures__',
|
||||
|
@ -33,7 +33,7 @@ describe('loadConfig', () => {
|
|||
expect(config).not.toEqual({});
|
||||
});
|
||||
|
||||
test('website with valid async config', async () => {
|
||||
it('website with valid async config', async () => {
|
||||
const siteDir = path.join(
|
||||
__dirname,
|
||||
'__fixtures__',
|
||||
|
@ -45,7 +45,7 @@ describe('loadConfig', () => {
|
|||
expect(config).not.toEqual({});
|
||||
});
|
||||
|
||||
test('website with valid async config creator function', async () => {
|
||||
it('website with valid async config creator function', async () => {
|
||||
const siteDir = path.join(
|
||||
__dirname,
|
||||
'__fixtures__',
|
||||
|
@ -57,7 +57,7 @@ describe('loadConfig', () => {
|
|||
expect(config).not.toEqual({});
|
||||
});
|
||||
|
||||
test('website with incomplete siteConfig', async () => {
|
||||
it('website with incomplete siteConfig', async () => {
|
||||
const siteDir = path.join(
|
||||
__dirname,
|
||||
'__fixtures__',
|
||||
|
@ -67,7 +67,7 @@ describe('loadConfig', () => {
|
|||
await expect(loadConfig(siteDir)).rejects.toThrowErrorMatchingSnapshot();
|
||||
});
|
||||
|
||||
test('website with useless field (wrong field) in siteConfig', async () => {
|
||||
it('website with useless field (wrong field) in siteConfig', async () => {
|
||||
const siteDir = path.join(
|
||||
__dirname,
|
||||
'__fixtures__',
|
||||
|
@ -77,7 +77,7 @@ describe('loadConfig', () => {
|
|||
await expect(loadConfig(siteDir)).rejects.toThrowErrorMatchingSnapshot();
|
||||
});
|
||||
|
||||
test('website with no siteConfig', async () => {
|
||||
it('website with no siteConfig', async () => {
|
||||
const siteDir = path.join(
|
||||
__dirname,
|
||||
'__fixtures__',
|
||||
|
|
|
@ -21,7 +21,7 @@ const baseConfig: DocusaurusConfig = {
|
|||
const normalizeConfig = (config) => validateConfig({...baseConfig, ...config});
|
||||
|
||||
describe('normalizeConfig', () => {
|
||||
test('should normalize empty config', () => {
|
||||
it('normalizes empty config', () => {
|
||||
const value = normalizeConfig({});
|
||||
expect(value).toEqual({
|
||||
...DEFAULT_CONFIG,
|
||||
|
@ -29,7 +29,7 @@ describe('normalizeConfig', () => {
|
|||
});
|
||||
});
|
||||
|
||||
test('should accept correctly defined config options', () => {
|
||||
it('accepts correctly defined config options', () => {
|
||||
const userConfig = {
|
||||
...DEFAULT_CONFIG,
|
||||
...baseConfig,
|
||||
|
@ -60,7 +60,7 @@ describe('normalizeConfig', () => {
|
|||
expect(normalizedConfig).toEqual(userConfig);
|
||||
});
|
||||
|
||||
test('should accept custom field in config', () => {
|
||||
it('accepts custom field in config', () => {
|
||||
const value = normalizeConfig({
|
||||
customFields: {
|
||||
author: 'anshul',
|
||||
|
@ -75,7 +75,7 @@ describe('normalizeConfig', () => {
|
|||
});
|
||||
});
|
||||
|
||||
test('should throw error for unknown field', () => {
|
||||
it('throws error for unknown field', () => {
|
||||
expect(() => {
|
||||
normalizeConfig({
|
||||
invalid: true,
|
||||
|
@ -83,7 +83,7 @@ describe('normalizeConfig', () => {
|
|||
}).toThrowErrorMatchingSnapshot();
|
||||
});
|
||||
|
||||
test('should throw error for baseUrl without trailing `/`', () => {
|
||||
it('throws error for baseUrl without trailing `/`', () => {
|
||||
expect(() => {
|
||||
normalizeConfig({
|
||||
baseUrl: 'noslash',
|
||||
|
@ -91,7 +91,7 @@ describe('normalizeConfig', () => {
|
|||
}).toThrowErrorMatchingSnapshot();
|
||||
});
|
||||
|
||||
test.each([
|
||||
it.each([
|
||||
['should throw error if plugins is not array', {}],
|
||||
[
|
||||
"should throw error if plugins is not a string and it's not an array #1",
|
||||
|
@ -117,7 +117,7 @@ describe('normalizeConfig', () => {
|
|||
}).toThrowErrorMatchingSnapshot();
|
||||
});
|
||||
|
||||
test.each([
|
||||
it.each([
|
||||
['should throw error if themes is not array', {}],
|
||||
[
|
||||
"should throw error if themes is not a string and it's not an array #1",
|
||||
|
@ -143,7 +143,7 @@ describe('normalizeConfig', () => {
|
|||
}).toThrowErrorMatchingSnapshot();
|
||||
});
|
||||
|
||||
test.each([
|
||||
it.each([
|
||||
['should accept [string] for plugins', ['plain/string']],
|
||||
[
|
||||
'should accept string[] for plugins',
|
||||
|
@ -184,7 +184,7 @@ describe('normalizeConfig', () => {
|
|||
}).not.toThrowError();
|
||||
});
|
||||
|
||||
test.each([
|
||||
it.each([
|
||||
['should accept [string] for themes', ['plain/string']],
|
||||
[
|
||||
'should accept string[] for themes',
|
||||
|
@ -225,7 +225,7 @@ describe('normalizeConfig', () => {
|
|||
}).not.toThrowError();
|
||||
});
|
||||
|
||||
test('should throw error if themes is not array', () => {
|
||||
it('throws error if themes is not array', () => {
|
||||
expect(() => {
|
||||
normalizeConfig({
|
||||
themes: {},
|
||||
|
@ -233,7 +233,7 @@ describe('normalizeConfig', () => {
|
|||
}).toThrowErrorMatchingSnapshot();
|
||||
});
|
||||
|
||||
test('should throw error if presets is not array', () => {
|
||||
it('throws error if presets is not array', () => {
|
||||
expect(() => {
|
||||
normalizeConfig({
|
||||
presets: {},
|
||||
|
@ -241,7 +241,7 @@ describe('normalizeConfig', () => {
|
|||
}).toThrowErrorMatchingSnapshot();
|
||||
});
|
||||
|
||||
test("should throw error if scripts doesn't have src", () => {
|
||||
it("throws error if scripts doesn't have src", () => {
|
||||
expect(() => {
|
||||
normalizeConfig({
|
||||
scripts: ['https://some.com', {}],
|
||||
|
@ -249,7 +249,7 @@ describe('normalizeConfig', () => {
|
|||
}).toThrowErrorMatchingSnapshot();
|
||||
});
|
||||
|
||||
test("should throw error if css doesn't have href", () => {
|
||||
it("throws error if css doesn't have href", () => {
|
||||
expect(() => {
|
||||
normalizeConfig({
|
||||
stylesheets: ['https://somescript.com', {type: 'text/css'}],
|
||||
|
@ -257,7 +257,7 @@ describe('normalizeConfig', () => {
|
|||
}).toThrowErrorMatchingSnapshot();
|
||||
});
|
||||
|
||||
test('should throw error for required fields', () => {
|
||||
it('throws error for required fields', () => {
|
||||
expect(
|
||||
() =>
|
||||
validateConfig({
|
||||
|
@ -276,12 +276,12 @@ describe('config warnings', () => {
|
|||
return ConfigSchema.validate(config).warning;
|
||||
}
|
||||
|
||||
test('baseConfig has no warning', () => {
|
||||
it('baseConfig has no warning', () => {
|
||||
const warning = getWarning(baseConfig);
|
||||
expect(warning).toBeUndefined();
|
||||
});
|
||||
|
||||
test('site url has warning when using subpath', () => {
|
||||
it('site url has warning when using subpath', () => {
|
||||
const warning = getWarning({
|
||||
...baseConfig,
|
||||
url: 'https://mysite.com/someSubpath',
|
||||
|
|
|
@ -41,11 +41,13 @@ const routes: RouteConfig[] = [
|
|||
},
|
||||
];
|
||||
|
||||
test('handleDuplicateRoutes', () => {
|
||||
expect(() => {
|
||||
handleDuplicateRoutes(routes, 'throw');
|
||||
}).toThrowErrorMatchingSnapshot();
|
||||
const consoleMock = jest.spyOn(console, 'log').mockImplementation(() => {});
|
||||
handleDuplicateRoutes(routes, 'ignore');
|
||||
expect(consoleMock).toBeCalledTimes(0);
|
||||
describe('handleDuplicateRoutes', () => {
|
||||
it('works', () => {
|
||||
expect(() => {
|
||||
handleDuplicateRoutes(routes, 'throw');
|
||||
}).toThrowErrorMatchingSnapshot();
|
||||
const consoleMock = jest.spyOn(console, 'log').mockImplementation(() => {});
|
||||
handleDuplicateRoutes(routes, 'ignore');
|
||||
expect(consoleMock).toBeCalledTimes(0);
|
||||
});
|
||||
});
|
||||
|
|
|
@ -30,7 +30,7 @@ function loadI18nTest(i18nConfig: I18nConfig, locale?: string) {
|
|||
describe('defaultLocaleConfig', () => {
|
||||
const canComputeLabel = typeof Intl.DisplayNames !== 'undefined';
|
||||
|
||||
test('returns correct labels', () => {
|
||||
it('returns correct labels', () => {
|
||||
expect(getDefaultLocaleConfig('fr')).toEqual({
|
||||
label: canComputeLabel ? 'Français' : 'fr',
|
||||
direction: 'ltr',
|
||||
|
@ -85,7 +85,7 @@ describe('loadI18n', () => {
|
|||
consoleSpy.mockClear();
|
||||
});
|
||||
|
||||
test('should load I18n for default config', async () => {
|
||||
it('loads I18n for default config', async () => {
|
||||
await expect(loadI18nTest(DEFAULT_I18N_CONFIG)).resolves.toEqual({
|
||||
defaultLocale: 'en',
|
||||
locales: ['en'],
|
||||
|
@ -94,7 +94,7 @@ describe('loadI18n', () => {
|
|||
});
|
||||
});
|
||||
|
||||
test('should load I18n for multi-lang config', async () => {
|
||||
it('loads I18n for multi-lang config', async () => {
|
||||
await expect(
|
||||
loadI18nTest({
|
||||
defaultLocale: 'fr',
|
||||
|
@ -109,7 +109,7 @@ describe('loadI18n', () => {
|
|||
});
|
||||
});
|
||||
|
||||
test('should load I18n for multi-locale config with specified locale', async () => {
|
||||
it('loads I18n for multi-locale config with specified locale', async () => {
|
||||
await expect(
|
||||
loadI18nTest(
|
||||
{
|
||||
|
@ -127,7 +127,7 @@ describe('loadI18n', () => {
|
|||
});
|
||||
});
|
||||
|
||||
test('should load I18n for multi-locale config with some xcustom locale configs', async () => {
|
||||
it('loads I18n for multi-locale config with some xcustom locale configs', async () => {
|
||||
await expect(
|
||||
loadI18nTest(
|
||||
{
|
||||
|
@ -152,7 +152,7 @@ describe('loadI18n', () => {
|
|||
});
|
||||
});
|
||||
|
||||
test('should warn when trying to load undeclared locale', async () => {
|
||||
it('warns when trying to load undeclared locale', async () => {
|
||||
await loadI18nTest(
|
||||
{
|
||||
defaultLocale: 'fr',
|
||||
|
@ -168,7 +168,7 @@ describe('loadI18n', () => {
|
|||
});
|
||||
|
||||
describe('localizePath', () => {
|
||||
test('should localize url path with current locale', () => {
|
||||
it('localizes url path with current locale', () => {
|
||||
expect(
|
||||
localizePath({
|
||||
pathType: 'url',
|
||||
|
@ -184,7 +184,7 @@ describe('localizePath', () => {
|
|||
).toEqual('/baseUrl/fr/');
|
||||
});
|
||||
|
||||
test('should localize fs path with current locale', () => {
|
||||
it('localizes fs path with current locale', () => {
|
||||
expect(
|
||||
localizePath({
|
||||
pathType: 'fs',
|
||||
|
@ -200,7 +200,7 @@ describe('localizePath', () => {
|
|||
).toEqual(`${path.sep}baseFsPath${path.sep}fr`);
|
||||
});
|
||||
|
||||
test('should localize path for default locale, if requested', () => {
|
||||
it('localizes path for default locale, if requested', () => {
|
||||
expect(
|
||||
localizePath({
|
||||
pathType: 'url',
|
||||
|
@ -216,7 +216,7 @@ describe('localizePath', () => {
|
|||
).toEqual('/baseUrl/en/');
|
||||
});
|
||||
|
||||
test('should not localize path for default locale by default', () => {
|
||||
it('does not localize path for default locale by default', () => {
|
||||
expect(
|
||||
localizePath({
|
||||
pathType: 'url',
|
||||
|
@ -232,7 +232,7 @@ describe('localizePath', () => {
|
|||
).toEqual('/baseUrl/');
|
||||
});
|
||||
|
||||
test('should localize path for non-default locale by default', () => {
|
||||
it('localizes path for non-default locale by default', () => {
|
||||
expect(
|
||||
localizePath({
|
||||
pathType: 'url',
|
||||
|
|
|
@ -8,7 +8,7 @@
|
|||
import {getNamePatterns, resolveModuleName} from '../moduleShorthand';
|
||||
|
||||
describe('getNamePatterns', () => {
|
||||
test('should resolve plain names', () => {
|
||||
it('resolves plain names', () => {
|
||||
expect(getNamePatterns('awesome', 'plugin')).toEqual([
|
||||
'awesome',
|
||||
'@docusaurus/plugin-awesome',
|
||||
|
@ -22,7 +22,7 @@ describe('getNamePatterns', () => {
|
|||
]);
|
||||
});
|
||||
|
||||
test('should expand bare scopes', () => {
|
||||
it('expands bare scopes', () => {
|
||||
expect(getNamePatterns('@joshcena', 'plugin')).toEqual([
|
||||
'@joshcena/docusaurus-plugin',
|
||||
]);
|
||||
|
@ -32,7 +32,7 @@ describe('getNamePatterns', () => {
|
|||
]);
|
||||
});
|
||||
|
||||
test('should expand scoped names', () => {
|
||||
it('expands scoped names', () => {
|
||||
expect(getNamePatterns('@joshcena/awesome', 'plugin')).toEqual([
|
||||
'@joshcena/awesome',
|
||||
'@joshcena/docusaurus-plugin-awesome',
|
||||
|
@ -44,7 +44,7 @@ describe('getNamePatterns', () => {
|
|||
]);
|
||||
});
|
||||
|
||||
test('should expand deep scoped paths', () => {
|
||||
it('expands deep scoped paths', () => {
|
||||
expect(getNamePatterns('@joshcena/awesome/web', 'plugin')).toEqual([
|
||||
'@joshcena/awesome/web',
|
||||
'@joshcena/docusaurus-plugin-awesome/web',
|
||||
|
@ -58,17 +58,17 @@ describe('getNamePatterns', () => {
|
|||
});
|
||||
|
||||
describe('resolveModuleName', () => {
|
||||
test('should resolve longhand', () => {
|
||||
it('resolves longhand', () => {
|
||||
expect(
|
||||
resolveModuleName('@docusaurus/plugin-content-docs', require, 'plugin'),
|
||||
).toBeDefined();
|
||||
});
|
||||
|
||||
test('should resolve shorthand', () => {
|
||||
it('resolves shorthand', () => {
|
||||
expect(resolveModuleName('content-docs', require, 'plugin')).toBeDefined();
|
||||
});
|
||||
|
||||
test('should throw good error message for longhand', () => {
|
||||
it('throws good error message for longhand', () => {
|
||||
expect(() =>
|
||||
resolveModuleName('@docusaurus/plugin-content-doc', require, 'plugin'),
|
||||
).toThrowErrorMatchingInlineSnapshot(`
|
||||
|
@ -78,7 +78,7 @@ describe('resolveModuleName', () => {
|
|||
`);
|
||||
});
|
||||
|
||||
test('should throw good error message for shorthand', () => {
|
||||
it('throws good error message for shorthand', () => {
|
||||
expect(() => resolveModuleName('content-doc', require, 'plugin'))
|
||||
.toThrowErrorMatchingInlineSnapshot(`
|
||||
"Docusaurus was unable to resolve the \\"content-doc\\" plugin. Make sure one of the following packages are installed:
|
||||
|
|
|
@ -9,7 +9,7 @@ import loadRoutes from '../routes';
|
|||
import type {RouteConfig} from '@docusaurus/types';
|
||||
|
||||
describe('loadRoutes', () => {
|
||||
test('nested route config', async () => {
|
||||
it('loads nested route config', async () => {
|
||||
const nestedRouteConfig: RouteConfig = {
|
||||
component: '@theme/DocPage',
|
||||
path: '/docs:route',
|
||||
|
@ -38,11 +38,12 @@ describe('loadRoutes', () => {
|
|||
},
|
||||
],
|
||||
};
|
||||
const result = await loadRoutes([nestedRouteConfig], '/');
|
||||
expect(result).toMatchSnapshot();
|
||||
await expect(
|
||||
loadRoutes([nestedRouteConfig], '/'),
|
||||
).resolves.toMatchSnapshot();
|
||||
});
|
||||
|
||||
test('flat route config', async () => {
|
||||
it('loads flat route config', async () => {
|
||||
const flatRouteConfig: RouteConfig = {
|
||||
path: '/blog',
|
||||
component: '@theme/BlogListPage',
|
||||
|
@ -66,39 +67,37 @@ describe('loadRoutes', () => {
|
|||
],
|
||||
},
|
||||
};
|
||||
const result = await loadRoutes([flatRouteConfig], '/');
|
||||
expect(result).toMatchSnapshot();
|
||||
await expect(loadRoutes([flatRouteConfig], '/')).resolves.toMatchSnapshot();
|
||||
});
|
||||
|
||||
test('invalid route config', async () => {
|
||||
it('rejects invalid route config', async () => {
|
||||
const routeConfigWithoutPath = {
|
||||
component: 'hello/world.js',
|
||||
} as RouteConfig;
|
||||
|
||||
await expect(loadRoutes([routeConfigWithoutPath], '/')).rejects
|
||||
.toMatchInlineSnapshot(`
|
||||
[Error: Invalid route config: path must be a string and component is required.
|
||||
{"component":"hello/world.js"}]
|
||||
`);
|
||||
.toThrowErrorMatchingInlineSnapshot(`
|
||||
"Invalid route config: path must be a string and component is required.
|
||||
{\\"component\\":\\"hello/world.js\\"}"
|
||||
`);
|
||||
|
||||
const routeConfigWithoutComponent = {
|
||||
path: '/hello/world',
|
||||
} as RouteConfig;
|
||||
|
||||
await expect(loadRoutes([routeConfigWithoutComponent], '/')).rejects
|
||||
.toMatchInlineSnapshot(`
|
||||
[Error: Invalid route config: path must be a string and component is required.
|
||||
{"path":"/hello/world"}]
|
||||
`);
|
||||
.toThrowErrorMatchingInlineSnapshot(`
|
||||
"Invalid route config: path must be a string and component is required.
|
||||
{\\"path\\":\\"/hello/world\\"}"
|
||||
`);
|
||||
});
|
||||
|
||||
test('route config with empty (but valid) path string', async () => {
|
||||
it('loads route config with empty (but valid) path string', async () => {
|
||||
const routeConfig = {
|
||||
path: '',
|
||||
component: 'hello/world.js',
|
||||
} as RouteConfig;
|
||||
|
||||
const result = await loadRoutes([routeConfig], '/');
|
||||
expect(result).toMatchSnapshot();
|
||||
await expect(loadRoutes([routeConfig], '/')).resolves.toMatchSnapshot();
|
||||
});
|
||||
});
|
||||
|
|
|
@ -9,7 +9,7 @@ import type {RouteConfig} from '@docusaurus/types';
|
|||
import {getAllFinalRoutes} from '../utils';
|
||||
|
||||
describe('getAllFinalRoutes', () => {
|
||||
test('should get final routes correctly', () => {
|
||||
it('gets final routes correctly', () => {
|
||||
const routes: RouteConfig[] = [
|
||||
{
|
||||
path: '/docs',
|
||||
|
|
|
@ -12,12 +12,12 @@ import pluginFooBar from './__fixtures__/plugin-foo-bar';
|
|||
import pluginHelloWorld from './__fixtures__/plugin-hello-world';
|
||||
|
||||
describe('loadClientModules', () => {
|
||||
test('empty', () => {
|
||||
it('empty', () => {
|
||||
const clientModules = loadClientModules([pluginEmpty()]);
|
||||
expect(clientModules).toMatchInlineSnapshot(`Array []`);
|
||||
});
|
||||
|
||||
test('non-empty', () => {
|
||||
it('non-empty', () => {
|
||||
const clientModules = loadClientModules([pluginFooBar()]);
|
||||
expect(clientModules).toMatchInlineSnapshot(`
|
||||
Array [
|
||||
|
@ -27,7 +27,7 @@ describe('loadClientModules', () => {
|
|||
`);
|
||||
});
|
||||
|
||||
test('multiple non-empty', () => {
|
||||
it('multiple non-empty', () => {
|
||||
const clientModules = loadClientModules([
|
||||
pluginFooBar(),
|
||||
pluginHelloWorld(),
|
||||
|
@ -42,7 +42,7 @@ describe('loadClientModules', () => {
|
|||
`);
|
||||
});
|
||||
|
||||
test('multiple non-empty different order', () => {
|
||||
it('multiple non-empty different order', () => {
|
||||
const clientModules = loadClientModules([
|
||||
pluginHelloWorld(),
|
||||
pluginFooBar(),
|
||||
|
@ -57,7 +57,7 @@ describe('loadClientModules', () => {
|
|||
`);
|
||||
});
|
||||
|
||||
test('empty and non-empty', () => {
|
||||
it('empty and non-empty', () => {
|
||||
const clientModules = loadClientModules([
|
||||
pluginHelloWorld(),
|
||||
pluginEmpty(),
|
||||
|
@ -73,7 +73,7 @@ describe('loadClientModules', () => {
|
|||
`);
|
||||
});
|
||||
|
||||
test('empty and non-empty different order', () => {
|
||||
it('empty and non-empty different order', () => {
|
||||
const clientModules = loadClientModules([
|
||||
pluginHelloWorld(),
|
||||
pluginFooBar(),
|
||||
|
|
|
@ -8,7 +8,7 @@
|
|||
import htmlTagObjectToString from '../htmlTags';
|
||||
|
||||
describe('htmlTagObjectToString', () => {
|
||||
test('valid html tag', () => {
|
||||
it('valid html tag', () => {
|
||||
expect(
|
||||
htmlTagObjectToString({
|
||||
tagName: 'script',
|
||||
|
@ -55,7 +55,7 @@ describe('htmlTagObjectToString', () => {
|
|||
).toMatchInlineSnapshot(`"<div>Test</div>"`);
|
||||
});
|
||||
|
||||
test('valid html void tag', () => {
|
||||
it('valid html void tag', () => {
|
||||
expect(
|
||||
htmlTagObjectToString({
|
||||
tagName: 'meta',
|
||||
|
@ -83,7 +83,7 @@ describe('htmlTagObjectToString', () => {
|
|||
);
|
||||
});
|
||||
|
||||
test('invalid tag', () => {
|
||||
it('invalid tag', () => {
|
||||
expect(() =>
|
||||
htmlTagObjectToString({
|
||||
tagName: 'endiliey',
|
||||
|
@ -96,7 +96,7 @@ describe('htmlTagObjectToString', () => {
|
|||
);
|
||||
});
|
||||
|
||||
test('invalid tagName', () => {
|
||||
it('invalid tagName', () => {
|
||||
expect(() =>
|
||||
htmlTagObjectToString({
|
||||
tagName: true,
|
||||
|
@ -106,7 +106,7 @@ describe('htmlTagObjectToString', () => {
|
|||
);
|
||||
});
|
||||
|
||||
test('invalid html tag object', () => {
|
||||
it('invalid html tag object', () => {
|
||||
expect(() =>
|
||||
htmlTagObjectToString('fooofofoofo'),
|
||||
).toThrowErrorMatchingInlineSnapshot(
|
||||
|
|
|
@ -13,7 +13,7 @@ import pluginHeadTags from './__fixtures__/plugin-headTags';
|
|||
import pluginPostBodyTags from './__fixtures__/plugin-postBodyTags';
|
||||
|
||||
describe('loadHtmlTags', () => {
|
||||
test('empty plugin', () => {
|
||||
it('empty plugin', () => {
|
||||
const htmlTags = loadHtmlTags([pluginEmpty()]);
|
||||
expect(htmlTags).toMatchInlineSnapshot(`
|
||||
Object {
|
||||
|
@ -24,7 +24,7 @@ describe('loadHtmlTags', () => {
|
|||
`);
|
||||
});
|
||||
|
||||
test('only inject headTags', () => {
|
||||
it('only inject headTags', () => {
|
||||
const htmlTags = loadHtmlTags([pluginHeadTags()]);
|
||||
expect(htmlTags).toMatchInlineSnapshot(`
|
||||
Object {
|
||||
|
@ -36,7 +36,7 @@ describe('loadHtmlTags', () => {
|
|||
`);
|
||||
});
|
||||
|
||||
test('only inject preBodyTags', () => {
|
||||
it('only inject preBodyTags', () => {
|
||||
const htmlTags = loadHtmlTags([pluginPreBodyTags()]);
|
||||
expect(htmlTags).toMatchInlineSnapshot(`
|
||||
Object {
|
||||
|
@ -47,7 +47,7 @@ describe('loadHtmlTags', () => {
|
|||
`);
|
||||
});
|
||||
|
||||
test('only inject postBodyTags', () => {
|
||||
it('only inject postBodyTags', () => {
|
||||
const htmlTags = loadHtmlTags([pluginPostBodyTags()]);
|
||||
expect(htmlTags).toMatchInlineSnapshot(`
|
||||
Object {
|
||||
|
@ -58,7 +58,7 @@ describe('loadHtmlTags', () => {
|
|||
`);
|
||||
});
|
||||
|
||||
test('multiple plugins that inject different part of html tags', () => {
|
||||
it('multiple plugins that inject different part of html tags', () => {
|
||||
const htmlTags = loadHtmlTags([
|
||||
pluginHeadTags(),
|
||||
pluginPostBodyTags(),
|
||||
|
@ -74,7 +74,7 @@ describe('loadHtmlTags', () => {
|
|||
`);
|
||||
});
|
||||
|
||||
test('multiple plugins that might/might not inject html tags', () => {
|
||||
it('multiple plugins that might/might not inject html tags', () => {
|
||||
const htmlTags = loadHtmlTags([
|
||||
pluginEmpty(),
|
||||
pluginHeadTags(),
|
||||
|
|
|
@ -28,7 +28,7 @@ Example valid plugin config:
|
|||
"
|
||||
`;
|
||||
|
||||
exports[`sortConfig should sort route config correctly 1`] = `
|
||||
exports[`sortConfig sorts route config correctly 1`] = `
|
||||
Array [
|
||||
Object {
|
||||
"component": "",
|
||||
|
@ -83,7 +83,7 @@ Array [
|
|||
]
|
||||
`;
|
||||
|
||||
exports[`sortConfig should sort route config given a baseURL 1`] = `
|
||||
exports[`sortConfig sorts route config given a baseURL 1`] = `
|
||||
Array [
|
||||
Object {
|
||||
"component": "",
|
||||
|
|
|
@ -27,7 +27,7 @@ function params(
|
|||
}
|
||||
|
||||
describe('applyRouteTrailingSlash', () => {
|
||||
test('apply to empty', () => {
|
||||
it('apply to empty', () => {
|
||||
expect(applyRouteTrailingSlash(route(''), params(true))).toEqual(
|
||||
route('/'),
|
||||
);
|
||||
|
@ -39,7 +39,7 @@ describe('applyRouteTrailingSlash', () => {
|
|||
);
|
||||
});
|
||||
|
||||
test('apply to /', () => {
|
||||
it('apply to /', () => {
|
||||
expect(applyRouteTrailingSlash(route('/'), params(true))).toEqual(
|
||||
route('/'),
|
||||
);
|
||||
|
@ -51,7 +51,7 @@ describe('applyRouteTrailingSlash', () => {
|
|||
);
|
||||
});
|
||||
|
||||
test('apply to /abc', () => {
|
||||
it('apply to /abc', () => {
|
||||
expect(applyRouteTrailingSlash(route('/abc'), params(true))).toEqual(
|
||||
route('/abc/'),
|
||||
);
|
||||
|
@ -63,7 +63,7 @@ describe('applyRouteTrailingSlash', () => {
|
|||
);
|
||||
});
|
||||
|
||||
test('apply to /abc/', () => {
|
||||
it('apply to /abc/', () => {
|
||||
expect(applyRouteTrailingSlash(route('/abc/'), params(true))).toEqual(
|
||||
route('/abc/'),
|
||||
);
|
||||
|
@ -75,7 +75,7 @@ describe('applyRouteTrailingSlash', () => {
|
|||
);
|
||||
});
|
||||
|
||||
test('apply to /abc?search#anchor', () => {
|
||||
it('apply to /abc?search#anchor', () => {
|
||||
expect(
|
||||
applyRouteTrailingSlash(route('/abc?search#anchor'), params(true)),
|
||||
).toEqual(route('/abc/?search#anchor'));
|
||||
|
@ -87,7 +87,7 @@ describe('applyRouteTrailingSlash', () => {
|
|||
).toEqual(route('/abc?search#anchor'));
|
||||
});
|
||||
|
||||
test('apply to /abc/?search#anchor', () => {
|
||||
it('apply to /abc/?search#anchor', () => {
|
||||
expect(
|
||||
applyRouteTrailingSlash(route('/abc/?search#anchor'), params(true)),
|
||||
).toEqual(route('/abc/?search#anchor'));
|
||||
|
@ -99,7 +99,7 @@ describe('applyRouteTrailingSlash', () => {
|
|||
).toEqual(route('/abc/?search#anchor'));
|
||||
});
|
||||
|
||||
test('not apply to /abc/?search#anchor when baseUrl=/abc/', () => {
|
||||
it('not apply to /abc/?search#anchor when baseUrl=/abc/', () => {
|
||||
const baseUrl = '/abc/';
|
||||
expect(
|
||||
applyRouteTrailingSlash(
|
||||
|
@ -121,7 +121,7 @@ describe('applyRouteTrailingSlash', () => {
|
|||
).toEqual(route('/abc/?search#anchor'));
|
||||
});
|
||||
|
||||
test('apply to subroutes', () => {
|
||||
it('apply to subroutes', () => {
|
||||
expect(
|
||||
applyRouteTrailingSlash(
|
||||
route('/abc', ['/abc/1', '/abc/2']),
|
||||
|
@ -142,7 +142,7 @@ describe('applyRouteTrailingSlash', () => {
|
|||
).toEqual(route('/abc', ['/abc/1', '/abc/2']));
|
||||
});
|
||||
|
||||
test('apply for complex case', () => {
|
||||
it('apply for complex case', () => {
|
||||
expect(
|
||||
applyRouteTrailingSlash(
|
||||
route('/abc?search#anchor', ['/abc/1?search', '/abc/2#anchor']),
|
||||
|
@ -153,7 +153,7 @@ describe('applyRouteTrailingSlash', () => {
|
|||
);
|
||||
});
|
||||
|
||||
test('apply for complex case with baseUrl', () => {
|
||||
it('apply for complex case with baseUrl', () => {
|
||||
const baseUrl = '/abc/';
|
||||
expect(
|
||||
applyRouteTrailingSlash(
|
||||
|
|
|
@ -29,7 +29,7 @@ describe('initPlugins', () => {
|
|||
return {siteDir, context, plugins};
|
||||
}
|
||||
|
||||
test('plugins gets parsed correctly and loads in correct order', async () => {
|
||||
it('plugins gets parsed correctly and loads in correct order', async () => {
|
||||
const {context, plugins} = await loadSite();
|
||||
expect(context.siteConfig.plugins?.length).toBe(4);
|
||||
expect(plugins.length).toBe(8);
|
||||
|
@ -45,7 +45,7 @@ describe('initPlugins', () => {
|
|||
expect(context.siteConfig.themeConfig).toEqual({a: 1});
|
||||
});
|
||||
|
||||
test('plugins with bad values throw user-friendly error message', async () => {
|
||||
it('plugins with bad values throw user-friendly error message', async () => {
|
||||
await expect(() =>
|
||||
loadSite({
|
||||
customConfigFilePath: 'badPlugins.docusaurus.config.js',
|
||||
|
@ -55,7 +55,7 @@ describe('initPlugins', () => {
|
|||
});
|
||||
|
||||
describe('sortConfig', () => {
|
||||
test('should sort route config correctly', () => {
|
||||
it('sorts route config correctly', () => {
|
||||
const routes: RouteConfig[] = [
|
||||
{
|
||||
path: '/',
|
||||
|
@ -97,7 +97,7 @@ describe('sortConfig', () => {
|
|||
expect(routes).toMatchSnapshot();
|
||||
});
|
||||
|
||||
test('should sort route config given a baseURL', () => {
|
||||
it('sorts route config given a baseURL', () => {
|
||||
const baseURL = '/latest';
|
||||
const routes: RouteConfig[] = [
|
||||
{
|
||||
|
|
|
@ -17,7 +17,7 @@ function createTestPlugin(name: string, id?: string): InitializedPlugin {
|
|||
}
|
||||
|
||||
describe('ensureUniquePluginInstanceIds', () => {
|
||||
test('accept single instance plugins', async () => {
|
||||
it('accept single instance plugins', async () => {
|
||||
ensureUniquePluginInstanceIds([
|
||||
createTestPlugin('plugin-docs'),
|
||||
createTestPlugin('plugin-blog'),
|
||||
|
@ -25,7 +25,7 @@ describe('ensureUniquePluginInstanceIds', () => {
|
|||
]);
|
||||
});
|
||||
|
||||
test('accept single instance plugins, all with sameId', async () => {
|
||||
it('accept single instance plugins, all with sameId', async () => {
|
||||
ensureUniquePluginInstanceIds([
|
||||
createTestPlugin('plugin-docs', 'sameId'),
|
||||
createTestPlugin('plugin-blog', 'sameId'),
|
||||
|
@ -33,7 +33,7 @@ describe('ensureUniquePluginInstanceIds', () => {
|
|||
]);
|
||||
});
|
||||
|
||||
test('accept multi instance plugins without id', async () => {
|
||||
it('accept multi instance plugins without id', async () => {
|
||||
ensureUniquePluginInstanceIds([
|
||||
createTestPlugin('plugin-docs', 'ios'),
|
||||
createTestPlugin('plugin-docs', 'android'),
|
||||
|
@ -41,7 +41,7 @@ describe('ensureUniquePluginInstanceIds', () => {
|
|||
]);
|
||||
});
|
||||
|
||||
test('reject multi instance plugins without id', async () => {
|
||||
it('reject multi instance plugins without id', async () => {
|
||||
expect(() =>
|
||||
ensureUniquePluginInstanceIds([
|
||||
createTestPlugin('plugin-docs'),
|
||||
|
@ -50,7 +50,7 @@ describe('ensureUniquePluginInstanceIds', () => {
|
|||
).toThrowErrorMatchingSnapshot();
|
||||
});
|
||||
|
||||
test('reject multi instance plugins with same id', async () => {
|
||||
it('reject multi instance plugins with same id', async () => {
|
||||
expect(() =>
|
||||
ensureUniquePluginInstanceIds([
|
||||
createTestPlugin('plugin-docs', 'sameId'),
|
||||
|
@ -59,7 +59,7 @@ describe('ensureUniquePluginInstanceIds', () => {
|
|||
).toThrowErrorMatchingSnapshot();
|
||||
});
|
||||
|
||||
test('reject multi instance plugins with some without id', async () => {
|
||||
it('reject multi instance plugins with some without id', async () => {
|
||||
expect(() =>
|
||||
ensureUniquePluginInstanceIds([
|
||||
createTestPlugin('plugin-docs'),
|
||||
|
|
|
@ -0,0 +1,164 @@
|
|||
// Jest Snapshot v1, https://goo.gl/fbAQLP
|
||||
|
||||
exports[`loadPresets array form 1`] = `
|
||||
Object {
|
||||
"plugins": Array [
|
||||
Array [
|
||||
"@docusaurus/plugin-content-docs",
|
||||
undefined,
|
||||
],
|
||||
Array [
|
||||
"@docusaurus/plugin-content-blog",
|
||||
undefined,
|
||||
],
|
||||
],
|
||||
"themes": Array [],
|
||||
}
|
||||
`;
|
||||
|
||||
exports[`loadPresets array form composite 1`] = `
|
||||
Object {
|
||||
"plugins": Array [
|
||||
Array [
|
||||
"@docusaurus/plugin-content-docs",
|
||||
Object {
|
||||
"path": "../",
|
||||
},
|
||||
],
|
||||
Array [
|
||||
"@docusaurus/plugin-content-blog",
|
||||
undefined,
|
||||
],
|
||||
Array [
|
||||
"@docusaurus/plugin-content-pages",
|
||||
Object {
|
||||
"path": "../",
|
||||
},
|
||||
],
|
||||
Array [
|
||||
"@docusaurus/plugin-sitemap",
|
||||
undefined,
|
||||
],
|
||||
],
|
||||
"themes": Array [],
|
||||
}
|
||||
`;
|
||||
|
||||
exports[`loadPresets array form with options 1`] = `
|
||||
Object {
|
||||
"plugins": Array [
|
||||
Array [
|
||||
"@docusaurus/plugin-content-docs",
|
||||
Object {
|
||||
"path": "../",
|
||||
},
|
||||
],
|
||||
Array [
|
||||
"@docusaurus/plugin-content-blog",
|
||||
undefined,
|
||||
],
|
||||
],
|
||||
"themes": Array [],
|
||||
}
|
||||
`;
|
||||
|
||||
exports[`loadPresets mixed form 1`] = `
|
||||
Object {
|
||||
"plugins": Array [
|
||||
Array [
|
||||
"@docusaurus/plugin-content-docs",
|
||||
Object {
|
||||
"path": "../",
|
||||
},
|
||||
],
|
||||
Array [
|
||||
"@docusaurus/plugin-content-blog",
|
||||
undefined,
|
||||
],
|
||||
Array [
|
||||
"@docusaurus/plugin-content-pages",
|
||||
undefined,
|
||||
],
|
||||
Array [
|
||||
"@docusaurus/plugin-sitemap",
|
||||
undefined,
|
||||
],
|
||||
],
|
||||
"themes": Array [],
|
||||
}
|
||||
`;
|
||||
|
||||
exports[`loadPresets mixed form with themes 1`] = `
|
||||
Object {
|
||||
"plugins": Array [
|
||||
Array [
|
||||
"@docusaurus/plugin-content-docs",
|
||||
Object {
|
||||
"path": "../",
|
||||
},
|
||||
],
|
||||
Array [
|
||||
"@docusaurus/plugin-content-blog",
|
||||
undefined,
|
||||
],
|
||||
Array [
|
||||
"@docusaurus/plugin-content-pages",
|
||||
undefined,
|
||||
],
|
||||
Array [
|
||||
"@docusaurus/plugin-sitemap",
|
||||
undefined,
|
||||
],
|
||||
Array [
|
||||
"@docusaurus/plugin-test",
|
||||
undefined,
|
||||
],
|
||||
],
|
||||
"themes": Array [
|
||||
Array [
|
||||
"@docusaurus/theme-classic",
|
||||
undefined,
|
||||
],
|
||||
],
|
||||
}
|
||||
`;
|
||||
|
||||
exports[`loadPresets string form 1`] = `
|
||||
Object {
|
||||
"plugins": Array [
|
||||
Array [
|
||||
"@docusaurus/plugin-content-docs",
|
||||
undefined,
|
||||
],
|
||||
Array [
|
||||
"@docusaurus/plugin-content-blog",
|
||||
undefined,
|
||||
],
|
||||
],
|
||||
"themes": Array [],
|
||||
}
|
||||
`;
|
||||
|
||||
exports[`loadPresets string form composite 1`] = `
|
||||
Object {
|
||||
"plugins": Array [
|
||||
Array [
|
||||
"@docusaurus/plugin-content-docs",
|
||||
undefined,
|
||||
],
|
||||
Array [
|
||||
"@docusaurus/plugin-content-blog",
|
||||
undefined,
|
||||
],
|
||||
Array [
|
||||
"@docusaurus/plugin-content-pages",
|
||||
undefined,
|
||||
],
|
||||
Array [
|
||||
"@docusaurus/plugin-sitemap",
|
||||
undefined,
|
||||
],
|
||||
],
|
||||
"themes": Array [],
|
||||
}
|
||||
`;
|
|
@ -11,7 +11,7 @@ import loadPresets from '../index';
|
|||
import type {LoadContext} from '@docusaurus/types';
|
||||
|
||||
describe('loadPresets', () => {
|
||||
test('no presets', async () => {
|
||||
it('no presets', async () => {
|
||||
const context = {
|
||||
siteConfigPath: __dirname,
|
||||
siteConfig: {
|
||||
|
@ -27,7 +27,7 @@ describe('loadPresets', () => {
|
|||
`);
|
||||
});
|
||||
|
||||
test('string form', async () => {
|
||||
it('string form', async () => {
|
||||
const context = {
|
||||
siteConfigPath: __dirname,
|
||||
siteConfig: {
|
||||
|
@ -35,24 +35,10 @@ describe('loadPresets', () => {
|
|||
},
|
||||
} as LoadContext;
|
||||
const presets = await loadPresets(context);
|
||||
expect(presets).toMatchInlineSnapshot(`
|
||||
Object {
|
||||
"plugins": Array [
|
||||
Array [
|
||||
"@docusaurus/plugin-content-docs",
|
||||
undefined,
|
||||
],
|
||||
Array [
|
||||
"@docusaurus/plugin-content-blog",
|
||||
undefined,
|
||||
],
|
||||
],
|
||||
"themes": Array [],
|
||||
}
|
||||
`);
|
||||
expect(presets).toMatchSnapshot();
|
||||
});
|
||||
|
||||
test('string form composite', async () => {
|
||||
it('string form composite', async () => {
|
||||
const context = {
|
||||
siteConfigPath: __dirname,
|
||||
siteConfig: {
|
||||
|
@ -63,32 +49,10 @@ describe('loadPresets', () => {
|
|||
},
|
||||
} as LoadContext;
|
||||
const presets = await loadPresets(context);
|
||||
expect(presets).toMatchInlineSnapshot(`
|
||||
Object {
|
||||
"plugins": Array [
|
||||
Array [
|
||||
"@docusaurus/plugin-content-docs",
|
||||
undefined,
|
||||
],
|
||||
Array [
|
||||
"@docusaurus/plugin-content-blog",
|
||||
undefined,
|
||||
],
|
||||
Array [
|
||||
"@docusaurus/plugin-content-pages",
|
||||
undefined,
|
||||
],
|
||||
Array [
|
||||
"@docusaurus/plugin-sitemap",
|
||||
undefined,
|
||||
],
|
||||
],
|
||||
"themes": Array [],
|
||||
}
|
||||
`);
|
||||
expect(presets).toMatchSnapshot();
|
||||
});
|
||||
|
||||
test('array form', async () => {
|
||||
it('array form', async () => {
|
||||
const context = {
|
||||
siteConfigPath: __dirname,
|
||||
siteConfig: {
|
||||
|
@ -96,24 +60,10 @@ describe('loadPresets', () => {
|
|||
},
|
||||
} as Partial<LoadContext>;
|
||||
const presets = await loadPresets(context);
|
||||
expect(presets).toMatchInlineSnapshot(`
|
||||
Object {
|
||||
"plugins": Array [
|
||||
Array [
|
||||
"@docusaurus/plugin-content-docs",
|
||||
undefined,
|
||||
],
|
||||
Array [
|
||||
"@docusaurus/plugin-content-blog",
|
||||
undefined,
|
||||
],
|
||||
],
|
||||
"themes": Array [],
|
||||
}
|
||||
`);
|
||||
expect(presets).toMatchSnapshot();
|
||||
});
|
||||
|
||||
test('array form with options', async () => {
|
||||
it('array form with options', async () => {
|
||||
const context = {
|
||||
siteConfigPath: __dirname,
|
||||
siteConfig: {
|
||||
|
@ -126,26 +76,10 @@ describe('loadPresets', () => {
|
|||
},
|
||||
} as Partial<LoadContext>;
|
||||
const presets = await loadPresets(context);
|
||||
expect(presets).toMatchInlineSnapshot(`
|
||||
Object {
|
||||
"plugins": Array [
|
||||
Array [
|
||||
"@docusaurus/plugin-content-docs",
|
||||
Object {
|
||||
"path": "../",
|
||||
},
|
||||
],
|
||||
Array [
|
||||
"@docusaurus/plugin-content-blog",
|
||||
undefined,
|
||||
],
|
||||
],
|
||||
"themes": Array [],
|
||||
}
|
||||
`);
|
||||
expect(presets).toMatchSnapshot();
|
||||
});
|
||||
|
||||
test('array form composite', async () => {
|
||||
it('array form composite', async () => {
|
||||
const context = {
|
||||
siteConfigPath: __dirname,
|
||||
siteConfig: {
|
||||
|
@ -162,36 +96,10 @@ describe('loadPresets', () => {
|
|||
},
|
||||
} as Partial<LoadContext>;
|
||||
const presets = await loadPresets(context);
|
||||
expect(presets).toMatchInlineSnapshot(`
|
||||
Object {
|
||||
"plugins": Array [
|
||||
Array [
|
||||
"@docusaurus/plugin-content-docs",
|
||||
Object {
|
||||
"path": "../",
|
||||
},
|
||||
],
|
||||
Array [
|
||||
"@docusaurus/plugin-content-blog",
|
||||
undefined,
|
||||
],
|
||||
Array [
|
||||
"@docusaurus/plugin-content-pages",
|
||||
Object {
|
||||
"path": "../",
|
||||
},
|
||||
],
|
||||
Array [
|
||||
"@docusaurus/plugin-sitemap",
|
||||
undefined,
|
||||
],
|
||||
],
|
||||
"themes": Array [],
|
||||
}
|
||||
`);
|
||||
expect(presets).toMatchSnapshot();
|
||||
});
|
||||
|
||||
test('mixed form', async () => {
|
||||
it('mixed form', async () => {
|
||||
const context = {
|
||||
siteConfigPath: __dirname,
|
||||
siteConfig: {
|
||||
|
@ -205,34 +113,10 @@ describe('loadPresets', () => {
|
|||
},
|
||||
} as LoadContext;
|
||||
const presets = await loadPresets(context);
|
||||
expect(presets).toMatchInlineSnapshot(`
|
||||
Object {
|
||||
"plugins": Array [
|
||||
Array [
|
||||
"@docusaurus/plugin-content-docs",
|
||||
Object {
|
||||
"path": "../",
|
||||
},
|
||||
],
|
||||
Array [
|
||||
"@docusaurus/plugin-content-blog",
|
||||
undefined,
|
||||
],
|
||||
Array [
|
||||
"@docusaurus/plugin-content-pages",
|
||||
undefined,
|
||||
],
|
||||
Array [
|
||||
"@docusaurus/plugin-sitemap",
|
||||
undefined,
|
||||
],
|
||||
],
|
||||
"themes": Array [],
|
||||
}
|
||||
`);
|
||||
expect(presets).toMatchSnapshot();
|
||||
});
|
||||
|
||||
test('mixed form with themes', async () => {
|
||||
it('mixed form with themes', async () => {
|
||||
const context = {
|
||||
siteConfigPath: __dirname,
|
||||
siteConfig: {
|
||||
|
@ -247,39 +131,6 @@ describe('loadPresets', () => {
|
|||
},
|
||||
} as LoadContext;
|
||||
const presets = await loadPresets(context);
|
||||
expect(presets).toMatchInlineSnapshot(`
|
||||
Object {
|
||||
"plugins": Array [
|
||||
Array [
|
||||
"@docusaurus/plugin-content-docs",
|
||||
Object {
|
||||
"path": "../",
|
||||
},
|
||||
],
|
||||
Array [
|
||||
"@docusaurus/plugin-content-blog",
|
||||
undefined,
|
||||
],
|
||||
Array [
|
||||
"@docusaurus/plugin-content-pages",
|
||||
undefined,
|
||||
],
|
||||
Array [
|
||||
"@docusaurus/plugin-sitemap",
|
||||
undefined,
|
||||
],
|
||||
Array [
|
||||
"@docusaurus/plugin-test",
|
||||
undefined,
|
||||
],
|
||||
],
|
||||
"themes": Array [
|
||||
Array [
|
||||
"@docusaurus/theme-classic",
|
||||
undefined,
|
||||
],
|
||||
],
|
||||
}
|
||||
`);
|
||||
expect(presets).toMatchSnapshot();
|
||||
});
|
||||
});
|
||||
|
|
|
@ -10,7 +10,7 @@ import fs from 'fs-extra';
|
|||
import themeAlias from '../alias';
|
||||
|
||||
describe('themeAlias', () => {
|
||||
test('valid themePath 1 with components', async () => {
|
||||
it('valid themePath 1 with components', async () => {
|
||||
const fixtures = path.join(__dirname, '__fixtures__');
|
||||
const themePath = path.join(fixtures, 'theme-1');
|
||||
const alias = await themeAlias(themePath, true);
|
||||
|
@ -26,7 +26,7 @@ describe('themeAlias', () => {
|
|||
expect(alias).not.toEqual({});
|
||||
});
|
||||
|
||||
test('valid themePath 1 with components without original', async () => {
|
||||
it('valid themePath 1 with components without original', async () => {
|
||||
const fixtures = path.join(__dirname, '__fixtures__');
|
||||
const themePath = path.join(fixtures, 'theme-1');
|
||||
const alias = await themeAlias(themePath, false);
|
||||
|
@ -40,7 +40,7 @@ describe('themeAlias', () => {
|
|||
expect(alias).not.toEqual({});
|
||||
});
|
||||
|
||||
test('valid themePath 2 with components', async () => {
|
||||
it('valid themePath 2 with components', async () => {
|
||||
const fixtures = path.join(__dirname, '__fixtures__');
|
||||
const themePath = path.join(fixtures, 'theme-2');
|
||||
const alias = await themeAlias(themePath, true);
|
||||
|
@ -83,7 +83,7 @@ describe('themeAlias', () => {
|
|||
expect(alias).not.toEqual({});
|
||||
});
|
||||
|
||||
test('valid themePath 2 with components without original', async () => {
|
||||
it('valid themePath 2 with components without original', async () => {
|
||||
const fixtures = path.join(__dirname, '__fixtures__');
|
||||
const themePath = path.join(fixtures, 'theme-2');
|
||||
const alias = await themeAlias(themePath, false);
|
||||
|
@ -107,7 +107,7 @@ describe('themeAlias', () => {
|
|||
expect(alias).not.toEqual({});
|
||||
});
|
||||
|
||||
test('valid themePath with no components', async () => {
|
||||
it('valid themePath with no components', async () => {
|
||||
const fixtures = path.join(__dirname, '__fixtures__');
|
||||
const themePath = path.join(fixtures, 'empty-theme');
|
||||
await fs.ensureDir(themePath);
|
||||
|
@ -115,7 +115,7 @@ describe('themeAlias', () => {
|
|||
expect(alias).toEqual({});
|
||||
});
|
||||
|
||||
test('valid themePath with no components without original', async () => {
|
||||
it('valid themePath with no components without original', async () => {
|
||||
const fixtures = path.join(__dirname, '__fixtures__');
|
||||
const themePath = path.join(fixtures, 'empty-theme');
|
||||
await fs.ensureDir(themePath);
|
||||
|
@ -123,7 +123,7 @@ describe('themeAlias', () => {
|
|||
expect(alias).toEqual({});
|
||||
});
|
||||
|
||||
test('invalid themePath that does not exist', async () => {
|
||||
it('invalid themePath that does not exist', async () => {
|
||||
const fixtures = path.join(__dirname, '__fixtures__');
|
||||
const themePath = path.join(fixtures, '__noExist__');
|
||||
const alias = await themeAlias(themePath, true);
|
||||
|
|
|
@ -9,7 +9,7 @@ import path from 'path';
|
|||
import {loadThemeAliases} from '../index';
|
||||
|
||||
describe('loadThemeAliases', () => {
|
||||
test('next alias can override the previous alias', async () => {
|
||||
it('next alias can override the previous alias', async () => {
|
||||
const fixtures = path.join(__dirname, '__fixtures__');
|
||||
const theme1Path = path.join(fixtures, 'theme-1');
|
||||
const theme2Path = path.join(fixtures, 'theme-2');
|
||||
|
|
|
@ -52,7 +52,7 @@ async function createTmpTranslationFile(
|
|||
}
|
||||
|
||||
describe('ensureTranslationFileContent', () => {
|
||||
test('should pass valid translation file content', () => {
|
||||
it('passes valid translation file content', () => {
|
||||
ensureTranslationFileContent({});
|
||||
ensureTranslationFileContent({key1: {message: ''}});
|
||||
ensureTranslationFileContent({key1: {message: 'abc'}});
|
||||
|
@ -63,7 +63,7 @@ describe('ensureTranslationFileContent', () => {
|
|||
});
|
||||
});
|
||||
|
||||
test('should fail for invalid translation file content', () => {
|
||||
it('fails for invalid translation file content', () => {
|
||||
expect(() =>
|
||||
ensureTranslationFileContent(null),
|
||||
).toThrowErrorMatchingInlineSnapshot(
|
||||
|
@ -101,7 +101,7 @@ describe('ensureTranslationFileContent', () => {
|
|||
});
|
||||
|
||||
describe('writeTranslationFileContent', () => {
|
||||
test('should create new translation file', async () => {
|
||||
it('creates new translation file', async () => {
|
||||
const {filePath, readFile} = await createTmpTranslationFile(null);
|
||||
|
||||
await writeTranslationFileContent({
|
||||
|
@ -120,7 +120,7 @@ describe('writeTranslationFileContent', () => {
|
|||
});
|
||||
});
|
||||
|
||||
test('should create new translation file with prefix', async () => {
|
||||
it('creates new translation file with prefix', async () => {
|
||||
const {filePath, readFile} = await createTmpTranslationFile(null);
|
||||
|
||||
await writeTranslationFileContent({
|
||||
|
@ -142,7 +142,7 @@ describe('writeTranslationFileContent', () => {
|
|||
});
|
||||
});
|
||||
|
||||
test('should append missing translations', async () => {
|
||||
it('appends missing translations', async () => {
|
||||
const {filePath, readFile} = await createTmpTranslationFile({
|
||||
key1: {message: 'key1 message'},
|
||||
key2: {message: 'key2 message'},
|
||||
|
@ -167,7 +167,7 @@ describe('writeTranslationFileContent', () => {
|
|||
});
|
||||
});
|
||||
|
||||
test('should append missing translations with prefix', async () => {
|
||||
it('appends missing translations with prefix', async () => {
|
||||
const {filePath, readFile} = await createTmpTranslationFile({
|
||||
key1: {message: 'key1 message'},
|
||||
});
|
||||
|
@ -189,7 +189,7 @@ describe('writeTranslationFileContent', () => {
|
|||
});
|
||||
});
|
||||
|
||||
test('should override missing translations', async () => {
|
||||
it('overrides missing translations', async () => {
|
||||
const {filePath, readFile} = await createTmpTranslationFile({
|
||||
key1: {message: 'key1 message'},
|
||||
});
|
||||
|
@ -211,7 +211,7 @@ describe('writeTranslationFileContent', () => {
|
|||
});
|
||||
});
|
||||
|
||||
test('should override missing translations with prefix', async () => {
|
||||
it('overrides missing translations with prefix', async () => {
|
||||
const {filePath, readFile} = await createTmpTranslationFile({
|
||||
key1: {message: 'key1 message'},
|
||||
});
|
||||
|
@ -234,7 +234,7 @@ describe('writeTranslationFileContent', () => {
|
|||
});
|
||||
});
|
||||
|
||||
test('should always override message description', async () => {
|
||||
it('always overrides message description', async () => {
|
||||
const {filePath, readFile} = await createTmpTranslationFile({
|
||||
key1: {message: 'key1 message', description: 'key1 desc'},
|
||||
key2: {message: 'key2 message', description: 'key2 desc'},
|
||||
|
@ -257,7 +257,7 @@ describe('writeTranslationFileContent', () => {
|
|||
});
|
||||
});
|
||||
|
||||
test('should throw for invalid content', async () => {
|
||||
it('throws for invalid content', async () => {
|
||||
const {filePath} = await createTmpTranslationFile(
|
||||
// @ts-expect-error: bad content on purpose
|
||||
{bad: 'content'},
|
||||
|
@ -277,7 +277,7 @@ describe('writeTranslationFileContent', () => {
|
|||
});
|
||||
|
||||
describe('writePluginTranslations', () => {
|
||||
test('should write plugin translations', async () => {
|
||||
it('writes plugin translations', async () => {
|
||||
const siteDir = await createTmpSiteDir();
|
||||
|
||||
const filePath = path.join(
|
||||
|
@ -315,7 +315,7 @@ describe('writePluginTranslations', () => {
|
|||
});
|
||||
});
|
||||
|
||||
test('should write plugin translations consecutively with different options', async () => {
|
||||
it('writes plugin translations consecutively with different options', async () => {
|
||||
const siteDir = await createTmpSiteDir();
|
||||
|
||||
const filePath = path.join(
|
||||
|
@ -396,7 +396,7 @@ describe('writePluginTranslations', () => {
|
|||
});
|
||||
|
||||
describe('localizePluginTranslationFile', () => {
|
||||
test('not localize if localized file does not exist', async () => {
|
||||
it('does not localize if localized file does not exist', async () => {
|
||||
const siteDir = await createTmpSiteDir();
|
||||
|
||||
const translationFile: TranslationFile = {
|
||||
|
@ -422,7 +422,7 @@ describe('localizePluginTranslationFile', () => {
|
|||
expect(localizedTranslationFile).toEqual(translationFile);
|
||||
});
|
||||
|
||||
test('not localize if localized file does not exist 2', async () => {
|
||||
it('does not localize if localized file does not exist 2', async () => {
|
||||
const siteDir = await createTmpSiteDir();
|
||||
|
||||
await writeTranslationFileContent({
|
||||
|
@ -481,21 +481,21 @@ describe('getPluginsDefaultCodeTranslationMessages', () => {
|
|||
return {getDefaultCodeTranslationMessages: fn} as InitializedPlugin;
|
||||
}
|
||||
|
||||
test('for empty plugins', async () => {
|
||||
it('works for empty plugins', async () => {
|
||||
const plugins: InitializedPlugin[] = [];
|
||||
await expect(
|
||||
getPluginsDefaultCodeTranslationMessages(plugins),
|
||||
).resolves.toEqual({});
|
||||
});
|
||||
|
||||
test('for 1 plugin without lifecycle', async () => {
|
||||
it('works for 1 plugin without lifecycle', async () => {
|
||||
const plugins: InitializedPlugin[] = [createTestPlugin(undefined)];
|
||||
await expect(
|
||||
getPluginsDefaultCodeTranslationMessages(plugins),
|
||||
).resolves.toEqual({});
|
||||
});
|
||||
|
||||
test('for 1 plugin with lifecycle', async () => {
|
||||
it('works for 1 plugin with lifecycle', async () => {
|
||||
const plugins: InitializedPlugin[] = [
|
||||
createTestPlugin(async () => ({
|
||||
a: '1',
|
||||
|
@ -510,7 +510,7 @@ describe('getPluginsDefaultCodeTranslationMessages', () => {
|
|||
});
|
||||
});
|
||||
|
||||
test('for 2 plugins with lifecycles', async () => {
|
||||
it('works for 2 plugins with lifecycles', async () => {
|
||||
const plugins: InitializedPlugin[] = [
|
||||
createTestPlugin(async () => ({
|
||||
a: '1',
|
||||
|
@ -531,7 +531,7 @@ describe('getPluginsDefaultCodeTranslationMessages', () => {
|
|||
});
|
||||
});
|
||||
|
||||
test('for realistic use-case', async () => {
|
||||
it('works for realistic use-case', async () => {
|
||||
const plugins: InitializedPlugin[] = [
|
||||
createTestPlugin(undefined),
|
||||
createTestPlugin(async () => ({
|
||||
|
@ -566,7 +566,7 @@ describe('applyDefaultCodeTranslations', () => {
|
|||
consoleSpy.mockClear();
|
||||
});
|
||||
|
||||
test('for no code and message', () => {
|
||||
it('works for no code and message', () => {
|
||||
expect(
|
||||
applyDefaultCodeTranslations({
|
||||
extractedCodeTranslations: {},
|
||||
|
@ -576,7 +576,7 @@ describe('applyDefaultCodeTranslations', () => {
|
|||
expect(consoleSpy).toHaveBeenCalledTimes(0);
|
||||
});
|
||||
|
||||
test('for code and message', () => {
|
||||
it('works for code and message', () => {
|
||||
expect(
|
||||
applyDefaultCodeTranslations({
|
||||
extractedCodeTranslations: {
|
||||
|
@ -598,7 +598,7 @@ describe('applyDefaultCodeTranslations', () => {
|
|||
expect(consoleSpy).toHaveBeenCalledTimes(0);
|
||||
});
|
||||
|
||||
test('for code and message mismatch', () => {
|
||||
it('works for code and message mismatch', () => {
|
||||
expect(
|
||||
applyDefaultCodeTranslations({
|
||||
extractedCodeTranslations: {
|
||||
|
@ -621,7 +621,7 @@ describe('applyDefaultCodeTranslations', () => {
|
|||
expect(consoleSpy.mock.calls[0][0]).toMatch(/unknownId/);
|
||||
});
|
||||
|
||||
test('for realistic scenario', () => {
|
||||
it('works for realistic scenario', () => {
|
||||
expect(
|
||||
applyDefaultCodeTranslations({
|
||||
extractedCodeTranslations: {
|
||||
|
|
|
@ -47,8 +47,8 @@ async function createTmpSourceCodeFile({
|
|||
};
|
||||
}
|
||||
|
||||
describe('extractSourceCodeTranslations', () => {
|
||||
test('throw for bad source code', async () => {
|
||||
describe('extractSourceCodeFileTranslations', () => {
|
||||
it('throws for bad source code', async () => {
|
||||
const {sourceCodeFilePath} = await createTmpSourceCodeFile({
|
||||
extension: 'js',
|
||||
content: `
|
||||
|
@ -58,7 +58,7 @@ const default => {
|
|||
`,
|
||||
});
|
||||
|
||||
const errorMock = jest.spyOn(console, 'error').mockImplementation();
|
||||
const errorMock = jest.spyOn(console, 'error').mockImplementation(() => {});
|
||||
|
||||
await expect(
|
||||
extractSourceCodeFileTranslations(sourceCodeFilePath, TestBabelOptions),
|
||||
|
@ -71,7 +71,7 @@ const default => {
|
|||
);
|
||||
});
|
||||
|
||||
test('extract nothing from untranslated source code', async () => {
|
||||
it('extracts nothing from untranslated source code', async () => {
|
||||
const {sourceCodeFilePath} = await createTmpSourceCodeFile({
|
||||
extension: 'js',
|
||||
content: `
|
||||
|
@ -91,7 +91,7 @@ const unrelated = 42;
|
|||
});
|
||||
});
|
||||
|
||||
test('extract from a translate() functions calls', async () => {
|
||||
it('extracts from a translate() functions calls', async () => {
|
||||
const {sourceCodeFilePath} = await createTmpSourceCodeFile({
|
||||
extension: 'js',
|
||||
content: `
|
||||
|
@ -124,7 +124,7 @@ export default function MyComponent() {
|
|||
});
|
||||
});
|
||||
|
||||
test('extract from a <Translate> components', async () => {
|
||||
it('extracts from a <Translate> components', async () => {
|
||||
const {sourceCodeFilePath} = await createTmpSourceCodeFile({
|
||||
extension: 'js',
|
||||
content: `
|
||||
|
@ -159,7 +159,7 @@ export default function MyComponent() {
|
|||
});
|
||||
});
|
||||
|
||||
test('extract statically evaluable content', async () => {
|
||||
it('extracts statically evaluable content', async () => {
|
||||
const {sourceCodeFilePath} = await createTmpSourceCodeFile({
|
||||
extension: 'js',
|
||||
content: `
|
||||
|
@ -220,7 +220,7 @@ export default function MyComponent() {
|
|||
});
|
||||
});
|
||||
|
||||
test('extract from TypeScript file', async () => {
|
||||
it('extracts from TypeScript file', async () => {
|
||||
const {sourceCodeFilePath} = await createTmpSourceCodeFile({
|
||||
extension: 'tsx',
|
||||
content: `
|
||||
|
@ -252,7 +252,7 @@ export default function MyComponent<T>(props: ComponentProps<T>) {
|
|||
});
|
||||
});
|
||||
|
||||
test('do not extract from functions that is not docusaurus provided', async () => {
|
||||
it('does not extract from functions that is not docusaurus provided', async () => {
|
||||
const {sourceCodeFilePath} = await createTmpSourceCodeFile({
|
||||
extension: 'js',
|
||||
content: `
|
||||
|
@ -277,7 +277,7 @@ export default function somethingElse() {
|
|||
});
|
||||
});
|
||||
|
||||
test('do not extract from functions that is internal', async () => {
|
||||
it('does not extract from functions that is internal', async () => {
|
||||
const {sourceCodeFilePath} = await createTmpSourceCodeFile({
|
||||
extension: 'js',
|
||||
content: `
|
||||
|
@ -304,7 +304,7 @@ export default function somethingElse() {
|
|||
});
|
||||
});
|
||||
|
||||
test('recognize aliased imports', async () => {
|
||||
it('recognizes aliased imports', async () => {
|
||||
const {sourceCodeFilePath} = await createTmpSourceCodeFile({
|
||||
extension: 'js',
|
||||
content: `
|
||||
|
@ -354,7 +354,7 @@ export default function () {
|
|||
});
|
||||
});
|
||||
|
||||
test('recognize aliased imports as string literal', async () => {
|
||||
it('recognizes aliased imports as string literal', async () => {
|
||||
const {sourceCodeFilePath} = await createTmpSourceCodeFile({
|
||||
extension: 'js',
|
||||
content: `
|
||||
|
@ -388,7 +388,7 @@ export default function () {
|
|||
});
|
||||
});
|
||||
|
||||
test('warn about id if no children', async () => {
|
||||
it('warns about id if no children', async () => {
|
||||
const {sourceCodeFilePath} = await createTmpSourceCodeFile({
|
||||
extension: 'js',
|
||||
content: `
|
||||
|
@ -419,7 +419,7 @@ Full code: <Translate description="foo" />`,
|
|||
});
|
||||
});
|
||||
|
||||
test('warn about dynamic id', async () => {
|
||||
it('warns about dynamic id', async () => {
|
||||
const {sourceCodeFilePath} = await createTmpSourceCodeFile({
|
||||
extension: 'js',
|
||||
content: `
|
||||
|
@ -455,7 +455,7 @@ Full code: <Translate id={index}>foo</Translate>`,
|
|||
});
|
||||
});
|
||||
|
||||
test('warn about dynamic children', async () => {
|
||||
it('warns about dynamic children', async () => {
|
||||
const {sourceCodeFilePath} = await createTmpSourceCodeFile({
|
||||
extension: 'js',
|
||||
content: `
|
||||
|
@ -485,7 +485,7 @@ Full code: <Translate id='foo'><a>hhh</a></Translate>`,
|
|||
});
|
||||
});
|
||||
|
||||
test('warn about dynamic translate argument', async () => {
|
||||
it('warns about dynamic translate argument', async () => {
|
||||
const {sourceCodeFilePath} = await createTmpSourceCodeFile({
|
||||
extension: 'js',
|
||||
content: `
|
||||
|
@ -513,7 +513,7 @@ Full code: translate(foo)`,
|
|||
});
|
||||
});
|
||||
|
||||
test('warn about too many arguments', async () => {
|
||||
it('warns about too many arguments', async () => {
|
||||
const {sourceCodeFilePath} = await createTmpSourceCodeFile({
|
||||
extension: 'js',
|
||||
content: `
|
||||
|
@ -545,7 +545,7 @@ Full code: translate({
|
|||
});
|
||||
|
||||
describe('extractSiteSourceCodeTranslations', () => {
|
||||
test('should extract translation from all plugins source code', async () => {
|
||||
it('extracts translation from all plugins source code', async () => {
|
||||
const siteDir = await createTmpDir();
|
||||
|
||||
const siteComponentFile1 = path.join(
|
||||
|
|
|
@ -9,7 +9,7 @@ import {getPluginVersion} from '..';
|
|||
import path from 'path';
|
||||
|
||||
describe('getPluginVersion', () => {
|
||||
it('Can detect external packages plugins versions of correctly.', async () => {
|
||||
it('detects external packages plugins versions', async () => {
|
||||
await expect(
|
||||
getPluginVersion(
|
||||
path.join(__dirname, '__fixtures__/dummy-plugin.js'),
|
||||
|
@ -19,7 +19,7 @@ describe('getPluginVersion', () => {
|
|||
).resolves.toEqual({type: 'package', version: 'random-version'});
|
||||
});
|
||||
|
||||
it('Can detect project plugins versions correctly.', async () => {
|
||||
it('detects project plugins versions', async () => {
|
||||
await expect(
|
||||
getPluginVersion(
|
||||
path.join(__dirname, '__fixtures__/dummy-plugin.js'),
|
||||
|
@ -29,7 +29,7 @@ describe('getPluginVersion', () => {
|
|||
).resolves.toEqual({type: 'project'});
|
||||
});
|
||||
|
||||
it('Can detect local packages versions correctly.', async () => {
|
||||
it('detect local packages versions', async () => {
|
||||
await expect(getPluginVersion('/', '/')).resolves.toEqual({type: 'local'});
|
||||
});
|
||||
});
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
// Jest Snapshot v1, https://goo.gl/fbAQLP
|
||||
|
||||
exports[`base webpack config should create webpack aliases 1`] = `
|
||||
exports[`base webpack config creates webpack aliases 1`] = `
|
||||
Object {
|
||||
"@docusaurus/BrowserOnly": "../../../../client/exports/BrowserOnly.tsx",
|
||||
"@docusaurus/ComponentCreator": "../../../../client/exports/ComponentCreator.tsx",
|
||||
|
@ -47,7 +47,7 @@ Object {
|
|||
}
|
||||
`;
|
||||
|
||||
exports[`getDocusaurusAliases() return appropriate webpack aliases 1`] = `
|
||||
exports[`getDocusaurusAliases() returns appropriate webpack aliases 1`] = `
|
||||
Object {
|
||||
"@docusaurus/BrowserOnly": "../../client/exports/BrowserOnly.tsx",
|
||||
"@docusaurus/ComponentCreator": "../../client/exports/ComponentCreator.tsx",
|
||||
|
|
|
@ -20,7 +20,7 @@ import _ from 'lodash';
|
|||
import type {Props, ThemeAliases} from '@docusaurus/types';
|
||||
|
||||
describe('babel transpilation exclude logic', () => {
|
||||
test('always transpile client dir files', () => {
|
||||
it('always transpiles client dir files', () => {
|
||||
const clientFiles = [
|
||||
'App.js',
|
||||
'clientEntry.js',
|
||||
|
@ -32,7 +32,7 @@ describe('babel transpilation exclude logic', () => {
|
|||
});
|
||||
});
|
||||
|
||||
test('always transpile non node_module files', () => {
|
||||
it('always transpiles non node_module files', () => {
|
||||
const moduleFiles = [
|
||||
'/pages/user/App.jsx',
|
||||
'/website/src/components/foo.js',
|
||||
|
@ -43,7 +43,7 @@ describe('babel transpilation exclude logic', () => {
|
|||
});
|
||||
});
|
||||
|
||||
test('transpile docusaurus npm packages even in node_modules', () => {
|
||||
it('transpiles docusaurus npm packages even in node_modules', () => {
|
||||
const moduleFiles = [
|
||||
'/website/node_modules/docusaurus-theme-search/theme/Navbar/index.js',
|
||||
'node_modules/@docusaurus/theme-classic/theme/Layout.js',
|
||||
|
@ -54,7 +54,7 @@ describe('babel transpilation exclude logic', () => {
|
|||
});
|
||||
});
|
||||
|
||||
test('does not transpile node_modules', () => {
|
||||
it('does not transpile node_modules', () => {
|
||||
const moduleFiles = [
|
||||
'node_modules/react-toggle.js',
|
||||
'/website/node_modules/react-trend/index.js',
|
||||
|
@ -69,7 +69,7 @@ describe('babel transpilation exclude logic', () => {
|
|||
});
|
||||
|
||||
describe('getDocusaurusAliases()', () => {
|
||||
test('return appropriate webpack aliases', async () => {
|
||||
it('returns appropriate webpack aliases', async () => {
|
||||
// using relative paths makes tests work everywhere
|
||||
const relativeDocusaurusAliases = _.mapValues(
|
||||
await getDocusaurusAliases(),
|
||||
|
@ -121,7 +121,7 @@ describe('base webpack config', () => {
|
|||
jest.restoreAllMocks();
|
||||
});
|
||||
|
||||
test('should create webpack aliases', async () => {
|
||||
it('creates webpack aliases', async () => {
|
||||
// @ts-expect-error: Docusaurus webpack alias is always an object
|
||||
const aliases: ThemeAliases =
|
||||
(await createBaseConfig(props, true)).resolve?.alias ?? {};
|
||||
|
@ -132,7 +132,7 @@ describe('base webpack config', () => {
|
|||
expect(relativeAliases).toMatchSnapshot();
|
||||
});
|
||||
|
||||
test('should use svg rule', async () => {
|
||||
it('uses svg rule', async () => {
|
||||
const fileLoaderUtils = utils.getFileLoaderUtils();
|
||||
const mockSvg = jest.spyOn(fileLoaderUtils.rules, 'svg');
|
||||
jest
|
||||
|
|
|
@ -5,23 +5,20 @@
|
|||
* LICENSE file in the root directory of this source tree.
|
||||
*/
|
||||
|
||||
import {jest} from '@jest/globals';
|
||||
import webpack from 'webpack';
|
||||
|
||||
import createClientConfig from '../client';
|
||||
import loadSetup from '../../server/__tests__/testUtils';
|
||||
|
||||
describe('webpack dev config', () => {
|
||||
test('simple', async () => {
|
||||
console.log = jest.fn();
|
||||
it('simple', async () => {
|
||||
const props = await loadSetup('simple');
|
||||
const config = await createClientConfig(props);
|
||||
const errors = webpack.validate(config);
|
||||
expect(errors).toBeUndefined();
|
||||
});
|
||||
|
||||
test('custom', async () => {
|
||||
console.log = jest.fn();
|
||||
it('custom', async () => {
|
||||
const props = await loadSetup('custom');
|
||||
const config = await createClientConfig(props);
|
||||
const errors = webpack.validate(config);
|
||||
|
|
|
@ -12,7 +12,7 @@ import createServerConfig from '../server';
|
|||
import loadSetup from '../../server/__tests__/testUtils';
|
||||
|
||||
describe('webpack production config', () => {
|
||||
test('simple', async () => {
|
||||
it('simple', async () => {
|
||||
console.log = jest.fn();
|
||||
const props = await loadSetup('simple');
|
||||
const config = await createServerConfig({props});
|
||||
|
@ -20,7 +20,7 @@ describe('webpack production config', () => {
|
|||
expect(errors).toBeUndefined();
|
||||
});
|
||||
|
||||
test('custom', async () => {
|
||||
it('custom', async () => {
|
||||
console.log = jest.fn();
|
||||
const props = await loadSetup('custom');
|
||||
const config = await createServerConfig({props});
|
||||
|
|
|
@ -19,7 +19,7 @@ import type {
|
|||
} from '@docusaurus/types';
|
||||
|
||||
describe('customize JS loader', () => {
|
||||
test('getCustomizableJSLoader defaults to babel loader', () => {
|
||||
it('getCustomizableJSLoader defaults to babel loader', () => {
|
||||
expect(getCustomizableJSLoader()({isServer: true}).loader).toBe(
|
||||
require.resolve('babel-loader'),
|
||||
);
|
||||
|
@ -28,7 +28,7 @@ describe('customize JS loader', () => {
|
|||
);
|
||||
});
|
||||
|
||||
test('getCustomizableJSLoader accepts loaders with preset', () => {
|
||||
it('getCustomizableJSLoader accepts loaders with preset', () => {
|
||||
expect(getCustomizableJSLoader('babel')({isServer: true}).loader).toBe(
|
||||
require.resolve('babel-loader'),
|
||||
);
|
||||
|
@ -37,7 +37,7 @@ describe('customize JS loader', () => {
|
|||
);
|
||||
});
|
||||
|
||||
test('getCustomizableJSLoader allows customization', () => {
|
||||
it('getCustomizableJSLoader allows customization', () => {
|
||||
const customJSLoader = (isServer: boolean): RuleSetRule => ({
|
||||
loader: 'my-fast-js-loader',
|
||||
options: String(isServer),
|
||||
|
@ -53,7 +53,7 @@ describe('customize JS loader', () => {
|
|||
});
|
||||
|
||||
describe('extending generated webpack config', () => {
|
||||
test('direct mutation on generated webpack config object', async () => {
|
||||
it('direct mutation on generated webpack config object', async () => {
|
||||
// fake generated webpack config
|
||||
let config: Configuration = {
|
||||
output: {
|
||||
|
@ -90,7 +90,7 @@ describe('extending generated webpack config', () => {
|
|||
expect(errors).toBeUndefined();
|
||||
});
|
||||
|
||||
test('webpack-merge with user webpack config object', async () => {
|
||||
it('webpack-merge with user webpack config object', async () => {
|
||||
let config: Configuration = {
|
||||
output: {
|
||||
path: __dirname,
|
||||
|
@ -120,7 +120,7 @@ describe('extending generated webpack config', () => {
|
|||
expect(errors).toBeUndefined();
|
||||
});
|
||||
|
||||
test('webpack-merge with custom strategy', async () => {
|
||||
it('webpack-merge with custom strategy', async () => {
|
||||
const config: Configuration = {
|
||||
module: {
|
||||
rules: [{use: 'xxx'}, {use: 'yyy'}],
|
||||
|
@ -178,7 +178,7 @@ describe('extending generated webpack config', () => {
|
|||
});
|
||||
|
||||
describe('extending PostCSS', () => {
|
||||
test('user plugin should be appended in PostCSS loader', () => {
|
||||
it('user plugin should be appended in PostCSS loader', () => {
|
||||
let webpackConfig: Configuration = {
|
||||
output: {
|
||||
path: __dirname,
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue