test: fix ALL type errors in tests (#7487)

This commit is contained in:
Joshua Chen 2022-05-25 14:01:10 +08:00 committed by GitHub
parent e2e40b8f5f
commit d50fe3b670
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
37 changed files with 407 additions and 184 deletions

View file

@ -84,11 +84,15 @@ exports[`translateLoadedContent returns translated loaded content 1`] = `
{
"loadedVersions": [
{
"badge": true,
"banner": null,
"className": "",
"contentPath": "any",
"contentPathLocalized": "any",
"docs": [
{
"description": "doc1 description",
"draft": false,
"editUrl": "any",
"frontMatter": {
"sidebar_label": "doc1 title",
@ -101,12 +105,15 @@ exports[`translateLoadedContent returns translated loaded content 1`] = `
"previous": undefined,
"slug": "any",
"source": "any",
"sourceDirName": "",
"tags": [],
"title": "doc1 title",
"unversionedId": "any",
"version": "any",
},
{
"description": "doc2 description",
"draft": false,
"editUrl": "any",
"frontMatter": {
"sidebar_label": "doc2 title",
@ -119,12 +126,15 @@ exports[`translateLoadedContent returns translated loaded content 1`] = `
"previous": undefined,
"slug": "any",
"source": "any",
"sourceDirName": "",
"tags": [],
"title": "doc2 title",
"unversionedId": "any",
"version": "any",
},
{
"description": "doc3 description",
"draft": false,
"editUrl": "any",
"frontMatter": {
"sidebar_label": "doc3 title",
@ -137,12 +147,15 @@ exports[`translateLoadedContent returns translated loaded content 1`] = `
"previous": undefined,
"slug": "any",
"source": "any",
"sourceDirName": "",
"tags": [],
"title": "doc3 title",
"unversionedId": "any",
"version": "any",
},
{
"description": "doc4 description",
"draft": false,
"editUrl": "any",
"frontMatter": {
"sidebar_label": "doc4 title",
@ -155,12 +168,15 @@ exports[`translateLoadedContent returns translated loaded content 1`] = `
"previous": undefined,
"slug": "any",
"source": "any",
"sourceDirName": "",
"tags": [],
"title": "doc4 title",
"unversionedId": "any",
"version": "any",
},
{
"description": "doc5 description",
"draft": false,
"editUrl": "any",
"frontMatter": {
"sidebar_label": "doc5 title",
@ -173,14 +189,16 @@ exports[`translateLoadedContent returns translated loaded content 1`] = `
"previous": undefined,
"slug": "any",
"source": "any",
"sourceDirName": "",
"tags": [],
"title": "doc5 title",
"unversionedId": "any",
"version": "any",
},
],
"drafts": [],
"isLast": true,
"label": "current label (translated)",
"mainDocId": "",
"path": "/docs/",
"routePriority": undefined,
"sidebarFilePath": "any",
@ -188,6 +206,7 @@ exports[`translateLoadedContent returns translated loaded content 1`] = `
"docs": [
{
"collapsed": false,
"collapsible": true,
"items": [
{
"id": "doc1",
@ -233,14 +252,19 @@ exports[`translateLoadedContent returns translated loaded content 1`] = `
},
],
},
"tagsPath": "/tags/",
"versionName": "current",
},
{
"badge": true,
"banner": null,
"className": "",
"contentPath": "any",
"contentPathLocalized": "any",
"docs": [
{
"description": "doc1 description",
"draft": false,
"editUrl": "any",
"frontMatter": {
"sidebar_label": "doc1 title",
@ -253,12 +277,15 @@ exports[`translateLoadedContent returns translated loaded content 1`] = `
"previous": undefined,
"slug": "any",
"source": "any",
"sourceDirName": "",
"tags": [],
"title": "doc1 title",
"unversionedId": "any",
"version": "any",
},
{
"description": "doc2 description",
"draft": false,
"editUrl": "any",
"frontMatter": {
"sidebar_label": "doc2 title",
@ -271,12 +298,15 @@ exports[`translateLoadedContent returns translated loaded content 1`] = `
"previous": undefined,
"slug": "any",
"source": "any",
"sourceDirName": "",
"tags": [],
"title": "doc2 title",
"unversionedId": "any",
"version": "any",
},
{
"description": "doc3 description",
"draft": false,
"editUrl": "any",
"frontMatter": {
"sidebar_label": "doc3 title",
@ -289,12 +319,15 @@ exports[`translateLoadedContent returns translated loaded content 1`] = `
"previous": undefined,
"slug": "any",
"source": "any",
"sourceDirName": "",
"tags": [],
"title": "doc3 title",
"unversionedId": "any",
"version": "any",
},
{
"description": "doc4 description",
"draft": false,
"editUrl": "any",
"frontMatter": {
"sidebar_label": "doc4 title",
@ -307,12 +340,15 @@ exports[`translateLoadedContent returns translated loaded content 1`] = `
"previous": undefined,
"slug": "any",
"source": "any",
"sourceDirName": "",
"tags": [],
"title": "doc4 title",
"unversionedId": "any",
"version": "any",
},
{
"description": "doc5 description",
"draft": false,
"editUrl": "any",
"frontMatter": {
"sidebar_label": "doc5 title",
@ -325,14 +361,16 @@ exports[`translateLoadedContent returns translated loaded content 1`] = `
"previous": undefined,
"slug": "any",
"source": "any",
"sourceDirName": "",
"tags": [],
"title": "doc5 title",
"unversionedId": "any",
"version": "any",
},
],
"drafts": [],
"isLast": true,
"label": "2.0.0 label (translated)",
"mainDocId": "",
"path": "/docs/",
"routePriority": undefined,
"sidebarFilePath": "any",
@ -340,6 +378,7 @@ exports[`translateLoadedContent returns translated loaded content 1`] = `
"docs": [
{
"collapsed": false,
"collapsible": true,
"items": [
{
"id": "doc1",
@ -385,14 +424,19 @@ exports[`translateLoadedContent returns translated loaded content 1`] = `
},
],
},
"tagsPath": "/tags/",
"versionName": "2.0.0",
},
{
"badge": true,
"banner": null,
"className": "",
"contentPath": "any",
"contentPathLocalized": "any",
"docs": [
{
"description": "doc1 description",
"draft": false,
"editUrl": "any",
"frontMatter": {
"sidebar_label": "doc1 title",
@ -405,12 +449,15 @@ exports[`translateLoadedContent returns translated loaded content 1`] = `
"previous": undefined,
"slug": "any",
"source": "any",
"sourceDirName": "",
"tags": [],
"title": "doc1 title",
"unversionedId": "any",
"version": "any",
},
{
"description": "doc2 description",
"draft": false,
"editUrl": "any",
"frontMatter": {
"sidebar_label": "doc2 title",
@ -423,12 +470,15 @@ exports[`translateLoadedContent returns translated loaded content 1`] = `
"previous": undefined,
"slug": "any",
"source": "any",
"sourceDirName": "",
"tags": [],
"title": "doc2 title",
"unversionedId": "any",
"version": "any",
},
{
"description": "doc3 description",
"draft": false,
"editUrl": "any",
"frontMatter": {
"sidebar_label": "doc3 title",
@ -441,12 +491,15 @@ exports[`translateLoadedContent returns translated loaded content 1`] = `
"previous": undefined,
"slug": "any",
"source": "any",
"sourceDirName": "",
"tags": [],
"title": "doc3 title",
"unversionedId": "any",
"version": "any",
},
{
"description": "doc4 description",
"draft": false,
"editUrl": "any",
"frontMatter": {
"sidebar_label": "doc4 title",
@ -459,12 +512,15 @@ exports[`translateLoadedContent returns translated loaded content 1`] = `
"previous": undefined,
"slug": "any",
"source": "any",
"sourceDirName": "",
"tags": [],
"title": "doc4 title",
"unversionedId": "any",
"version": "any",
},
{
"description": "doc5 description",
"draft": false,
"editUrl": "any",
"frontMatter": {
"sidebar_label": "doc5 title",
@ -477,14 +533,16 @@ exports[`translateLoadedContent returns translated loaded content 1`] = `
"previous": undefined,
"slug": "any",
"source": "any",
"sourceDirName": "",
"tags": [],
"title": "doc5 title",
"unversionedId": "any",
"version": "any",
},
],
"drafts": [],
"isLast": true,
"label": "1.0.0 label (translated)",
"mainDocId": "",
"path": "/docs/",
"routePriority": undefined,
"sidebarFilePath": "any",
@ -492,6 +550,7 @@ exports[`translateLoadedContent returns translated loaded content 1`] = `
"docs": [
{
"collapsed": false,
"collapsible": true,
"items": [
{
"id": "doc1",
@ -537,6 +596,7 @@ exports[`translateLoadedContent returns translated loaded content 1`] = `
},
],
},
"tagsPath": "/tags/",
"versionName": "1.0.0",
},
],

View file

@ -25,9 +25,11 @@ import {DisabledSidebars} from '../sidebars';
import * as cliDocs from '../cli';
import {validateOptions} from '../options';
import type {RouteConfig} from '@docusaurus/types';
import type {RouteConfig, Validate, Plugin} from '@docusaurus/types';
import type {
LoadedVersion,
Options,
PluginOptions,
PropSidebarItemLink,
} from '@docusaurus/plugin-content-docs';
import type {
@ -133,7 +135,7 @@ describe('sidebar', () => {
const plugin = await pluginContentDocs(
context,
validateOptions({
validate: normalizePluginOptions,
validate: normalizePluginOptions as Validate<Options, PluginOptions>,
options: {
sidebarPath,
},
@ -150,7 +152,7 @@ describe('sidebar', () => {
const plugin = await pluginContentDocs(
context,
validateOptions({
validate: normalizePluginOptions,
validate: normalizePluginOptions as Validate<Options, PluginOptions>,
options: {
sidebarPath: 'wrong-path-sidebar.json',
},
@ -173,7 +175,7 @@ describe('sidebar', () => {
const plugin = await pluginContentDocs(
context,
validateOptions({
validate: normalizePluginOptions,
validate: normalizePluginOptions as Validate<Options, PluginOptions>,
options: {
sidebarPath: undefined,
},
@ -191,7 +193,7 @@ describe('sidebar', () => {
const plugin = await pluginContentDocs(
context,
validateOptions({
validate: normalizePluginOptions,
validate: normalizePluginOptions as Validate<Options, PluginOptions>,
options: {
sidebarPath: false,
},
@ -212,7 +214,10 @@ describe('empty/no docs website', () => {
await fs.ensureDir(path.join(siteDir, 'docs'));
const plugin = await pluginContentDocs(
context,
validateOptions({validate: normalizePluginOptions, options: {}}),
validateOptions({
validate: normalizePluginOptions as Validate<Options, PluginOptions>,
options: {},
}),
);
await expect(
plugin.loadContent!(),
@ -227,7 +232,7 @@ describe('empty/no docs website', () => {
pluginContentDocs(
context,
validateOptions({
validate: normalizePluginOptions,
validate: normalizePluginOptions as Validate<Options, PluginOptions>,
options: {
path: 'path/does/not/exist',
},
@ -245,7 +250,7 @@ describe('simple website', () => {
const context = await loadContext({siteDir});
const sidebarPath = path.join(siteDir, 'sidebars.json');
const options = validateOptions({
validate: normalizePluginOptions,
validate: normalizePluginOptions as Validate<Options, PluginOptions>,
options: {
path: 'docs',
sidebarPath,
@ -299,7 +304,7 @@ describe('simple website', () => {
const content = await plugin.loadContent?.();
const config = applyConfigureWebpack(
plugin.configureWebpack,
plugin.configureWebpack as NonNullable<Plugin['configureWebpack']>,
{
entry: './src/index.js',
output: {
@ -352,7 +357,7 @@ describe('versioned website', () => {
const sidebarPath = path.join(siteDir, 'sidebars.json');
const routeBasePath = 'docs';
const options = validateOptions({
validate: normalizePluginOptions,
validate: normalizePluginOptions as Validate<Options, PluginOptions>,
options: {
routeBasePath,
sidebarPath,
@ -478,7 +483,7 @@ describe('versioned website (community)', () => {
const routeBasePath = 'community';
const pluginId = 'community';
const options = validateOptions({
validate: normalizePluginOptions,
validate: normalizePluginOptions as Validate<Options, PluginOptions>,
options: {
id: 'community',
path: 'community',
@ -581,7 +586,7 @@ describe('site with doc label', () => {
const plugin = await pluginContentDocs(
context,
validateOptions({
validate: normalizePluginOptions,
validate: normalizePluginOptions as Validate<Options, PluginOptions>,
options: {
path: 'docs',
sidebarPath,
@ -626,7 +631,7 @@ describe('site with full autogenerated sidebar', () => {
const plugin = await pluginContentDocs(
context,
validateOptions({
validate: normalizePluginOptions,
validate: normalizePluginOptions as Validate<Options, PluginOptions>,
options: {
path: 'docs',
},
@ -681,7 +686,7 @@ describe('site with partial autogenerated sidebars', () => {
const plugin = await pluginContentDocs(
context,
validateOptions({
validate: normalizePluginOptions,
validate: normalizePluginOptions as Validate<Options, PluginOptions>,
options: {
path: 'docs',
sidebarPath: path.join(
@ -737,7 +742,7 @@ describe('site with partial autogenerated sidebars 2 (fix #4638)', () => {
const plugin = await pluginContentDocs(
context,
validateOptions({
validate: normalizePluginOptions,
validate: normalizePluginOptions as Validate<Options, PluginOptions>,
options: {
path: 'docs',
sidebarPath: path.join(
@ -774,7 +779,7 @@ describe('site with custom sidebar items generator', () => {
const plugin = await pluginContentDocs(
context,
validateOptions({
validate: normalizePluginOptions,
validate: normalizePluginOptions as Validate<Options, PluginOptions>,
options: {
path: 'docs',
sidebarItemsGenerator,

View file

@ -13,14 +13,18 @@ import {
DefaultNumberPrefixParser,
DisabledNumberPrefixParser,
} from '../numberPrefix';
import type {Options} from '@docusaurus/plugin-content-docs';
import type {Options, PluginOptions} from '@docusaurus/plugin-content-docs';
import type {Validate} from '@docusaurus/types';
// The type of remark/rehype plugins can be function/object
const markdownPluginsFunctionStub = () => {};
const markdownPluginsObjectStub = {};
function testValidate(options: Options) {
return validateOptions({validate: normalizePluginOptions, options});
return validateOptions({
validate: normalizePluginOptions as Validate<Options, PluginOptions>,
options,
});
}
const defaultOptions = {

View file

@ -19,6 +19,9 @@ import type {
function createSampleDoc(doc: Pick<DocMetadata, 'id'>): DocMetadata {
return {
sourceDirName: '',
draft: false,
tags: [],
editUrl: 'any',
lastUpdatedAt: 0,
lastUpdatedBy: 'any',
@ -44,12 +47,16 @@ function createSampleVersion(
return {
label: `${version.versionName} label`,
path: '/docs/',
mainDocId: '',
routePriority: undefined,
sidebarFilePath: 'any',
isLast: true,
contentPath: 'any',
contentPathLocalized: 'any',
tagsPath: '/tags/',
banner: null,
badge: true,
className: '',
drafts: [],
docs: [
createSampleDoc({id: 'doc1'}),
createSampleDoc({id: 'doc2'}),
@ -63,6 +70,7 @@ function createSampleVersion(
type: 'category',
label: 'Getting started',
collapsed: false,
collapsible: true,
link: {
type: 'generated-index',
slug: '/category/getting-started-index-slug',