Skip to content

Commit 8b577db

Browse files
committed
fix: pass regex flags too
1 parent a6f4ab9 commit 8b577db

File tree

2 files changed

+5
-3
lines changed

2 files changed

+5
-3
lines changed

lib/index.ts

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ const domLibraryAsString = readFileSync(
1212
/* istanbul ignore next */
1313
function mapArgument(argument: any, index: number): any {
1414
return index === 0 && typeof argument === 'object' && argument.regex
15-
? new RegExp(argument.regex)
15+
? new RegExp(argument.regex, argument.flags)
1616
: argument
1717
}
1818

@@ -84,14 +84,16 @@ function createDelegateFor<T = DOMReturnType>(
8484
// @ts-ignore
8585
processHandleFn = processHandleFn || processQuery
8686

87+
const convertRegExp = (regex: RegExp) => ({regex: regex.source, flags: regex.flags})
88+
8789
return async function(...args: any[]): Promise<T> {
8890
// @ts-ignore
8991
const containerHandle: ElementHandle = contextFn ? contextFn.apply(this, args) : this
9092
// @ts-ignore
9193
const evaluateFn: EvaluateFn = {toString: () => delegateFnToExecuteInPage}
9294

9395
// Convert RegExp to a special format since they don't serialize well
94-
let argsToForward = args.map(arg => (arg instanceof RegExp ? {regex: arg.source} : arg))
96+
let argsToForward = args.map(arg => (arg instanceof RegExp ? convertRegExp(arg) : arg))
9597
// Remove the container from the argsToForward since it's always the first argument
9698
if (containerHandle === args[0]) {
9799
argsToForward = args.slice(1)

test/extend.test.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ describe('lib/extend.ts', () => {
2626
})
2727

2828
it('should handle regex matching', async () => {
29-
const element = await document.queryByText(/Hello/)
29+
const element = await document.queryByText(/HeLlO/i)
3030
expect(element).toBeTruthy()
3131
/* istanbul ignore next */
3232
expect(await page.evaluate(el => el.textContent, element)).toEqual('Hello h1')

0 commit comments

Comments
 (0)