-
Notifications
You must be signed in to change notification settings - Fork 921
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'resolve-route' into route-option
- Loading branch information
Showing
23 changed files
with
246 additions
and
75 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
import { getDirname, path } from 'vuepress/utils' | ||
|
||
const __dirname = getDirname(import.meta.url) | ||
|
||
export const fooPlugin = { | ||
name: 'test-plugin', | ||
clientConfigFile: path.resolve( | ||
__dirname, | ||
'./nonDefaultExportClientConfig.js', | ||
), | ||
} |
2 changes: 2 additions & 0 deletions
2
e2e/docs/.vuepress/plugins/foo/nonDefaultExportClientConfig.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
// test non-default-export clientConfig | ||
import './test.css' |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
#non-default-export { | ||
font-size: 123px; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,4 @@ | ||
<template> | ||
<div class="e2e-theme-not-found">404 Not Found</div> | ||
<div class="e2e-theme-not-found-content"><Content /></div> | ||
</template> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2,3 +2,5 @@ | |
routeMeta: | ||
foo: bar | ||
--- | ||
|
||
## NotFound H2 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1,3 @@ | ||
foo | ||
|
||
## Home H2 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
# non-default-export |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
## Markdown Links with html | ||
|
||
- [Home with query](/?home=true) | ||
- [Home with query and hash](/?home=true#home) | ||
- [404 with hash](/404.html#404) | ||
- [404 with hash and query](/404.html#404?notFound=true) | ||
|
||
## Markdown Links with md | ||
|
||
- [Home with query](/README.md?home=true) | ||
- [Home with query and hash](/README.md?home=true#home) | ||
- [404 with hash](/404.md#404) | ||
- [404 with hash and query](/404.md#404?notFound=true) | ||
|
||
## HTML Links | ||
|
||
<a href="/?home=true" class="home-with-query">Home</a> | ||
<a href="/?home=true#home" class="home-with-query-and-hash">Home</a> | ||
<a href="/404.html#404" class="not-found-with-hash">404</a> | ||
<a href="/404.html#404?notFound=true" class="not-found-with-hash-and-query">404</a> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
<button id="home-with-query" @click="goHomeWithQuery">Home</button> | ||
<button id="home-with-query-and-hash" @click="goHomeWithQueryAndHash">Home</button> | ||
<button id="not-found-with-hash" @click="go404WithHash">404</button> | ||
<button id="not-found-with-hash-and-query" @click="go404WithHashAndQuery">404</button> | ||
|
||
<script setup lang="ts"> | ||
import { useRouter } from 'vuepress/client'; | ||
|
||
const router = useRouter(); | ||
|
||
const goHomeWithQuery = () => { | ||
router.push('/?home=true'); | ||
} | ||
|
||
const goHomeWithQueryAndHash = () => { | ||
router.push('/?home=true#home'); | ||
} | ||
|
||
const go404WithHash = () => { | ||
router.push('/404.html#404'); | ||
} | ||
|
||
const go404WithHashAndQuery = () => { | ||
router.push('/404.html#404?notFound=true'); | ||
} | ||
</script> |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
import { expect, test } from '@playwright/test' | ||
|
||
test('should apply styles correctly if the client config file does not have default export', async ({ | ||
page, | ||
}) => { | ||
await page.goto('client-config/non-default-export.html') | ||
await expect(page.locator('#non-default-export')).toHaveCSS( | ||
'font-size', | ||
'123px', | ||
) | ||
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,86 @@ | ||
import { expect, test } from '@playwright/test' | ||
import { BASE } from '../../utils/env' | ||
|
||
test.beforeEach(async ({ page }) => { | ||
await page.goto('router/navigate-by-link.html') | ||
}) | ||
|
||
test.describe('should preserve query', () => { | ||
test('markdown links with html suffix', async ({ page }) => { | ||
await page.locator('#markdown-links-with-html + ul > li > a').nth(0).click() | ||
await expect(page).toHaveURL(`${BASE}?home=true`) | ||
await expect(page.locator('#home-h2')).toHaveText('Home H2') | ||
}) | ||
|
||
test('markdown links with md suffix', async ({ page }) => { | ||
await page.locator('#markdown-links-with-md + ul > li > a').nth(0).click() | ||
await expect(page).toHaveURL(`${BASE}?home=true`) | ||
await expect(page.locator('#home-h2')).toHaveText('Home H2') | ||
}) | ||
|
||
test('html links', async ({ page }) => { | ||
await page.locator('#html-links + p > a').nth(0).click() | ||
await expect(page).toHaveURL(`${BASE}?home=true`) | ||
await expect(page.locator('#home-h2')).toHaveText('Home H2') | ||
}) | ||
}) | ||
|
||
test.describe('should preserve query and hash', () => { | ||
test('markdown links with html suffix', async ({ page }) => { | ||
await page.locator('#markdown-links-with-html + ul > li > a').nth(1).click() | ||
await expect(page).toHaveURL(`${BASE}?home=true#home`) | ||
await expect(page.locator('#home-h2')).toHaveText('Home H2') | ||
}) | ||
|
||
test('markdown links with md suffix', async ({ page }) => { | ||
await page.locator('#markdown-links-with-md + ul > li > a').nth(1).click() | ||
await expect(page).toHaveURL(`${BASE}?home=true#home`) | ||
await expect(page.locator('#home-h2')).toHaveText('Home H2') | ||
}) | ||
|
||
test('html links', async ({ page }) => { | ||
await page.locator('#html-links + p > a').nth(1).click() | ||
await expect(page).toHaveURL(`${BASE}?home=true#home`) | ||
await expect(page.locator('#home-h2')).toHaveText('Home H2') | ||
}) | ||
}) | ||
|
||
test.describe('should preserve hash', () => { | ||
test('markdown links with html suffix', async ({ page }) => { | ||
await page.locator('#markdown-links-with-html + ul > li > a').nth(2).click() | ||
await expect(page).toHaveURL(`${BASE}404.html#404`) | ||
await expect(page.locator('#notfound-h2')).toHaveText('NotFound H2') | ||
}) | ||
|
||
test('markdown links with md suffix', async ({ page }) => { | ||
await page.locator('#markdown-links-with-md + ul > li > a').nth(2).click() | ||
await expect(page).toHaveURL(`${BASE}404.html#404`) | ||
await expect(page.locator('#notfound-h2')).toHaveText('NotFound H2') | ||
}) | ||
|
||
test('html links', async ({ page }) => { | ||
await page.locator('#html-links + p > a').nth(2).click() | ||
await expect(page).toHaveURL(`${BASE}404.html#404`) | ||
await expect(page.locator('#notfound-h2')).toHaveText('NotFound H2') | ||
}) | ||
}) | ||
|
||
test.describe('should preserve hash and query', () => { | ||
test('markdown links with html suffix', async ({ page }) => { | ||
await page.locator('#markdown-links-with-html + ul > li > a').nth(3).click() | ||
await expect(page).toHaveURL(`${BASE}404.html#404?notFound=true`) | ||
await expect(page.locator('#notfound-h2')).toHaveText('NotFound H2') | ||
}) | ||
|
||
test('markdown links with md suffix', async ({ page }) => { | ||
await page.locator('#markdown-links-with-md + ul > li > a').nth(3).click() | ||
await expect(page).toHaveURL(`${BASE}404.html#404?notFound=true`) | ||
await expect(page.locator('#notfound-h2')).toHaveText('NotFound H2') | ||
}) | ||
|
||
test('html links', async ({ page }) => { | ||
await page.locator('#html-links + p > a').nth(3).click() | ||
await expect(page).toHaveURL(`${BASE}404.html#404?notFound=true`) | ||
await expect(page.locator('#notfound-h2')).toHaveText('NotFound H2') | ||
}) | ||
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
import { expect, test } from '@playwright/test' | ||
import { BASE } from '../../utils/env' | ||
|
||
test.beforeEach(async ({ page }) => { | ||
await page.goto('router/navigate-by-router.html') | ||
}) | ||
|
||
test('should preserve query', async ({ page }) => { | ||
await page.locator('#home-with-query').click() | ||
await expect(page).toHaveURL(`${BASE}?home=true`) | ||
await expect(page.locator('#home-h2')).toHaveText('Home H2') | ||
}) | ||
|
||
test('should preserve query and hash', async ({ page }) => { | ||
await page.locator('#home-with-query-and-hash').click() | ||
await expect(page).toHaveURL(`${BASE}?home=true#home`) | ||
await expect(page.locator('#home-h2')).toHaveText('Home H2') | ||
}) | ||
|
||
test('should preserve hash', async ({ page }) => { | ||
await page.locator('#not-found-with-hash').click() | ||
await expect(page).toHaveURL(`${BASE}404.html#404`) | ||
await expect(page.locator('#notfound-h2')).toHaveText('NotFound H2') | ||
}) | ||
|
||
test('should preserve hash and query', async ({ page }) => { | ||
await page.locator('#not-found-with-hash-and-query').click() | ||
await expect(page).toHaveURL(`${BASE}404.html#404?notFound=true`) | ||
await expect(page.locator('#notfound-h2')).toHaveText('NotFound H2') | ||
}) |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
const SPLIT_CHAR_REGEXP = /(#|\?)/ | ||
|
||
/** | ||
* Split a path into pathname and hashAndQueries | ||
*/ | ||
export const splitPath = ( | ||
path: string, | ||
): { | ||
pathname: string | ||
hashAndQueries: string | ||
} => { | ||
const [pathname, ...hashAndQueries] = path.split(SPLIT_CHAR_REGEXP) | ||
return { | ||
pathname, | ||
hashAndQueries: hashAndQueries.join(''), | ||
} | ||
} |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
import { expect, it } from 'vitest' | ||
import { splitPath } from '../../src/index.js' | ||
|
||
const testCases: [string, ReturnType<typeof splitPath>][] = [ | ||
['/a/b/c/', { pathname: '/a/b/c/', hashAndQueries: '' }], | ||
['/a/b/c/?a=1', { pathname: '/a/b/c/', hashAndQueries: '?a=1' }], | ||
['/a/b/c/#b', { pathname: '/a/b/c/', hashAndQueries: '#b' }], | ||
['/a/b/c/?a=1#b', { pathname: '/a/b/c/', hashAndQueries: '?a=1#b' }], | ||
['a/index.html', { pathname: 'a/index.html', hashAndQueries: '' }], | ||
['/a/index.html?a=1', { pathname: '/a/index.html', hashAndQueries: '?a=1' }], | ||
['/a/index.html#a', { pathname: '/a/index.html', hashAndQueries: '#a' }], | ||
[ | ||
'/a/index.html?a=1#b', | ||
{ pathname: '/a/index.html', hashAndQueries: '?a=1#b' }, | ||
], | ||
] | ||
|
||
testCases.forEach(([source, expected]) => { | ||
it(`${source} -> ${expected}`, () => { | ||
expect(splitPath(source)).toEqual(expected) | ||
}) | ||
}) |