1
0
Fork 0
mirror of https://github.com/terribleplan/next.js.git synced 2024-01-19 02:48:18 +00:00

Use getBrowserBodyText for HMR test (#5290)

This commit is contained in:
Tim Neutkens 2018-09-26 01:41:39 +02:00 committed by GitHub
parent 7961946c07
commit 6e4f0d8e70
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
3 changed files with 16 additions and 21 deletions

View file

@ -2,7 +2,7 @@
import webdriver from 'next-webdriver'
import { readFileSync, writeFileSync, renameSync, existsSync } from 'fs'
import { join } from 'path'
import { waitFor, check } from 'next-test-utils'
import { waitFor, check, getBrowserBodyText } from 'next-test-utils'
import cheerio from 'cheerio'
export default (context, renderViaHTTP) => {
@ -22,7 +22,7 @@ export default (context, renderViaHTTP) => {
renameSync(contactPagePath, newContactPagePath)
await check(
() => browser.elementByCss('body').text(),
() => getBrowserBodyText(browser),
/This page could not be found/
)
@ -31,7 +31,7 @@ export default (context, renderViaHTTP) => {
// wait until the page comes back
await check(
() => browser.elementByCss('body').text(),
() => getBrowserBodyText(browser),
/This is the contact page/
)
} finally {
@ -63,7 +63,7 @@ export default (context, renderViaHTTP) => {
writeFileSync(aboutPagePath, editedContent, 'utf8')
await check(
() => browser.elementByCss('body').text(),
() => getBrowserBodyText(browser),
/COOL page/
)
@ -71,7 +71,7 @@ export default (context, renderViaHTTP) => {
writeFileSync(aboutPagePath, originalContent, 'utf8')
await check(
() => browser.elementByCss('body').text(),
() => getBrowserBodyText(browser),
/This is the about page/
)
} finally {

View file

@ -1,6 +1,6 @@
/* global describe, it, expect */
import webdriver from 'next-webdriver'
import { check } from 'next-test-utils'
import { check, getBrowserBodyText } from 'next-test-utils'
export default function (context) {
describe('Render via browser', () => {
@ -147,23 +147,21 @@ export default function (context) {
describe('pages in the nested level: level1', () => {
it('should render the home page', async () => {
const browser = await webdriver(context.port, '/')
const text = await browser
.elementByCss('#level1-home-page').click()
.waitForElementByCss('#level1-home-page')
.elementByCss('#level1-home-page p').text()
expect(text).toBe('This is the Level1 home page')
await browser.eval('document.getElementById("level1-home-page").click()')
await check(() => getBrowserBodyText(browser), /This is the Level1 home page/)
browser.close()
})
it('should render the about page', async () => {
const browser = await webdriver(context.port, '/')
const text = await browser
.elementByCss('#level1-about-page').click()
.waitForElementByCss('#level1-about-page')
.elementByCss('#level1-about-page p').text()
expect(text).toBe('This is the Level1 about page')
await browser.eval('document.getElementById("level1-about-page").click()')
await check(() => getBrowserBodyText(browser), /This is the Level1 about page/)
browser.close()
})
})

View file

@ -1,6 +1,6 @@
/* global describe, it, expect */
import webdriver from 'next-webdriver'
import { renderViaHTTP } from 'next-test-utils'
import { renderViaHTTP, getBrowserBodyText, check } from 'next-test-utils'
import cheerio from 'cheerio'
const loadJSONInPage = pageContent => {
@ -12,11 +12,8 @@ export default function (context) {
describe('Render in development mode', () => {
it('should render the home page', async () => {
const browser = await webdriver(context.port, '/')
const text = await browser
.elementByCss('#home-page p').text()
expect(text).toBe('This is the home page')
browser.close()
await check(() => getBrowserBodyText(browser), /This is the home page/)
})
it('should render pages only existent in exportPathMap page', async () => {