fwa Node.js
在此页面上

fwa

TypeScript 7 fwa 2.1.6

用于 TypeScript 代码的测试运行器。该模块查找测试,将其与对应的源文件核对,并将准确的测试列表直接传给 Node.js。

安装

使用 Node.js 20.19.0 或更高版本。

Shell
npm install --save-dev fwa

第一个测试

将测试保存到 src 目录。

src/example.test.ts
import { strict as assert } from 'node:assert';
import { test } from 'node:test';

test('adds two numbers', () => {
  assert.equal(2 + 3, 5);
});

配置 TypeScript,将 src 中的源文件编译到 dist。

tsconfig.json
{
  "compilerOptions": {
    "target": "ES2022",
    "module": "NodeNext",
    "rootDir": "src",
    "outDir": "dist",
    "strict": true,
    "types": [
      "node"
    ]
  },
  "include": [
    "src/**/*.ts"
  ]
}

在 package.json 中添加模块类型以及构建和测试脚本。

package.json
{
  "type": "module",
  "scripts": {
    "build": "tsc",
    "test": "fwa --prune"
  }
}

构建项目并运行测试。fwa 会为 dist/example.test.js 找到对应的源测试,并将该文件交给 node:test。

Shell
npm run build
npm test

Habr 文章(俄语)——在 tsc 和 node:test 之间查找 dist 中过期的测试。