What is @tapjs/core?
@tapjs/core is a core library for the Test Anything Protocol (TAP) framework, which is used for writing and running tests in JavaScript. It provides a set of tools and utilities to create, manage, and execute tests, making it easier to ensure code quality and reliability.
What are @tapjs/core's main functionalities?
Basic Test Creation
This feature allows you to create basic tests using the TAP framework. The code sample demonstrates a simple test that checks if 1 + 1 equals 2.
const t = require('@tapjs/core');
t.test('basic test', t => {
t.equal(1 + 1, 2, '1 + 1 should equal 2');
t.end();
});
Asynchronous Testing
This feature supports asynchronous testing, allowing you to test functions that return promises or use async/await. The code sample shows how to test an asynchronous function.
const t = require('@tapjs/core');
t.test('async test', async t => {
const result = await someAsyncFunction();
t.equal(result, expectedValue, 'Async function should return expected value');
t.end();
});
Nested Tests
This feature allows you to create nested tests, which can help organize and structure your test cases better. The code sample demonstrates a parent test containing a child test.
const t = require('@tapjs/core');
t.test('parent test', t => {
t.test('child test', t => {
t.equal(2 * 2, 4, '2 * 2 should equal 4');
t.end();
});
t.end();
});
Other packages similar to @tapjs/core
mocha
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 for writing tests, including BDD, TDD, and exports-style. Compared to @tapjs/core, Mocha offers more flexibility in terms of test interfaces and has a larger ecosystem of plugins and integrations.
jest
Jest is a delightful JavaScript testing framework with a focus on simplicity. It works out of the box for most JavaScript projects and provides a rich API for writing tests. Jest includes built-in mocking, assertion, and coverage tools. Compared to @tapjs/core, Jest is more opinionated and comes with more built-in features, making it easier to get started with testing.
ava
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 @tapjs/core, AVA emphasizes simplicity and performance, making it a good choice for projects with a large number of tests.
@tapjs/core
This is the pluggable core of node-tap.
The TestBase
class has the basic flow-control aspects of a tap
Test
object, but only the t.pass()
and t.fail()
assertions.
All other assertions and features are added via plugins.
Full documentation available in the
typedocs.
Class Base
This is the base class of all sorts of test objects. It inherits
from minipass.
Class TestBase
This provides the core flow control and TAP
generation
facilities. The Test
class inherits from this.
Class Spawn
A child test class representing a child process that emits TAP
on its standard output.
Class Worker
A child test class representing a worker thread that emits TAP
on its standard output.
Class Stdin
A child test class representing TAP
parsed from standard input.
Class TapFile
A child test class representing a file containing TAP
data.
Class Counts
An object used to count pass, fail, todo, skip, total,
and completed tests.
Class Lists
An object containing lists of test results.
Class TestPoint
An object representing a single ok
/not ok
test point.
Class Minimal
A very minimal Test class with no plugins, which can be used in
tap internal tests.
It is essentially just the TestBase class, but automatically
starting in the constructor, and with a .test() method so that it
can be used somewhat like a "normal" Test instance.
The reason that this method does not live on TestBase itself is
that it would make it more awkward to define on the Test class,
with all its plugins and extensions.
Only useful if you want a Test without any plugins, for some
reason.
proc
, argv
, cwd
, env
Captured values of process
, process.argv
, process.cwd()
,
and process.env
at the start of the process, in case they
change later on or are not available for some other reason.
tapDir
The string path to the location of @tapjs/core
.
mainScript(defaultName = 'TAP'): string
The path to the main module that node ran.
TapPlugin<PluginValue, OptionsValue>
The type of a plugin function which returns PluginValue
and
optionally which takes OptionsValue
as options.
The extra info passed to assertions.
Extended by BaseOpts, TestBaseOpts, and ultimately TestOpts,
since any subtest is also an assertion, and can take all the same
assertion options.