Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix(vue-app): sanitize path with trailing slash in
getLocation
(#6744…
…) (#6745)
- Loading branch information
Showing
4 changed files
with
87 additions
and
1 deletion.
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,71 @@ | ||
import Browser from '../utils/browser' | ||
import { loadFixture, getPort, Nuxt } from '../utils' | ||
|
||
let port | ||
const browser = new Browser() | ||
const url = route => 'http://localhost:' + port + route | ||
|
||
let nuxt = null | ||
let page = null | ||
|
||
describe('spa router base browser', () => { | ||
beforeAll(async () => { | ||
const config = await loadFixture('spa-base') | ||
nuxt = new Nuxt(config) | ||
await nuxt.ready() | ||
|
||
port = await getPort() | ||
await nuxt.server.listen(port, 'localhost') | ||
|
||
await browser.start({ | ||
// slowMo: 50, | ||
// headless: false | ||
}) | ||
}) | ||
|
||
test('Open /app (router base)', async () => { | ||
page = await browser.page(url('/app')) | ||
|
||
expect(await page.evaluate(() => location.href)).toBe(url('/app')) | ||
|
||
expect(await page.html()).not.toContain('This page could not be found') | ||
|
||
expect(await page.evaluate(() => { | ||
const headings = document.evaluate("//div[text()='Hello SPA!']", document, null, XPathResult.ANY_TYPE, null) | ||
return headings.iterateNext() | ||
})).not.toBe(null) | ||
}) | ||
|
||
test('Open /app/ (router base with trailing slash)', async () => { | ||
page = await browser.page(url('/app/')) | ||
|
||
expect(await page.evaluate(() => location.href)).toBe(url('/app/')) | ||
|
||
expect(await page.html()).not.toContain('This page could not be found') | ||
}) | ||
|
||
test('Open /app/mounted', async () => { | ||
page = await browser.page(url('/app/mounted')) | ||
|
||
expect(await page.$text('h1')).toMatch('Test: updated') | ||
}) | ||
|
||
test('/app/unknown', async () => { | ||
page = await browser.page(url('/app/unknown')) | ||
|
||
expect(await page.evaluate(() => location.href)).toBe(url('/app/unknown')) | ||
|
||
expect(await page.html()).toContain('This page could not be found') | ||
}) | ||
|
||
// Close server and ask nuxt to stop listening to file changes | ||
afterAll(async () => { | ||
await nuxt.close() | ||
}) | ||
|
||
// Stop browser | ||
afterAll(async () => { | ||
await page.close() | ||
await browser.close() | ||
}) | ||
}) |
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,13 @@ | ||
import { resolve } from 'path' | ||
import defaultsDeep from 'lodash/defaultsDeep' | ||
import baseNuxtConfig from '../spa/nuxt.config' | ||
|
||
const config = { | ||
buildDir: resolve(__dirname, '.nuxt'), | ||
srcDir: resolve(__dirname, '..', 'spa'), | ||
router: { | ||
base: '/app' | ||
} | ||
} | ||
|
||
export default defaultsDeep(config, baseNuxtConfig) |
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