Skip to content

Commit 70ed565

Browse files
committed
fix: support puppeteer 1.6.x
1 parent 8b577db commit 70ed565

File tree

4 files changed

+13
-12
lines changed

4 files changed

+13
-12
lines changed

lib/index.ts

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -16,13 +16,11 @@ function mapArgument(argument: any, index: number): any {
1616
: argument
1717
}
1818

19-
const delegateFnToExecuteInPage = `
20-
function evaluateInPage(container, fnName, ...args) {
21-
${domLibraryAsString}
19+
const delegateFnBodyToExecuteInPage = `
20+
${domLibraryAsString};
2221
23-
const mappedArgs = args.map(${mapArgument.toString()})
24-
return __dom_testing_library__[fnName](container, ...mappedArgs)
25-
}
22+
const mappedArgs = args.map(${mapArgument.toString()});
23+
return __dom_testing_library__[fnName](container, ...mappedArgs);
2624
`
2725

2826
type DOMReturnType = ElementHandle | ElementHandle[] | null
@@ -90,7 +88,10 @@ function createDelegateFor<T = DOMReturnType>(
9088
// @ts-ignore
9189
const containerHandle: ElementHandle = contextFn ? contextFn.apply(this, args) : this
9290
// @ts-ignore
93-
const evaluateFn: EvaluateFn = {toString: () => delegateFnToExecuteInPage}
91+
const evaluateFn: EvaluateFn = new Function(
92+
'container, fnName, ...args',
93+
delegateFnBodyToExecuteInPage,
94+
)
9495

9596
// Convert RegExp to a special format since they don't serialize well
9697
let argsToForward = args.map(arg => (arg instanceof RegExp ? convertRegExp(arg) : arg))

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@
5151
"@types/puppeteer": "^1.3.4",
5252
"generate-export-aliases": "^1.1.0",
5353
"jest": "^23.1.0",
54-
"puppeteer": "^1.5.0",
54+
"puppeteer": "^1.6.0",
5555
"rollup": "^0.61.1",
5656
"rollup-plugin-commonjs": "^9.1.3",
5757
"rollup-plugin-node-resolve": "^3.3.0",

test/__snapshots__/extend.test.ts.snap

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ exports[`lib/extend.ts should handle the get* method failures 1`] = `
2020
at getAllByTitle <stack>:X:X)
2121
at firstResultOrNull <stack>:X:X)
2222
at Object.getByTitle <stack>:X:X)
23-
at evaluateInPage <stack>:X:X)"
23+
at anonymous <stack>:X:X)"
2424
`;
2525
2626
exports[`lib/extend.ts should handle the get* methods 1`] = `"<input type=\\"text\\" data-testid=\\"testid-text-input\\">"`;

yarn.lock

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3781,9 +3781,9 @@ punycode@^2.1.0:
37813781
version "2.1.1"
37823782
resolved "https://registry.yarnpkg.com/punycode/-/punycode-2.1.1.tgz#b58b010ac40c22c5657616c8d2c2c02c7bf479ec"
37833783

3784-
puppeteer@^1.5.0:
3785-
version "1.5.0"
3786-
resolved "https://registry.yarnpkg.com/puppeteer/-/puppeteer-1.5.0.tgz#e35db3f3ba3d41013feb65be02bdaa727ec7b8ec"
3784+
puppeteer@^1.6.0:
3785+
version "1.6.0"
3786+
resolved "https://registry.yarnpkg.com/puppeteer/-/puppeteer-1.6.0.tgz#b6b6bd6a063a0b7591258613ec89a135f2cf8f2e"
37873787
dependencies:
37883788
debug "^3.1.0"
37893789
extract-zip "^1.6.6"

0 commit comments

Comments
 (0)