11/* eslint-env jest */
2- import webdriver from 'next- webdriver'
2+ /* global webdriver */
33import { join } from 'path'
44import { check , File , waitFor , getReactErrorOverlayContent , getBrowserBodyText } from 'next-test-utils'
55
@@ -40,9 +40,8 @@ export default (context, renderViaHTTP) => {
4040 it ( 'should have installed the react-overlay-editor editor handler' , async ( ) => {
4141 let browser
4242 const aboutPage = new File ( join ( __dirname , '../' , 'pages' , 'hmr' , 'about.js' ) )
43- aboutPage . replace ( '</div>' , 'div' )
44-
4543 try {
44+ aboutPage . replace ( '</div>' , 'div' )
4645 browser = await webdriver ( context . appPort , '/hmr/about' )
4746
4847 // react-error-overlay uses the following inline style if an editorHandler is installed
@@ -76,8 +75,10 @@ export default (context, renderViaHTTP) => {
7675 const aboutPage = new File ( join ( __dirname , '../' , 'pages' , 'hmr' , 'about.js' ) )
7776 try {
7877 browser = await webdriver ( context . appPort , '/hmr/about' )
79- const text = await browser . elementByCss ( 'p' ) . text ( )
80- expect ( text ) . toBe ( 'This is the about page.' )
78+ await check (
79+ ( ) => getBrowserBodyText ( browser ) ,
80+ / T h i s i s t h e a b o u t p a g e /
81+ )
8182
8283 aboutPage . replace ( '</div>' , 'div' )
8384
@@ -147,9 +148,10 @@ export default (context, renderViaHTTP) => {
147148 const aboutPage = new File ( join ( __dirname , '../' , 'pages' , 'hmr' , 'about.js' ) )
148149 try {
149150 browser = await webdriver ( context . appPort , '/hmr/about' )
150- const text = await browser
151- . elementByCss ( 'p' ) . text ( )
152- expect ( text ) . toBe ( 'This is the about page.' )
151+ await check (
152+ ( ) => getBrowserBodyText ( browser ) ,
153+ / T h i s i s t h e a b o u t p a g e /
154+ )
153155
154156 aboutPage . replace ( 'export' , 'aa=20;\nexport' )
155157
@@ -174,9 +176,10 @@ export default (context, renderViaHTTP) => {
174176 const aboutPage = new File ( join ( __dirname , '../' , 'pages' , 'hmr' , 'about.js' ) )
175177 try {
176178 browser = await webdriver ( context . appPort , '/hmr/about' )
177- const text = await browser . elementByCss ( 'p' ) . text ( )
178-
179- expect ( text ) . toBe ( 'This is the about page.' )
179+ await check (
180+ ( ) => getBrowserBodyText ( browser ) ,
181+ / T h i s i s t h e a b o u t p a g e /
182+ )
180183
181184 aboutPage . replace ( 'return' , 'throw new Error("an-expected-error");\nreturn' )
182185
@@ -210,8 +213,10 @@ export default (context, renderViaHTTP) => {
210213 const aboutPage = new File ( join ( __dirname , '../' , 'pages' , 'hmr' , 'about.js' ) )
211214 try {
212215 browser = await webdriver ( context . appPort , '/hmr/about' )
213- const text = await browser . elementByCss ( 'p' ) . text ( )
214- expect ( text ) . toBe ( 'This is the about page.' )
216+ await check (
217+ ( ) => getBrowserBodyText ( browser ) ,
218+ / T h i s i s t h e a b o u t p a g e /
219+ )
215220
216221 aboutPage . replace ( 'export default' , 'export default {};\nexport const fn =' )
217222
@@ -249,8 +254,10 @@ export default (context, renderViaHTTP) => {
249254 const aboutPage = new File ( join ( __dirname , '../' , 'pages' , 'hmr' , 'about.js' ) )
250255 try {
251256 browser = await webdriver ( context . appPort , '/hmr/about' )
252- const text = await browser . elementByCss ( 'p' ) . text ( )
253- expect ( text ) . toBe ( 'This is the about page.' )
257+ await check (
258+ ( ) => getBrowserBodyText ( browser ) ,
259+ / T h i s i s t h e a b o u t p a g e /
260+ )
254261
255262 aboutPage . replace ( 'export default' , 'export default () => /search/;\nexport const fn =' )
256263
@@ -288,8 +295,10 @@ export default (context, renderViaHTTP) => {
288295 const aboutPage = new File ( join ( __dirname , '../' , 'pages' , 'hmr' , 'about.js' ) )
289296 try {
290297 browser = await webdriver ( context . appPort , '/hmr/about' )
291- const text = await browser . elementByCss ( 'p' ) . text ( )
292- expect ( text ) . toBe ( 'This is the about page.' )
298+ await check (
299+ ( ) => getBrowserBodyText ( browser ) ,
300+ / T h i s i s t h e a b o u t p a g e /
301+ )
293302
294303 aboutPage . replace ( 'export default' , 'export default undefined;\nexport const fn =' )
295304
0 commit comments