Unit testing for JavaScript in the context of a web application

I’ve done some research about this topic, and I think I know what to do. However, as per my understanding this requires confusing or complex configuration.

Objective:

Ability to perform unit testing for JavaScript code that is used within the context of a web application.

The JavaScript functions are deployed in script file and linked to the HTML page using traditional methods.

We need to used a simple Unit Testing Framework similar to Jest and avoid the need to get into Brower Control such as using Selenium WebDriver and the like.

The problem is Jest works with NodeJS and not sure how to make this work with front-end web application.

High-Level Approach:

Based on my research, it seems I have to keep the script used for the web application in a separate configuration of the test project. See example below:

//Main JavaScript used by HTML: sciprt.js
function addTwoNumbers(a, b) {
  return a+b;
}
...
...
other functions
...
...
<!DOCTYPE html>
<html>
<body>

<h1>The script src attribute</h1>

<script src="script.js">
</script>

</body>
...
...
</html>

Now let’s say we need to used Jest to write test scripts, then we have to setup a NodeJS project which means we have to copy the script file script.js to the test project, and convert it to use JavaScript Modules.

I am trying to avoid this confusing setup, and looking for a method to write test scripts to use the same deployed parts of the web application without the need to mess around with files.

Another problem I will face is how to deal with functions that references HTML components? Those will not be available to NodeJS, correct? I believe this can be done by refactoring the code to become modular so that the functions to be tested will not reference web elements.

I appreciate your help to setup a test project and use the deployed script and avoid the need to do complex or confusing setup.