I'm developing a nodejs library similar to live-reload/browser-sync and I'm using jest-puppeteer for the automated tests.
When I manually test my library, opening the browser and modifying a file, voilá, the pages refreshes (through an injected code that runs a location.reload( true )
when it receives a signal through a websocket).
But when I run the test with Jest, it seems that Puppeteer doesn't get the refresh.
// "reloader" is my library
import reloader from './../src/index';
import * as fs from 'fs';
import { promisify } from 'util';
const read = promisify( fs.readFile )
const write = promisify( fs.writeFile )
test('1. Refresh when file changes', async () => {
const server = await reloader( { dir: 'test/01' } );
await page.goto( 'http://localhost:' + server.port );
// This test passes
await expect( page.title()).resolves.toMatch( 'Old title' );
// Read and modify index.html to generate a refresh
const file = 'test/01/index.html'
const content = await read( file, 'utf8' );
await write( file, content.replace( 'Old title', 'New title' ) );
// Wait the page to refresh
await page.waitForNavigation( { waitUntil: 'networkidle2' } )
// This test doesn't pass
// Still receiving "Old title"
await expect( page.title()).resolves.toMatch( 'New title' );
// Undo the changes
write( file, content );
});
On the last test, instead of receiving the New title
(that is being written correctly in the index.html
file), I'm still receiving Old title