From 3733dfee525201f4520daccddf9c56563cb7ff76 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?S=C3=A9bastien=20Lorber?= Date: Mon, 7 Jul 2025 16:50:01 +0200 Subject: [PATCH] test: fix site test infinite loop in Jest --watch mode + simplify test (#11312) --- jest.config.mjs | 7 +++-- .../__tests__/__snapshots__/site.test.ts.snap | 2 +- .../src/server/__tests__/site.test.ts | 28 ++++++++----------- 3 files changed, 17 insertions(+), 20 deletions(-) diff --git a/jest.config.mjs b/jest.config.mjs index 3245daa850..e8e4f3d235 100644 --- a/jest.config.mjs +++ b/jest.config.mjs @@ -32,15 +32,16 @@ const ignorePatterns = [ export default { rootDir: fileURLToPath(new URL('.', import.meta.url)), verbose: true, + // Default 5s timeout often fails on Windows :s, + // see https://github.com/facebook/docusaurus/pull/8259 + testTimeout: 15000, setupFiles: ['./jest/setup.js'], testEnvironmentOptions: { url: 'https://docusaurus.io/', }, testEnvironment: 'node', testPathIgnorePatterns: ignorePatterns, - // Default 5s timeout often fails on Windows :s, - // see https://github.com/facebook/docusaurus/pull/8259 - testTimeout: 15000, + watchPathIgnorePatterns: ['/\\.docusaurus'], coveragePathIgnorePatterns: [ ...ignorePatterns, // We also ignore all package entry points diff --git a/packages/docusaurus/src/server/__tests__/__snapshots__/site.test.ts.snap b/packages/docusaurus/src/server/__tests__/__snapshots__/site.test.ts.snap index b15943ef82..4b335e062b 100644 --- a/packages/docusaurus/src/server/__tests__/__snapshots__/site.test.ts.snap +++ b/packages/docusaurus/src/server/__tests__/__snapshots__/site.test.ts.snap @@ -1,6 +1,6 @@ // Jest Snapshot v1, https://goo.gl/fbAQLP -exports[`load loads props for site with custom i18n path 1`] = ` +exports[`load loads props for site 1`] = ` { "baseUrl": "/", "codeTranslations": {}, diff --git a/packages/docusaurus/src/server/__tests__/site.test.ts b/packages/docusaurus/src/server/__tests__/site.test.ts index dc6027c780..7ce18bfa4d 100644 --- a/packages/docusaurus/src/server/__tests__/site.test.ts +++ b/packages/docusaurus/src/server/__tests__/site.test.ts @@ -6,26 +6,22 @@ */ import path from 'path'; -import {mergeWithCustomize} from 'webpack-merge'; import {loadSetup} from './testUtils'; -import type {Props} from '@docusaurus/types'; -import type {DeepPartial} from 'utility-types'; describe('load', () => { - it('loads props for site with custom i18n path', async () => { + it('loads props for site', async () => { const site = await loadSetup('custom-i18n-site'); expect(site.props).toMatchSnapshot(); - const site2 = await loadSetup('custom-i18n-site', {locale: 'zh-Hans'}); - expect(site2.props).toEqual( - mergeWithCustomize>({ - customizeArray(a, b, key) { - return ['routesPaths', 'plugins'].includes(key) ? b : undefined; - }, - })(site.props, { + }); + + it('loads props for site - custom i18n path', async () => { + const site = await loadSetup('custom-i18n-site', {locale: 'zh-Hans'}); + expect(site.props).toEqual( + expect.objectContaining({ baseUrl: '/zh-Hans/', - i18n: { + i18n: expect.objectContaining({ currentLocale: 'zh-Hans', - }, + }), localizationDir: path.join( __dirname, '__fixtures__/custom-i18n-site/i18n/zh-Hans-custom', @@ -35,14 +31,14 @@ describe('load', () => { '__fixtures__/custom-i18n-site/build/zh-Hans', ), routesPaths: ['/zh-Hans/404.html'], - siteConfig: { + siteConfig: expect.objectContaining({ baseUrl: '/zh-Hans/', - }, + }), siteStorage: { namespace: '', type: 'localStorage', }, - plugins: site2.props.plugins, + plugins: site.props.plugins, }), ); });