Can't make both mocha tests and dom events work together

Hello there, wise folk.

So I’m studying Mocha tests and I’ve decided to apply the TDD concept to the credit card checker challenge from JS.

It worked fine and the tests went well. However, after it was ready, I decided to make a simple page so I could make a Luhn checker project and also exercise DOM events.

This was born Luhn Algorithm Checker
repo: GitHub - ribeiroAllison/luhn-algorithm-checker: Program checks if a series of number passes the Luhn Algorithm logic

However, now that I have both Mocha and DOM events in the same project they seem to not work at the same time anymore.

If I put the DOM events in a different JS file than the main one the page stops working and I get the “require is not defined” error at the console browser

If I put the DOM handlers in the main JS file the page works but Mocha tests stop working as I get the “document is not defined” error from Node console.

And finally, if I don’t use require and switch to ES6 import/export syntax Mocha also fails to work and I get a module error

Is there any way around this?

Or these two concepts just don’t work together at all?

Thank you very much an sorry for the long post.

Cheers,
Allison