Whenever we run mocha tests in browser, it displays execution time of a test case only when they run "slow" which is about 50-75 ms. Here is an example screen shot:
How do I get execution time of all test cases?
Here is an example HTML from: https://nicolas.perriault.net/code/2013/testing-frontend-javascript-code-using-mocha-chai-and-sinon/
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title>Cow tests</title>
<link rel="stylesheet" media="all" href="vendor/mocha.css">
</head>
<body>
<div id="mocha"><p><a href=".">Index</a></p></div>
<div id="messages"></div>
<div id="fixtures"></div>
<script src="vendor/mocha.js"></script>
<script src="vendor/chai.js"></script>
<script src="cow.js"></script>
<script>mocha.setup('bdd')</script>
<script src="cow_test.js"></script>
<script>mocha.run();</script>
</body>
</html>
To spit out execution times of all test cases when running in the browser, setup mocha and set the " slow " parameter to 0. This is done through the mocha.setup () API.
<script>mocha.setup({slow: "0"})</script>
Example HTML:
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title>Cow tests</title>
<link rel="stylesheet" media="all" href="vendor/mocha.css">
</head>
<body>
<div id="mocha"><p><a href=".">Index</a></p></div>
<div id="messages"></div>
<div id="fixtures"></div>
<script src="vendor/mocha.js"></script>
<script src="vendor/chai.js"></script>
<script src="cow.js"></script>
<script>mocha.setup('bdd')</script>
<script>mocha.setup({slow: "0"})</script>
<script src="cow_test.js"></script>
<script>mocha.run();</script>
</body>
</html>
Of course, if the execution time is 0ms (Almost 0ms) mocha still does not print.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.