|
| 1 | +'use strict'; |
| 2 | + |
| 3 | +const testServer = require('../helpers/test-server'); |
| 4 | +const config = require('../fixtures/client-config/webpack.config'); |
| 5 | +const runBrowser = require('../helpers/run-browser'); |
| 6 | +const port = require('../ports-map').Iframe; |
| 7 | + |
| 8 | +// iframe mode should be tested while still supported, because |
| 9 | +// its sources differ from those of inline mode, which can cause unexpected |
| 10 | +// breaking changes: https://github.com/webpack/webpack-dev-server/issues/2006 |
| 11 | +describe('Client iframe console.log', () => { |
| 12 | + const baseOptions = { |
| 13 | + port, |
| 14 | + host: '0.0.0.0', |
| 15 | + }; |
| 16 | + const cases = [ |
| 17 | + { |
| 18 | + title: 'hot disabled', |
| 19 | + options: { |
| 20 | + hot: false, |
| 21 | + }, |
| 22 | + }, |
| 23 | + { |
| 24 | + title: 'hot enabled', |
| 25 | + options: { |
| 26 | + hot: true, |
| 27 | + }, |
| 28 | + }, |
| 29 | + { |
| 30 | + title: 'liveReload disabled', |
| 31 | + options: { |
| 32 | + liveReload: false, |
| 33 | + }, |
| 34 | + }, |
| 35 | + { |
| 36 | + title: 'liveReload enabled', |
| 37 | + options: { |
| 38 | + liveReload: true, |
| 39 | + }, |
| 40 | + }, |
| 41 | + { |
| 42 | + title: 'clientLogLevel is silent', |
| 43 | + options: { |
| 44 | + clientLogLevel: 'silent', |
| 45 | + }, |
| 46 | + }, |
| 47 | + ]; |
| 48 | + |
| 49 | + for (const { title, options } of cases) { |
| 50 | + it(title, () => { |
| 51 | + const res = []; |
| 52 | + const testOptions = Object.assign({}, baseOptions, options); |
| 53 | + |
| 54 | + // TODO: use async/await when Node.js v6 support is dropped |
| 55 | + return Promise.resolve() |
| 56 | + .then(() => { |
| 57 | + return new Promise((resolve) => { |
| 58 | + testServer.startAwaitingCompilation(config, testOptions, resolve); |
| 59 | + }); |
| 60 | + }) |
| 61 | + .then(runBrowser) |
| 62 | + .then(({ page, browser }) => { |
| 63 | + return new Promise((resolve) => { |
| 64 | + page.goto(`http://localhost:${port}/webpack-dev-server/main`); |
| 65 | + page.on('console', ({ _text }) => { |
| 66 | + res.push(_text); |
| 67 | + }); |
| 68 | + setTimeout(() => { |
| 69 | + browser.close().then(() => { |
| 70 | + expect(res).toMatchSnapshot(); |
| 71 | + resolve(); |
| 72 | + }); |
| 73 | + }, 3000); |
| 74 | + }); |
| 75 | + }) |
| 76 | + .then(() => { |
| 77 | + return new Promise((resolve) => { |
| 78 | + testServer.close(resolve); |
| 79 | + }); |
| 80 | + }); |
| 81 | + }); |
| 82 | + } |
| 83 | +}); |
0 commit comments