mirror of
https://github.com/facebook/docusaurus.git
synced 2025-05-23 05:57:05 +02:00
chore(v2): fix windows Jest tests (#3959)
* test(v2): Fix docusaurus-utils tests for windows * test(v2): Fix plugin-client-redirects test - add the posixPath in writeRedirectsFiles.ts * test(v2): Fix plugin-content-pages test add posixPath in test and index * test(v2): add window test configuration - add the window test configuration in nodejs-windows.yml * test(v2): revert plugin-content-pages test fix * test(v2): Fix mdx-loader/transformImage test * test(v2): add cleanPath in transformImage test * fix version path tests for windows * make versionMetadata test work on Windows * try to fix posix/win32 path issues * attempt to fix windows test * try to make source alias less win32 sensitive * try to make source alias less win32 sensitive * try to make source alias less win32 sensitive * try to make source alias less win32 sensitive * try to make source alias less win32 sensitive * try to make source alias less win32 sensitive * specific jest config for windows * attempt to fix windows testing issue * attempt to fix windows testing issue * attempt to fix windows testing issue * attempt to fix windows testing issue * attempt to fix windows testing issue * attempt to fix windows testing issue * attempt to fix windows testing issue * remove bad cleanPath fn * try to fix windows tests * try to fix windows tests * blog: try to fix windows tests by using same logic as on docs plugin * try to fix windows tests * try to fix windows tests * try to fix windows tests * try to fix windows tests * improve the Github CI setup for windows: make jobs run in parallel * revert GH action change Co-authored-by: Sachin Kumar Rajput <skr571999@gmail.com>
This commit is contained in:
parent
863a4d85d3
commit
141d062c3b
29 changed files with 189 additions and 131 deletions
|
@ -20,6 +20,7 @@ import {LoadContext} from '@docusaurus/types';
|
|||
import {DEFAULT_PLUGIN_ID} from '@docusaurus/core/lib/constants';
|
||||
import {DEFAULT_OPTIONS} from '../options';
|
||||
import {Optional} from 'utility-types';
|
||||
import {posixPath} from '@docusaurus/utils';
|
||||
|
||||
const fixtureDir = path.join(__dirname, '__fixtures__');
|
||||
|
||||
|
@ -89,10 +90,10 @@ function createTestUtils({
|
|||
lastUpdatedAt: undefined,
|
||||
sidebar_label: undefined,
|
||||
editUrl: undefined,
|
||||
source: path.join(
|
||||
source: path.posix.join(
|
||||
'@site',
|
||||
path.relative(siteDir, versionMetadata.docsDirPath),
|
||||
docFileSource,
|
||||
posixPath(path.relative(siteDir, versionMetadata.docsDirPath)),
|
||||
posixPath(docFileSource),
|
||||
),
|
||||
...expectedMetadata,
|
||||
});
|
||||
|
|
|
@ -140,11 +140,15 @@ describe('empty/no docs website', () => {
|
|||
pluginContentDocs(
|
||||
context,
|
||||
normalizePluginOptions(OptionsSchema, {
|
||||
path: '/path/does/not/exist/',
|
||||
path: `path/doesnt/exist`,
|
||||
}),
|
||||
),
|
||||
).toThrowErrorMatchingInlineSnapshot(
|
||||
`"The docs folder does not exist for version [current]. A docs folder is expected to be found at /path/does/not/exist"`,
|
||||
).toThrowError(
|
||||
`The docs folder does not exist for version [current]. A docs folder is expected to be found at ${
|
||||
process.platform === 'win32'
|
||||
? 'path\\doesnt\\exist'
|
||||
: 'path/doesnt/exist'
|
||||
}`,
|
||||
);
|
||||
});
|
||||
});
|
||||
|
@ -248,9 +252,9 @@ describe('simple website', () => {
|
|||
permalink: '/docs/foo/bazSlug.html',
|
||||
},
|
||||
sidebar: 'docs',
|
||||
source: path.join(
|
||||
source: path.posix.join(
|
||||
'@site',
|
||||
path.relative(siteDir, currentVersion.docsDirPath),
|
||||
posixPath(path.relative(siteDir, currentVersion.docsDirPath)),
|
||||
'hello.md',
|
||||
),
|
||||
title: 'Hello, World !',
|
||||
|
@ -270,9 +274,9 @@ describe('simple website', () => {
|
|||
permalink: '/docs/foo/bar',
|
||||
slug: '/foo/bar',
|
||||
sidebar: 'docs',
|
||||
source: path.join(
|
||||
source: path.posix.join(
|
||||
'@site',
|
||||
path.relative(siteDir, currentVersion.docsDirPath),
|
||||
posixPath(path.relative(siteDir, currentVersion.docsDirPath)),
|
||||
'foo',
|
||||
'bar.md',
|
||||
),
|
||||
|
@ -418,9 +422,9 @@ describe('versioned website', () => {
|
|||
isDocsHomePage: false,
|
||||
permalink: '/docs/next/foo/barSlug',
|
||||
slug: '/foo/barSlug',
|
||||
source: path.join(
|
||||
source: path.posix.join(
|
||||
'@site',
|
||||
path.relative(siteDir, currentVersion.docsDirPath),
|
||||
posixPath(path.relative(siteDir, currentVersion.docsDirPath)),
|
||||
'foo',
|
||||
'bar.md',
|
||||
),
|
||||
|
@ -440,9 +444,9 @@ describe('versioned website', () => {
|
|||
isDocsHomePage: true,
|
||||
permalink: '/docs/next/',
|
||||
slug: '/',
|
||||
source: path.join(
|
||||
source: path.posix.join(
|
||||
'@site',
|
||||
path.relative(siteDir, currentVersion.docsDirPath),
|
||||
posixPath(path.relative(siteDir, currentVersion.docsDirPath)),
|
||||
'hello.md',
|
||||
),
|
||||
title: 'hello',
|
||||
|
@ -461,9 +465,9 @@ describe('versioned website', () => {
|
|||
isDocsHomePage: true,
|
||||
permalink: '/docs/',
|
||||
slug: '/',
|
||||
source: path.join(
|
||||
source: path.posix.join(
|
||||
'@site',
|
||||
path.relative(siteDir, version101.docsDirPath),
|
||||
posixPath(path.relative(siteDir, version101.docsDirPath)),
|
||||
'hello.md',
|
||||
),
|
||||
title: 'hello',
|
||||
|
@ -482,9 +486,9 @@ describe('versioned website', () => {
|
|||
isDocsHomePage: false,
|
||||
permalink: '/docs/1.0.0/foo/baz',
|
||||
slug: '/foo/baz',
|
||||
source: path.join(
|
||||
source: path.posix.join(
|
||||
'@site',
|
||||
path.relative(siteDir, version100.docsDirPath),
|
||||
posixPath(path.relative(siteDir, version100.docsDirPath)),
|
||||
'foo',
|
||||
'baz.md',
|
||||
),
|
||||
|
@ -629,13 +633,6 @@ describe('versioned website (community)', () => {
|
|||
isDocsHomePage: false,
|
||||
permalink: '/community/next/team',
|
||||
slug: '/team',
|
||||
/*
|
||||
source: path.join(
|
||||
'@site',
|
||||
path.relative(siteDir, currentVersion.docsDirPath),
|
||||
'team.md',
|
||||
),
|
||||
*/
|
||||
source:
|
||||
'@site/i18n/en/docusaurus-plugin-content-docs-community/current/team.md',
|
||||
title: 'Team title translated',
|
||||
|
@ -650,9 +647,9 @@ describe('versioned website (community)', () => {
|
|||
isDocsHomePage: false,
|
||||
permalink: '/community/team',
|
||||
slug: '/team',
|
||||
source: path.join(
|
||||
source: path.posix.join(
|
||||
'@site',
|
||||
path.relative(siteDir, version100.docsDirPath),
|
||||
posixPath(path.relative(siteDir, version100.docsDirPath)),
|
||||
'team.md',
|
||||
),
|
||||
title: 'team',
|
||||
|
|
|
@ -24,30 +24,30 @@ const DefaultI18N: I18n = {
|
|||
};
|
||||
|
||||
describe('version paths', () => {
|
||||
test('getVersionedDocsDirPath', () => {
|
||||
test('getVersionsFilePath', () => {
|
||||
expect(getVersionsFilePath('someSiteDir', DEFAULT_PLUGIN_ID)).toBe(
|
||||
'someSiteDir/versions.json',
|
||||
`someSiteDir${path.sep}versions.json`,
|
||||
);
|
||||
expect(getVersionsFilePath('otherSite/dir', 'pluginId')).toBe(
|
||||
'otherSite/dir/pluginId_versions.json',
|
||||
`otherSite${path.sep}dir${path.sep}pluginId_versions.json`,
|
||||
);
|
||||
});
|
||||
|
||||
test('getVersionedDocsDirPath', () => {
|
||||
expect(getVersionedDocsDirPath('someSiteDir', DEFAULT_PLUGIN_ID)).toBe(
|
||||
'someSiteDir/versioned_docs',
|
||||
`someSiteDir${path.sep}versioned_docs`,
|
||||
);
|
||||
expect(getVersionedDocsDirPath('otherSite/dir', 'pluginId')).toBe(
|
||||
'otherSite/dir/pluginId_versioned_docs',
|
||||
`otherSite${path.sep}dir${path.sep}pluginId_versioned_docs`,
|
||||
);
|
||||
});
|
||||
|
||||
test('getVersionedSidebarsDirPath', () => {
|
||||
expect(getVersionedSidebarsDirPath('someSiteDir', DEFAULT_PLUGIN_ID)).toBe(
|
||||
'someSiteDir/versioned_sidebars',
|
||||
`someSiteDir${path.sep}versioned_sidebars`,
|
||||
);
|
||||
expect(getVersionedSidebarsDirPath('otherSite/dir', 'pluginId')).toBe(
|
||||
'otherSite/dir/pluginId_versioned_sidebars',
|
||||
`otherSite${path.sep}dir${path.sep}pluginId_versioned_sidebars`,
|
||||
);
|
||||
});
|
||||
});
|
||||
|
|
|
@ -16,6 +16,7 @@ import {
|
|||
docuHash,
|
||||
aliasedSitePath,
|
||||
reportMessage,
|
||||
posixPath,
|
||||
} from '@docusaurus/utils';
|
||||
import {LoadContext, Plugin, RouteConfig} from '@docusaurus/types';
|
||||
|
||||
|
@ -66,7 +67,7 @@ export default function pluginContentDocs(
|
|||
);
|
||||
const dataDir = path.join(pluginDataDirRoot, pluginId);
|
||||
const aliasedSource = (source: string) =>
|
||||
`~docs/${path.relative(pluginDataDirRoot, source)}`;
|
||||
`~docs/${posixPath(path.relative(pluginDataDirRoot, source))}`;
|
||||
|
||||
return {
|
||||
name: 'docusaurus-plugin-content-docs',
|
||||
|
|
|
@ -5,7 +5,6 @@
|
|||
* LICENSE file in the root directory of this source tree.
|
||||
*/
|
||||
|
||||
import path from 'path';
|
||||
import {resolve} from 'url';
|
||||
import {
|
||||
DocsMarkdownOption,
|
||||
|
@ -13,6 +12,7 @@ import {
|
|||
BrokenMarkdownLink,
|
||||
} from '../types';
|
||||
import {getDocsDirPaths} from '../versions';
|
||||
import {aliasedSitePath} from '@docusaurus/utils';
|
||||
|
||||
function getVersion(filePath: string, options: DocsMarkdownOption) {
|
||||
const versionFound = options.versionsMetadata.find((version) =>
|
||||
|
@ -58,7 +58,7 @@ function replaceMarkdownLinks(
|
|||
const mdLink = mdMatch[1];
|
||||
|
||||
const aliasedSource = (source: string) =>
|
||||
`@site/${path.relative(siteDir, source)}`;
|
||||
aliasedSitePath(source, siteDir);
|
||||
|
||||
const permalink =
|
||||
sourceToPermalink[aliasedSource(resolve(filePath, mdLink))] ||
|
||||
|
|
|
@ -316,13 +316,21 @@ function createVersionMetadata({
|
|||
}
|
||||
|
||||
function checkVersionMetadataPaths({
|
||||
versionName,
|
||||
docsDirPath,
|
||||
sidebarFilePath,
|
||||
}: VersionMetadata) {
|
||||
versionMetadata,
|
||||
context,
|
||||
}: {
|
||||
versionMetadata: VersionMetadata;
|
||||
context: Pick<LoadContext, 'siteDir'>;
|
||||
}) {
|
||||
const {versionName, docsDirPath, sidebarFilePath} = versionMetadata;
|
||||
const {siteDir} = context;
|
||||
|
||||
if (!fs.existsSync(docsDirPath)) {
|
||||
throw new Error(
|
||||
`The docs folder does not exist for version [${versionName}]. A docs folder is expected to be found at ${docsDirPath}`,
|
||||
`The docs folder does not exist for version [${versionName}]. A docs folder is expected to be found at ${path.relative(
|
||||
siteDir,
|
||||
docsDirPath,
|
||||
)}`,
|
||||
);
|
||||
}
|
||||
|
||||
|
@ -457,7 +465,9 @@ export function readVersionsMetadata({
|
|||
options,
|
||||
}),
|
||||
);
|
||||
versionsMetadata.forEach(checkVersionMetadataPaths);
|
||||
versionsMetadata.forEach((versionMetadata) =>
|
||||
checkVersionMetadataPaths({versionMetadata, context}),
|
||||
);
|
||||
return versionsMetadata;
|
||||
}
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue