Skip to content

Commit bf882eb

Browse files
Zn4rKtimneutkens
authored andcommitted
Failing test for #4620 (#4625)
Failing test for #4620
1 parent c4d0b21 commit bf882eb

File tree

3 files changed

+72
-0
lines changed

3 files changed

+72
-0
lines changed
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
import React from 'react'
2+
import App, {Container} from 'next/app'
3+
4+
export default class MyApp extends App {
5+
// find this
6+
7+
static async getInitialProps ({ ctx }) {
8+
const { query, pathname, asPath } = ctx
9+
return {url: {query, pathname, asPath}}
10+
}
11+
12+
render () {
13+
const {Component, url} = this.props
14+
return <Container><Component url={url} /></Container>
15+
}
16+
}
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
export default props => JSON.stringify(props, null, 2)
Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
/* global jasmine, describe, it, expect, beforeAll, afterAll */
2+
3+
import webdriver from 'next-webdriver'
4+
import { readFileSync, writeFileSync } from 'fs'
5+
import { join } from 'path'
6+
import {
7+
renderViaHTTP,
8+
findPort,
9+
launchApp,
10+
killApp,
11+
waitFor
12+
} from 'next-test-utils'
13+
14+
let appPort
15+
let server
16+
jasmine.DEFAULT_TIMEOUT_INTERVAL = 1000 * 60 * 5
17+
18+
describe('App asPath', () => {
19+
beforeAll(async () => {
20+
appPort = await findPort()
21+
server = await launchApp(join(__dirname, '../'), appPort, true)
22+
23+
// pre-build all pages at the start
24+
await Promise.all([
25+
renderViaHTTP(appPort, '/')
26+
])
27+
})
28+
afterAll(() => killApp(server))
29+
30+
it('should not have any changes in asPath after a bundle rebuild', async () => {
31+
const browser = await webdriver(appPort, '/')
32+
const appPath = join(__dirname, '../', 'pages', '_app.js')
33+
const originalContent = readFileSync(appPath, 'utf8')
34+
35+
try {
36+
const text = await browser.elementByCss('body').text()
37+
expect(text).toBe('{ "url": { "query": {}, "pathname": "/", "asPath": "/" } }')
38+
39+
const editedContent = originalContent.replace('find this', 'replace with this')
40+
41+
// Change the content to trigger a bundle rebuild
42+
await writeFileSync(appPath, editedContent, 'utf8')
43+
44+
// Wait for the bundle rebuild
45+
await waitFor(5000)
46+
47+
const newContent = await browser.elementByCss('body').text()
48+
expect(newContent).toBe('{ "url": { "query": {}, "pathname": "/", "asPath": "/" } }')
49+
} finally {
50+
// Change back to the original content
51+
writeFileSync(appPath, originalContent, 'utf8')
52+
browser.close()
53+
}
54+
})
55+
})

0 commit comments

Comments
 (0)