metarhia / metatests

Extremely simple to use test framework and runner for Metarhia technology stack 🧪
https://metarhia.com
Other
18 stars 4 forks source link
assert assertion assertions case cases ci continuous-integration declarative impress javascript js maojian metarhia mock node node-tap nodejs runner tap test

metatests

ci status snyk npm version npm downloads/month npm downloads license

metatests is an extremely simple to use test framework and runner for Metarhia technology stack built on the following principles:

Contributors

API

Interface: metatests

case(caption, namespace, list, runner)

Create declarative test

class DeclarativeTest extends Test

DeclarativeTest.prototype.constructor(caption, namespace, list, options)
DeclarativeTest.prototype.run()
DeclarativeTest.prototype.runNow()

equal(val1, val2)

strictEqual(val1, val2)

class reporters.Reporter

reporters.Reporter.prototype.constructor(options)
reporters.Reporter.prototype.error(test, error)

Fail test with error

reporters.Reporter.prototype.finish()
reporters.Reporter.prototype.log(...args)
reporters.Reporter.prototype.logComment(...args)
reporters.Reporter.prototype.record(test)

Record test

class reporters.ConciseReporter extends Reporter

reporters.ConciseReporter.prototype.constructor(options)
reporters.ConciseReporter.prototype.error(test, error)
reporters.ConciseReporter.prototype.finish()
reporters.ConciseReporter.prototype.listFailure(test, res, message)
reporters.ConciseReporter.prototype.parseTestResults(test, subtest)
reporters.ConciseReporter.prototype.printAssertErrorSeparator()
reporters.ConciseReporter.prototype.printSubtestSeparator()
reporters.ConciseReporter.prototype.printTestSeparator()
reporters.ConciseReporter.prototype.record(test)

class reporters.TapReporter extends Reporter

reporters.TapReporter.prototype.constructor(options)
reporters.TapReporter.prototype.error(test, error)
reporters.TapReporter.prototype.finish()
reporters.TapReporter.prototype.listFailure(test, res, offset)
reporters.TapReporter.prototype.logComment(...args)
reporters.TapReporter.prototype.parseTestResults(test, offset = 0)
reporters.TapReporter.prototype.record(test)

class runner.Runner extends EventEmitter

runner.Runner.prototype.constructor(options)
runner.Runner.prototype.addTest(test)
runner.Runner.prototype.finish()
runner.Runner.prototype.removeReporter()
runner.Runner.prototype.resume()
runner.Runner.prototype.runTodo(active = true)
runner.Runner.prototype.setReporter(reporter)
runner.Runner.prototype.wait()

runner.instance

speed(caption, count, cases)

Microbenchmark each passed function and compare results.

measure(cases[, options])

Returns: <Array> results of all cases as objects of structure

Microbenchmark each passed configuration multiple times

convertToCsv(results)

Returns: <string> valid CSV representation of the results

Convert metatests.measure result to csv.

class ImperativeTest extends Test

ImperativeTest.prototype.constructor(caption, func, options)
ImperativeTest.prototype.afterEach(func)

Set a function to run after each subtest.

The function must either return a promise or call a callback.

ImperativeTest.prototype.assert(value[, message])

Check if value is truthy.

ImperativeTest.prototype.assertNot(value[, message])

Check if value is falsy.

ImperativeTest.prototype.bailout([err][, message])

Fail this test and throw an error.

If both err and message are provided err.toString() will be appended to message.

ImperativeTest.prototype.beforeEach(func)

Set a function to run before each subtest.

The function must either return a promise or call a callback.

ImperativeTest.prototype.case(message, namespace, list, options = {})

Create a declarative case() subtest of this test.

ImperativeTest.prototype.cb([msg][, cb])

Returns: <Function> function to pass to callback

Create error-first callback wrapper to perform automatic checks.

This will check for test.mustCall() the callback and {test.error()} the first callback argument.

ImperativeTest.prototype.cbFail([fail][, cb[, afterAllCb]])

Returns: <Function> function to pass to callback

Create error-first callback wrapper to fail test if call fails.

This will check for test.mustCall() the callback and if the call errored will use test.fail() and test.end()

ImperativeTest.prototype.contains(actual, subObj[, message[, sort[, test]]])

Check that actual contains all properties of subObj.

Properties will be compared with test function.

ImperativeTest.prototype.containsGreedy(actual, subObj[, message[, sort[, test]]])

Check greedily that actual contains all properties of subObj.

Similar to test.contains() but will succeed if at least one of the properties in actual match the one in subObj.

ImperativeTest.prototype.defer(fn, options)

Defer a function call until the 'before' end of test.

ImperativeTest.prototype.doesNotThrow(fn[, message])

Check that fn doesn't throw.

ImperativeTest.prototype.end()

Finish the test.

This will fail if the test has unfinished subtests or plan is not complete.

ImperativeTest.prototype.endAfterSubtests()

Mark this test to call end after its subtests are done.

ImperativeTest.prototype.equal(actual, expected[, message])

Compare actual and expected for non-strict equality.

ImperativeTest.prototype.error(err[, message])

Fail if err is instance of Error.

ImperativeTest.prototype.fail([message][, err])

Fail this test recording failure message.

This doesn't call test.end().

ImperativeTest.prototype.is(checkFn, val[, message])

Check whether val satisfies custom checkFn condition.

ImperativeTest.prototype.isArray(val[, message])

Check if val satisfies Array.isArray.

ImperativeTest.prototype.isBuffer(val[, message])

Check if val satisfies Buffer.isBuffer.

ImperativeTest.prototype.isError(actual[, expected[, message]])

Check if actual is equal to expected error.

ImperativeTest.prototype.isRejected(input, err)

Check that input rejects.

ImperativeTest.prototype.isResolved(input[, expected])

Verify that input resolves.

ImperativeTest.prototype.mustCall([fn[, count[, name]]])

Returns: <Function> function to check with, will forward all arguments to fn, and result from fn

Check that fn is called specified amount of times.

ImperativeTest.prototype.mustNotCall([fn[, name]])

Returns: <Function> function to check with, will forward all arguments to fn, and result from fn

Check that fn is not called.

ImperativeTest.prototype.notEqual(actual, expected[, message])

Compare actual and expected for non-strict not-equality.

ImperativeTest.prototype.notOk(value[, message])

Check if value is falsy.

ImperativeTest.prototype.notSameTopology(obj1, obj2[, message])

Compare actual and expected to not have the same topology.

ImperativeTest.prototype.ok(value[, message])

Check if value is truthy.

ImperativeTest.prototype.on(name, listener)
ImperativeTest.prototype.pass([message])

Record a passing assertion.

ImperativeTest.prototype.plan(n)

Plan this test to have exactly n assertions and end test after

this amount of assertions is reached.

ImperativeTest.prototype.regex(regex, input[, message])

Test whether input matches the provided RegExp.

ImperativeTest.prototype.rejects(input, err)

Check that input rejects.

ImperativeTest.prototype.resolves(input[, expected])

Verify that input resolves.

ImperativeTest.prototype.run()

Start running the test.

ImperativeTest.prototype.same(actual, expected[, message])

Compare actual and expected for non-strict equality.

ImperativeTest.prototype.sameTopology(obj1, obj2[, message])

Compare actual and expected to have same topology.

Useful for comparing objects with circular references for equality.

ImperativeTest.prototype.strictEqual(actual, expected[, message])

Compare actual and expected for strict equality.

ImperativeTest.prototype.strictNotSame(actual, expected[, message])

Compare actual and expected for strict non-equality.

ImperativeTest.prototype.strictSame(actual, expected[, message])

Compare actual and expected for strict equality.

ImperativeTest.prototype.test(caption, func, options)

Returns: <ImperativeTest> subtest instance

Create a subtest of this test.

If the subtest fails this test will fail as well.

ImperativeTest.prototype.testAsync(message, func, options = {})

Create an asynchronous subtest of this test.

Simple wrapper for test.test() setting async option to true.

ImperativeTest.prototype.testSync(message, func, options = {})

Create a synchronous subtest of this test

Simple wrapper for test.test() setting async option to false.

ImperativeTest.prototype.throws(fn[, expected[, message]])

Check that fn throws expected error.

ImperativeTest.prototype.type(obj, type[, message])

Check if obj is of specified type.

test(caption, func[, options[, runner]])

Returns: <ImperativeTest> test instance

Create a test case.

testSync(caption, func, options = {}, runner = runnerInstance)

Create a synchronous test

Simple wrapper for test() setting async option to false.

testAsync(caption, func, options = {}, runner = runnerInstance)

Create an asynchronous test

Simple wrapper for test() setting async option to true.