From c5d17e2c57145cb5768416d09bb9aa4441ba582c Mon Sep 17 00:00:00 2001 From: artem-babich Date: Fri, 23 Sep 2022 15:40:34 +0400 Subject: [PATCH] fix: SkipJsErrors RegExp parsed incorrectly when enclosed in quotes(closes #7301) --- src/utils/make-reg-exp.js | 2 +- test/functional/fixtures/page-js-errors/test.js | 4 ++++ .../testcafe-fixtures/test-controller.js | 17 +++++++++++++++-- 3 files changed, 20 insertions(+), 3 deletions(-) diff --git a/src/utils/make-reg-exp.js b/src/utils/make-reg-exp.js index f2cc49c70f1..ef7595f6589 100644 --- a/src/utils/make-reg-exp.js +++ b/src/utils/make-reg-exp.js @@ -9,7 +9,7 @@ export function parseRegExpString (regExp) { const parsedRegExpWithFlags = regExp.match(SPLIT_INPUT_AND_FLAGS_REG_EXP); if (parsedRegExpWithFlags) - return makeRegExp(parsedRegExpWithFlags[1], parsedRegExpWithFlags[2]); + return RegExp(parsedRegExpWithFlags[1], parsedRegExpWithFlags[2]); return makeRegExp(regExp); } diff --git a/test/functional/fixtures/page-js-errors/test.js b/test/functional/fixtures/page-js-errors/test.js index 597f2625519..e4a8c1265e4 100644 --- a/test/functional/fixtures/page-js-errors/test.js +++ b/test/functional/fixtures/page-js-errors/test.js @@ -102,6 +102,10 @@ const expectFailAttempt = (errors, expectedMessage) => { return runTests('./testcafe-fixtures/test-controller.js', 'Should skip JS errors with SkipJsErrorsCallbackOptions'); }); + it('Should skip JS errors with SkipJsErrorsCallbackOptions containing RegExp enclosed in quotes', async () => { + return runTests('./testcafe-fixtures/test-controller.js', 'Should skip JS errors with SkipJsErrorsCallbackOptions containing RegExp enclosed in quotes'); + }); + it('Should skip JS errors with callback function returning Promise', async () => { return runTests('./testcafe-fixtures/test-controller.js', 'Should skip JS errors with callback function returning Promise', { skip: ['ie'] }); }); diff --git a/test/functional/fixtures/page-js-errors/testcafe-fixtures/test-controller.js b/test/functional/fixtures/page-js-errors/testcafe-fixtures/test-controller.js index 5c6bc7eff97..bb92c1e48a1 100644 --- a/test/functional/fixtures/page-js-errors/testcafe-fixtures/test-controller.js +++ b/test/functional/fixtures/page-js-errors/testcafe-fixtures/test-controller.js @@ -1,4 +1,10 @@ -const { CLIENT_ERROR_MESSAGE, CLIENT_PAGE_URL, CLIENT_PAGE_URL_REGEXP, SKIP_JS_ERRORS_CALLBACK_OPTIONS } = require('../constants'); +const { + CLIENT_ERROR_MESSAGE, + CLIENT_PAGE_URL, + CLIENT_PAGE_URL_REGEXP, + SKIP_JS_ERRORS_CALLBACK_OPTIONS, + CLIENT_ERROR_REGEXP, +} = require('../constants'); fixture`TestController method` .page('http://localhost:3000/fixtures/page-js-errors/pages/skip-js-errors.html'); @@ -22,7 +28,7 @@ test('Should skip JS errors with SkipJsErrorsCallbackOptions', async t => { }); test('Should skip JS errors with callback function returning Promise', async t => { - const asyncFunc = () => + const asyncFunc = () => new Promise(resolve => setTimeout(() => resolve(true), 3000)); await t.skipJsErrors(asyncFunc) @@ -33,6 +39,13 @@ test('Should skip JS errors without param', async t => { await t.skipJsErrors(); }); +test('Should skip JS errors with SkipJsErrorsCallbackOptions containing RegExp enclosed in quotes', async t => { + await t.skipJsErrors({ + message: `${ CLIENT_ERROR_REGEXP }`, + }) + .click('button'); +}); + test('Should correctly skip JS errors with multiple method calls', async t => { await t.skipJsErrors(true) .click('button')