Running Mocha Tests in a Browser

Hiii, I wrote mocha tests for nodejs that run well in the terminal, I need to run the tests and display the results in the browser, I did it as suggested by Mocha's documentaion . I created a test runner file and included the template structure and included my test files. I set up the route correctly in nodejs and now when I call the url in Postman. I just got the same html file as the answer, can someone help me run the tests in the browser.

Here is my test runner file:

<html>
<head>
    <meta charset="utf-8">
    <title>Mocha Tests</title>
    <link href="https://cdn.rawgit.com/mochajs/mocha/2.2.5/mocha.css" rel="stylesheet" />
</head>
<body>
    <div id="mocha"></div>
    <script src="https://cdn.rawgit.com/jquery/jquery/2.1.4/dist/jquery.min.js"></script>
    <script src="https://cdn.rawgit.com/Automattic/expect.js/0.3.1/index.js"></script>
    <script src="https://cdn.rawgit.com/mochajs/mocha/2.2.5/mocha.js">         </script>
    <script>mocha.setup('bdd')</script>
    <script src="../test/notification_nodetest.js"></script>
    <script src="../test/performance_check.js"></script>
    <script>
    mocha.checkLeaks();
    mocha.globals(['jQuery']);
    mocha.run();
    </script>
</body>
</html>

here i am setting the url:

app.get('/notifications/test', notificator.test_results);

test_results: function(req, res) {
  app.get('/index.htm', function (req, res) {
  var path = require('path');
  res.sendFile( path.resolve("test/index.html") );
               })    
+4
source share

Source: https://habr.com/ru/post/1659689/


All Articles