Skip to content

Commit

Permalink
Add WIP browser test
Browse files Browse the repository at this point in the history
  • Loading branch information
marcofugaro committed Mar 11, 2019
1 parent 0b31b3a commit f2156a3
Showing 1 changed file with 24 additions and 6 deletions.
30 changes: 24 additions & 6 deletions test/ContentBase.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,10 @@
const path = require('path');
const fs = require('fs');
const request = require('supertest');
const addEntries = require('../lib/utils/addEntries');
const helper = require('./helper');
const config = require('./fixtures/contentbase-config/webpack.config');
const runBrowser = require('./helpers/run-browser');

const contentBasePublic = path.join(
__dirname,
Expand All @@ -22,10 +24,17 @@ describe('ContentBase', () => {

describe('to directory', () => {
beforeAll((done) => {
const options = {
port: 9001,
host: '0.0.0.0',
disableHostCheck: true,
};
addEntries(config, options);
server = helper.start(
config,
{
contentBase: contentBasePublic,
watchContentBase: true,
},
done
);
Expand All @@ -43,12 +52,21 @@ describe('ContentBase', () => {
it('Watches recursively', (done) => {
const nestedFile = path.join(contentBasePublic, 'assets/example.txt');

fs.truncateSync(nestedFile);
fs.writeFileSync(nestedFile, 'Heyo', 'utf8');

// TODO check if the browser has refreshed

done();
runBrowser().then(({ page, browser }) => {
// wait for first load
page.goto('http://localhost:9001').then(() => {
// page reloaded after the first load,
// meaning it watched the file correctly
page.on('load', () => {
browser.close();
done();
});

// trigger chokidar's file change event
fs.truncateSync(nestedFile);
fs.writeFileSync(nestedFile, 'Heyo', 'utf8');
});
});
});
});

Expand Down

0 comments on commit f2156a3

Please sign in to comment.