Comparing version 7.1.1 to 7.2.0
@@ -0,0 +0,0 @@ import {current} from './tst.js' |
{ | ||
"name": "tst", | ||
"description": "Tests without efforts", | ||
"version": "7.1.1", | ||
"version": "7.2.0", | ||
"repository": "dy/tst", | ||
@@ -6,0 +6,0 @@ "author": "Dmitry Iv.", |
@@ -5,18 +5,17 @@ # tst | ||
## Gems | ||
* tape API | ||
* no tooling, vanilla ESM | ||
* works with any [assert](https://www.npmjs.com/package/assert), [chai](https://www.npmjs.com/package/chai) etc. | ||
* async functions support | ||
* inspectable errors | ||
* correct stacktrace with sourcemaps | ||
* nice look & feel in browser/node | ||
* good l&f in browser/node | ||
* supports [assert](https://www.npmjs.com/package/assert), [chai](https://www.npmjs.com/package/chai) etc. | ||
* tiny bundle, 0dep | ||
## Usage | ||
## usage | ||
```js | ||
import test, {ok,is,not,throws} from 'tst.js' | ||
import test, { ok, is, not, throws } from 'tst.js' | ||
test('these tests will all pass', () => { | ||
test('pass', () => { | ||
ok(true); | ||
@@ -35,14 +34,6 @@ ok(true, 'this time with an optional message'); | ||
test('these tests will not pass', () => { | ||
test('fail', () => { | ||
is(42, '42'); | ||
is({}, {x:1}); | ||
}) | ||
test.skip('this test will not run', () => { | ||
}) | ||
test.browser('browser-only test', () => { | ||
}) | ||
``` | ||
@@ -54,3 +45,3 @@ | ||
## test types | ||
## api | ||
@@ -60,11 +51,9 @@ * `test.skip` โ bypass test, mutes output | ||
* `test.todo` โ bypass test, indicate WIP sign | ||
* `test.node` โ run test in node/deno only env. | ||
* `test.browser` โ run test in browser only test. | ||
<!-- * `test.demo` โ demo run, ignores doesn't count. --> | ||
* `test.demo` โ demo run, skips failed assertions. | ||
## assertions | ||
## assert | ||
* `ok(a, msg?)` โ generic truthfulness assert | ||
* `is(a, b, msg?)` โ assert with `equal` for primitives and `deepEqual` for objects | ||
* `not(a, b, msg?)` - assert with `equal` for primitives and `deepEqual` for objects | ||
* `is(a, b, msg?)` โ assert with `Object.is` for primitives and `deepEqual` for objects | ||
* `not(a, b, msg?)` - assert with `!Object.is` for primitives and `!deepEqual` for objects | ||
* `any(a, [a, b, c], msg?)` โ assert with optional results | ||
@@ -76,4 +65,10 @@ * `almost(a, b, eps, msg?)` โ assert approximate value/array | ||
### Neighbors | ||
## why? | ||
Testing should not involve maintaining test runner.<br/> | ||
It should be simple as [tap/tape](https://ghub.io/tape), working in browser/node, ESM, with nice l&f, done in a straightforward way.<br/> | ||
I wasn't able to find such test runner that so I had to create one. | ||
### similar | ||
* [uvu](https://github.com/lukeed/uvu) | ||
@@ -84,2 +79,2 @@ * [tape-modern](https://ghub.io/tape-modern) | ||
<p align="center">๐๏ธ</p> | ||
<p align="center"><a href="https://github.com/krishnized/license">๐๏ธ</a></p> |
28
tst.js
@@ -5,12 +5,12 @@ const GREEN = '\u001b[32m', RED = '\u001b[31m', YELLOW = '\u001b[33m', RESET = '\u001b[0m', CYAN = '\u001b[36m', GRAY = '\u001b[30m' | ||
let assertIndex = 0, | ||
index = 1, | ||
passed = 0, | ||
failed = 0, | ||
skipped = 0, | ||
only = 0, | ||
current = null, | ||
start, | ||
queue = new Promise(resolve => start = resolve) | ||
index = 1, | ||
passed = 0, | ||
failed = 0, | ||
skipped = 0, | ||
only = 0, | ||
current = null, | ||
start, | ||
queue = new Promise(resolve => start = resolve) | ||
export {current} | ||
export { current } | ||
@@ -35,8 +35,2 @@ | ||
} | ||
test.node = function (name, run) { | ||
return createTest({ name, run, skip: !isNode, tag: 'node' }) | ||
} | ||
test.browser = function (name, run) { | ||
return createTest({ name, run, skip: isNode, tag: 'browser' }) | ||
} | ||
@@ -69,3 +63,3 @@ function createTest(test) { | ||
let {operator: op, message: msg} = arg; | ||
let { operator: op, message: msg } = arg; | ||
@@ -91,3 +85,3 @@ assertIndex++ | ||
let {operator: op, message: msg, ...info} = arg; | ||
let { operator: op, message: msg, ...info } = arg; | ||
@@ -94,0 +88,0 @@ isNode ? ( |
Sorry, the diff of this file is not supported yet
13212
280
75