Skip to content

Commit

Permalink
Add full parameters for emulateNetworkConditions
Browse files Browse the repository at this point in the history
  • Loading branch information
tellthemachines committed Jul 23, 2020
1 parent bf74f23 commit 02e53bb
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 7 deletions.
12 changes: 10 additions & 2 deletions docs/contributors/testing-overview.md
Original file line number Diff line number Diff line change
Expand Up @@ -432,10 +432,18 @@ THROTTLE_CPU=4 npm run test-e2e
Related: https://chromedevtools.github.io/devtools-protocol/tot/Emulation#method-setCPUThrottlingRate

```
DOWNLOAD_THROUGHPUT=125000 npm run test-e2e
SLOW_NETWORK=true npm run test-e2e
```

`DOWNLOAD_THROUGHPUT` is a numeric value representing bytes-per-second network download (in this example, a 1Mbps download speed).
`SLOW_NETWORK` emulates a network speed equivalent to "Fast 3G" in the Chrome devtools.

Related: https://chromedevtools.github.io/devtools-protocol/tot/Network#method-emulateNetworkConditions and https://github.com/ChromeDevTools/devtools-frontend/blob/80c102878fd97a7a696572054007d40560dcdd21/front_end/sdk/NetworkManager.js#L252-L274

```
OFFLINE=true npm run test-e2e
```

`OFFLINE` emulates network disconnection.

Related: https://chromedevtools.github.io/devtools-protocol/tot/Network#method-emulateNetworkConditions

Expand Down
23 changes: 18 additions & 5 deletions packages/e2e-tests/config/setup-test-framework.js
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,14 @@ const THROTTLE_CPU = process.env.THROTTLE_CPU;
*
* @type {string|undefined}
*/
const DOWNLOAD_THROUGHPUT = process.env.DOWNLOAD_THROUGHPUT;
const SLOW_NETWORK = process.env.SLOW_NETWORK;

/**
* Emulate no internet connection.
*
* @type {string|undefined}
*/
const OFFLINE = process.env.OFFLINE;

/**
* Set of console logging types observed to protect against unexpected yet
Expand Down Expand Up @@ -213,17 +220,23 @@ async function runAxeTestsForBlockEditor() {
* Simulate slow network or throttled CPU if provided via environment variables.
*/
async function simulateAdverseConditions() {
if ( ! DOWNLOAD_THROUGHPUT && ! THROTTLE_CPU ) {
if ( ! SLOW_NETWORK && ! OFFLINE && ! THROTTLE_CPU ) {
return;
}

const client = await page.target().createCDPSession();

if ( DOWNLOAD_THROUGHPUT ) {
if ( SLOW_NETWORK || OFFLINE ) {
// See: https://chromedevtools.github.io/devtools-protocol/tot/Network#method-emulateNetworkConditions
await client.send( 'Network.emulateNetworkConditions', {
// Simulated download speed (bytes/s)
downloadThroughput: Number( DOWNLOAD_THROUGHPUT ),
// Network connectivity is absent
offline: Boolean( OFFLINE || false ),
// Download speed (bytes/s)
downloadThroughput: ( ( 1.6 * 1024 * 1024 ) / 8 ) * 0.9,
// Upload speed (bytes/s)
uploadThroughput: ( ( 750 * 1024 ) / 8 ) * 0.9,
// Latency (ms)
latency: 150 * 3.75,
} );
}

Expand Down

0 comments on commit 02e53bb

Please sign in to comment.