Skip to content

ada87/tsest

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

10 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

tsest

中文 | npm version

tsest is a Bootstarp Script of node:test, support typescript, None dependencies;

Write testcase in official syntax, ref:

  1. Node Test : https://nodejs.org/api/test.html
  2. Node Assert : https://nodejs.org/api/assert.html

Ussage

  1. Install
# For ts usage, must install typescript ts-node in your project.
npm install --save-dev typescript ts-node tsest
  1. 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"
}
  1. 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);
});
  1. 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:

  1. 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)
}
  1. modify package.json,change node_modules/tsest/run to script.ts.
"scripts": {
    "test": "node -r ts-node/register script.ts",
    "watch": "node -r ts-node/register script.ts -w"
},

About

Prue `node:test`, No dependencies, For TypeScript project, Extremely simple.

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published