Skip to content

test(e2e): improve puppeteer argument flags #2127

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 18 commits into from
Jul 23, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
18 commits
Select commit Hold shift + click to select a range
6a14a9c
test(e2e): improve puppeteer argument flags
knagaitsev Jul 16, 2019
17e131d
test(e2e): wait for page load before checking console output
knagaitsev Jul 17, 2019
1d3f30f
test(e2e): improve timing on client test
knagaitsev Jul 18, 2019
0e777c1
test(e2e): remove failed connection error messages at end of client mode
knagaitsev Jul 18, 2019
a72785c
test(e2e): move client mode test delay back down
knagaitsev Jul 18, 2019
a1686bc
Merge branch 'master' into e2e-test-improvements
evilebottnawi Jul 18, 2019
14dcf18
test(e2e): improve timing, prevent sending at wrong readyState
knagaitsev Jul 18, 2019
40c8342
test(e2e): update client options snapshot
knagaitsev Jul 18, 2019
14db723
test(e2e): add pause before closing browser
knagaitsev Jul 18, 2019
7460fc3
test(server): moved base test port up by 10
knagaitsev Jul 18, 2019
b293750
test(e2e): change timing again, change watch options
knagaitsev Jul 18, 2019
e5fbb06
test(e2e): make client test run first
knagaitsev Jul 18, 2019
6ef06cd
test(e2e): space out when e2e tests are run due to concurrency
knagaitsev Jul 19, 2019
ae0e06f
test(e2e): back to original port map, do test right before callback
knagaitsev Jul 19, 2019
af15036
test(e2e): server constants, explain sequencer
knagaitsev Jul 19, 2019
8a96cfb
test(e2e): rename server constants to puppeteer constants
knagaitsev Jul 19, 2019
1baded3
test(e2e): fix path testing in test sequencer for windows
knagaitsev Jul 19, 2019
7f6712f
Merge branch 'master' into e2e-test-improvements
hiroppy Jul 22, 2019
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions jest.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,4 +8,5 @@ module.exports = {
testMatch: ['**/test/**/*.test.js'],
setupFilesAfterEnv: ['<rootDir>/setupTest.js'],
globalSetup: '<rootDir>/globalSetupTest.js',
testSequencer: '<rootDir>/test/testSequencer.js',
};
5 changes: 5 additions & 0 deletions lib/servers/SockJSServer.js
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,11 @@ module.exports = class SockJSServer extends BaseServer {
}

send(connection, message) {
// prevent cases where the server is trying to send data while connection is closing
if (connection.readyState !== 1) {
return;
}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

hm, let's rewrite

if (connection.readyState !== 1) {
  return;
}

connection.write(message);

Hope it is not break code 😄


connection.write(message);
}

Expand Down
5 changes: 5 additions & 0 deletions lib/servers/WebsocketServer.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,11 @@ module.exports = class WebsocketServer extends BaseServer {
}

send(connection, message) {
// prevent cases where the server is trying to send data while connection is closing
if (connection.readyState !== 1) {
return;
}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Look above


connection.send(message);
}

Expand Down
52 changes: 31 additions & 21 deletions test/e2e/Client.test.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
/**
* @jest-environment node
*/

'use strict';

/* eslint-disable
Expand All @@ -9,6 +13,10 @@ const testServer = require('../helpers/test-server');
const reloadConfig = require('../fixtures/reload-config/webpack.config');
const runBrowser = require('../helpers/run-browser');
const port = require('../ports-map').Client;
const {
reloadReadyDelay,
completeReloadDelay,
} = require('../helpers/puppeteer-constants');

const cssFilePath = resolve(__dirname, '../fixtures/reload-config/main.css');

Expand Down Expand Up @@ -53,7 +61,7 @@ describe('reload', () => {
host: '0.0.0.0',
inline: true,
watchOptions: {
poll: 500,
poll: true,
},
},
mode.options
Expand Down Expand Up @@ -91,27 +99,29 @@ describe('reload', () => {
}
req.continue();
});
fs.writeFileSync(
cssFilePath,
'body { background-color: rgb(255, 0, 0); }'
);
page.waitFor(10000).then(() => {
page
.evaluate(() => {
const body = document.body;
const bgColor = getComputedStyle(body)[
'background-color'
];
return bgColor;
})
.then((color2) => {
browser.close().then(() => {
expect(color).toEqual('rgb(0, 0, 255)');
expect(color2).toEqual('rgb(255, 0, 0)');
expect(refreshed).toEqual(mode.shouldRefresh);
done();
page.waitFor(reloadReadyDelay).then(() => {
fs.writeFileSync(
cssFilePath,
'body { background-color: rgb(255, 0, 0); }'
);
page.waitFor(completeReloadDelay).then(() => {
page
.evaluate(() => {
const body = document.body;
const bgColor = getComputedStyle(body)[
'background-color'
];
return bgColor;
})
.then((color2) => {
browser.close().then(() => {
expect(color).toEqual('rgb(0, 0, 255)');
expect(color2).toEqual('rgb(255, 0, 0)');
expect(refreshed).toEqual(mode.shouldRefresh);
done();
});
});
});
});
});
});
});
Expand Down
24 changes: 20 additions & 4 deletions test/e2e/ClientMode.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,10 @@ 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').ClientMode;
const {
initConsoleDelay,
awaitServerCloseDelay,
} = require('../helpers/puppeteer-constants');

describe('clientMode', () => {
const modes = [
Expand Down Expand Up @@ -54,17 +58,29 @@ describe('clientMode', () => {
res.push(_text);
});

setTimeout(() => {
page.waitFor(initConsoleDelay).then(() => {
testServer.close(() => {
// make sure the client gets the close message
setTimeout(() => {
page.waitFor(awaitServerCloseDelay).then(() => {
browser.close().then(() => {
for (let i = res.length - 1; i >= 0; i--) {
if (res[i] === '[WDS] Disconnected!') {
break;
} else if (
res[i] === 'close' ||
res[i].includes('net::ERR_CONNECTION_REFUSED')
) {
// remove additional logging for the now failing connection,
// since this could be a variable number of error messages
res.splice(i, 1);
}
}
expect(res).toMatchSnapshot();
done();
});
}, 1000);
});
});
}, 3000);
});
});
});
});
Expand Down
110 changes: 65 additions & 45 deletions test/e2e/ClientOptions.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ const testServer = require('../helpers/test-server');
const config = require('../fixtures/client-config/webpack.config');
const runBrowser = require('../helpers/run-browser');
const [port1, port2, port3] = require('../ports-map').ClientOptions;
const { beforeBrowserCloseDelay } = require('../helpers/puppeteer-constants');

describe('Client code', () => {
function startProxy(port) {
Expand Down Expand Up @@ -70,13 +71,15 @@ describe('Client code', () => {
page
.waitForRequest((requestObj) => requestObj.url().match(/sockjs-node/))
.then((requestObj) => {
browser.close().then(() => {
expect(
requestObj
.url()
.includes(`http://localhost:${port1}/sockjs-node`)
).toBeTruthy();
done();
page.waitFor(beforeBrowserCloseDelay).then(() => {
browser.close().then(() => {
expect(
requestObj
.url()
.includes(`http://localhost:${port1}/sockjs-node`)
).toBeTruthy();
done();
});
});
});
page.goto(`http://localhost:${port2}/main`);
Expand Down Expand Up @@ -111,13 +114,15 @@ describe('Client complex inline script path', () => {
requestObj.url().match(/foo\/test\/bar/)
)
.then((requestObj) => {
browser.close().then(() => {
expect(
requestObj
.url()
.includes(`http://myhost.test:${port2}/foo/test/bar/`)
).toBeTruthy();
done();
page.waitFor(beforeBrowserCloseDelay).then(() => {
browser.close().then(() => {
expect(
requestObj
.url()
.includes(`http://myhost.test:${port2}/foo/test/bar/`)
).toBeTruthy();
done();
});
});
});
page.goto(`http://localhost:${port2}/main`);
Expand Down Expand Up @@ -152,13 +157,15 @@ describe('Client complex inline script path with sockPort', () => {
requestObj.url().match(/foo\/test\/bar/)
)
.then((requestObj) => {
browser.close().then(() => {
expect(
requestObj
.url()
.includes(`http://localhost:${port3}/foo/test/bar`)
).toBeTruthy();
done();
page.waitFor(beforeBrowserCloseDelay).then(() => {
browser.close().then(() => {
expect(
requestObj
.url()
.includes(`http://localhost:${port3}/foo/test/bar`)
).toBeTruthy();
done();
});
});
});

Expand Down Expand Up @@ -194,13 +201,15 @@ describe('Client complex inline script path with sockPort, no sockPath', () => {
page
.waitForRequest((requestObj) => requestObj.url().match(/sockjs-node/))
.then((requestObj) => {
browser.close().then(() => {
expect(
requestObj
.url()
.includes(`http://localhost:${port3}/sockjs-node`)
).toBeTruthy();
done();
page.waitFor(beforeBrowserCloseDelay).then(() => {
browser.close().then(() => {
expect(
requestObj
.url()
.includes(`http://localhost:${port3}/sockjs-node`)
).toBeTruthy();
done();
});
});
});
page.goto(`http://localhost:${port2}/main`);
Expand Down Expand Up @@ -232,13 +241,15 @@ describe('Client complex inline script path with sockHost', () => {
page
.waitForRequest((requestObj) => requestObj.url().match(/sockjs-node/))
.then((requestObj) => {
browser.close().then(() => {
expect(
requestObj
.url()
.includes(`http://myhost.test:${port2}/sockjs-node`)
).toBeTruthy();
done();
page.waitFor(beforeBrowserCloseDelay).then(() => {
browser.close().then(() => {
expect(
requestObj
.url()
.includes(`http://myhost.test:${port2}/sockjs-node`)
).toBeTruthy();
done();
});
});
});
page.goto(`http://localhost:${port2}/main`);
Expand Down Expand Up @@ -286,38 +297,47 @@ describe('Client console.log', () => {
},
];

for (const { title, options } of cases) {
it(title, () => {
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
return Promise.resolve()
Promise.resolve()
.then(() => {
return new Promise((resolve) => {
testServer.startAwaitingCompilation(config, testOptions, resolve);
});
})
.then(runBrowser)
.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:${port2}/main`);
page.on('console', ({ _text }) => {
res.push(_text);
});
setTimeout(() => {
browser.close().then(() => {
expect(res).toMatchSnapshot();
resolve();
// wait for load before closing the browser
page.waitForNavigation({ waitUntil: 'load' }).then(() => {
page.waitFor(beforeBrowserCloseDelay).then(() => {
browser.close().then(() => {
resolve();
});
});
}, 1000);
});
});
})
.then(() => {
return new Promise((resolve) => {
testServer.close(resolve);
});
})
.then(() => {
expect(res).toMatchSnapshot();
done();
});
});
}
});
});
29 changes: 19 additions & 10 deletions test/e2e/Iframe.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ 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
Expand Down Expand Up @@ -46,38 +47,46 @@ describe('Client iframe console.log', () => {
},
];

for (const { title, options } of cases) {
it(title, () => {
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
return Promise.resolve()
Promise.resolve()
.then(() => {
return new Promise((resolve) => {
testServer.startAwaitingCompilation(config, testOptions, resolve);
});
})
.then(runBrowser)
.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);
});
setTimeout(() => {
browser.close().then(() => {
expect(res).toMatchSnapshot();
resolve();
page.waitForNavigation({ waitUntil: 'load' }).then(() => {
page.waitFor(beforeBrowserCloseDelay).then(() => {
browser.close().then(() => {
resolve();
});
});
}, 3000);
});
});
})
.then(() => {
return new Promise((resolve) => {
testServer.close(resolve);
});
})
.then(() => {
expect(res).toMatchSnapshot();
done();
});
});
}
});
});
Loading