question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Random failures over Regexp: Invalid regular expression

See original GitHub issue

I get very strange non-deterministic errors when opening my website in Cypress. It complains about a failing Regexp, but the weird thing is that this never causes a problem in a normal browser, and in fact, even within the Cypress browser, if I open a new tab and reload the code, it works perfectly. And I also added on Cypress.on(‘uncaught.exception’) to my code, which does not seem to help.

Here’s my test script:

const uuid = require('cuid');
Cypress.on('uncaught:exception', (err, runnable) => {
  return false;
});

describe('My First Test', function() {
  it('finds the content "type"', function() {
    const id = uuid();
    // cy.wait(30000 * Math.random());
    cy.visit(`https://icchilisrv3.epfl.ch:7000/w948?login=${id}`);

    cy.get('video', { timeout: 90000 });
    cy
      // .wait(10000)
      .then(() => cy.wrap(Cypress.$('video')[0].networkState).should('eq', 2));
    cy.wait(180000);
  });
});

Here you see two tabs of the same browser, consistently showing completely different behaviour (even when reloading etc). What’s very strange is that when I deploy this in 30 different browsers using Kubernetes, I get half of them failing with this error, and the other half working normally! Perhaps this is a timing issue (the reason for the non-determinism) with some interaction between my code and Cypress test code?

screen shot 2018-05-20 at 14 21 31 screen shot 2018-05-20 at 14 21 00

Here you see examples of failing and successful Cypress runs - these are exactly the same code in different Kubernetes containers:

screen shot 2018-05-20 at 14 27 06

(in this case, I don’t get the error exceptions, because of the uncaught.exception setting, but the behaviour is exactly the same as in interactive mode, making me believe that the problem is identical).

Reference to Cypress dashboard run

Issue Analytics

  • State:closed
  • Created 5 years ago
  • Reactions:6
  • Comments:18 (5 by maintainers)

github_iconTop GitHub Comments

9reactions
rufushonourcommented, Jun 15, 2018

@houshuang Not sure if you fixed this issue or not but I’ve managed to get around it by adding "modifyObstructiveCode": false to my cypress.json

I think this might be related to #1396 ?

4reactions
SeanBEcommented, Jul 12, 2019

Ran this example https://github.com/cypress-io/cypress/issues/2112#issuecomment-510899430 with the #4698 build and I still get invalid regular expression.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Why this is an invalid regular expression? - Stack Overflow
1 Answer 1 · I have tried to escape the escape : new RegExp("^\\(?(?:(?:0(?:0|11))?[\s ...etc But this gives the same error · You'd...
Read more >
SyntaxError: invalid regular expression flag "x" - MDN Web Docs
The JavaScript exception "invalid regular expression flag" occurs when the flags in a regular expression contain any flag that is not one of:...
Read more >
JavaScript SyntaxError - Invalid regular expression flag "x"
Cause for Error: Somewhere in the code, There are regular expression flags that are not valid. Example 1: This example has valid RegExp...
Read more >
Why is my regex working intermittently? - DEV Community ‍ ‍
Why is my Regular Expression failing every other time it is called? Nasty weird bugs caused by silly things.
Read more >
JavaScript RegExp Group [0-9] - W3Schools
JavaScript RegExp Group [0-9] · Definition and Usage · Browser Support · Syntax · Syntax with modifiers · Tip · More Examples ·...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found