1
I’m developing a client-side Javascript application, and I want to run some tests using Mochajs, only that the test depends on several Javascript files to run, which are in different folders, for example:
Files needed to run the test:
js/a.js js/b.js vendor/js/c.js
Test file:
test/test.js
My question would be: what is the simplest way to include these dependencies in the test file.
I found a way to do this using "require" only it would lead to modifying the code to run with nodejs using things like "module.Exports" and in my case the code would run in the browser.
Another way I found was the "Requirejs" only in this case it would be necessary to include the script in an HTML file, and this would not be very useful.
How do files export global variables? It is possible to encapsulate the files to work in Node and Browser environment, provided that the variables are exported in a certain and global way as
document
andwindow
are called in a controlled manner.– Sergio
The way I did not have global variables, I have only Javascript files with the functions, and one file uses the functions of another, so they are being called in a specific order in the HTML file for the execution of the project, only that in the test I do not know how to reference this dependency that the test has to other Javascript files, would have a way to do this without modifying the Javascript files?
– André N. Darcie
André, did you manage this? At Mootools we have a system with Phantomjs that would help you here. If you have not solved, give a touch.
– Sergio