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
Original file line number Diff line number Diff line change
Expand Up @@ -25,3 +25,11 @@
[../../api/](../../api/)

[../../api](../../api)

## Corner cases

[/en](/en)

[/en/](/en/)

[/](/)
10 changes: 9 additions & 1 deletion e2e/fixtures/check-dead-link/doc/zh/guide/basic/quick-start.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@

[/guide/basic/install.mdx](/guide/basic/install.mdx)

[/en/guide/basic/install.mdx](/en/guide/basic/install.mdx)
[/zh/guide/basic/install.mdx](/zh/guide/basic/install.mdx)

## 相对路径

Expand All @@ -25,3 +25,11 @@
[../../api/](../../api/)

[../../api](../../api)

## Corner cases

[/zh](/zh)

[/zh/](/zh/)

[/](/)
161 changes: 115 additions & 46 deletions e2e/fixtures/check-dead-link/index.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,30 +21,64 @@ test.describe('check dead links', async () => {
await runBuildCommand(appDir);
app = await runPreviewCommand(appDir, appPort);

await page.goto(
`http://localhost:${appPort}/base/guide/basic/quick-start`,
{
waitUntil: 'networkidle',
},
);
// Get all the <a /> element
const linkDoms = await page.$$('.rspress-doc a');
{
await page.goto(
`http://localhost:${appPort}/base/guide/basic/quick-start`,
{
waitUntil: 'networkidle',
},
);
// Get all the <a /> element
const linkDoms = await page.$$('.rspress-doc a');

const links = (
await Promise.all(linkDoms.map(linkDom => linkDom.getAttribute('href')))
).filter(i => !i?.startsWith('#'));
expect(links).toEqual([
'/base/guide/basic/install.html',
'/base/guide/basic/install.html',
'/base/guide/basic/install.html',
'/base/guide/basic/install.html',
'/base/guide/basic/install.html',
'/base/guide/basic/install.html',
'/base/guide/basic/install.html',
'/base/api/index.html',
'/base/api.html',
'/base/api.html',
]);
const links = (
await Promise.all(linkDoms.map(linkDom => linkDom.getAttribute('href')))
).filter(i => !i?.startsWith('#'));
expect(links).toEqual([
'/base/guide/basic/install.html',
'/base/guide/basic/install.html',
'/base/guide/basic/install.html',
'/base/guide/basic/install.html',
'/base/guide/basic/install.html',
'/base/guide/basic/install.html',
'/base/guide/basic/install.html',
'/base/api/index.html',
'/base/api.html', // FIXME: should be /base/api/index.html
'/base/api.html',
'/base/index.html',
'/base/index.html',
'/base/index.html',
]);
}
{
await page.goto(
`http://localhost:${appPort}/base/en/guide/basic/quick-start`,
{
waitUntil: 'networkidle',
},
);
// Get all the <a /> element
const linkDoms = await page.$$('.rspress-doc a');

const links = (
await Promise.all(linkDoms.map(linkDom => linkDom.getAttribute('href')))
).filter(i => !i?.startsWith('#'));
expect(links).toEqual([
'/base/en/guide/basic/install.html',
'/base/en/guide/basic/install.html',
'/base/en/guide/basic/install.html',
'/base/en/guide/basic/install.html',
'/base/en/guide/basic/install.html',
'/base/en/guide/basic/install.html',
'/base/en/guide/basic/install.html',
'/base/en/api/index.html',
'/base/en/api.html',
'/base/en/api.html',
'/base/en/index.html',
'/base/en/index.html',
'/base/en/index.html',
]);
}
});

test('should link the correct page - cleanUrl', async ({ page }) => {
Expand All @@ -53,29 +87,64 @@ test.describe('check dead links', async () => {
await runBuildCommand(appDir, 'rspress-clean.config.ts');
app = await runPreviewCommand(appDir, appPort);

await page.goto(
`http://localhost:${appPort}/base/guide/basic/quick-start`,
{
waitUntil: 'networkidle',
},
);
// Get all the <a /> element
const linkDoms = await page.$$('.rspress-doc a');
{
await page.goto(
`http://localhost:${appPort}/base/guide/basic/quick-start`,
{
waitUntil: 'networkidle',
},
);
// Get all the <a /> element
const linkDoms = await page.$$('.rspress-doc a');

const links = (
await Promise.all(linkDoms.map(linkDom => linkDom.getAttribute('href')))
).filter(i => !i?.startsWith('#'));
expect(links).toEqual([
'/base/guide/basic/install',
'/base/guide/basic/install',
'/base/guide/basic/install',
'/base/guide/basic/install',
'/base/guide/basic/install',
'/base/guide/basic/install',
'/base/guide/basic/install',
'/base/api',
'/base/api',
'/base/api',
]);
const links = (
await Promise.all(linkDoms.map(linkDom => linkDom.getAttribute('href')))
).filter(i => !i?.startsWith('#'));
expect(links).toEqual([
'/base/guide/basic/install',
'/base/guide/basic/install',
'/base/guide/basic/install',
'/base/guide/basic/install',
'/base/guide/basic/install',
'/base/guide/basic/install',
'/base/guide/basic/install',
'/base/api',
'/base/api',
'/base/api',
'/base/',
'/base/',
'/base/',
]);
}

{
await page.goto(
`http://localhost:${appPort}/base/en/guide/basic/quick-start`,
{
waitUntil: 'networkidle',
},
);
// Get all the <a /> element
const linkDoms = await page.$$('.rspress-doc a');

const links = (
await Promise.all(linkDoms.map(linkDom => linkDom.getAttribute('href')))
).filter(i => !i?.startsWith('#'));
expect(links).toEqual([
'/base/en/guide/basic/install',
'/base/en/guide/basic/install',
'/base/en/guide/basic/install',
'/base/en/guide/basic/install',
'/base/en/guide/basic/install',
'/base/en/guide/basic/install',
'/base/en/guide/basic/install',
'/base/en/api',
'/base/en/api',
'/base/en/api',
'/base/en',
'/base/en',
'/base/en',
]);
}
});
});
36 changes: 18 additions & 18 deletions e2e/fixtures/markdown-link/doc/guide/index.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -14,56 +14,56 @@
## RelativeLinks

- [./installation](./installation)
- [installation(TODO)](installation)
- [installation](installation)

- [./installation.mdx](./installation.mdx)
- [installation.mdx(TODO)](installation.mdx).
- [installation.mdx](installation.mdx).

- [Definition: ./installation]
- [Definition: installation(TODO)]
- [Definition: installation]

- [Definition: ./installation.mdx]
- [Definition: installation.mdx(TODO)]
- [Definition: installation.mdx]

[Definition: ./installation]: ./installation
[Definition: installation(TODO)]: installation
[Definition: installation]: installation
[Definition: ./installation.mdx]: ./installation.mdx
[Definition: installation.mdx(TODO)]: installation.mdx
[Definition: installation.mdx]: installation.mdx

## RelativeLinks with subfolders

- [./subfolder/foo](./subfolder/foo)
- [subfolder/foo(TODO)](subfolder/foo)
- [subfolder/foo](subfolder/foo)

- [./subfolder/foo.mdx](./subfolder/foo.mdx)
- [subfolder/foo.mdx(TODO)](subfolder/foo.mdx).
- [subfolder/foo.mdx](subfolder/foo.mdx).

- [Definition2: ./subfolder/foo]
- [Definition2: subfolder/foo(TODO)]
- [Definition2: subfolder/foo]

- [Definition2: ./subfolder/foo.mdx]
- [Definition2: subfolder/foo.mdx(TODO)]
- [Definition2: subfolder/foo.mdx]

[Definition2: ./subfolder/foo]: ./subfolder/foo
[Definition2: subfolder/foo(TODO)]: subfolder/foo
[Definition2: subfolder/foo]: subfolder/foo
[Definition2: ./subfolder/foo.mdx]: ./subfolder/foo.mdx
[Definition2: subfolder/foo.mdx(TODO)]: subfolder/foo.mdx
[Definition2: subfolder/foo.mdx]: subfolder/foo.mdx

## RelativeLinks to subfolders index

- [./subfolder](./subfolder)
- [subfolder(TODO)](subfolder)
- [subfolder](subfolder)

- [./subfolder/index.mdx](./subfolder/index.mdx)
- [subfolder/index.mdx(TODO)](subfolder/index.mdx).
- [subfolder/index.mdx](subfolder/index.mdx).

- [Definition3: ./subfolder]
- [Definition3: subfolder(TODO)]
- [Definition3: subfolder]

- [Definition3: ./subfolder/index.mdx]
- [Definition3: subfolder/index.mdx(TODO)]
- [Definition3: subfolder/index.mdx]

[Definition3: ./subfolder]: ./subfolder
[Definition3: subfolder(TODO)]: subfolder
[Definition3: subfolder]: subfolder
[Definition3: ./subfolder/index.mdx]: ./subfolder/index.mdx
[Definition3: subfolder/index.mdx(TODO)]: subfolder/index.mdx
[Definition3: subfolder/index.mdx]: subfolder/index.mdx
65 changes: 34 additions & 31 deletions e2e/fixtures/markdown-link/index.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ test.describe('basic test', async () => {
});

test('all links should be normalized', async ({ page }) => {
await page.goto(`http://localhost:${appPort}/guide`);
await page.goto(`http://localhost:${appPort}/base/guide`);
const links = await page.$$('.rspress-doc ul li a');
const urls = await Promise.all(
links.map(async link => {
Expand All @@ -27,35 +27,38 @@ test.describe('basic test', async () => {
}),
);

const snapshot = urls.join('\n');

expect(snapshot).toEqual(`/guide/installation.html
/guide/installation.html
/guide/installation.html
/guide/installation.html
/guide/installation.html
/installation.html
/guide/installation.html
/installation.html
/guide/installation.html
/installation.html
/guide/installation.html
/installation.html
/guide/subfolder/foo.html
/subfolder/foo.html
/guide/subfolder/foo.html
/subfolder/foo.html
/guide/subfolder/foo.html
/subfolder/foo.html
/guide/subfolder/foo.html
/subfolder/foo.html
/guide/subfolder.html
/subfolder.html
/guide/subfolder/index.html
/subfolder/index.html
/guide/subfolder.html
/subfolder.html
/guide/subfolder/index.html
/subfolder/index.html`);
expect(urls).toEqual([
'/base/guide/installation.html',
'/base/guide/installation.html',
'/base/guide/installation.html',
'/base/guide/installation.html',
//
'/base/guide/installation.html',
'/base/guide/installation.html',
'/base/guide/installation.html',
'/base/guide/installation.html',
'/base/guide/installation.html',
'/base/guide/installation.html',
'/base/guide/installation.html',
'/base/guide/installation.html',
//
'/base/guide/subfolder/foo.html',
'/base/guide/subfolder/foo.html',
'/base/guide/subfolder/foo.html',
'/base/guide/subfolder/foo.html',
'/base/guide/subfolder/foo.html',
'/base/guide/subfolder/foo.html',
'/base/guide/subfolder/foo.html',
'/base/guide/subfolder/foo.html',
//
'/base/guide/subfolder.html',
'/base/guide/subfolder.html',
'/base/guide/subfolder/index.html',
'/base/guide/subfolder/index.html',
'/base/guide/subfolder.html',
'/base/guide/subfolder.html',
'/base/guide/subfolder/index.html',
'/base/guide/subfolder/index.html',
]);
});
});
1 change: 1 addition & 0 deletions e2e/fixtures/markdown-link/rspress.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,5 +2,6 @@ import * as path from 'node:path';
import { defineConfig } from 'rspress/config';

export default defineConfig({
base: '/base/',
root: path.join(__dirname, 'doc'),
});
Loading