test: enable a few jest eslint rules (#6900)

* test: enable a few jest eslint rules

* more
This commit is contained in:
Joshua Chen 2022-03-12 08:43:09 +08:00 committed by GitHub
parent 1efc6c6091
commit aa5a2d4c04
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
155 changed files with 3644 additions and 3478 deletions

View file

@ -0,0 +1,105 @@
// Jest Snapshot v1, https://goo.gl/fbAQLP
exports[`docusaurus-plugin-content-pages loads simple pages 1`] = `
Array [
Object {
"permalink": "/",
"source": "@site/src/pages/index.js",
"type": "jsx",
},
Object {
"permalink": "/typescript",
"source": "@site/src/pages/typescript.tsx",
"type": "jsx",
},
Object {
"description": "Markdown index page",
"frontMatter": Object {},
"permalink": "/hello/",
"source": "@site/src/pages/hello/index.md",
"title": "Index",
"type": "mdx",
},
Object {
"description": "my mdx page",
"frontMatter": Object {
"description": "my mdx page",
"title": "mdx page",
},
"permalink": "/hello/mdxPage",
"source": "@site/src/pages/hello/mdxPage.mdx",
"title": "mdx page",
"type": "mdx",
},
Object {
"permalink": "/hello/translatedJs",
"source": "@site/src/pages/hello/translatedJs.js",
"type": "jsx",
},
Object {
"description": "translated markdown page",
"frontMatter": Object {},
"permalink": "/hello/translatedMd",
"source": "@site/src/pages/hello/translatedMd.md",
"title": undefined,
"type": "mdx",
},
Object {
"permalink": "/hello/world",
"source": "@site/src/pages/hello/world.js",
"type": "jsx",
},
]
`;
exports[`docusaurus-plugin-content-pages loads simple pages with french translations 1`] = `
Array [
Object {
"permalink": "/",
"source": "@site/src/pages/index.js",
"type": "jsx",
},
Object {
"permalink": "/typescript",
"source": "@site/src/pages/typescript.tsx",
"type": "jsx",
},
Object {
"description": "Markdown index page",
"frontMatter": Object {},
"permalink": "/hello/",
"source": "@site/src/pages/hello/index.md",
"title": "Index",
"type": "mdx",
},
Object {
"description": "my mdx page",
"frontMatter": Object {
"description": "my mdx page",
"title": "mdx page",
},
"permalink": "/hello/mdxPage",
"source": "@site/src/pages/hello/mdxPage.mdx",
"title": "mdx page",
"type": "mdx",
},
Object {
"permalink": "/hello/translatedJs",
"source": "@site/i18n/fr/docusaurus-plugin-content-pages/hello/translatedJs.js",
"type": "jsx",
},
Object {
"description": "translated markdown page (fr)",
"frontMatter": Object {},
"permalink": "/hello/translatedMd",
"source": "@site/i18n/fr/docusaurus-plugin-content-pages/hello/translatedMd.md",
"title": undefined,
"type": "mdx",
},
Object {
"permalink": "/hello/world",
"source": "@site/src/pages/hello/world.js",
"type": "jsx",
},
]
`;

View file

@ -12,83 +12,23 @@ import pluginContentPages from '../index';
import {PluginOptionSchema} from '../pluginOptionSchema';
describe('docusaurus-plugin-content-pages', () => {
test('simple pages', async () => {
it('loads simple pages', async () => {
const siteDir = path.join(__dirname, '__fixtures__', 'website');
const context = await loadContext(siteDir);
const pluginPath = 'src/pages';
const plugin = await pluginContentPages(
context,
PluginOptionSchema.validate({
path: pluginPath,
path: 'src/pages',
}).value,
);
const pagesMetadata = await plugin.loadContent?.();
const pagesMetadata = await plugin.loadContent!();
expect(pagesMetadata).toEqual([
{
type: 'jsx',
permalink: '/',
source: path.posix.join('@site', pluginPath, 'index.js'),
},
{
type: 'jsx',
permalink: '/typescript',
source: path.posix.join('@site', pluginPath, 'typescript.tsx'),
},
{
type: 'mdx',
permalink: '/hello/',
source: path.posix.join('@site', pluginPath, 'hello', 'index.md'),
description: 'Markdown index page',
frontMatter: {},
title: 'Index',
},
{
type: 'mdx',
permalink: '/hello/mdxPage',
source: path.posix.join('@site', pluginPath, 'hello', 'mdxPage.mdx'),
description: 'my mdx page',
title: 'mdx page',
frontMatter: {
description: 'my mdx page',
title: 'mdx page',
},
},
{
type: 'jsx',
permalink: '/hello/translatedJs',
source: path.posix.join(
'@site',
pluginPath,
'hello',
'translatedJs.js',
),
},
{
type: 'mdx',
permalink: '/hello/translatedMd',
source: path.posix.join(
'@site',
pluginPath,
'hello',
'translatedMd.md',
),
description: 'translated markdown page',
frontMatter: {},
title: undefined,
},
{
type: 'jsx',
permalink: '/hello/world',
source: path.posix.join('@site', pluginPath, 'hello', 'world.js'),
},
]);
expect(pagesMetadata).toMatchSnapshot();
});
test('simple pages with french translations', async () => {
it('loads simple pages with french translations', async () => {
const siteDir = path.join(__dirname, '__fixtures__', 'website');
const context = await loadContext(siteDir);
const pluginPath = 'src/pages';
const plugin = await pluginContentPages(
{
...context,
@ -98,66 +38,11 @@ describe('docusaurus-plugin-content-pages', () => {
},
},
PluginOptionSchema.validate({
path: pluginPath,
path: 'src/pages',
}).value,
);
const pagesMetadata = await plugin.loadContent?.();
const pagesMetadata = await plugin.loadContent!();
const frTranslationsPath = path.posix.join(
'@site',
'i18n',
'fr',
'docusaurus-plugin-content-pages',
);
expect(pagesMetadata).toEqual([
{
type: 'jsx',
permalink: '/',
source: path.posix.join('@site', pluginPath, 'index.js'),
},
{
type: 'jsx',
permalink: '/typescript',
source: path.posix.join('@site', pluginPath, 'typescript.tsx'),
},
{
type: 'mdx',
permalink: '/hello/',
source: path.posix.join('@site', pluginPath, 'hello', 'index.md'),
description: 'Markdown index page',
frontMatter: {},
title: 'Index',
},
{
type: 'mdx',
permalink: '/hello/mdxPage',
source: path.posix.join('@site', pluginPath, 'hello', 'mdxPage.mdx'),
description: 'my mdx page',
title: 'mdx page',
frontMatter: {
description: 'my mdx page',
title: 'mdx page',
},
},
{
type: 'jsx',
permalink: '/hello/translatedJs',
source: path.posix.join(frTranslationsPath, 'hello', 'translatedJs.js'),
},
{
type: 'mdx',
permalink: '/hello/translatedMd',
source: path.posix.join(frTranslationsPath, 'hello', 'translatedMd.md'),
description: 'translated markdown page (fr)',
frontMatter: {},
title: undefined,
},
{
type: 'jsx',
permalink: '/hello/world',
source: path.posix.join('@site', pluginPath, 'hello', 'world.js'),
},
]);
expect(pagesMetadata).toMatchSnapshot();
});
});

View file

@ -22,17 +22,17 @@ function normalizePluginOptions(
}
describe('normalizePagesPluginOptions', () => {
test('should return default options for undefined user options', () => {
it('returns default options for undefined user options', () => {
const value = normalizePluginOptions({});
expect(value).toEqual(DEFAULT_OPTIONS);
});
test('should fill in default options for partially defined user options', () => {
it('fills in default options for partially defined user options', () => {
const value = normalizePluginOptions({path: 'src/pages'});
expect(value).toEqual(DEFAULT_OPTIONS);
});
test('should accept correctly defined user options', () => {
it('accepts correctly defined user options', () => {
const userOptions = {
path: 'src/my-pages',
routeBasePath: 'my-pages',
@ -43,7 +43,7 @@ describe('normalizePagesPluginOptions', () => {
expect(value).toEqual({...DEFAULT_OPTIONS, ...userOptions});
});
test('should reject bad path inputs', () => {
it('rejects bad path inputs', () => {
expect(() => {
normalizePluginOptions({
// @ts-expect-error: bad attribute