Miss any of our Open RFC calls?Watch the recordings here! »

metatests

0.7.2 • Public • Published

metatests

TravisCI Codacy Badge NPM Version NPM Downloads/Month NPM Downloads

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

  • Test cases are files, tests are either imperative (functions) or declarative (arrays and structures).

  • Assertions are done using the built-in Node.js assert module. The framework also provides additional testing facilities (like spies).

  • Tests can be run in parallel.

  • All tests are executed in isolated sandboxes. The framework allows to easily mock modules required by tests and provides ready-to-use mocks for timers and other core functionality.

  • Testing asynchronous operations must be supported.

  • Testing pure functions without asynchronous operations and state can be done without extra boilerplate code using DSL based on arrays.

    mt.case(
      'Test common.duration',
      { common },
      {
        // ...
        'common.duration': [
          ['1d', 86400000],
          ['10h', 36000000],
          ['7m', 420000],
          ['13s', 13000],
          ['2d 43s', 172843000],
          // ...
        ],
        // ...
      }
    );

    (Prior art)

  • The framework must work in Node.js and browsers (using Webpack or any other module bundler that supports CommonJS modules and emulates Node.js globals).

Contributors

API

Interface: metatests

case(caption, namespace, list, runner)

  • caption: <string> case caption
  • namespace: <Object> namespace to use in this case test
  • list: <Object> hash of <Array>, hash keys are function and method names. <Array> contains call parameters last <Array> item is an expected result (to compare) or <Function> (pass result to compare)
  • runner: <Runner> runner for this case test, optional, default: metatests.runner.instance

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)
  • options: <Object>
    • stream: <stream.Writable> optional
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)
  • test: <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, tests)

class ImperativeTest extends Test

ImperativeTest.prototype.constructor(caption, func, options)
ImperativeTest.prototype.afterEach(func)
ImperativeTest.prototype.assert(value, message)
ImperativeTest.prototype.assertNot(value, message)
ImperativeTest.prototype.bailout(err, message)
ImperativeTest.prototype.beforeEach(func)
ImperativeTest.prototype.case(message, namespace, list, options = {})
ImperativeTest.prototype.cb(msg, cb)
ImperativeTest.prototype.cbFail(fail, cb, afterAllCb)
ImperativeTest.prototype.contains(actual, subObj, message, sort, test = compare.strictEqual)
ImperativeTest.prototype.containsGreedy(actual, subObj, message, test = compare.strictEqual)
ImperativeTest.prototype.doesNotThrow(fn, message)
ImperativeTest.prototype.end()
ImperativeTest.prototype.endAfterSubtests()
ImperativeTest.prototype.equal(actual, expected, message)
ImperativeTest.prototype.error(err, message)
ImperativeTest.prototype.fail(message, err)
ImperativeTest.prototype.is(checkFn, val[, message])
  • checkFn: <Function> condition function
    • val: <any> provided value
  • Returns: <boolean> true if condition is satisfied and false otherwise
  • val: <any> value to check the condition against
  • message: <string> check message, optional

Check whether val satisfies custom checkFn condition.

ImperativeTest.prototype.isArray(val[, message])
  • val: <any> value to check
  • message: <string> check message, optional

Check if val satisfies Array.isArray.

ImperativeTest.prototype.isBuffer(val[, message])
  • val: <any> value to check
  • message: <string> check message, optional

Check if val satisfies Buffer.isBuffer.

ImperativeTest.prototype.isError(actual, expected = new Error(), message = undefined)
ImperativeTest.prototype.isRejected(input, err)

Check that input is rejected.

ImperativeTest.prototype.isResolved(input, ...expected)
ImperativeTest.prototype.mustCall()
ImperativeTest.prototype.mustNotCall()
ImperativeTest.prototype.notEqual(actual, expected, message)
ImperativeTest.prototype.notOk(value, message)
ImperativeTest.prototype.notSameTopology(obj1, obj2, message)
ImperativeTest.prototype.ok(value, message)
ImperativeTest.prototype.on(name, listener)
ImperativeTest.prototype.pass(message)
ImperativeTest.prototype.plan(n)
ImperativeTest.prototype.regex(regex, input[, message])

Test whether input matches the provided RegExp

ImperativeTest.prototype.rejects(input, err)

Check that input is rejected.

ImperativeTest.prototype.resolves(input, ...expected)
ImperativeTest.prototype.run()
ImperativeTest.prototype.runNow()
ImperativeTest.prototype.same(actual, expected, message)
ImperativeTest.prototype.sameTopology(obj1, obj2, message)
ImperativeTest.prototype.strictEqual(actual, expected, message)
ImperativeTest.prototype.strictNotSame(actual, expected, message)
ImperativeTest.prototype.strictSame(actual, expected, message)
ImperativeTest.prototype.test(message, func, options = {})
ImperativeTest.prototype.testAsync(message, func, options = {})
ImperativeTest.prototype.testSync(message, func, options = {})
ImperativeTest.prototype.throws(fn, expected = new Error(), message = undefined)
ImperativeTest.prototype.type(obj, type, message)

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

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

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

Install

npm i metatests

DownloadsWeekly Downloads

253

Version

0.7.2

License

MIT

Unpacked Size

90.8 kB

Total Files

14

Last publish

Collaborators

  • avatar