-
Notifications
You must be signed in to change notification settings - Fork 4.2k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Tests: Refactor pressKeyTimes to use for loop for simplicity
- Loading branch information
Showing
4 changed files
with
5 additions
and
27 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,31 +1,11 @@ | ||
/** | ||
* External dependencies | ||
*/ | ||
import { times } from 'lodash'; | ||
|
||
/** | ||
* Given an array of functions, each returning a promise, performs all | ||
* promises in sequence (waterfall) order. | ||
* | ||
* @param {Function[]} sequence Array of promise creators. | ||
* | ||
* @return {Promise} Promise resolving once all in the sequence complete. | ||
*/ | ||
async function promiseSequence( sequence ) { | ||
return sequence.reduce( | ||
( current, next ) => current.then( next ), | ||
Promise.resolve() | ||
); | ||
} | ||
|
||
/** | ||
* Presses the given keyboard key a number of times in sequence. | ||
* | ||
* @param {string} key Key to press. | ||
* @param {number} count Number of times to press. | ||
* | ||
* @return {Promise} Promise resolving when key presses complete. | ||
*/ | ||
export async function pressKeyTimes( key, count ) { | ||
return promiseSequence( times( count, () => () => page.keyboard.press( key ) ) ); | ||
for ( let i = 0; i < count; i++ ) { | ||
await page.keyboard.press( key ); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters