mirror of
https://github.com/facebook/docusaurus.git
synced 2025-08-02 16:29:47 +02:00
refactor: import jest as global; unify import style of some modules (#6898)
* refactor: import jest as global * fix react
This commit is contained in:
parent
e97dc0d37e
commit
c9ee6e467c
59 changed files with 177 additions and 139 deletions
|
@ -5,6 +5,7 @@
|
|||
* LICENSE file in the root directory of this source tree.
|
||||
*/
|
||||
|
||||
import {jest} from '@jest/globals';
|
||||
import logger from '../index';
|
||||
|
||||
describe('formatters', () => {
|
||||
|
|
|
@ -5,6 +5,7 @@
|
|||
* LICENSE file in the root directory of this source tree.
|
||||
*/
|
||||
|
||||
import {jest} from '@jest/globals';
|
||||
import path from 'path';
|
||||
import remark from 'remark';
|
||||
import mdx from 'remark-mdx';
|
||||
|
|
|
@ -5,22 +5,20 @@
|
|||
* LICENSE file in the root directory of this source tree.
|
||||
*/
|
||||
|
||||
import {join} from 'path';
|
||||
import path from 'path';
|
||||
import remark from 'remark';
|
||||
import mdx from 'remark-mdx';
|
||||
import vfile from 'to-vfile';
|
||||
import plugin from '..';
|
||||
|
||||
const processFixture = async (name) => {
|
||||
const path = join(__dirname, '__fixtures__', name);
|
||||
const file = await vfile.read(path);
|
||||
const processFixture = async (name: string) => {
|
||||
const file = await vfile.read(path.join(__dirname, '__fixtures__', name));
|
||||
const result = await remark().use(mdx).use(plugin).process(file);
|
||||
return result.toString();
|
||||
};
|
||||
|
||||
const processFixtureAST = async (name) => {
|
||||
const path = join(__dirname, '__fixtures__', name);
|
||||
const file = await vfile.read(path);
|
||||
const processFixtureAST = async (name: string) => {
|
||||
const file = await vfile.read(path.join(__dirname, '__fixtures__', name));
|
||||
return remark().use(mdx).use(plugin).parse(file);
|
||||
};
|
||||
|
||||
|
|
|
@ -5,6 +5,7 @@
|
|||
* LICENSE file in the root directory of this source tree.
|
||||
*/
|
||||
|
||||
import {jest} from '@jest/globals';
|
||||
import {migrateDocusaurusProject} from '../index';
|
||||
import path from 'path';
|
||||
import fs from 'fs-extra';
|
||||
|
|
|
@ -5,6 +5,7 @@
|
|||
* LICENSE file in the root directory of this source tree.
|
||||
*/
|
||||
|
||||
import {jest} from '@jest/globals';
|
||||
import path from 'path';
|
||||
import fs from 'fs-extra';
|
||||
import {createBlogFeedFiles} from '../feed';
|
||||
|
|
|
@ -5,6 +5,7 @@
|
|||
* LICENSE file in the root directory of this source tree.
|
||||
*/
|
||||
|
||||
import {jest} from '@jest/globals';
|
||||
import path from 'path';
|
||||
import pluginContentBlog from '../index';
|
||||
import type {DocusaurusConfig, LoadContext, I18n} from '@docusaurus/types';
|
||||
|
|
|
@ -5,6 +5,7 @@
|
|||
* LICENSE file in the root directory of this source tree.
|
||||
*/
|
||||
|
||||
import {jest} from '@jest/globals';
|
||||
import fs from 'fs-extra';
|
||||
import path from 'path';
|
||||
import {linkify, type LinkifyParams, getSourceToPermalink} from '../blogUtils';
|
||||
|
|
|
@ -5,6 +5,7 @@
|
|||
* LICENSE file in the root directory of this source tree.
|
||||
*/
|
||||
|
||||
import {jest} from '@jest/globals';
|
||||
import path from 'path';
|
||||
import {cliDocsVersionCommand} from '../cli';
|
||||
import type {
|
||||
|
|
|
@ -5,6 +5,7 @@
|
|||
* LICENSE file in the root directory of this source tree.
|
||||
*/
|
||||
|
||||
import {jest} from '@jest/globals';
|
||||
import path from 'path';
|
||||
import {loadContext} from '@docusaurus/core/src/server/index';
|
||||
import {
|
||||
|
|
|
@ -5,6 +5,7 @@
|
|||
* LICENSE file in the root directory of this source tree.
|
||||
*/
|
||||
|
||||
import {jest} from '@jest/globals';
|
||||
import path from 'path';
|
||||
import {isMatch} from 'picomatch';
|
||||
import commander from 'commander';
|
||||
|
@ -29,7 +30,7 @@ import type {
|
|||
} from '../sidebars/types';
|
||||
import {toSidebarsProp} from '../props';
|
||||
|
||||
import {validate} from 'webpack';
|
||||
import webpack from 'webpack';
|
||||
import {DefaultSidebarItemsGenerator} from '../sidebars/generator';
|
||||
import {DisabledSidebars} from '../sidebars';
|
||||
|
||||
|
@ -311,7 +312,7 @@ describe('simple website', () => {
|
|||
undefined,
|
||||
content,
|
||||
);
|
||||
const errors = validate(config);
|
||||
const errors = webpack.validate(config);
|
||||
expect(errors).toBeUndefined();
|
||||
});
|
||||
|
||||
|
|
|
@ -5,6 +5,7 @@
|
|||
* LICENSE file in the root directory of this source tree.
|
||||
*/
|
||||
|
||||
import {jest} from '@jest/globals';
|
||||
import fs from 'fs-extra';
|
||||
import path from 'path';
|
||||
import shell from 'shelljs';
|
||||
|
|
|
@ -5,6 +5,7 @@
|
|||
* LICENSE file in the root directory of this source tree.
|
||||
*/
|
||||
|
||||
import {jest} from '@jest/globals';
|
||||
import path from 'path';
|
||||
import {
|
||||
getVersionsFilePath,
|
||||
|
|
|
@ -5,6 +5,7 @@
|
|||
* LICENSE file in the root directory of this source tree.
|
||||
*/
|
||||
|
||||
import {jest} from '@jest/globals';
|
||||
import fs from 'fs-extra';
|
||||
import path from 'path';
|
||||
import {linkify} from '../linkify';
|
||||
|
|
|
@ -5,6 +5,7 @@
|
|||
* LICENSE file in the root directory of this source tree.
|
||||
*/
|
||||
|
||||
import {jest} from '@jest/globals';
|
||||
import {DefaultSidebarItemsGenerator} from '../generator';
|
||||
import type {SidebarItemsGenerator} from '../types';
|
||||
import {DefaultNumberPrefixParser} from '../../numberPrefix';
|
||||
|
|
|
@ -5,6 +5,7 @@
|
|||
* LICENSE file in the root directory of this source tree.
|
||||
*/
|
||||
|
||||
import {jest} from '@jest/globals';
|
||||
import {processSidebars} from '../processor';
|
||||
import type {
|
||||
SidebarItem,
|
||||
|
|
|
@ -6,8 +6,8 @@
|
|||
*/
|
||||
|
||||
import React, {
|
||||
type ComponentProps,
|
||||
isValidElement,
|
||||
type ComponentProps,
|
||||
type ReactElement,
|
||||
} from 'react';
|
||||
import Head from '@docusaurus/Head';
|
||||
|
@ -52,7 +52,7 @@ const MDXComponents: MDXComponentsObject = {
|
|||
const shouldBeInline = React.Children.toArray(props.children).every(
|
||||
(el) =>
|
||||
(typeof el === 'string' && !el.includes('\n')) ||
|
||||
(React.isValidElement(el) && inlineElements.includes(el.props.mdxType)),
|
||||
(isValidElement(el) && inlineElements.includes(el.props.mdxType)),
|
||||
);
|
||||
|
||||
return shouldBeInline ? <code {...props} /> : <CodeBlock {...props} />;
|
||||
|
|
|
@ -8,7 +8,6 @@
|
|||
import React, {
|
||||
useState,
|
||||
cloneElement,
|
||||
Children,
|
||||
isValidElement,
|
||||
type ReactElement,
|
||||
} from 'react';
|
||||
|
@ -40,7 +39,7 @@ function TabsComponent(props: Props): JSX.Element {
|
|||
groupId,
|
||||
className,
|
||||
} = props;
|
||||
const children = Children.map(props.children, (child) => {
|
||||
const children = React.Children.map(props.children, (child) => {
|
||||
if (isValidElement(child) && isTabItem(child)) {
|
||||
return child;
|
||||
}
|
||||
|
|
|
@ -11,11 +11,11 @@ import React, {
|
|||
useEffect,
|
||||
useRef,
|
||||
useCallback,
|
||||
useLayoutEffect,
|
||||
type RefObject,
|
||||
type Dispatch,
|
||||
type SetStateAction,
|
||||
type ReactNode,
|
||||
useLayoutEffect,
|
||||
} from 'react';
|
||||
|
||||
const DefaultAnimationEasing = 'ease-in-out';
|
||||
|
|
|
@ -6,10 +6,10 @@
|
|||
*/
|
||||
|
||||
import React, {
|
||||
type ComponentProps,
|
||||
type ReactElement,
|
||||
useRef,
|
||||
useState,
|
||||
type ComponentProps,
|
||||
type ReactElement,
|
||||
} from 'react';
|
||||
import useIsBrowser from '@docusaurus/useIsBrowser';
|
||||
import clsx from 'clsx';
|
||||
|
|
|
@ -10,9 +10,8 @@ import React, {
|
|||
useEffect,
|
||||
useCallback,
|
||||
useMemo,
|
||||
type ReactNode,
|
||||
useContext,
|
||||
createContext,
|
||||
type ReactNode,
|
||||
} from 'react';
|
||||
import useIsBrowser from '@docusaurus/useIsBrowser';
|
||||
import {createStorageSlot} from './storageUtils';
|
||||
|
@ -96,7 +95,9 @@ const useAnnouncementBarContextValue = (): AnnouncementBarAPI => {
|
|||
);
|
||||
};
|
||||
|
||||
const AnnouncementBarContext = createContext<AnnouncementBarAPI | null>(null);
|
||||
const AnnouncementBarContext = React.createContext<AnnouncementBarAPI | null>(
|
||||
null,
|
||||
);
|
||||
|
||||
export function AnnouncementBarProvider({
|
||||
children,
|
||||
|
|
|
@ -11,6 +11,7 @@ import React, {
|
|||
useEffect,
|
||||
useContext,
|
||||
useMemo,
|
||||
useRef,
|
||||
type ReactNode,
|
||||
} from 'react';
|
||||
import {ReactContextError} from './reactUtils';
|
||||
|
@ -96,7 +97,7 @@ function useColorModeContextValue(): ColorModeContextValue {
|
|||
// be reset to dark when exiting print mode, disregarding user settings. When
|
||||
// the listener fires only because of a print/screen switch, we don't change
|
||||
// color mode. See https://github.com/facebook/docusaurus/pull/6490
|
||||
const previousMediaIsPrint = React.useRef(false);
|
||||
const previousMediaIsPrint = useRef(false);
|
||||
|
||||
useEffect(() => {
|
||||
if (disableSwitch && !respectPrefersColorScheme) {
|
||||
|
|
|
@ -6,12 +6,11 @@
|
|||
*/
|
||||
|
||||
import React, {
|
||||
createContext,
|
||||
type ReactNode,
|
||||
useContext,
|
||||
useEffect,
|
||||
useMemo,
|
||||
useState,
|
||||
type ReactNode,
|
||||
} from 'react';
|
||||
import {useThemeConfig, type DocsVersionPersistence} from '../useThemeConfig';
|
||||
import {isDocsPluginEnabled} from '../docsUtils';
|
||||
|
@ -131,7 +130,9 @@ function useContextValue() {
|
|||
|
||||
type DocsPreferredVersionContextValue = ReturnType<typeof useContextValue>;
|
||||
|
||||
const Context = createContext<DocsPreferredVersionContextValue | null>(null);
|
||||
const Context = React.createContext<DocsPreferredVersionContextValue | null>(
|
||||
null,
|
||||
);
|
||||
|
||||
export function DocsPreferredVersionContextProvider({
|
||||
children,
|
||||
|
|
|
@ -5,7 +5,7 @@
|
|||
* LICENSE file in the root directory of this source tree.
|
||||
*/
|
||||
|
||||
import React, {createContext, type ReactNode, useContext} from 'react';
|
||||
import React, {type ReactNode, useContext} from 'react';
|
||||
import {
|
||||
useActivePlugin,
|
||||
useAllDocsData,
|
||||
|
@ -29,7 +29,7 @@ export const isDocsPluginEnabled: boolean = !!useAllDocsData;
|
|||
// Inspired by https://github.com/jamiebuilds/unstated-next/blob/master/src/unstated-next.tsx
|
||||
const EmptyContextValue: unique symbol = Symbol('EmptyContext');
|
||||
|
||||
const DocsVersionContext = createContext<
|
||||
const DocsVersionContext = React.createContext<
|
||||
PropVersionMetadata | typeof EmptyContextValue
|
||||
>(EmptyContextValue);
|
||||
|
||||
|
@ -69,7 +69,7 @@ export function useDocById(id: string | undefined): PropVersionDoc | undefined {
|
|||
return doc;
|
||||
}
|
||||
|
||||
const DocsSidebarContext = createContext<
|
||||
const DocsSidebarContext = React.createContext<
|
||||
PropSidebar | null | typeof EmptyContextValue
|
||||
>(EmptyContextValue);
|
||||
|
||||
|
|
|
@ -7,12 +7,11 @@
|
|||
|
||||
import React, {
|
||||
useState,
|
||||
type ReactNode,
|
||||
useContext,
|
||||
createContext,
|
||||
useEffect,
|
||||
type ComponentType,
|
||||
useMemo,
|
||||
type ReactNode,
|
||||
type ComponentType,
|
||||
} from 'react';
|
||||
import {ReactContextError} from './reactUtils';
|
||||
|
||||
|
@ -46,7 +45,7 @@ function useContextValue() {
|
|||
|
||||
type ContextValue = ReturnType<typeof useContextValue>;
|
||||
|
||||
const Context = createContext<ContextValue | null>(null);
|
||||
const Context = React.createContext<ContextValue | null>(null);
|
||||
|
||||
export function MobileSecondaryMenuProvider({
|
||||
children,
|
||||
|
|
|
@ -6,14 +6,13 @@
|
|||
*/
|
||||
|
||||
import React, {
|
||||
createContext,
|
||||
type ReactNode,
|
||||
useCallback,
|
||||
useContext,
|
||||
useEffect,
|
||||
useLayoutEffect,
|
||||
useMemo,
|
||||
useRef,
|
||||
type ReactNode,
|
||||
} from 'react';
|
||||
import {useDynamicCallback, ReactContextError} from './reactUtils';
|
||||
import ExecutionEnvironment from '@docusaurus/ExecutionEnvironment';
|
||||
|
@ -57,7 +56,7 @@ function useScrollControllerContextValue(): ScrollController {
|
|||
);
|
||||
}
|
||||
|
||||
const ScrollMonitorContext = createContext<ScrollController | undefined>(
|
||||
const ScrollMonitorContext = React.createContext<ScrollController | undefined>(
|
||||
undefined,
|
||||
);
|
||||
|
||||
|
|
|
@ -9,7 +9,6 @@ import React, {
|
|||
useState,
|
||||
useCallback,
|
||||
useEffect,
|
||||
createContext,
|
||||
useMemo,
|
||||
useContext,
|
||||
type ReactNode,
|
||||
|
@ -24,7 +23,7 @@ type TabGroupChoiceContextValue = {
|
|||
readonly setTabGroupChoices: (groupId: string, newChoice: string) => void;
|
||||
};
|
||||
|
||||
const TabGroupChoiceContext = createContext<
|
||||
const TabGroupChoiceContext = React.createContext<
|
||||
TabGroupChoiceContextValue | undefined
|
||||
>(undefined);
|
||||
|
||||
|
|
|
@ -5,6 +5,7 @@
|
|||
* LICENSE file in the root directory of this source tree.
|
||||
*/
|
||||
|
||||
import {jest} from '@jest/globals';
|
||||
import {extractThemeCodeMessages} from '../update';
|
||||
import path from 'path';
|
||||
import fs from 'fs-extra';
|
||||
|
|
|
@ -5,6 +5,7 @@
|
|||
* LICENSE file in the root directory of this source tree.
|
||||
*/
|
||||
|
||||
import {jest} from '@jest/globals';
|
||||
import Joi from '../Joi';
|
||||
import {JoiFrontMatter} from '../JoiFrontMatter';
|
||||
import {validateFrontMatter} from '../validationUtils';
|
||||
|
@ -21,7 +22,9 @@ describe('validateFrontMatter', () => {
|
|||
});
|
||||
|
||||
test('should reject bad values', () => {
|
||||
const consoleError = jest.spyOn(console, 'error').mockImplementation();
|
||||
const consoleError = jest
|
||||
.spyOn(console, 'error')
|
||||
.mockImplementation(() => {});
|
||||
const schema = Joi.object<{test: string}>({
|
||||
test: Joi.string(),
|
||||
});
|
||||
|
|
|
@ -5,6 +5,7 @@
|
|||
* LICENSE file in the root directory of this source tree.
|
||||
*/
|
||||
|
||||
import {jest} from '@jest/globals';
|
||||
import {genChunkName, readOutputHTMLFile, generate} from '../emitUtils';
|
||||
import path from 'path';
|
||||
import fs from 'fs-extra';
|
||||
|
|
|
@ -5,6 +5,7 @@
|
|||
* LICENSE file in the root directory of this source tree.
|
||||
*/
|
||||
|
||||
import {jest} from '@jest/globals';
|
||||
import {
|
||||
removeSuffix,
|
||||
removePrefix,
|
||||
|
|
|
@ -5,7 +5,7 @@
|
|||
* LICENSE file in the root directory of this source tree.
|
||||
*/
|
||||
|
||||
import React, {type ReactNode, useContext, createContext} from 'react';
|
||||
import React, {type ReactNode, useContext} from 'react';
|
||||
|
||||
type LinksCollector = {
|
||||
collectLink: (link: string) => void;
|
||||
|
@ -26,7 +26,7 @@ export const createStatefulLinksCollector = (): StatefulLinksCollector => {
|
|||
};
|
||||
};
|
||||
|
||||
const Context = createContext<LinksCollector>({
|
||||
const Context = React.createContext<LinksCollector>({
|
||||
collectLink: () => {
|
||||
// noop by default for client
|
||||
// we only use the broken links checker server-side
|
||||
|
|
|
@ -5,6 +5,7 @@
|
|||
* LICENSE file in the root directory of this source tree.
|
||||
*/
|
||||
|
||||
import {jest} from '@jest/globals';
|
||||
import normalizeLocation from '../normalizeLocation';
|
||||
|
||||
describe('normalizeLocation', () => {
|
||||
|
|
|
@ -6,7 +6,7 @@
|
|||
*/
|
||||
|
||||
import React from 'react';
|
||||
import {hydrate, render} from 'react-dom';
|
||||
import ReactDOM from 'react-dom';
|
||||
import {BrowserRouter} from 'react-router-dom';
|
||||
import {HelmetProvider} from 'react-helmet-async';
|
||||
|
||||
|
@ -30,7 +30,8 @@ if (ExecutionEnvironment.canUseDOM) {
|
|||
// first-load experience.
|
||||
// For development, there is no existing markup so we had to render it.
|
||||
// We also preload async component to avoid first-load loading screen.
|
||||
const renderMethod = process.env.NODE_ENV === 'production' ? hydrate : render;
|
||||
const renderMethod =
|
||||
process.env.NODE_ENV === 'production' ? ReactDOM.hydrate : ReactDOM.render;
|
||||
preload(routes, window.location.pathname).then(() => {
|
||||
renderMethod(
|
||||
<HelmetProvider>
|
||||
|
|
|
@ -5,7 +5,7 @@
|
|||
* LICENSE file in the root directory of this source tree.
|
||||
*/
|
||||
|
||||
import React, {type ReactNode} from 'react';
|
||||
import React, {isValidElement, type ReactNode} from 'react';
|
||||
import type {
|
||||
InterpolateProps,
|
||||
InterpolateValues,
|
||||
|
@ -49,7 +49,7 @@ export function interpolate<Str extends string, Value extends ReactNode>(
|
|||
const value = values?.[key];
|
||||
|
||||
if (typeof value !== 'undefined') {
|
||||
const element = React.isValidElement(value)
|
||||
const element = isValidElement(value)
|
||||
? value
|
||||
: // For non-React elements: basic primitive->string conversion
|
||||
String(value);
|
||||
|
|
|
@ -5,6 +5,7 @@
|
|||
* LICENSE file in the root directory of this source tree.
|
||||
*/
|
||||
|
||||
import {jest} from '@jest/globals';
|
||||
import React from 'react';
|
||||
import renderer from 'react-test-renderer';
|
||||
import BrowserOnly from '../BrowserOnly';
|
||||
|
|
|
@ -5,12 +5,13 @@
|
|||
* LICENSE file in the root directory of this source tree.
|
||||
*/
|
||||
|
||||
import {jest} from '@jest/globals';
|
||||
import useBaseUrl, {useBaseUrlUtils} from '../useBaseUrl';
|
||||
import useDocusaurusContext from '../useDocusaurusContext';
|
||||
|
||||
jest.mock('../useDocusaurusContext', () => jest.fn(), {virtual: true});
|
||||
jest.mock('../useDocusaurusContext');
|
||||
|
||||
const mockedContext = <jest.Mock>useDocusaurusContext;
|
||||
const mockedContext = useDocusaurusContext as jest.Mock;
|
||||
|
||||
const forcePrepend = {forcePrependBaseUrl: true};
|
||||
|
||||
|
|
|
@ -5,6 +5,7 @@
|
|||
* LICENSE file in the root directory of this source tree.
|
||||
*/
|
||||
|
||||
import {jest} from '@jest/globals';
|
||||
import path from 'path';
|
||||
import fs from 'fs-extra';
|
||||
import {ThemePath, createTempSiteDir, Components} from './testUtils';
|
||||
|
|
2
packages/docusaurus/src/deps.d.ts
vendored
2
packages/docusaurus/src/deps.d.ts
vendored
|
@ -62,7 +62,7 @@ declare module '@slorber/static-site-generator-webpack-plugin' {
|
|||
}
|
||||
|
||||
declare module 'webpack/lib/HotModuleReplacementPlugin' {
|
||||
import {HotModuleReplacementPlugin} from 'webpack';
|
||||
import type {HotModuleReplacementPlugin} from 'webpack';
|
||||
|
||||
export default HotModuleReplacementPlugin;
|
||||
}
|
||||
|
|
|
@ -5,6 +5,7 @@
|
|||
* LICENSE file in the root directory of this source tree.
|
||||
*/
|
||||
|
||||
import {jest} from '@jest/globals';
|
||||
import path from 'path';
|
||||
import _ from 'lodash';
|
||||
import {handleBrokenLinks} from '../brokenLinks';
|
||||
|
@ -157,7 +158,7 @@ describe('handleBrokenLinks', () => {
|
|||
test('no-op for ignore', async () => {
|
||||
// In any case, _.mapValues will always be called, unless handleBrokenLinks
|
||||
// has already bailed
|
||||
const lodashMock = jest.spyOn(_, 'mapValues').mockImplementation();
|
||||
const lodashMock = jest.spyOn(_, 'mapValues');
|
||||
await handleBrokenLinks({
|
||||
allCollectedLinks,
|
||||
onBrokenLinks: 'ignore',
|
||||
|
|
|
@ -5,6 +5,7 @@
|
|||
* LICENSE file in the root directory of this source tree.
|
||||
*/
|
||||
|
||||
import {jest} from '@jest/globals';
|
||||
import {handleDuplicateRoutes} from '../duplicateRoutes';
|
||||
import type {RouteConfig} from '@docusaurus/types';
|
||||
|
||||
|
|
|
@ -5,6 +5,7 @@
|
|||
* LICENSE file in the root directory of this source tree.
|
||||
*/
|
||||
|
||||
import {jest} from '@jest/globals';
|
||||
import {loadI18n, localizePath, getDefaultLocaleConfig} from '../i18n';
|
||||
import {DEFAULT_I18N_CONFIG} from '../configValidation';
|
||||
import path from 'path';
|
||||
|
@ -79,7 +80,7 @@ describe('defaultLocaleConfig', () => {
|
|||
});
|
||||
|
||||
describe('loadI18n', () => {
|
||||
const consoleSpy = jest.spyOn(console, 'warn').mockImplementation();
|
||||
const consoleSpy = jest.spyOn(console, 'warn').mockImplementation(() => {});
|
||||
beforeEach(() => {
|
||||
consoleSpy.mockClear();
|
||||
});
|
||||
|
|
|
@ -20,6 +20,7 @@ export function sortAliases(aliases: ThemeAliases): ThemeAliases {
|
|||
const entries = _.sortBy(Object.entries(aliases), ([alias]) => alias);
|
||||
// @theme/NavbarItem should be after @theme/NavbarItem/LocaleDropdown
|
||||
entries.sort(([alias1], [alias2]) =>
|
||||
// eslint-disable-next-line no-nested-ternary
|
||||
alias1.includes(`${alias2}/`) ? -1 : alias2.includes(`${alias1}/`) ? 1 : 0,
|
||||
);
|
||||
return Object.fromEntries(entries);
|
||||
|
|
|
@ -5,6 +5,7 @@
|
|||
* LICENSE file in the root directory of this source tree.
|
||||
*/
|
||||
|
||||
import {jest} from '@jest/globals';
|
||||
import {
|
||||
ensureTranslationFileContent,
|
||||
writeTranslationFileContent,
|
||||
|
@ -560,7 +561,7 @@ describe('getPluginsDefaultCodeTranslationMessages', () => {
|
|||
});
|
||||
|
||||
describe('applyDefaultCodeTranslations', () => {
|
||||
const consoleSpy = jest.spyOn(console, 'warn').mockImplementation();
|
||||
const consoleSpy = jest.spyOn(console, 'warn').mockImplementation(() => {});
|
||||
beforeEach(() => {
|
||||
consoleSpy.mockClear();
|
||||
});
|
||||
|
|
|
@ -5,6 +5,7 @@
|
|||
* LICENSE file in the root directory of this source tree.
|
||||
*/
|
||||
|
||||
import {jest} from '@jest/globals';
|
||||
import fs from 'fs-extra';
|
||||
import tmp from 'tmp-promise';
|
||||
import {
|
||||
|
|
|
@ -5,6 +5,7 @@
|
|||
* LICENSE file in the root directory of this source tree.
|
||||
*/
|
||||
|
||||
import {jest} from '@jest/globals';
|
||||
import path from 'path';
|
||||
|
||||
import {
|
||||
|
|
|
@ -5,7 +5,8 @@
|
|||
* LICENSE file in the root directory of this source tree.
|
||||
*/
|
||||
|
||||
import {validate} from 'webpack';
|
||||
import {jest} from '@jest/globals';
|
||||
import webpack from 'webpack';
|
||||
|
||||
import createClientConfig from '../client';
|
||||
import loadSetup from '../../server/__tests__/testUtils';
|
||||
|
@ -15,7 +16,7 @@ describe('webpack dev config', () => {
|
|||
console.log = jest.fn();
|
||||
const props = await loadSetup('simple');
|
||||
const config = await createClientConfig(props);
|
||||
const errors = validate(config);
|
||||
const errors = webpack.validate(config);
|
||||
expect(errors).toBeUndefined();
|
||||
});
|
||||
|
||||
|
@ -23,7 +24,7 @@ describe('webpack dev config', () => {
|
|||
console.log = jest.fn();
|
||||
const props = await loadSetup('custom');
|
||||
const config = await createClientConfig(props);
|
||||
const errors = validate(config);
|
||||
const errors = webpack.validate(config);
|
||||
expect(errors).toBeUndefined();
|
||||
});
|
||||
});
|
||||
|
|
|
@ -5,7 +5,8 @@
|
|||
* LICENSE file in the root directory of this source tree.
|
||||
*/
|
||||
|
||||
import {validate} from 'webpack';
|
||||
import {jest} from '@jest/globals';
|
||||
import webpack from 'webpack';
|
||||
|
||||
import createServerConfig from '../server';
|
||||
import loadSetup from '../../server/__tests__/testUtils';
|
||||
|
@ -15,7 +16,7 @@ describe('webpack production config', () => {
|
|||
console.log = jest.fn();
|
||||
const props = await loadSetup('simple');
|
||||
const config = await createServerConfig({props});
|
||||
const errors = validate(config);
|
||||
const errors = webpack.validate(config);
|
||||
expect(errors).toBeUndefined();
|
||||
});
|
||||
|
||||
|
@ -23,7 +24,7 @@ describe('webpack production config', () => {
|
|||
console.log = jest.fn();
|
||||
const props = await loadSetup('custom');
|
||||
const config = await createServerConfig({props});
|
||||
const errors = validate(config);
|
||||
const errors = webpack.validate(config);
|
||||
expect(errors).toBeUndefined();
|
||||
});
|
||||
});
|
||||
|
|
|
@ -5,7 +5,7 @@
|
|||
* LICENSE file in the root directory of this source tree.
|
||||
*/
|
||||
|
||||
import {validate, type Configuration, type RuleSetRule} from 'webpack';
|
||||
import webpack, {type Configuration, type RuleSetRule} from 'webpack';
|
||||
import path from 'path';
|
||||
|
||||
import {
|
||||
|
@ -86,7 +86,7 @@ describe('extending generated webpack config', () => {
|
|||
filename: 'new.bundle.js',
|
||||
},
|
||||
});
|
||||
const errors = validate(config);
|
||||
const errors = webpack.validate(config);
|
||||
expect(errors).toBeUndefined();
|
||||
});
|
||||
|
||||
|
@ -116,7 +116,7 @@ describe('extending generated webpack config', () => {
|
|||
filename: 'new.bundle.js',
|
||||
},
|
||||
});
|
||||
const errors = validate(config);
|
||||
const errors = webpack.validate(config);
|
||||
expect(errors).toBeUndefined();
|
||||
});
|
||||
|
||||
|
|
|
@ -5,7 +5,7 @@
|
|||
* LICENSE file in the root directory of this source tree.
|
||||
*/
|
||||
|
||||
import {Template, type Compiler} from 'webpack';
|
||||
import webpack, {type Compiler} from 'webpack';
|
||||
|
||||
const pluginName = 'chunk-asset-plugin';
|
||||
|
||||
|
@ -48,7 +48,7 @@ export default class ChunkAssetPlugin {
|
|||
chunkNameToId,
|
||||
)}[chunkId]||chunkId; return __webpack_require__.p + __webpack_require__.u(chunkId); };`,
|
||||
);
|
||||
return Template.asString(buf);
|
||||
return webpack.Template.asString(buf);
|
||||
});
|
||||
});
|
||||
}
|
||||
|
|
|
@ -13,7 +13,9 @@ describe('lqip library', () => {
|
|||
const invalidPath = path.join(__dirname, '__fixtures__', 'docusaurus.svg');
|
||||
|
||||
it('should reject unknown or unsupported file format', async () => {
|
||||
await expect(lqip.base64(invalidPath)).rejects.toBeTruthy();
|
||||
await expect(lqip.base64(invalidPath)).rejects.toThrow(
|
||||
/Error: Input file is missing or uses unsupported image format, lqip v.*/,
|
||||
);
|
||||
});
|
||||
|
||||
it('should generate a valid base64', async () => {
|
||||
|
|
|
@ -11,36 +11,35 @@ import type {Palette} from 'node-vibrant/lib/color';
|
|||
|
||||
import {toPalette, toBase64} from '../utils';
|
||||
|
||||
describe('lqip-loader', () => {
|
||||
describe('toBase64', () => {
|
||||
test('should return a properly formatted Base64 image string', () => {
|
||||
const expected = 'data:image/jpeg;base64,aGVsbG8gd29ybGQ=';
|
||||
const mockedMimeType = 'image/jpeg';
|
||||
const mockedBase64Data = Buffer.from('hello world');
|
||||
expect(toBase64(mockedMimeType, mockedBase64Data)).toEqual(expected);
|
||||
});
|
||||
});
|
||||
|
||||
describe('toPalette', () => {
|
||||
let correctTestSwatch: Palette = {};
|
||||
let testSwatchWithNull: Palette & {Vibrant?: null} = {};
|
||||
|
||||
beforeAll(() => {
|
||||
const imgPath = path.join(__dirname, '__fixtures__', 'endi.jpg');
|
||||
const vibrant = new Vibrant(imgPath, {});
|
||||
|
||||
return vibrant.getPalette().then((palette) => {
|
||||
correctTestSwatch = {...palette};
|
||||
testSwatchWithNull = {...palette, Vibrant: null};
|
||||
});
|
||||
});
|
||||
|
||||
it('should return 6 hex colours sorted by popularity', () => {
|
||||
expect(toPalette(correctTestSwatch)).toHaveLength(6);
|
||||
});
|
||||
|
||||
it('should return 5 hex colours with no errors if a palette was incomplete', () => {
|
||||
expect(toPalette(testSwatchWithNull)).toHaveLength(5);
|
||||
});
|
||||
describe('toBase64', () => {
|
||||
test('should return a properly formatted Base64 image string', () => {
|
||||
const mockedMimeType = 'image/jpeg';
|
||||
const mockedBase64Data = Buffer.from('hello world');
|
||||
expect(toBase64(mockedMimeType, mockedBase64Data)).toEqual(
|
||||
'data:image/jpeg;base64,aGVsbG8gd29ybGQ=',
|
||||
);
|
||||
});
|
||||
});
|
||||
|
||||
describe('toPalette', () => {
|
||||
let correctTestSwatch: Palette = {};
|
||||
let testSwatchWithNull: Palette & {Vibrant?: null} = {};
|
||||
|
||||
beforeAll(() => {
|
||||
const imgPath = path.join(__dirname, '__fixtures__/endi.jpg');
|
||||
const vibrant = new Vibrant(imgPath, {});
|
||||
|
||||
return vibrant.getPalette().then((palette) => {
|
||||
correctTestSwatch = {...palette};
|
||||
testSwatchWithNull = {...palette, Vibrant: null};
|
||||
});
|
||||
});
|
||||
|
||||
it('should return 6 hex colours sorted by popularity', () => {
|
||||
expect(toPalette(correctTestSwatch)).toHaveLength(6);
|
||||
});
|
||||
|
||||
it('should return 5 hex colours with no errors if a palette was incomplete', () => {
|
||||
expect(toPalette(testSwatchWithNull)).toHaveLength(5);
|
||||
});
|
||||
});
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue