Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion jest.config.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ export default {
// Default 5s timeout often fails on Windows :s,
// see https://github.com/facebook/docusaurus/pull/8259
testTimeout: 15000,
setupFiles: ['./jest/setup.js'],
setupFiles: ['./jest/setup.ts'],
testEnvironmentOptions: {
url: 'https://docusaurus.io/',
},
Expand Down
11 changes: 0 additions & 11 deletions jest/setup.js

This file was deleted.

8 changes: 8 additions & 0 deletions jest/setup.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
/**
* Copyright (c) Facebook, Inc. and its affiliates.
*
* This source code is licensed under the MIT license found in the
* LICENSE file in the root directory of this source tree.
*/

// Currently not used anymore, but kept for potential future setup needs
73 changes: 70 additions & 3 deletions jest/snapshotPathNormalizer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,60 @@

import os from 'os';
import path from 'path';
import fs from 'fs';
import _ from 'lodash';
import {escapePath} from '@docusaurus/utils';
import {version} from '@docusaurus/core/package.json';
import stripAnsi from 'strip-ansi';

/*
This weird thing is to normalize paths on our Windows GitHub Actions runners

For some reason, os.tmpdir() returns the "legacy 8.3 DOS short paths"
This prevents snapshot normalization on Windows

tempDir: 'C:\\Users\\RUNNER~1\\AppData\\Local\\Temp',
tempDirReal: 'C:\\Users\\RUNNER~1\\AppData\\Local\\Temp',
homeDir: 'C:\\Users\\runneradmin',
homeDirReal: 'C:\\Users\\runneradmin',
*/
function normalizeWindowTempDirShortPath(str: string): string {
return str.replace('\\RUNNER~1\\', '\\runneradmin\\');
}

function readPathsForNormalization() {
const cwd = process.cwd();

const tempDir = os.tmpdir();
const homeDir = os.homedir();

// Can we get rid of this legacy sync FS function?
function getRealPathSync(pathname: string): string {
try {
// eslint-disable-next-line no-restricted-properties
return fs.realpathSync(pathname);
} catch (err) {
return pathname;
}
}

const tempDirReal = getRealPathSync(tempDir);
const homeDirReal = getRealPathSync(homeDir);

return {
cwd,
tempDir: normalizeWindowTempDirShortPath(tempDir),
tempDirReal: normalizeWindowTempDirShortPath(tempDirReal),
homeDir,
homeDirReal,
};
}

// We memoize it to avoid useless FS calls on each path normalization
const getPathsForNormalization: typeof readPathsForNormalization = _.memoize(
readPathsForNormalization,
);

export function print(
val: unknown,
serialize: (val: unknown) => string,
Expand Down Expand Up @@ -63,9 +112,8 @@ function normalizePaths<T>(value: T): T {
return value;
}

const cwd = process.cwd();
const tempDir = os.tmpdir();
const homeDir = os.homedir();
const {cwd, tempDir, tempDirReal, homeDir, homeDirReal} =
getPathsForNormalization();

const homeRelativeToTemp = path.relative(tempDir, homeDir);

Expand All @@ -75,17 +123,36 @@ function normalizePaths<T>(value: T): T {
(val) => val.split(cwd).join('<PROJECT_ROOT>'),

// Replace temp directory with <TEMP_DIR>
(val) => val.split(tempDirReal).join('<TEMP_DIR>'),
(val) => val.split(tempDir).join('<TEMP_DIR>'),

(val) => val.split(tempDirReal).join('<TEMP_DIR>'),
(val) => val.split(tempDir).join('<TEMP_DIR>'),

// Replace home directory with <HOME_DIR>
(val) => val.split(homeDirReal).join('<HOME_DIR>'),
(val) => val.split(homeDir).join('<HOME_DIR>'),

// Handle HOME_DIR nested inside TEMP_DIR
// This happens on windows GitHub actions runners
// tempDir: 'C:\\Users\\RUNNER~1\\AppData\\Local\\Temp',
// homeDir: 'C:\\Users\\runneradmin',
(val) =>
val
.split(`<TEMP_DIR>${path.sep + homeRelativeToTemp}`)
.join('<HOME_DIR>'),

// replace /prefix___MKDTEMP_DIR___ABC123 with /prefix<MKDTEMP_DIR_STABLE>
// The random 6-char suffix of mkdtemp() is removed to make snapshots stable
(val) => {
const [before, after] = val.split('___MKDTEMP_DIR___');
if (after) {
const afterSub = after.substring(6);
return [before, afterSub].join('<MKDTEMP_DIR_STABLE>');
}
return before;
},

// Replace the Docusaurus version with a stub
(val) => val.split(version).join('<CURRENT_VERSION>'),

Expand Down
26 changes: 14 additions & 12 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -78,15 +78,16 @@
"@crowdin/cli": "^3.13.0",
"@prettier/plugin-xml": "^2.2.0",
"@swc/core": "^1.7.14",
"@swc/jest": "^0.2.36",
"@testing-library/react-hooks": "^8.0.1",
"@swc/jest": "^0.2.39",
"@testing-library/dom": "^10.4.1",
"@testing-library/jest-dom": "^6.9.1",
"@testing-library/react": "^16.3.2",
"@types/fs-extra": "^9.0.13",
"@types/jest": "^29.5.12",
"@types/jest": "^30.0.0",
"@types/lodash": "^4.14.197",
"@types/node": "^18.16.19",
"@types/prompts": "^2.4.4",
"@types/react": "^19.2.10",
"@types/react-test-renderer": "^18.0.0",
"@types/semver": "^7.5.0",
"@types/shelljs": "^0.8.12",
"@typescript-eslint/eslint-plugin": "^5.62.0",
Expand All @@ -98,17 +99,17 @@
"eslint-config-prettier": "^8.8.0",
"eslint-plugin-header": "^3.1.1",
"eslint-plugin-import": "^2.27.5",
"eslint-plugin-jest": "^27.2.3",
"eslint-plugin-jest": "^27.9.0",
"eslint-plugin-jsx-a11y": "^6.7.1",
"eslint-plugin-react": "^7.32.2",
"eslint-plugin-react-compiler": "^19.0.0-beta-40c6c23-20250301",
"eslint-plugin-react-hooks": "^4.6.0",
"eslint-plugin-regexp": "^1.15.0",
"husky": "^8.0.3",
"image-size": "^2.0.2",
"jest": "^29.7.0",
"jest-environment-jsdom": "^29.7.0",
"jest-serializer-ansi-escapes": "^3.0.0",
"jest": "^30.2.0",
"jest-environment-jsdom": "^30.2.0",
"jest-serializer-ansi-escapes": "^4.0.0",
"jest-serializer-react-helmet-async": "^1.0.21",
"lerna": "^6.6.2",
"lerna-changelog": "^2.2.0",
Expand All @@ -118,9 +119,8 @@
"patch-package": "^8.0.0",
"postinstall-postinstall": "^2.1.0",
"prettier": "^2.8.8",
"react": "^18.0.0",
"react-dom": "^18.0.0",
"react-test-renderer": "^18.0.0",
"react": "^19.2.4",
"react-dom": "^19.2.4",
"rimraf": "^3.0.2",
"sharp": "^0.32.3",
"strip-ansi": "^6.0.1",
Expand All @@ -129,6 +129,8 @@
"stylelint-config-standard": "^29.0.0",
"typescript": "~5.8.2"
},
"resolutions": {},
"resolutions": {
"**/pretty-format/react-is": "^19.2.4"
},
"packageManager": "yarn@1.22.22+sha512.a6b2f7906b721bba3d67d4aff083df04dad64c399707841b7acf00f6b133b7ac24255f2652fa22ae3534329dc6180534e98d17432037ff6fd140556e2bb3137e"
}
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// Jest Snapshot v1, https://goo.gl/fbAQLP
// Jest Snapshot v1, https://jestjs.io/docs/snapshot-testing

exports[`remove-overridden-custom-properties overridden custom properties should be removed 1`] = `
"/* stylelint-disable docusaurus/copyright-header, declaration-block-no-duplicate-custom-properties */
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// Jest Snapshot v1, https://goo.gl/fbAQLP
// Jest Snapshot v1, https://jestjs.io/docs/snapshot-testing

exports[`error prints objects 1`] = `
[
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// Jest Snapshot v1, https://goo.gl/fbAQLP
// Jest Snapshot v1, https://jestjs.io/docs/snapshot-testing

exports[`admonitions remark plugin add custom keyword 1`] = `
"<p>The blog feature enables you to deploy in no time a full-featured blog.</p>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// Jest Snapshot v1, https://goo.gl/fbAQLP
// Jest Snapshot v1, https://jestjs.io/docs/snapshot-testing

exports[`toc remark plugin does not overwrite TOC var if no TOC 1`] = `
"import {Fragment as _Fragment, jsx as _jsx, jsxs as _jsxs} from "react/jsx-runtime";
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// Jest Snapshot v1, https://goo.gl/fbAQLP
// Jest Snapshot v1, https://jestjs.io/docs/snapshot-testing

exports[`transformImage plugin does not choke on invalid image 1`] = `
"<img alt="invalid image" src={require("!<PROJECT_ROOT>/node_modules/url-loader/dist/cjs.js?limit=10000&name=assets/images/[name]-[contenthash].[ext]&fallback=<PROJECT_ROOT>/node_modules/file-loader/dist/cjs.js!./../static/invalid.png").default} />
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// Jest Snapshot v1, https://goo.gl/fbAQLP
// Jest Snapshot v1, https://jestjs.io/docs/snapshot-testing

exports[`transformLinks plugin transform md links to <a /> 1`] = `
"[asset](https://example.com/asset.pdf)
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// Jest Snapshot v1, https://goo.gl/fbAQLP
// Jest Snapshot v1, https://jestjs.io/docs/snapshot-testing

exports[`directives remark plugin - client compiler default behavior for container directives: console 1`] = `
[
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// Jest Snapshot v1, https://goo.gl/fbAQLP
// Jest Snapshot v1, https://jestjs.io/docs/snapshot-testing

exports[`collectRedirects throw if plugin option redirects contain invalid to paths 1`] = `
"You are trying to create client-side redirections to invalid paths.
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// Jest Snapshot v1, https://goo.gl/fbAQLP
// Jest Snapshot v1, https://jestjs.io/docs/snapshot-testing

exports[`createRedirectPageContent encodes uri special chars 1`] = `
"<!DOCTYPE html>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// Jest Snapshot v1, https://goo.gl/fbAQLP
// Jest Snapshot v1, https://jestjs.io/docs/snapshot-testing

exports[`normalizePluginOptions rejects bad createRedirects user inputs 1`] = `""createRedirects" must be of type function"`;

Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// Jest Snapshot v1, https://goo.gl/fbAQLP
// Jest Snapshot v1, https://jestjs.io/docs/snapshot-testing

exports[`validateRedirect throw for bad redirects 1`] = `"{"from":"https://fb.com/fromSomePath","to":"/toSomePath"} => Validation error: "from" (https://fb.com/fromSomePath) is not a valid pathname. Pathname should start with slash and not contain any domain or query string."`;

Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// Jest Snapshot v1, https://goo.gl/fbAQLP
// Jest Snapshot v1, https://jestjs.io/docs/snapshot-testing

exports[`toRedirectFiles creates appropriate metadata absolute url: fileContent 1`] = `
[
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// Jest Snapshot v1, https://goo.gl/fbAQLP
// Jest Snapshot v1, https://jestjs.io/docs/snapshot-testing

exports[`paginateBlogPosts generates a single page 1`] = `
[
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// Jest Snapshot v1, https://goo.gl/fbAQLP
// Jest Snapshot v1, https://jestjs.io/docs/snapshot-testing

exports[`atom filters to the first two entries 1`] = `
[
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// Jest Snapshot v1, https://goo.gl/fbAQLP
// Jest Snapshot v1, https://jestjs.io/docs/snapshot-testing

exports[`blog plugin process blog posts load content 1`] = `
{
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// Jest Snapshot v1, https://goo.gl/fbAQLP
// Jest Snapshot v1, https://jestjs.io/docs/snapshot-testing

exports[`validateOptions feed throws Error in case of invalid feed type 1`] = `""feedOptions.type" does not match any of the allowed types"`;

Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// Jest Snapshot v1, https://goo.gl/fbAQLP
// Jest Snapshot v1, https://jestjs.io/docs/snapshot-testing

exports[`buildAllRoutes works for realistic blog post 2`] = `
[
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// Jest Snapshot v1, https://goo.gl/fbAQLP
// Jest Snapshot v1, https://jestjs.io/docs/snapshot-testing

exports[`getContentTranslationFiles returns translation files matching snapshot 1`] = `
[
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// Jest Snapshot v1, https://goo.gl/fbAQLP
// Jest Snapshot v1, https://jestjs.io/docs/snapshot-testing

exports[`footnoteIDFixer remark plugin appends a hash to each footnote def/ref 1`] = `
"import {Fragment as _Fragment, jsx as _jsx, jsxs as _jsxs} from "react/jsx-runtime";
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// Jest Snapshot v1, https://goo.gl/fbAQLP
// Jest Snapshot v1, https://jestjs.io/docs/snapshot-testing

exports[`docsVersion first time versioning 1`] = `
{
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// Jest Snapshot v1, https://goo.gl/fbAQLP
// Jest Snapshot v1, https://jestjs.io/docs/snapshot-testing

exports[`simple site custom pagination - development 1`] = `
{
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// Jest Snapshot v1, https://goo.gl/fbAQLP
// Jest Snapshot v1, https://jestjs.io/docs/snapshot-testing

exports[`toGlobalDataVersion generates the right docs, sidebars, and metadata 1`] = `
{
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// Jest Snapshot v1, https://goo.gl/fbAQLP
// Jest Snapshot v1, https://jestjs.io/docs/snapshot-testing

exports[`sidebar site with undefined sidebar 1`] = `
{
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// Jest Snapshot v1, https://goo.gl/fbAQLP
// Jest Snapshot v1, https://jestjs.io/docs/snapshot-testing

exports[`getLoadedContentTranslationFiles returns translation files 1`] = `
[
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,14 @@
*
* This source code is licensed under the MIT license found in the
* LICENSE file in the root directory of this source tree.
*
* @jest-environment jsdom
*/

// Jest doesn't allow pragma below other comments. https://github.com/facebook/jest/issues/12573
// eslint-disable-next-line header/header
import React from 'react';
import {renderHook} from '@testing-library/react-hooks';
import {renderHook} from '@testing-library/react';
import {useDocsSidebar, DocsSidebarProvider} from '../docsSidebar';
import type {PropSidebar} from '@docusaurus/plugin-content-docs';

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,14 @@
*
* This source code is licensed under the MIT license found in the
* LICENSE file in the root directory of this source tree.
*
* @jest-environment jsdom
*/

// Jest doesn't allow pragma below other comments. https://github.com/facebook/jest/issues/12573
// eslint-disable-next-line header/header
import React from 'react';
import {renderHook} from '@testing-library/react-hooks';
import {renderHook} from '@testing-library/react';
import {StaticRouter} from 'react-router-dom';
import {Context} from '@docusaurus/core/src/client/docusaurusContext';
import {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,14 @@
*
* This source code is licensed under the MIT license found in the
* LICENSE file in the root directory of this source tree.
*
* @jest-environment jsdom
*/

// Jest doesn't allow pragma below other comments. https://github.com/facebook/jest/issues/12573
// eslint-disable-next-line header/header
import React from 'react';
import {renderHook} from '@testing-library/react-hooks';
import {renderHook} from '@testing-library/react';
import {useDocsVersion, DocsVersionProvider} from '../docsVersion';
import type {PropVersionMetadata} from '@docusaurus/plugin-content-docs';

Expand Down
Loading
Loading