Commit 31f3bfa1 authored by JJ Kasper's avatar JJ Kasper Committed by Joe Haddad

Add test ensuring basePath is added to routes-manifest (#9885)

parent 078b2a5e
...@@ -17,23 +17,27 @@ import { ...@@ -17,23 +17,27 @@ import {
File, File,
nextStart, nextStart,
} from 'next-test-utils' } from 'next-test-utils'
import { readFileSync, writeFileSync, renameSync, existsSync } from 'fs' import fs, {
readFileSync,
writeFileSync,
renameSync,
existsSync,
} from 'fs-extra'
import cheerio from 'cheerio' import cheerio from 'cheerio'
jasmine.DEFAULT_TIMEOUT_INTERVAL = 1000 * 60 * 5 jasmine.DEFAULT_TIMEOUT_INTERVAL = 1000 * 60 * 2
describe('basePath development', () => { const appDir = join(__dirname, '..')
let server
let context = {}
beforeAll(async () => { const runTests = (context, dev = false) => {
context.appPort = await findPort() if (!dev) {
server = await launchApp(join(__dirname, '..'), context.appPort) it('should add basePath to routes-manifest', async () => {
}) const routesManifest = await fs.readJSON(
afterAll(async () => { join(appDir, '.next/routes-manifest.json')
await killApp(server) )
}) expect(routesManifest.basePath).toBe('/docs')
})
}
it('should show the hello page under the /docs prefix', async () => { it('should show the hello page under the /docs prefix', async () => {
const browser = await webdriver(context.appPort, '/docs/hello') const browser = await webdriver(context.appPort, '/docs/hello')
...@@ -72,6 +76,22 @@ describe('basePath development', () => { ...@@ -72,6 +76,22 @@ describe('basePath development', () => {
await browser.close() await browser.close()
} }
}) })
}
describe('basePath development', () => {
let server
let context = {}
beforeAll(async () => {
context.appPort = await findPort()
server = await launchApp(join(__dirname, '..'), context.appPort)
})
afterAll(async () => {
await killApp(server)
})
runTests(context, true)
describe('Hot Module Reloading', () => { describe('Hot Module Reloading', () => {
describe('delete a page and add it back', () => { describe('delete a page and add it back', () => {
...@@ -379,7 +399,6 @@ describe('basePath development', () => { ...@@ -379,7 +399,6 @@ describe('basePath development', () => {
}) })
describe('basePath production', () => { describe('basePath production', () => {
const appDir = join(__dirname, '../')
let context = {} let context = {}
let server let server
let app let app
...@@ -398,47 +417,10 @@ describe('basePath production', () => { ...@@ -398,47 +417,10 @@ describe('basePath production', () => {
afterAll(() => stopApp(server)) afterAll(() => stopApp(server))
it('should show the hello page under the /docs prefix', async () => { runTests(context)
const browser = await webdriver(context.appPort, '/docs/hello')
try {
const text = await browser.elementByCss('h1').text()
expect(text).toBe('Hello World')
} finally {
await browser.close()
}
})
it('should show the other-page page under the /docs prefix', async () => {
const browser = await webdriver(context.appPort, '/docs/other-page')
try {
const text = await browser.elementByCss('h1').text()
expect(text).toBe('Hello Other')
} finally {
await browser.close()
}
})
it('should navigate to the page without refresh', async () => {
const browser = await webdriver(context.appPort, '/docs/hello')
try {
await browser.eval('window.itdidnotrefresh = "hello"')
const text = await browser
.elementByCss('#other-page-link')
.click()
.waitForElementByCss('#other-page-title')
.elementByCss('h1')
.text()
expect(text).toBe('Hello Other')
expect(await browser.eval('window.itdidnotrefresh')).toBe('hello')
} finally {
await browser.close()
}
})
}) })
describe('basePath serverless', () => { describe('basePath serverless', () => {
const appDir = join(__dirname, '../')
let context = {} let context = {}
let app let app
...@@ -457,41 +439,5 @@ describe('basePath serverless', () => { ...@@ -457,41 +439,5 @@ describe('basePath serverless', () => {
await nextConfig.restore() await nextConfig.restore()
}) })
it('should show the hello page under the /docs prefix', async () => { runTests(context)
const browser = await webdriver(context.appPort, '/docs/hello')
try {
const text = await browser.elementByCss('h1').text()
expect(text).toBe('Hello World')
} finally {
await browser.close()
}
})
it('should show the other-page page under the /docs prefix', async () => {
const browser = await webdriver(context.appPort, '/docs/other-page')
try {
const text = await browser.elementByCss('h1').text()
expect(text).toBe('Hello Other')
} finally {
await browser.close()
}
})
it('should navigate to the page without refresh', async () => {
const browser = await webdriver(context.appPort, '/docs/hello')
try {
await browser.eval('window.itdidnotrefresh = "hello"')
const text = await browser
.elementByCss('#other-page-link')
.click()
.waitForElementByCss('#other-page-title')
.elementByCss('h1')
.text()
expect(text).toBe('Hello Other')
expect(await browser.eval('window.itdidnotrefresh')).toBe('hello')
} finally {
await browser.close()
}
})
}) })
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment