Skip to content

Commit

Permalink
fix tests
Browse files Browse the repository at this point in the history
  • Loading branch information
slorber committed Aug 27, 2024
1 parent 1b49ebf commit d486371
Show file tree
Hide file tree
Showing 4 changed files with 18 additions and 7 deletions.
17 changes: 13 additions & 4 deletions packages/docusaurus-mdx-loader/src/createMDXLoader.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,18 +9,27 @@ import {createProcessors} from './processor';
import type {Options} from './loader';
import type {RuleSetRule, RuleSetUseItem} from 'webpack';

export async function createMDXLoaderItem(
options: Options,
): Promise<RuleSetUseItem> {
async function enhancedOptions(options: Options): Promise<Options> {
// Because Jest doesn't like ESM / createProcessors()
if (process.env.N0DE_ENV === 'test' || process.env.JEST_WORKER_ID) {
return options;
}

// We create the processor earlier here, to avoid the lazy processor creating
// Lazy creation messes-up with Rsdoctor ability to measure mdx-loader perf
const newOptions: Options = options.processors
? options
: {...options, processors: await createProcessors({options})};

return newOptions;
}

export async function createMDXLoaderItem(
options: Options,
): Promise<RuleSetUseItem> {
return {
loader: require.resolve('@docusaurus/mdx-loader'),
options: newOptions,
options: await enhancedOptions(options),
};
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -107,6 +107,7 @@ const getPlugin = async (
url: 'https://docusaurus.io',
markdown,
future: {},
staticDirectories: ['static'],
} as DocusaurusConfig;
return pluginContentBlog(
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ describe('docusaurus-plugin-content-pages', () => {
it('loads simple pages', async () => {
const siteDir = path.join(__dirname, '__fixtures__', 'website');
const context = await loadContext({siteDir});
const plugin = pluginContentPages(
const plugin = await pluginContentPages(
context,
validateOptions({
validate: normalizePluginOptions,
Expand All @@ -33,7 +33,7 @@ describe('docusaurus-plugin-content-pages', () => {
it('loads simple pages with french translations', async () => {
const siteDir = path.join(__dirname, '__fixtures__', 'website');
const context = await loadContext({siteDir, locale: 'fr'});
const plugin = pluginContentPages(
const plugin = await pluginContentPages(
context,
validateOptions({
validate: normalizePluginOptions,
Expand All @@ -50,7 +50,7 @@ describe('docusaurus-plugin-content-pages', () => {
it('loads simple pages with last update', async () => {
const siteDir = path.join(__dirname, '__fixtures__', 'website');
const context = await loadContext({siteDir});
const plugin = pluginContentPages(
const plugin = await pluginContentPages(
context,
validateOptions({
validate: normalizePluginOptions,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ async function testLoad({
baseUrl: '/',
trailingSlash: true,
themeConfig: {},
staticDirectories: [],
presets: [],
plugins,
themes,
Expand Down

0 comments on commit d486371

Please sign in to comment.