|
| 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