简体   繁体   English

如何在HTML中配置mocha来打印每个测试的执行时间?

[英]How to configure mocha in HTML to print execution time of each test?

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. 每当我们在浏览器中运行Mocha测试时,它仅在测试用例运行“慢速”(大约50-75毫秒)时显示测试用例的执行时间。 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/ 以下是HTML的示例: 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. 要在浏览器中运行时吐出所有测试用例的执行时间,请设置mocha并将“ slow ”参数设置为0。这是通过mocha.setup()API完成的。

<script>mocha.setup({slow: "0"})</script>

Example HTML: 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>

Sample Output: 样本输出: 在此处输入图片说明

Of course, if the execution time is 0ms (Almost 0ms) mocha still does not print. 当然,如果执行时间为0毫秒(几乎为0毫秒),则仍然不会打印Mocha。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM