mirror of
https://github.com/terribleplan/next.js.git
synced 2024-01-19 02:48:18 +00:00
18488f47b0
* Fix linter * Add test env * Fix lint errors
54 lines
1.5 KiB
JavaScript
54 lines
1.5 KiB
JavaScript
/* eslint-env jest */
|
|
/* global jasmine */
|
|
import webdriver from 'next-webdriver'
|
|
import { readFileSync, writeFileSync } from 'fs'
|
|
import { join } from 'path'
|
|
import {
|
|
renderViaHTTP,
|
|
findPort,
|
|
launchApp,
|
|
killApp,
|
|
waitFor
|
|
} from 'next-test-utils'
|
|
|
|
let appPort
|
|
let server
|
|
jasmine.DEFAULT_TIMEOUT_INTERVAL = 1000 * 60 * 5
|
|
|
|
describe('App asPath', () => {
|
|
beforeAll(async () => {
|
|
appPort = await findPort()
|
|
server = await launchApp(join(__dirname, '../'), appPort)
|
|
|
|
// pre-build all pages at the start
|
|
await Promise.all([
|
|
renderViaHTTP(appPort, '/')
|
|
])
|
|
})
|
|
afterAll(() => killApp(server))
|
|
|
|
it('should not have any changes in asPath after a bundle rebuild', async () => {
|
|
const browser = await webdriver(appPort, '/')
|
|
const appPath = join(__dirname, '../', 'pages', '_app.js')
|
|
const originalContent = readFileSync(appPath, 'utf8')
|
|
|
|
const text = await browser.elementByCss('body').text()
|
|
expect(text).toBe('{ "url": { "query": {}, "pathname": "/", "asPath": "/" } }')
|
|
|
|
const editedContent = originalContent.replace('find this', 'replace with this')
|
|
|
|
// Change the content to trigger a bundle rebuild
|
|
await writeFileSync(appPath, editedContent, 'utf8')
|
|
|
|
// Wait for the bundle rebuild
|
|
await waitFor(5000)
|
|
|
|
const newContent = await browser.elementByCss('body').text()
|
|
expect(newContent).toBe('{ "url": { "query": {}, "pathname": "/", "asPath": "/" } }')
|
|
|
|
// Change back to the original content
|
|
writeFileSync(appPath, originalContent, 'utf8')
|
|
browser.quit()
|
|
})
|
|
})
|