/
Iframe.test.js
93 lines (89 loc) · 2.54 KB
/
Iframe.test.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
'use strict';
const testServer = require('../helpers/test-server');
const config = require('../fixtures/client-config/webpack.config');
const runBrowser = require('../helpers/run-browser');
const port = require('../ports-map').Iframe;
const { beforeBrowserCloseDelay } = require('../helpers/puppeteer-constants');
// iframe mode should be tested while still supported, because
// its sources differ from those of inline mode, which can cause unexpected
// breaking changes: https://github.com/webpack/webpack-dev-server/issues/2006
describe('Client iframe console.log', () => {
const baseOptions = {
port,
host: '0.0.0.0',
};
const cases = [
{
title: 'hot disabled',
options: {
hot: false,
},
},
{
title: 'hot enabled',
options: {
hot: true,
},
},
{
title: 'liveReload disabled',
options: {
liveReload: false,
},
},
{
title: 'liveReload enabled',
options: {
liveReload: true,
},
},
{
title: 'clientLogLevel is silent',
options: {
clientLogLevel: 'silent',
},
},
];
cases.forEach(({ title, options }) => {
it(title, (done) => {
const res = [];
const testOptions = Object.assign({}, baseOptions, options);
// TODO: use async/await when Node.js v6 support is dropped
Promise.resolve()
.then(() => {
return new Promise((resolve) => {
testServer.startAwaitingCompilation(config, testOptions, resolve);
});
})
.then(() => {
// make sure the previous Promise is not passing along strange arguments to runBrowser
return runBrowser();
})
.then(({ page, browser }) => {
return new Promise((resolve) => {
page.goto(`http://localhost:${port}/webpack-dev-server/main`);
page.on('console', ({ _text }) => {
res.push(_text);
});
page.waitForNavigation({ waitUntil: 'load' }).then(() => {
page.waitFor(beforeBrowserCloseDelay).then(() => {
browser.close().then(() => {
resolve();
});
});
});
});
})
.then(() => {
return new Promise((resolve) => {
testServer.close(resolve);
});
})
.then(() => {
// Order doesn't matter, maybe we should improve that in future
expect(res.sort()).toMatchSnapshot();
done();
});
});
});
});