cypress: Random failures over Regexp: Invalid regular expression
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?


Here you see examples of failing and successful Cypress runs - these are exactly the same code in different Kubernetes containers:
(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
About this issue
- Original URL
- State: closed
- Created 6 years ago
- Reactions: 6
- Comments: 18 (7 by maintainers)
@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.jsonI think this might be related to #1396 ?
Ran this example https://github.com/cypress-io/cypress/issues/2112#issuecomment-510899430 with the #4698 build and I still get invalid regular expression.
Just ran into this issue.
"modifyObstructiveCode": false"
fixes the issue. I encourage the cypress team to treat this issue as more of a priority, as it appears to be breaking core Angular code.I have to correct myself. It did fix our issue.
Best Regards
@SeanBE This doesn’t seem like an encoding issue, rather, a browser compatibility error. When I add that RegEx, the app no longer works in Firefox:
It’s because you’re using negative lookbehind in the RegEx:
cypress open
with Chrome 75cypress run
.Read more about the development of this feature.
Try using
cypress run
with--browser=chrome
, you’ll find that it does work now because you’re using the Chrome bundled with your system.We’re working on upgrading the Chrome/Electron version bundled with Cypress: #3568 For now, you’ll need to run tests in Chrome to support negative lookbehind, or use some other method of pattern-matching to support your needs.
I am still looking for a way to reproduce the issue in the OP, which is a character encoding corruption causing an invalid RegEx.
FakeNews… still getting garbage regex error
I can confirm, adding
"modifyObstructiveCode": false
to your config fixes the issue.