mochajs / mocha

☕️ simple, flexible, fun javascript test framework for node.js & the browser
https://mochajs.org
MIT License
22.52k stars 3k forks source link

🐛 Bug: test links in the browser reporter keep the original fgrep and invert params #5102

Open danny0838 opened 5 months ago

danny0838 commented 5 months ago

Bug Report Checklist

Expected

A link of the browser reporter should remove fgrep and invert parameters in the original URL.

Actual

A link of the browser reporter keeps the original fgrep and invert parameters in the original URL.

Minimal, Reproducible Example

  1. Create a test page like:
<!DOCTYPE html>
<meta charset="UTF-8">
<link rel="stylesheet" href="mocha.css">
<div id="mocha"></div>
<script src="mocha.js"></script>
<script>
mocha.setup('bdd');

describe('tests', function () {
  it('test1', function () {});
  it('test2', function () {});
});

mocha.run();
</script>
  1. Open the page in the browser.

  2. Append ?fgrep=tests in the address and visit it.

  3. Wait for the test to complete, and click the replay link of test1.

Versions

mocha@10.3.0 in javascript ES2018

Additional Info

No response

danny0838 commented 5 months ago

This issue should be able to be fixed by replacing this line:

search = search.replace(/[?&]grep=[^&\s]*/g, '').replace(/^&/, '?');

with:

search = search.replace(/[?&](?:f?grep|invert)=[^&\s]*/g, '').replace(/^&/, '?');