@@ -12,7 +12,7 @@ import {
1212 validateConfig ,
1313} from '../configValidation' ;
1414import type { StorageConfig } from '@docusaurus/types/src/config' ;
15- import type { Config , DocusaurusConfig } from '@docusaurus/types' ;
15+ import type { Config , DocusaurusConfig , PluginConfig } from '@docusaurus/types' ;
1616import type { DeepPartial } from 'utility-types' ;
1717
1818const baseConfig = {
@@ -466,6 +466,11 @@ describe('markdown', () => {
466466} ) ;
467467
468468describe ( 'plugins' , ( ) => {
469+ // Only here to verify typing
470+ function ensurePlugins ( plugins : PluginConfig [ ] ) : PluginConfig [ ] {
471+ return plugins ;
472+ }
473+
469474 it . each ( [
470475 [ 'should throw error if plugins is not array' , { } ] ,
471476 [
@@ -494,64 +499,86 @@ describe('plugins', () => {
494499 } ) ;
495500
496501 it . each ( [
497- [ 'should throw error if themes is not array' , { } ] ,
498- [
499- "should throw error if themes is not a string and it's not an array #1" ,
500- [ 123 ] ,
501- ] ,
502- [
503- 'should throw error if themes is not an array of [string, object][] #1' ,
504- [ [ 'example/path' , 'wrong parameter here' ] ] ,
505- ] ,
506- [
507- 'should throw error if themes is not an array of [string, object][] #2' ,
508- [ [ { } , 'example/path' ] ] ,
509- ] ,
510- [
511- 'should throw error if themes is not an array of [string, object][] #3' ,
512- [ [ { } , { } ] ] ,
513- ] ,
514- ] ) ( `%s for the input of: %p` , ( _message , themes ) => {
515- expect ( ( ) => {
516- normalizeConfig ( {
517- // @ts -expect-error: test
518- themes,
519- } ) ;
520- } ) . toThrowErrorMatchingSnapshot ( ) ;
521- } ) ;
522-
523- it . each ( [
524- [ 'should accept [string] for plugins' , [ 'plain/string' ] ] ,
502+ [ 'should accept [string] for plugins' , ensurePlugins ( [ 'plain/string' ] ) ] ,
525503 [
526504 'should accept string[] for plugins' ,
527- [ 'plain/string' , 'another/plain/string/path' ] ,
505+ ensurePlugins ( [ 'plain/string' , 'another/plain/string/path' ] ) ,
528506 ] ,
529507 [
530508 'should accept [string, object] for plugins' ,
531- [ [ 'plain/string' , { it : 'should work' } ] ] ,
509+ ensurePlugins ( [ [ 'plain/string' , { it : 'should work' } ] ] ) ,
532510 ] ,
533511 [
534512 'should accept [string, object][] for plugins' ,
535- [
513+ ensurePlugins ( [
536514 [ 'plain/string' , { it : 'should work' } ] ,
537515 [ 'this/should/work' , { too : 'yes' } ] ,
538- ] ,
516+ ] ) ,
539517 ] ,
540518 [
541519 'should accept ([string, object]|string)[] for plugins' ,
542- [
520+ ensurePlugins ( [
543521 'plain/string' ,
544522 [ 'plain' , { it : 'should work' } ] ,
545523 [ 'this/should/work' , { too : 'yes' } ] ,
546- ] ,
524+ ] ) ,
525+ ] ,
526+ [
527+ 'should accept function returning null' ,
528+ ensurePlugins ( [
529+ function plugin ( ) {
530+ return null ;
531+ } ,
532+ ] ) ,
533+ ] ,
534+ [
535+ 'should accept function returning plugin' ,
536+ ensurePlugins ( [
537+ function plugin ( ) {
538+ return { name : 'plugin' } ;
539+ } ,
540+ ] ) ,
541+ ] ,
542+ [
543+ 'should accept function returning plugin or null' ,
544+ ensurePlugins ( [
545+ function plugin ( ) {
546+ return Math . random ( ) > 0.5 ? null : { name : 'plugin' } ;
547+ } ,
548+ ] ) ,
549+ ] ,
550+ [
551+ 'should accept async function returning null' ,
552+ ensurePlugins ( [
553+ async function plugin ( ) {
554+ return null ;
555+ } ,
556+ ] ) ,
557+ ] ,
558+ [
559+ 'should accept async function returning plugin' ,
560+ ensurePlugins ( [
561+ async function plugin ( ) {
562+ return { name : 'plugin' } ;
563+ } ,
564+ ] ) ,
565+ ] ,
566+ [
567+ 'should accept function returning plugin or null' ,
568+ ensurePlugins ( [
569+ async function plugin ( ) {
570+ return Math . random ( ) > 0.5 ? null : { name : 'plugin' } ;
571+ } ,
572+ ] ) ,
547573 ] ,
548- [ 'should accept function for plugin' , [ function plugin ( ) { } ] ] ,
549- [ 'should accept async function for plugin' , [ async function plugin ( ) { } ] ] ,
550574 [
551575 'should accept [function, object] for plugin' ,
552576 [ [ ( ) => { } , { it : 'should work' } ] ] ,
553577 ] ,
554- [ 'should accept false/null for plugin' , [ false as const , null , 'classic' ] ] ,
578+ [
579+ 'should accept false/null for plugin' ,
580+ ensurePlugins ( [ false as const , null , 'classic' ] ) ,
581+ ] ,
555582 ] ) ( `%s for the input of: %p` , ( _message , plugins ) => {
556583 expect ( ( ) => {
557584 normalizeConfig ( {
@@ -562,6 +589,33 @@ describe('plugins', () => {
562589} ) ;
563590
564591describe ( 'themes' , ( ) => {
592+ it . each ( [
593+ [ 'should throw error if themes is not array' , { } ] ,
594+ [
595+ "should throw error if themes is not a string and it's not an array #1" ,
596+ [ 123 ] ,
597+ ] ,
598+ [
599+ 'should throw error if themes is not an array of [string, object][] #1' ,
600+ [ [ 'example/path' , 'wrong parameter here' ] ] ,
601+ ] ,
602+ [
603+ 'should throw error if themes is not an array of [string, object][] #2' ,
604+ [ [ { } , 'example/path' ] ] ,
605+ ] ,
606+ [
607+ 'should throw error if themes is not an array of [string, object][] #3' ,
608+ [ [ { } , { } ] ] ,
609+ ] ,
610+ ] ) ( `%s for the input of: %p` , ( _message , themes ) => {
611+ expect ( ( ) => {
612+ normalizeConfig ( {
613+ // @ts -expect-error: test
614+ themes,
615+ } ) ;
616+ } ) . toThrowErrorMatchingSnapshot ( ) ;
617+ } ) ;
618+
565619 it . each ( [
566620 [ 'should accept [string] for themes' , [ 'plain/string' ] ] ,
567621 [
0 commit comments