Introducing Socket Firewall: Free, Proactive Protection for Your Software Supply Chain.Learn More
Socket
Book a DemoInstallSign in
Socket

zip-tap

Package Overview
Dependencies
Maintainers
1
Versions
7
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

zip-tap

A fast, promise-based TAP testing library

latest
Source
npmnpm
Version
1.0.6
Version published
Maintainers
1
Created
Source

Psst — Want a reporter for this module? Go here -> Vehmloewff/zip-tap-reporter

zip-tap

A fast, promise-based TAP testing library

Installation

npm i -D zip-tap

Usage

The syntax is easy, humman readable, and familiar.

const { tests, describe } = require('zip-tap');

describe(`passing tests`, it => {
	it(`should add`, expect => {
		expect(1 + 1).toBe(2);
	});

	it(`should be the right type`, expect => {
		expect(2 + 1).toBeType('number');
		expect({}).not.toBeType('number');
	});
});

To bring promises into the game, just add in await and async.

If there are delays between describe functions, just wrap everyting in a tests function.

const { tests, describe } = require('zip-tap');
const delay = require('delay');

tests(async () => {
	await delay(100);

	await describe(`first`, async it => {
		await delay(300);

		it(`should work with a promise`, async expect => {
			await delay(400);

			expect('Vehmloewff').toMatch(/loe/);
		});

		it(`should work without a promise`, expect => {
			expect({ a: 'b', c: { d: ['e'], f: 'g' } }).toMatchObject({
				a: 'b',
				c: { d: ['e'], f: 'g' },
			});
		});
	});

	await delay(200);

	describe(`second`, it => {
		it(`should be third`, expect => {
			expect(() => {
				throw new Error(`Hello!`);
			}).toThrow(/hello/i);
		});
	});
});

It is easy to add custom assertions:

const { tests, describe, addAssertion } = require('zip-tap');

addAssertion((actual, expected) => {
	return {
		ok: actual.length === expected,
		actual: actual.length,
		expected: expected,
	};
}, `isLength`);

describe(`custom assertion`, it => {
	it(`should be the same length`, expect => {
		expect('foo').custom(`isLength`, 3);
	});
});

Example output:

TAP version 13
# tests
ok 1 - should add the numbers
ok 2 - should subtract the numbers
# add() should work
ok 3 - should add the numbers
not ok 4 - should subtract the numbers and not be 0
  ---
  message: failed at '!toBe'
  operator: !toBe
  at: !toBe(/home/vehmloewff/Code/zip-tap/dist/build.cjs.js:3252:95)
  expected: -1
  actual: -1
  ...
ok 5 - should be even
# try things async
ok 6 - should still run async
# try things even more async
ok 7 - should pass
1...7

# not ok
# success: 6
# failure: 1

Can I contribute?

Sure!

# fork and clone repo
cd zip-tap
npm install
npm test -- -w

Issues and PR's are welcome!

Just don't forget to npm run lint! :sweat_smile:

License

MIT

FAQs

Package last updated on 08 Feb 2020

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts