Security News
vlt Debuts New JavaScript Package Manager and Serverless Registry at NodeConf EU
vlt introduced its new package manager and a serverless registry this week, innovating in a space where npm has stagnated.
Tape is a minimalist JavaScript testing framework for Node.js. It provides a simple and straightforward way to write tests for your code, focusing on simplicity and ease of use.
Basic Test
This feature allows you to write basic tests. The example demonstrates a simple test that checks if the sum of 1 and 1 equals 2.
const test = require('tape');
test('Basic test', function (t) {
t.plan(1);
t.equal(1 + 1, 2, '1 + 1 should equal 2');
});
Asynchronous Test
This feature allows you to write asynchronous tests. The example demonstrates a test that performs an assertion after a 1-second delay.
const test = require('tape');
test('Asynchronous test', function (t) {
t.plan(1);
setTimeout(function () {
t.equal(1 + 1, 2, '1 + 1 should equal 2');
}, 1000);
});
Nested Tests
This feature allows you to write nested tests. The example demonstrates a parent test containing a child test.
const test = require('tape');
test('Parent test', function (t) {
t.test('Child test', function (st) {
st.plan(1);
st.equal(1 + 1, 2, '1 + 1 should equal 2');
});
t.end();
});
Mocha is a feature-rich JavaScript test framework running on Node.js and in the browser, making asynchronous testing simple and fun. It provides a variety of interfaces (e.g., BDD, TDD) and supports a wide range of reporters. Compared to Tape, Mocha is more feature-rich and flexible but also more complex.
Jest is a delightful JavaScript testing framework with a focus on simplicity. It works out of the box for most JavaScript projects and includes features like snapshot testing and a built-in test runner. Compared to Tape, Jest is more opinionated and comes with more built-in features, making it easier to set up but less minimalistic.
AVA is a test runner for Node.js with a concise API, detailed error output, and process isolation. It runs tests concurrently, which can lead to faster test execution. Compared to Tape, AVA is more modern and provides better support for ES6/ES7 features, but it may be less familiar to those used to traditional test runners.
tap-producing test harness for node and browsers
chrome, firefox, opera, safari, IE6, IE7, IE8, IE9
using browserify@1.16.5
var test = require('tape');
test('timing test', function (t) {
t.plan(2);
t.equal(typeof Date.now, 'function');
var start = Date.now();
setTimeout(function () {
t.equal(Date.now() - start, 100);
}, 100);
});
$ node example/timing.js
TAP version 13
# timing test
ok 1 should be equal
not ok 2 should be equal
---
operator: equal
expected: 100
actual: 107
...
1..2
# tests 2
# pass 1
# fail 1
The assertion methods in tape are heavily influenced or copied from the methods in node-tap.
var test = require('tape')
Create a new test with an optional name
string. cb(t)
fires with the new
test object t
once all preceeding tests have finished. Tests execute serially.
If you forget to t.plan()
out how many assertions you are going to run and you
don't call t.end()
explicitly, your test will hang.
Declare that n
assertions should be run. t.end()
will be called
automatically after the n
th assertion. If there are any more assertions after
the n
th, or after t.end()
is called, they will generate errors.
Declare the end of a test explicitly.
Generate a failing assertion with a message msg
.
Generate a passing assertion with a message msg
.
Generate an assertion that will be skipped over.
Assert that value
is truthy with an optional description message msg
.
Aliases: t.true()
, t.assert()
Assert that value
is falsy with an optional description message msg
.
Aliases: t.false()
, t.notok()
Assert that err
is falsy. If err
is non-falsy, use its err.message
as the
description message.
Aliases: t.ifError()
, t.ifErr()
, t.iferror()
Assert that a === b
with an optional description msg
.
Aliases: t.equals()
, t.isEqual()
, t.is()
, t.strictEqual()
,
t.strictEquals()
Assert that a !== b
with an optional description msg
.
Aliases: t.notEquals()
, t.notStrictEqual()
, t.notStrictEquals()
,
t.isNotEqual()
, t.isNot()
, t.not()
, t.doesNotEqual()
, t.isInequal()
Assert that a
and b
have the same structure and nested values using
node's deepEqual() algorithm
with an optional description msg
.
Aliases: t.deepEquals()
, t.isEquivalent()
, t.looseEqual()
,
t.looseEquals()
, t.same()
Assert that a
and b
do not have the same structure and nested values using
node's deepEqual() algorithm
with an optional description msg
.
Aliases: t.notEquivalent()
, t.notDeeply()
, t.notSame()
,
t.isNotDeepEqual()
, t.isNotDeeply()
, t.isNotEquivalent()
,
t.isInequivalent()
Assert that the function call fn()
throws an exception.
Assert that the function call fn()
does not throw an exception.
Create a subtest with a new test handle st
from cb(st)
inside the current
test t
. cb(st)
will only fire when t
finishes. Additional tests queued up
after t
will not be run until all subtests finish.
Create a new test harness instance, which is a function like test()
, but with
a new pending stack and test state.
By default the TAP output goes to process.stdout
or console.log()
if the
environment doesn't have process.stdout
. You can pipe the output to someplace
else if you test.stream.pipe()
to a destination stream on the first tick.
Like test(name, cb)
except if you use .only
this is the only test case
that will run for the entire process, all other test cases using tape will
be ignored
With npm do:
npm install tape
MIT
v1.0.0 - 2013-05-03
827b59d
2a59c49
bd9e9a6
7951747
890382d
0ac88b8
6417cdc
fa706ae
c9def14
5544d26
4fbabba
ce0d62c
72e34ad
5ec8f42
6252fd2
b1c1d6a
88de699
876930e
9420e07
606b141
a5e709e
6df7fc0
f37d431
4f05679
8a80302
365ceab
5329dc6
78c7b77
c4dc7ac
FAQs
tap-producing test harness for node and browsers
The npm package tape receives a total of 403,640 weekly downloads. As such, tape popularity was classified as popular.
We found that tape demonstrated a healthy version release cadence and project activity because the last version was released less than a year ago. It has 0 open source maintainers collaborating on the project.
Did you know?
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.
Security News
vlt introduced its new package manager and a serverless registry this week, innovating in a space where npm has stagnated.
Security News
Research
The Socket Research Team uncovered a malicious Python package typosquatting the popular 'fabric' SSH library, silently exfiltrating AWS credentials from unsuspecting developers.
Security News
At its inaugural meeting, the JSR Working Group outlined plans for an open governance model and a roadmap to enhance JavaScript package management.