tsest
v0.0.8
Published
Extremely simple bootstarp of node:test, for TypeScript Project.
Downloads
12
Readme
tsest
中文 |
tsest is a Bootstarp Script of node:test
, support typescript
, None dependencies;
Write testcase in official syntax, ref:
- Node Test : https://nodejs.org/api/test.html
- Node Assert : https://nodejs.org/api/assert.html
Ussage
- Install
# For ts usage, must install typescript ts-node in your project.
npm install --save-dev typescript ts-node tsest
- Edit package.json
{
"test": "node -r ts-node/register node_modules/tsest/run",
"watch":"node -r ts-node/register node_modules/tsest/run --watch",
}
OR ESM:
{
"test": "node --loader ts-node/esm node_modules/tsest/run",
"watch": "node --loader ts-node/esm node_modules/tsest/run --watch"
}
- Write Test code with suffix :
.test.ts
, eg.sum.test.ts
import { test } from 'node:test';
import assert from 'node:assert';
import { sum } from './mylib';
test('test case',()=>{
assert.strictEqual(sum(1,2), 3);
});
- Done
Run Command Interface
# Test Code
npm run test
# Test Code Watch Mode
npm run watch
Custom Ussage
Use node_modules/tsest/run
, can start test without any code. But args is default:
| param | type | default |
| ------ | ----------------------------- | ---------------------------- |
| root | string | ./src
if exists, nor: ./
|
| suffix | string | '.test.ts' |
| filter | (filePath: string) => boolean | ()=>true |
you can change it by custom code:
- create script.ts
import { start } from 'jstest/start';
import { watch } from 'jstest/watch';
// test '*.spec.test.ts' code in './lib', 'only test file ends with StringUtil.spec.test.ts'
const options = {
root: './lib',
suffix: '.spec.test.ts',
filter:(fileName:string)=>fileName.endsWith('StringUtil.spec.test.ts')
}
const cmd = process.argv[process.argv.length - 1];
if (cmd == '--watch' || cmd == '-w') {
watch(options)
} else {
start(options)
}
- modify
package.json
,changenode_modules/tsest/run
toscript.ts
.
"scripts": {
"test": "node -r ts-node/register script.ts",
"watch": "node -r ts-node/register script.ts -w"
},