feat: worker convenience methods (#2677)

This patch:
- adds `worker.evaluate` and `worker.evaluateHandle` methods as a shortcut to their execution context equivalents.
- makes the error messages a bit nicer when interacting with a closed worker (as opposed to a closed page).
- moves the worker tests into their own spec file.
This commit is contained in:
Joel Einbinder
2018-06-06 18:16:17 -07:00
committed by Andrey Lushnikov
parent 3e82a54fd1
commit 2ff0adcad8
8 changed files with 100 additions and 41 deletions

View File

@@ -53,6 +53,24 @@ class Worker extends EventEmitter {
async executionContext() {
return this._executionContextPromise;
}
/**
* @param {function()|string} pageFunction
* @param {!Array<*>} args
* @return {!Promise<*>}
*/
async evaluate(pageFunction, ...args) {
return (await this._executionContextPromise).evaluate(pageFunction, ...args);
}
/**
* @param {function()|string} pageFunction
* @param {!Array<*>} args
* @return {!Promise<!JSHandle>}
*/
async evaluateHandle(pageFunction, ...args) {
return (await this._executionContextPromise).evaluateHandle(pageFunction, ...args);
}
}
module.exports = Worker;