justo.reporter.console
是一个优秀的 npm 包,用于在控制台上显示测试结果的报告。本文将介绍如何使用 justo.reporter.console
包,让你轻轻松松地完成测试结果的显示。
安装 justo.reporter.console
在使用 justo.reporter.console
之前,我们需要先安装它。可以通过以下命令进行安装:
npm install justo.reporter.console
安装成功后,我们需要在测试文件中引入它:
const consoleReporter = require("justo.reporter.console");
使用 justo.reporter.console
在引入 justo.reporter.console
之后,我们可以选择在 justo
测试运行器中使用它。示例如下:
-- -------------------- ---- ------- ----- ----- - ----------------- ----- --------------- - ---------------------------------- ----------- ------ ------- --------- ---------------- ------ - ----- --------- - --------------------- -- ----- --------- - --------------------- - - ---展开代码
在使用 justo
运行测试时,将会在控制台上显示如下的测试报告:
测试标题 ✖ test1 ✔ test2
使用参数设置自定义格式
在使用 justo.reporter.console
运行测试之前,还可以通过设置参数来自定义测试报告的格式。可用的参数如下:
nameLength
:设置任务名称的长度。默认为 20。resultChar
:设置通过测试的符号。默认为✔
。errorChar
:设置未通过测试的符号。默认为✖
。skipChar
:设置跳过测试的符号。默认为⸘
。
示例如下:
-- -------------------- ---- ------- ----- ----- - ----------------- ----- --------------- - ---------------------------------- ----- --- - - ------ ------- ------ - ----- --------- - --------------------- -- ----- --------- - ----- --- ------------------ -- ----- --------- - --------------------- -- ----- --------- - ------ -------------------- - - -- ----------- ------ ---------- --------- ---------------- ---------- - ----------- --- ------------- ----------- ---- --------- ---------- ---- --------- --------- --- --------- -- ------ --------- ---展开代码
在添加了自定义参数后,将会在控制台上显示如下的测试报告:
测试标题 ✖ test2 - + test1 + ? test4 ⸘ ✔ test3 +
通过上面的示例,你已经可以轻易使用 justo.reporter.console
包来完成测试报告的输出了。在实际项目中,合理利用这个工具可以更方便地进行代码测试,确保代码的质量和准确性。
来源:JavaScript中文网 ,转载请注明来源 https://www.javascriptcn.com/post/5f193b59403f2923b035c456