|
| 1 | +'use strict'; |
| 2 | + |
| 3 | +/* eslint-disable |
| 4 | + no-undef |
| 5 | +*/ |
| 6 | +const fs = require('fs'); |
| 7 | +const { resolve } = require('path'); |
| 8 | +const testServer = require('../helpers/test-server'); |
| 9 | +const reloadConfig = require('../fixtures/reload-config/webpack.config'); |
| 10 | +const runBrowser = require('../helpers/run-browser'); |
| 11 | +const port = require('../ports-map').Progress; |
| 12 | + |
| 13 | +const cssFilePath = resolve(__dirname, '../fixtures/reload-config/main.css'); |
| 14 | + |
| 15 | +describe('client progress', () => { |
| 16 | + describe('using hot', () => { |
| 17 | + beforeAll((done) => { |
| 18 | + fs.writeFileSync( |
| 19 | + cssFilePath, |
| 20 | + 'body { background-color: rgb(0, 0, 255); }' |
| 21 | + ); |
| 22 | + const options = { |
| 23 | + port, |
| 24 | + host: '0.0.0.0', |
| 25 | + inline: true, |
| 26 | + hot: true, |
| 27 | + progress: true, |
| 28 | + watchOptions: { |
| 29 | + poll: 500, |
| 30 | + }, |
| 31 | + }; |
| 32 | + testServer.startAwaitingCompilation(reloadConfig, options, done); |
| 33 | + }); |
| 34 | + |
| 35 | + afterAll((done) => { |
| 36 | + fs.unlinkSync(cssFilePath); |
| 37 | + testServer.close(done); |
| 38 | + }); |
| 39 | + |
| 40 | + describe('on browser client', () => { |
| 41 | + it('should console.log progress', (done) => { |
| 42 | + runBrowser().then(({ page, browser }) => { |
| 43 | + const res = []; |
| 44 | + page.waitForNavigation({ waitUntil: 'load' }).then(() => { |
| 45 | + fs.writeFileSync( |
| 46 | + cssFilePath, |
| 47 | + 'body { background-color: rgb(255, 0, 0); }' |
| 48 | + ); |
| 49 | + page.waitFor(10000).then(() => { |
| 50 | + browser.close().then(() => { |
| 51 | + // check that there is some percentage progress output |
| 52 | + const regExp = /^\[WDS\] [0-9]{1,3}% - /; |
| 53 | + const match = res.find((line) => { |
| 54 | + return regExp.test(line); |
| 55 | + }); |
| 56 | + // eslint-disable-next-line no-undefined |
| 57 | + expect(match).not.toEqual(undefined); |
| 58 | + done(); |
| 59 | + }); |
| 60 | + }); |
| 61 | + }); |
| 62 | + |
| 63 | + page.goto(`http://localhost:${port}/main`); |
| 64 | + page.on('console', (data) => { |
| 65 | + res.push(data.text()); |
| 66 | + }); |
| 67 | + }); |
| 68 | + }); |
| 69 | + }); |
| 70 | + }); |
| 71 | +}); |
0 commit comments