Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Failing test for #4620 #4625

Merged
merged 2 commits into from
Jun 18, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 16 additions & 0 deletions test/integration/app-aspath/pages/_app.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
import React from 'react'
import App, {Container} from 'next/app'

export default class MyApp extends App {
// find this

static async getInitialProps ({ ctx }) {
const { query, pathname, asPath } = ctx
return {url: {query, pathname, asPath}}
}

render () {
const {Component, url} = this.props
return <Container><Component url={url} /></Container>
}
}
1 change: 1 addition & 0 deletions test/integration/app-aspath/pages/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export default props => JSON.stringify(props, null, 2)
55 changes: 55 additions & 0 deletions test/integration/app-aspath/test/index.test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
/* global jasmine, describe, it, expect, beforeAll, afterAll */

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, true)

// 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')

try {
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": "/" } }')
} finally {
// Change back to the original content
writeFileSync(appPath, originalContent, 'utf8')
browser.close()
}
})
})