New Case Study:See how Anthropic automated 95% of dependency reviews with Socket.Learn More โ†’
Socket
Sign inDemoInstall
Socket

tst

Package Overview
Dependencies
Maintainers
0
Versions
73
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

tst - npm Package Compare versions

Comparing version 7.3.0 to 8.0.0

14

assert.js

@@ -60,16 +60,2 @@ import { current } from './tst.js'

export function almost(a, b, eps = 1.19209290e-7, msg = 'should almost equal') {
if (
isPrimitive(a) || isPrimitive(b) ? almostEqual(a, b, eps) :
[...a].every((a0, i) => a0 === b[i] || almostEqual(a0, b[i], eps))
) return current?.pass({ operator: 'almost', message: msg })
throw new Assertion({
operator: 'almost',
message: msg,
actual: slice(a),
expect: slice(b)
})
}
export function throws(fn, expect, msg = 'should throw') {

@@ -76,0 +62,0 @@ try {

8

package.json
{
"name": "tst",
"description": "Tests without efforts",
"version": "7.3.0",
"version": "8.0.0",
"repository": "dy/tst",

@@ -16,8 +16,4 @@ "author": "Dmitry Iv.",

"scripts": {
"test": "node test.js",
"start": "es-dev-server --node-resolve --dedupe"
},
"devDependencies": {
"es-dev-server": "^1.32.0"
"test": "node test.js"
}
}

@@ -5,10 +5,11 @@ # tst

* tape API
* no tooling, vanilla ESM
* works both node/browser
* async functions support
* inspectable errors
* correct stacktrace with sourcemaps
* good l&f in browser/node
* stacktrace with sourcemaps
* clean l&f in browser/node
* supports [assert](https://www.npmjs.com/package/assert), [chai](https://www.npmjs.com/package/chai) etc.
* tiny bundle, 0dep
* minimal, 0dep
* tape API

@@ -20,3 +21,3 @@ ## usage

test('pass', () => {
test('tst demo test', () => {
ok(true);

@@ -34,19 +35,11 @@ ok(true, 'this time with an optional message');

})
test('fail', () => {
is(42, '42');
is({}, {x:1});
})
```
Creates output in console:
![preview](./preview.png)
## api
* `test.skip` โˆ’ bypass test, mutes output
* `test.only` โˆ’ run only the indicated test, can be multiple
* `test.todo` โˆ’ bypass test, indicate WIP sign
* `test.demo` โˆ’ demo run, skips failed assertions.
* `test.only` โˆ’ run only selected test(s)
* `test.mute` โˆ’ run test(s), mute assertions
* `test.skip` โˆ’ bypass test(s)
* `test.todo` โˆ’ bypass test(s), mark as WIP
* `test.demo` โˆ’ demo run, skip failed assertions.

@@ -59,3 +52,2 @@ ## assert

* `any(a, [a, b, c], msg?)` โˆ’ assert with optional results
* `almost(a, b, eps, msg?)` โˆ’ assert approximate value/array
* `same(listA, listB, msg?)` โˆ’ assert same members of a list/set/map/object

@@ -71,9 +63,13 @@ * `throws(fn, msg?)` โˆ’ fn must throw

### similar
* [uvu](https://github.com/lukeed/uvu)
* [tape-modern](https://ghub.io/tape-modern)
* [@goto-bus-stop/tape-modern](https://github.com/goto-bus-stop/tape-modern#readme)
* [brittle](https://github.com/davidmarkclements/brittle)
* [tap](https://ghub.io/tap)
* [tape](https://github.com/tape-testing/tape)
* [zora](https://github.com/lorenzofox3/zora)
* [tapes](https://www.npmjs.com/package/tapes)
* [tape-es](https://github.com/vanillaes/tape-es)
* [uvu](https://github.com/lukeed/uvu)
* [pitesti](https://github.com/bengl/pitesti)
<p align="center"><a href="https://github.com/krishnized/license">๐Ÿ•‰๏ธ</a></p>
const GREEN = '\u001b[32m', RED = '\u001b[31m', YELLOW = '\u001b[33m', RESET = '\u001b[0m', CYAN = '\u001b[36m', GRAY = '\u001b[30m'
const isNode = typeof process !== 'undefined' && Object.prototype.toString.call(process) === '[object process]'
let assertIndex = 0,
let assertc = 0,
index = 1,
passed = 0,
failed = 0,
failed = [],
skipped = 0,

@@ -35,2 +35,6 @@ only = 0,

test.mute = function (name, run) {
return createTest({ name, run, mute: true })
}
function createTest(test) {

@@ -44,4 +48,4 @@ test.index = index++

isNode ?
console.log(`${CYAN}ยป ${test.name}${test.tag ? ` (${test.tag})` : ''}${RESET}`) :
console.log(`%c${test.name} ${test.todo ? '๐Ÿšง' : 'โ‰ซ'}` + (test.tag ? ` (${test.tag})` : ''), 'color: #dadada')
console.log(`${test.todo ? YELLOW : CYAN}ยป ${test.name}${test.tag ? ` (${test.tag})` : ''}${RESET}`) :
console.log(`%c${test.name} ${test.todo ? '๐Ÿšง' : 'โ‰ซ'}` + (test.tag ? ` (${test.tag})` : ''), 'color: gainsboro')
return test

@@ -58,2 +62,4 @@ })

demo: false,
mute: false,
pass(arg) {

@@ -66,13 +72,14 @@ if (typeof arg === 'string') return isNode ?

assertIndex++
assertc++
isNode ?
console.log(`${GREEN}โˆš ${assertIndex} ${op && `(${op})`} โ€” ${msg}${RESET}`) :
console.log(`%cโœ” ${assertIndex} ${op && `(${op})`} โ€” ${msg}`, 'color: #229944')
console.log(`${GREEN}โˆš ${assertc} ${op && `(${op})`} โ€” ${msg}${RESET}`) :
console.log(`%cโœ” ${assertc} ${op && `(${op})`} โ€” ${msg}`, 'color: #229944')
// if (!this.demo) {
test.assertion.push({ idx: assertIndex, msg })
test.assertion.push({ idx: assertc, msg })
passed += 1
// }
},
fail(arg) {
assertIndex++
assertc++

@@ -89,3 +96,3 @@ // FIXME: this syntax is due to chrome not always able to grasp the stack trace from source maps

isNode ? (
console.log(`${RED}ร— ${assertIndex} โ€” ${msg}`),
console.log(`${RED}ร— ${assertc} โ€” ${msg}`),
(info && 'actual' in info) && (

@@ -97,8 +104,5 @@ console.info(`actual:${RESET}`, typeof info.actual === 'string' ? JSON.stringify(info.actual) : info.actual, RED),

) :
info ? console.assert(false, `${assertIndex} โ€” ${msg}${RESET}`, info) :
console.assert(false, `${assertIndex} โ€” ${msg}${RESET}`)
// if (!this.demo) {
test.assertion.push({ idx: assertIndex, msg, info, error: new Error() })
// failed += 1
// }
info ? console.assert(false, `${assertc} โ€” ${msg}${RESET}`, info) :
console.assert(false, `${assertc} โ€” ${msg}${RESET}`)
test.assertion.push({ idx: assertc, msg, info, error: new Error() })
}

@@ -115,3 +119,3 @@ }, test)

console.log(`${RESET}${prev && (prev.skip || prev.todo) ? '\n' : ''}โ–บ ${test.name}${test.tag ? ` (${test.tag})` : ''}`) :
console.group(test.name + (test.tag ? ` (${test.tag})` : ''))
test.mute ? console.groupCollapsed(test.name + (test.tag ? ` (${test.tag})` : '')) : console.group(test.name + (test.tag ? ` (${test.tag})` : ''))

@@ -127,3 +131,3 @@ let result

test.fail(e)
if (!test.demo) failed += 1
if (!test.demo) failed.push([e.message, test])
}

@@ -151,8 +155,11 @@ finally {

// summary
console.log(`---\n`)
const total = passed + failed + skipped
console.log(`โ”€โ”€โ”€`)
const total = passed + failed.length + skipped
if (only) console.log(`# only ${only} cases`)
console.log(`# total ${total}`)
if (passed) console.log(`%c# pass ${passed}`, 'color: #229944')
if (failed) console.log(`# fail ${failed}`)
if (failed.length) {
let [msg, t] = failed[0]
console.log(`# fail ${failed.length} (${t.name} โ†’ ${msg})${failed.length > 1 ? `, ${failed.length -1} more...` : ''}`)
}
if (skipped) console.log(`# skip ${skipped}`)

@@ -159,0 +166,0 @@

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with โšก๏ธ by Socket Inc