Security News
tea.xyz Spam Plagues npm and RubyGems Package Registries
Tea.xyz, a crypto project aimed at rewarding open source contributions, is once again facing backlash due to an influx of spam packages flooding public package registries.
muggle-test
Advanced tools
Readme
Muggle is a testing library without magic.
It outputs TAP version 13, and supports any assertion library that throws an AssertionError
$ npm install muggle-test muggle-assert
A test passes if its callback finishes execution without throwing an error.
const test = require('muggle-test')
// passing test
test('3 + 2 should equal 5', () => {
if (3 + 2 !== 5) {
throw new Error('3 + 2 !== 5')
}
})
// failing test
test('3 + 10 should equal 5', () => {
if (3 + 10 !== 5) {
throw new Error('3 + 10 !== 5')
}
})
Async functions work exactly the same way! await
is used internally to catch both exceptions and rejections.
const test = require('muggle-test')
test('asyncAdd() should add correctly', async () => {
const sum = await asyncAdd(3, 2)
if (sum !== 5) {
throw new Error('asyncAdd(3, 2) should resolve with 5')
}
})
Use an assertion library like muggle-assert to keep tests simple and readable. See its readme for details on its API.
const test = require('muggle-test')
const assert = require('muggle-assert')
test('numbers should add up to 5', async () => {
const num1 = 3
const num2 = 2
// muggle-assert will throw an error if an assertion fails
assert(typeof num1 === 'number', 'num1 should be a number')
assert(typeof num2 === 'number', 'num2 should be a number')
const sum = await asyncAdd(num1, num2)
assert.equal(sum, 5)
})
Tests are run in parallel, so make sure tests don't interfere with each other by changing the same global state.
This makes tests complete faster, but it's also much more predictable to keep tests seperate.
To run tests simply execute the file
$ node test.js
and pipe to your favorite tap reporter
$ node test.js | tap-spec
To run in browser use tape-run
$ browserify test.js | tape-run
Muggle is compatible with any assertion library that throws an error, but muggle-assert is recommended.
The name
, message
, and stack
properties of errors thrown in a test callback will be printed to the TAP output if they are defined.
The actual
, expected
, and operator
properties from an AssertionError will also be included if defined.
There is also a third parameter opts
for the TAP todo and skip directives
If opts.skip
is truthy, then the test is marked as skipped in the TAP output, and the callback won't be run. If opts.skip
is a string, then it will be output as the explanation.
const test = require('muggle-test')
test('3 + 2 should equal 5', () => {
// won't run unless window is defined
}, { skip: window ? false : 'browser only test' })
If opts.todo
is truthy, then the test is marked as incomplete in the TAP output. If opts.todo
is a string, then it will be output as the explanation. The test will run normally and output a failing test on errors, but TAP reporters won't count it as a test failure.
const test = require('muggle-test')
test('sum(3, 2) should equal 5', () => {
// incomplete function
function sum () {}
if (sum(3, 2) !== 5) {
throw new Error('sum(3, 2) !== 5')
}
}, { todo: 'implement sum()' })
FAQs
A testing library without magic
The npm package muggle-test receives a total of 0 weekly downloads. As such, muggle-test popularity was classified as not popular.
We found that muggle-test demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 1 open source maintainer 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
Tea.xyz, a crypto project aimed at rewarding open source contributions, is once again facing backlash due to an influx of spam packages flooding public package registries.
Security News
As cyber threats become more autonomous, AI-powered defenses are crucial for businesses to stay ahead of attackers who can exploit software vulnerabilities at scale.
Security News
UnitedHealth Group disclosed that the ransomware attack on Change Healthcare compromised protected health information for millions in the U.S., with estimated costs to the company expected to reach $1 billion.