npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

cotest

v4.0.3

Published

unit test assertion and test runner using comparison operators

Downloads

51

Readme

cotest

yet another unit test assertion and test runner - small, simple, no dependencies

ScreenCap

WhyWhatHowLicense

Why

This originated as an attempt to have assertions that are less verbose because assert.notDeepStrictEqual is ugly.

What

Example

const ct = require('cotest')

ct('1. primitives - comparison', function(t) {
  t('==', 2, 2)
  t('!==', 3, 4, 'should be unequal')
  t('<', 1, 2)
  t('!', null, 'should be falsy')
  t.skip('>=', 55, 0, 'TODO')
})
ct('2. object - comparison', function(t) {
  t('!{===}', [], 'str', 'should be notDeepStrictEqual')
  t('{==}', [2], 2, 'should be deepEqual')
})
ct('3. async', function(t, end) {
  setTimeout(end, 0)
  t('!==', 3, 4)
  t('!{==}', 3, 4)
})
ct.skip('4. skip', function(t) {
  // all tests defined here will be skipped
})

Features

  • Javascript Comparison Operators (==, !==, ===, !===, <, <=, >, >=)
  • Negation (!, !!)
  • Other symbols for nested object
    • {==}: deepEqual
    • !{==}: notDeepEqual
    • {===}: strictDeepEqual
    • !{===}: notStrictDeepEqual
  • throws for assert.throws, !throws for doesNotThrows
  • Async support
  • Skip full test groups or individual assertions with t.skip()
  • Only run selected test group(s) with t.only()
  • Basic test runner to run multiple files and directories
  • Compact reporting
  • Support only running selected tests for troubleshooting

Limitations

  • No nesting of tests
  • Limited configuration

How

Installation

In node, from the project root folder type npm i -D cotest to install.

API

Command Line

  • cotest file1 directory1 directory2 file2 ...

Test Declaration

  • cotest(titleString[, testFunction [, message]])
  • cotest.skip(titleString[, testFunction [, message]])
  • cotest.only(titleString, testFunction [, message])

if no test function is provided, the test will be marked as skipped

Assertion Declaration

  • assert(operator, valueToTest, referenceValue[, additional message])
  • assert.skip(operator, valueToTest, referenceValue[, additional message])

Async use

Test are normally automatically completed after the test function is executed. Example: cotest('syncTest', function(assert) { /*assertions*/ })

To change this behaviour, add a callback to the test function. This calback must be called to end the test. Example: cotest('asyncTest', function(assert, done) { /*assertions*/; done()})

An error message can be passed to the donefunction. Example: cotest('asyncTest', function(assert, done) { if (true) done() else done('failed') })

If a callback is declared but not called, the test fails after 1000ms. To change the default duration: cotest.timeout = 1500

Use in a test file

	var co = require('cotest')
	co('async test, call the function argument to end', function(t, done) {
		t('<', Math.abs(error), 0.001)
		setTimeout(done, 0)
	})
	co('sync test - no function argument needed', function(t) {
		t('==', 1+1, 2)
		t('!', null)
		t('{==}', [1, 2], [1, 2])
	}, 'Any Truthy Value as 3rd argument will only run flagges tests')
	co('sync test - no function argument needed', function(t) {
		t('==', 1+1, 2)
		t('{==}', [1, 2], [1, 2])
	})

Use in package.json

"scripts": {
  "test": "cotest mytestdirectory",
  "test_file": "cotest mytestdirectory/mytestfile"
}

In any of the test files are flagged as priority, only these tests will run.

License

MIT © Hugo Villeneuve