dotest
One dev dependency to run ESLint, your test.js, coverage and report to Coveralls.io
Last updated 9 days ago by franklin .
Unlicense · Repository · Bugs · Original npm · Tarball · package.json
$ cnpm install dotest 
SYNC missed versions from official npm registry.

dotest

One dev dependency for your Node.js package to run ESLint, your test.js, coverage and report to Coveralls.io when running on Travis CI.

npm Build Status Coverage Status Greenkeeper badge

  • It first lists all new commits sinces the last release (tag) with their relative date
  • Then runs ESLint with your package's .eslintrc config
  • Finally it runs your test.js with istanbul for coverage
  • When it detects Travis CI it will also submit the coverage report to Coveralls.io

Console example

Example

test.js

// Load test runner and your app
const doTest = require ('dotest');
const app = require ('./');

// Check app interface
doTest.add ('App interface', test => {
  test()
    .isFunction ('fail', 'methodOne', app.methodOne)
    .isObject ('fail', 'sub', app.sub)
    .isFunction ('fail', 'sub.methodTwo', app.sub.methodTwo)
    .done()
  ;
});

// Check method response
doTest.add ('App methodOne', test => {
  app.methodOne ((err, data) => {
    test (err)
      .isObject ('fail', 'Callback data', data)
      .isArray ('fail', 'data.music', data.music)
      .isNotEmpty ('warn', 'data.music', data.music)
      .done()
    ;
  });
});

// Check promise
doTest.add ('Promise good', async test => {
  try {
    const data = await myPromise();

    test()
      .isObject ('fail', 'data', data)
      .done()
    ;
  }
  catch (err) {
    test (err).done();
  }
});

// Run the tests
doTest.run();

package.json

Full test including ESLint, test.js, coverage report and Coveralls.io submit.

  "scripts": {
    "test": "dotest"
  }

Or just run your test.js

  "scripts": {
    "test": "node test.js"
  }

Just run npm test

Installation

This is usually intended for CI builds, so best to make sure it's in your dev dependencies ;)

npm i dotest --save-dev

Configuration

The script takes these env variables. They override the code settings.

name default description
DOTEST_WAIT 0 Pause between tests, in ms (1000 = 1 sec)

.add

( label, testFunction )

Add a new test to the queue.

doTest.add ('App interface', function (test) {
  test()
    .isArray ('fail', 'my array', [])
    .done();
});

.run

( [wait] )

Run the tests from the queue, one by one.

param type required default description
wait int no 0 Wait time between tests in ms (1000 = 1 sec)
// Normal, without pause between tests
doTest.run();

// Or wait 2 seconds
doTest.run (2000);

.log

( [type], str, [dontCount] )

Fancy console.log with style.

param type default description
[type] string plain Text style to apply, see below
str string The string to output
[dontCount] boolean false Don't count a fail or error towards the exit status
style description
fail FAIL Text with FAIL in red
good good Text with good in green
warn warn Text with warn in yellow
info info Text with info in cyan
note Text with Text in bold
error ERROR Error.message\nError\nError.stack with ERROR in red
plain No styling

The styles error, fail and warn add to the errors and warnings counters, where error and fail also cause the script to fail.

// Bold text
doTest.log ('note', 'Hello world');

.exit

( )

Force exit the process, after writing statistics to the console.

doTest.exit();

.test

( [err] )

Returns check functions. Optionally test for err instance of Error and dump it to the console.

The check functions take a level parameter. When set to fail the check reports fail and the whole test script will eventually fail. When set to warn the check reports warn but won't cause the script to fail.

You can concat the check functions for clean code.

// Using the method
doTest.add ('App interface', function() {
  doTest.test()
    .isObject ('fail', 'Callback data', data)
    .done();
});

// Or using the shortcut
doTest.add ('App interface', function (test) {
  test()
    .isObject ('fail', 'Callback data', data)
    .done();
});

test() .done

( [callback] )

Run the next test from the queue. Optionally run a callback function before the next test.

See example above.

test() .exit

( )

Alias to dotest.exit(). Works similar to .done() where it ends the test, but .exit() also ends the whole script.

test()
  .isArray ('fail', 'data', [])
  .exit();

test() .info

( message )

Output 'info' log line.

The message can be of any type. When it is not a string, the type is written instead and the full value of message dumped right below.

test()
  .info ({ hello: 'world' })
  .done();

// Output:
// info    Object
// { hello: 'world' }

test() .good

( message )

Output 'good' log line.

The message can be of any type. When it is not a string, the type is written instead and the full value of message dumped right below.

test()
  .good ('It works great')
  .done();

// Output:
// good    It works great

test() .warn

( message )

Output 'warn' log line.

The message can be of any type. When it is not a string, the type is written instead and the full value of message dumped right below.

test()
  .warn ('Hmm something odd happened')
  .done();

// Output:
// warn    Hmm something odd happend

test() .fail

( message, [dontCount] )

Output 'FAIL' log line.

The message can be of any type. When it is not a string, the type is written instead and the full value of message dumped right below.

test()
  .fail ('We have a problem')
  .done();

// Output:
// FAIL    We have a problem

test() .error

( err, [dontCount] )

Output 'ERROR' log line with dump and stack trace.

const err = new Error ('Oops');

test()
  .error (err)
  .done();

// Output:
// ERROR   Oops
//
// [Error: Oops]
// ...

test() .isError

( level, what, input )

Check if input is an instance of Error.

param type required description
level string yes Either fail or warn
what string yes Text to prepend to check result
input mixed yes The variable to check
test()
  .isError ('fail', 'My data', data)
  .done();

test() .isObject

( level, what, input )

Check if input is an instance of Object.

param type required description
level string yes Either fail or warn
what string yes Text to prepend to check result
input mixed yes The variable to check
test()
  .isObject ('fail', 'My data', data)
  .done();

test() .isArray

( level, what, input )

Check if input is an instance of Array.

param type required description
level string yes Either fail or warn
what string yes Text to prepend to check result
input mixed yes The variable to check
test()
  .isArray ('fail', 'My data', data)
  .done();

test() .isString

( level, what, input )

Check if input is a string.

param type required description
level string yes Either fail or warn
what string yes Text to prepend to check result
input mixed yes The variable to check
test()
  .isString ('fail', 'My data', data)
  .done();

test() .isNumber

( level, what, input )

Check if input is a number.

param type required description
level string yes Either fail or warn
what string yes Text to prepend to check result
input mixed yes The variable to check
test()
  .isNumber ('fail', 'My data', data)
  .done();

test() .isUndefined

( level, what, input )

Check if input is undefined.

param type required description
level string yes Either fail or warn
what string yes Text to prepend to check result
input mixed yes The variable to check
function (err, data) {
  test()
    .isUndefined ('warn', 'My data', data)
    .done();
}

test() .isNull

( level, what, input )

Check if input is null.

param type required description
level string yes Either fail or warn
what string yes Text to prepend to check result
input mixed yes The variable to check
function (err, data) {
  test()
    .isNull ('warn', 'My data', data)
    .done();
}

test() .isNaN

( level, what, input )

Check if input is NaN.

param type required description
level string yes Either fail or warn
what string yes Text to prepend to check result
input mixed yes The variable to check
function (err, data) {
  test()
    .isNaN ('warn', 'My data', data)
    .done();
}

test() .isBoolean

( level, what, input )

Check if input is a boolean.

param type required description
level string yes Either fail or warn
what string yes Text to prepend to check result
input mixed yes The variable to check
test()
  .isBoolean ('fail', 'My data', data)
  .done();

test() .isFunction

( level, what, input )

Check if input is an instance of Function.

param type required description
level string yes Either fail or warn
what string yes Text to prepend to check result
input mixed yes The variable to check
test()
  .isFunction ('fail', 'My data', data)
  .done();

test() .isDate

( level, what, input )

Check if input is an instance of Date.

param type required description
level string yes Either fail or warn
what string yes Text to prepend to check result
input mixed yes The variable to check
const myDate = new Date();

test()
  .isDate ('fail', 'My data', myDate)
  .done();

test() .isExactly

( level, what, one, two )

Check if one is exactly of the same type and value as two.

param type required description
level string yes Either fail or warn
what string yes Text to prepend to check result
one mixed yes The variable to check
two mixed yes The variable to check against
test()
  .isExactly ('fail', 'My data', 'foo', 'bar')
  .done();

test() .isCondition

( level, what, one, operator, two )

Check if the two values meet the condition.

param type required description
level string yes Either fail or warn
what string yes Text to prepend to check result
one mixed yes Variable to test against
operator string <, >, <=, >=
two mixed Variable to test against
test()
  .isCondition ('fail', 'My data', 1, '<', 2)
  .done();

test() .isEmpty

( level, what, input )

Check if input is undefined, null, or an empty string, object, array or Error. In case of Error the input.message and Object.keys (input) are checked.

param type required description
level string yes Either fail or warn
what string yes Text to prepend to check result
input mixed yes The variable to check
// Object is empty
test()
  .isEmpty ('fail', 'My data', {})
  .done();

test() .isNotEmpty

( level, what, input )

Check if input is not undefined, null, or an empty string, object, array or Error. In case of Error the input.message and Object.keys (input) are checked.

param type required description
level string yes Either fail or warn
what string yes Text to prepend to check result
input mixed yes The variable to check
// Object is not empty
test()
  .isNotEmpty ('fail', 'My data', { foo: 'bar' })
  .done();

Unlicense

This is free and unencumbered software released into the public domain.

Anyone is free to copy, modify, publish, use, compile, sell, or distribute this software, either in source code form or as a compiled binary, for any purpose, commercial or non-commercial, and by any means.

In jurisdictions that recognize copyright laws, the author or authors of this software dedicate any and all copyright interest in the software to the public domain. We make this dedication for the benefit of the public at large and to the detriment of our heirs and successors. We intend this dedication to be an overt act of relinquishment in perpetuity of all present and future rights to this software under copyright law.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

For more information, please refer to http://unlicense.org

Author

Franklin van de Meent

Buy me a coffee

Current Tags

  • 2.7.1                                ...           latest (9 days ago)

45 Versions

  • 2.7.1                                ...           9 days ago
  • 2.7.0                                ...           9 days ago
  • 2.6.2                                ...           5 months ago
  • 2.6.1                                ...           a year ago
  • 2.6.0                                ...           a year ago
  • 2.5.0                                ...           2 years ago
  • 2.4.0                                ...           2 years ago
  • 2.3.0                                ...           2 years ago
  • 2.1.0                                ...           2 years ago
  • 2.0.0                                ...           3 years ago
  • 1.15.2                                ...           3 years ago
  • 1.15.1                                ...           3 years ago
  • 1.15.0                                ...           3 years ago
  • 1.14.0                                ...           4 years ago
  • 1.13.6                                ...           4 years ago
  • 1.13.5                                ...           4 years ago
  • 1.13.3                                ...           4 years ago
  • 1.13.2                                ...           4 years ago
  • 1.13.1                                ...           4 years ago
  • 1.13.0                                ...           4 years ago
  • 1.12.4                                ...           4 years ago
  • 1.12.3                                ...           4 years ago
  • 1.12.2                                ...           4 years ago
  • 1.12.1                                ...           4 years ago
  • 1.12.0                                ...           4 years ago
  • 1.11.0                                ...           4 years ago
  • 1.10.6                                ...           4 years ago
  • 1.10.5                                ...           4 years ago
  • 1.10.4                                ...           4 years ago
  • 1.10.2                                ...           4 years ago
  • 1.10.1                                ...           4 years ago
  • 1.10.0                                ...           4 years ago
  • 1.9.1                                ...           4 years ago
  • 1.9.0                                ...           4 years ago
  • 1.8.0                                ...           4 years ago
  • 1.7.1                                ...           4 years ago
  • 1.7.0                                ...           4 years ago
  • 1.6.0                                ...           4 years ago
  • 1.5.0                                ...           4 years ago
  • 1.4.0                                ...           4 years ago
  • 1.3.0                                ...           4 years ago
  • 1.2.1                                ...           4 years ago
  • 1.2.0                                ...           4 years ago
  • 1.1.0                                ...           4 years ago
  • 1.0.0                                ...           4 years ago
Maintainers (1)
Downloads
Today 0
This Week 0
This Month 106
Last Day 0
Last Week 6
Last Month 86
Dependencies (3)
Dev Dependencies (0)
None
Dependents (0)
None

Copyright 2014 - 2017 © taobao.org |