Simple-Test-of-Fate Node.js测试套件的快速指南

Simple-Test-of-Fate 是一个针对 Node.js 的简单测试套件,可方便地进行自动化测试。

安装

执行以下命令安装:

$ npm install --save-dev simple-test-of-fate

用法

package.json 文件中设置测试脚本:

// package.json
"scripts": {
  "test": "node ./test/index.js"
}

创建测试文件 test/index.js,并使用 Simple-Test-of-Fate 的 API:

// test/index.js
const stof = require('simple-test-of-fate');
stof.run({
  dir: '{DIR}', // 默认是 ./tests
  files: '{FILES}' // 默认是 *.js,支持 shell 格式(类似 find 命令)
});

示例

使用 assert 方法创建测试示例。

// test/sampleTest.js
const assert = require('assert');
// 测试内容
assert.strictEqual(1 + 1, 2);

配置完毕后,运行命令 npm test 即可启动测试。

zip 文件大小:2.3KB