Skip to content

Commit

Permalink
test: fix ALL type errors in tests
Browse files Browse the repository at this point in the history
  • Loading branch information
Josh-Cena committed May 25, 2022
1 parent e2e40b8 commit c66aa2c
Show file tree
Hide file tree
Showing 36 changed files with 348 additions and 183 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,15 @@ import {normalizePluginOptions} from '@docusaurus/utils-validation';
import {posixPath, getFileCommitDate} from '@docusaurus/utils';
import pluginContentBlog from '../index';
import {validateOptions} from '../options';
import type {DocusaurusConfig, LoadContext, I18n} from '@docusaurus/types';
import type {
DocusaurusConfig,
LoadContext,
I18n,
Validate,
} from '@docusaurus/types';
import type {
BlogPost,
Options,
PluginOptions,
EditUrlFunction,
} from '@docusaurus/plugin-content-blog';
Expand Down Expand Up @@ -77,7 +83,10 @@ const getPlugin = async (
i18n,
} as LoadContext,
validateOptions({
validate: normalizePluginOptions,
validate: normalizePluginOptions as Validate<
Options | undefined,
PluginOptions
>,
options: {
path: PluginPath,
editUrl: BaseEditUrl,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,17 @@

import {normalizePluginOptions} from '@docusaurus/utils-validation';
import {validateOptions, DEFAULT_OPTIONS} from '../options';
import type {Options} from '@docusaurus/plugin-content-blog';
import type {Options, PluginOptions} from '@docusaurus/plugin-content-blog';
import type {Validate} from '@docusaurus/types';

function testValidate(options?: Options) {
return validateOptions({validate: normalizePluginOptions, options});
return validateOptions({
validate: normalizePluginOptions as Validate<
Options | undefined,
PluginOptions
>,
options,
});
}

// The type of remark/rehype plugins can be either function, object or array
Expand Down
37 changes: 21 additions & 16 deletions packages/docusaurus-plugin-content-docs/src/__tests__/index.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -133,7 +135,7 @@ describe('sidebar', () => {
const plugin = await pluginContentDocs(
context,
validateOptions({
validate: normalizePluginOptions,
validate: normalizePluginOptions as Validate<Options, PluginOptions>,
options: {
sidebarPath,
},
Expand All @@ -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',
},
Expand All @@ -173,7 +175,7 @@ describe('sidebar', () => {
const plugin = await pluginContentDocs(
context,
validateOptions({
validate: normalizePluginOptions,
validate: normalizePluginOptions as Validate<Options, PluginOptions>,
options: {
sidebarPath: undefined,
},
Expand All @@ -191,7 +193,7 @@ describe('sidebar', () => {
const plugin = await pluginContentDocs(
context,
validateOptions({
validate: normalizePluginOptions,
validate: normalizePluginOptions as Validate<Options, PluginOptions>,
options: {
sidebarPath: false,
},
Expand All @@ -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!(),
Expand All @@ -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',
},
Expand All @@ -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,
Expand Down Expand Up @@ -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: {
Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -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',
Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -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',
},
Expand Down Expand Up @@ -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(
Expand Down Expand Up @@ -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(
Expand Down Expand Up @@ -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,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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 = {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,9 @@ import type {

function createSampleDoc(doc: Pick<DocMetadata, 'id'>): DocMetadata {
return {
sourceDirName: '',
draft: false,
tags: [],
editUrl: 'any',
lastUpdatedAt: 0,
lastUpdatedBy: 'any',
Expand All @@ -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'}),
Expand All @@ -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',
Expand Down
Loading

0 comments on commit c66aa2c

Please sign in to comment.