Skip to content

Commit

Permalink
test(e2e): use relative url for navigation
Browse files Browse the repository at this point in the history
  • Loading branch information
meteorlxy committed Apr 15, 2024
1 parent 5e7a76a commit eb578a1
Show file tree
Hide file tree
Showing 15 changed files with 32 additions and 28 deletions.
2 changes: 1 addition & 1 deletion e2e/tests/client-config/root-components.spec.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { expect, test } from '@playwright/test'

test('should render root components correctly', async ({ page }) => {
await page.goto('/', { waitUntil: 'domcontentloaded' })
await page.goto('', { waitUntil: 'domcontentloaded' })

await expect(page.locator('.root-component-from-theme p')).toHaveText(
'root component from theme',
Expand Down
2 changes: 1 addition & 1 deletion e2e/tests/components/route-link.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import { expect, test } from '@playwright/test'
import { BASE } from '../../utils/env'

test.beforeEach(async ({ page }) => {
await page.goto('/components/route-link.html')
await page.goto('components/route-link.html')
})

test('should render paths correctly', async ({ page }) => {
Expand Down
6 changes: 3 additions & 3 deletions e2e/tests/hmr.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ if (isDev) {
'.e2e-theme-content #rendered-foo + p',
)

await page.goto('/hmr/frontmatter.html')
await page.goto('hmr/frontmatter.html')

await expect(frontmatterLocator).toHaveText('HMR foo')
await hmrUpdateFrontmatter()
Expand All @@ -56,7 +56,7 @@ if (isDev) {
test('should update title correctly', async ({ page }) => {
const titleLocator = page.locator('.e2e-theme-content #rendered-title + p')

await page.goto('/hmr/title.html')
await page.goto('hmr/title.html')

await expect(page).toHaveTitle(/HMR Title/)
await expect(titleLocator).toHaveText('HMR Title')
Expand All @@ -73,7 +73,7 @@ if (isDev) {
'.e2e-theme-content #rendered-foo + p',
)

await page.goto('/hmr/title.html')
await page.goto('hmr/title.html')
await expect(page).toHaveTitle(/HMR Title/)
await expect(titleLocator).toHaveText('HMR Title')

Expand Down
4 changes: 2 additions & 2 deletions e2e/tests/imports/conditional-exports.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,14 @@ import { expect, test } from '@playwright/test'
import { COMMAND } from '../../utils/env'

test('should load different files correctly', async ({ page }) => {
await page.goto('/imports/conditional-exports.html')
await page.goto('imports/conditional-exports.html')

await expect(page.locator('.e2e-theme-content p')).toHaveText('browser-mjs')

if (COMMAND === 'build') {
expect(
await page.evaluate(() =>
fetch('/imports/conditional-exports.html').then((res) => res.text()),
fetch('./conditional-exports.html').then((res) => res.text()),
),
).toContain('<p>node-mjs</p>')
}
Expand Down
6 changes: 3 additions & 3 deletions e2e/tests/layouts.spec.ts
Original file line number Diff line number Diff line change
@@ -1,20 +1,20 @@
import { expect, test } from '@playwright/test'

test('CustomLayout', async ({ page }) => {
await page.goto('/layouts/custom-layout.html')
await page.goto('layouts/custom-layout.html')
await expect(page.locator('.e2e-theme-custom-layout-content')).toHaveText(
'Should use CustomLayout',
)
})

test('Layout', async ({ page }) => {
await page.goto('/layouts/layout.html')
await page.goto('layouts/layout.html')
await expect(page.locator('.e2e-theme-content')).toHaveText(
'Should use Layout',
)
})

test('NotFound', async ({ page }) => {
await page.goto('/404.html')
await page.goto('404.html')
await expect(page.locator('.e2e-theme-not-found')).toHaveText('404 Not Found')
})
2 changes: 1 addition & 1 deletion e2e/tests/markdown/anchors.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ test('should render anchors and navigate correctly', async ({ page }) => {
const anchorLocator = page.locator('.e2e-theme-content h1 > a')
const anchorOneDashOneLocator = page.locator('#anchor-1-1 > a')

await page.goto('/markdown/anchors.html')
await page.goto('markdown/anchors.html')

await expect(headingLocator).toHaveAttribute('id', 'title')
await expect(headingLocator).toHaveAttribute('tabindex', '-1')
Expand Down
2 changes: 1 addition & 1 deletion e2e/tests/markdown/images.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import { expect, test } from '@playwright/test'
test('should render images correctly', async ({ page }) => {
const imagesLocator = page.locator('.e2e-theme-content img')

await page.goto('/markdown/images/images.html')
await page.goto('markdown/images/images.html')

await expect(imagesLocator).toHaveCount(2)
await expect(imagesLocator.first()).toHaveAttribute('alt', 'logo-public')
Expand Down
2 changes: 1 addition & 1 deletion e2e/tests/markdown/links.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ test('should render links and navigate between pages correctly', async ({
}) => {
const linksLocator = page.locator('.e2e-theme-content ul li a')

await page.goto('/markdown/links/foo.html')
await page.goto('markdown/links/foo.html')

await expect(linksLocator).toHaveCount(2)
await expect(linksLocator.first()).toHaveText('bar')
Expand Down
6 changes: 3 additions & 3 deletions e2e/tests/page-data.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,19 +2,19 @@ import { expect, test } from '@playwright/test'

test.describe('title', () => {
test('should use title from frontmatter', async ({ page }) => {
await page.goto('/page-data/title-from-frontmatter.html')
await page.goto('page-data/title-from-frontmatter.html')
await expect(page).toHaveTitle(/title from frontmatter/)
})

test('should use title from h1', async ({ page }) => {
await page.goto('/page-data/title-from-h1.html')
await page.goto('page-data/title-from-h1.html')
await expect(page).toHaveTitle(/title from h1/)
})
})

test.describe('frontmatter', () => {
test('should set frontmatter correctly', async ({ page }) => {
await page.goto('/page-data/frontmatter.html')
await page.goto('page-data/frontmatter.html')
await expect(page.locator('.e2e-theme-content p')).toHaveText(
JSON.stringify({
str: 'str',
Expand Down
4 changes: 2 additions & 2 deletions e2e/tests/router/navigation.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,15 @@ import { expect, test } from '@playwright/test'
import { BASE } from '../../utils/env'

test('should preserve query', async ({ page }) => {
await page.goto('/router/navigation.html')
await page.goto('router/navigation.html')

await page.locator('#home').click()

await expect(page).toHaveURL(`${BASE}?home=true`)
})

test('should preserve hash', async ({ page }) => {
await page.goto('/router/navigation.html')
await page.goto('router/navigation.html')

await page.locator('#not-found').click()

Expand Down
2 changes: 1 addition & 1 deletion e2e/tests/router/resolve-route.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ const testCases = [
]

test('should resolve routes correctly', async ({ page }) => {
await page.goto('/router/resolve-route.html')
await page.goto('router/resolve-route.html')

for (const { selector, expected } of testCases) {
const listItemsLocator = await page
Expand Down
7 changes: 5 additions & 2 deletions e2e/tests/routes/non-ascii-paths.spec.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,12 @@
import { expect, test } from '@playwright/test'
import { removeLeadingSlash } from 'vuepress/shared'
import { BASE } from '../../utils/env'

test('should support visiting non-ASCII paths directly', async ({ page }) => {
await page.goto(
encodeURI('/routes/non-ascii-paths/中文目录名/中文文件名.html'),
removeLeadingSlash(
encodeURI('/routes/non-ascii-paths/中文目录名/中文文件名.html'),
),
)

await expect(page.locator('.e2e-theme-content p')).toHaveText(
Expand All @@ -14,7 +17,7 @@ test('should support visiting non-ASCII paths directly', async ({ page }) => {
test('should support rendering non-ASCII paths links and navigate to it correctly', async ({
page,
}) => {
await page.goto('/routes/non-ascii-paths/')
await page.goto('routes/non-ascii-paths/')

await expect(page.locator('.e2e-theme-content ul li a')).toHaveCount(1)
await expect(page.locator('.e2e-theme-content ul li a')).toHaveText(
Expand Down
9 changes: 5 additions & 4 deletions e2e/tests/routes/permalinks.spec.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
import { expect, test } from '@playwright/test'
import { removeEndingSlash, removeLeadingSlash } from 'vuepress/shared'
import { BASE } from '../../utils/env'

const PERMALINK_PREFIX = BASE.replace(/\/$/, '')
const PERMALINK_PREFIX = removeEndingSlash(BASE)

const CONFIGS = [
{
Expand All @@ -28,7 +29,7 @@ const CONFIGS = [

test('should support visiting permalinks directly', async ({ page }) => {
for (const { permalink } of CONFIGS) {
await page.goto(encodeURI(permalink))
await page.goto(removeLeadingSlash(encodeURI(permalink)))
await expect(page.locator('.e2e-theme-content p')).toHaveText(permalink)
}
})
Expand All @@ -40,7 +41,7 @@ test('should support rendering link by permalink and navigate to it correctly',
const linksLocator = page.locator(`.e2e-theme-content #${id} + ul > li a`)
const contentLocator = page.locator('.e2e-theme-content p')

await page.goto('/routes/permalinks/')
await page.goto('routes/permalinks/')

await expect(linksLocator).toHaveCount(3)

Expand Down Expand Up @@ -70,7 +71,7 @@ test('should support rendering link by filename and navigate to it correctly', a
const linksLocator = page.locator(`.e2e-theme-content #${id} + ul > li a`)
const contentLocator = page.locator('.e2e-theme-content p')

await page.goto('/routes/permalinks/')
await page.goto('routes/permalinks/')

await expect(linksLocator).toHaveCount(3)

Expand Down
4 changes: 2 additions & 2 deletions e2e/tests/site-data.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import { expect, test } from '@playwright/test'

test.describe('en-US', () => {
test.beforeEach(async ({ page }) => {
await page.goto('/')
await page.goto('')
})

test('lang', async ({ page }) => {
Expand Down Expand Up @@ -50,7 +50,7 @@ test.describe('en-US', () => {
})

test.describe('zh-CN', () => {
test.beforeEach(async ({ page }) => page.goto('/zh/'))
test.beforeEach(async ({ page }) => page.goto('zh/'))

test('lang', async ({ page }) => {
await expect(page.locator('html')).toHaveAttribute('lang', 'zh-CN')
Expand Down
2 changes: 1 addition & 1 deletion e2e/tests/update-head.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ test('should update head correctly', async ({ page }) => {
const fooZhLocator = page.locator('head meta[name="foo-zh"]')

// en-US
await page.goto('/')
await page.goto('')

// lang
await expect(htmlLocator).toHaveAttribute('lang', 'en-US')
Expand Down

0 comments on commit eb578a1

Please sign in to comment.