forked from vercel/next.js
-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.test.js
41 lines (35 loc) · 1.06 KB
/
index.test.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
/* eslint-env jest */
jest.setTimeout(1000 * 60 * 2)
import { fetchViaHTTP, findPort, killApp, launchApp } from 'next-test-utils'
import { join } from 'path'
import cheerio from 'cheerio'
import webdriver from 'next-webdriver'
const context = {}
context.appDir = join(__dirname, '../')
describe('Middleware base tests', () => {
beforeAll(async () => {
context.appPort = await findPort()
context.app = await launchApp(context.appDir, context.appPort)
})
afterAll(() => killApp(context.app))
runTests()
})
function runTests() {
it('should execute from absolute paths', async () => {
const browser = await webdriver(context.appPort, '/redirect-with-basepath')
try {
expect(await browser.eval(`window.location.pathname`)).toBe(
'/root/redirect-with-basepath'
)
} finally {
await browser.close()
}
const res = await fetchViaHTTP(
context.appPort,
'/root/redirect-with-basepath'
)
const html = await res.text()
const $ = cheerio.load(html)
expect($('.title').text()).toBe('About Page')
})
}