From 445567d24c5ac3c7fc8090cba281c5b052c18cb8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Alexander=20Liljenga=CC=8Ard?= Date: Sun, 17 Jun 2018 19:20:19 +0200 Subject: [PATCH] Failing test for #4620 --- test/integration/app-aspath/pages/_app.js | 16 ++++++ test/integration/app-aspath/pages/index.js | 1 + .../integration/app-aspath/test/index.test.js | 55 +++++++++++++++++++ 3 files changed, 72 insertions(+) create mode 100644 test/integration/app-aspath/pages/_app.js create mode 100644 test/integration/app-aspath/pages/index.js create mode 100644 test/integration/app-aspath/test/index.test.js diff --git a/test/integration/app-aspath/pages/_app.js b/test/integration/app-aspath/pages/_app.js new file mode 100644 index 0000000000000..846f130fce23e --- /dev/null +++ b/test/integration/app-aspath/pages/_app.js @@ -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 + } +} diff --git a/test/integration/app-aspath/pages/index.js b/test/integration/app-aspath/pages/index.js new file mode 100644 index 0000000000000..49e5509c50821 --- /dev/null +++ b/test/integration/app-aspath/pages/index.js @@ -0,0 +1 @@ +export default props => JSON.stringify(props, null, 2) diff --git a/test/integration/app-aspath/test/index.test.js b/test/integration/app-aspath/test/index.test.js new file mode 100644 index 0000000000000..1b9054164eb84 --- /dev/null +++ b/test/integration/app-aspath/test/index.test.js @@ -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() + } + }) +})