Giter VIP home page Giter VIP logo

nodejs-dotest's Introduction

dotest

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

npm Build Status Coverage Status

  • It runs ESLint with your package's eslint.config.mjs file
  • Then it runs your test.js with nyc to generate a coverage report
  • When it detects the code is running in a CI it will also submit the coverage report to Coveralls.io
  • In case it runs in a Github action the warning, fail and error lines are highlighted

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 => {
  let error;
  let data;

  try {
    data = await myPromise();
  }
  catch ( err ) {
    error = err;
  }

  test( error )
    .isObject( 'fail', 'data', data );
    .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 devDependencies

npm i dotest --save-dev

Configuration

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

name default description
[DOTEST_WAIT] 0 Pause N ms between tests
[DOTEST_NOCOV] Set to 'true' to skip coverage report
[DOTEST_MINCOV] 85 Minimum coverage % default
[DOTEST_COVBRANCHES] $DOTEST_MINCOV Minimum coverage % for branches
[DOTEST_COVLINES] $DOTEST_MINCOV Minimum coverage % for lines
[DOTEST_COVFUNCTIONS] $DOTEST_MINCOV Minimum coverage % for functions
[DOTEST_COVSTATEMENTS] $DOTEST_MINCOV Minimum coverage % for statements

Methods

add

( label, testFunction )

Add a new test to the queue.

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

run

( [wait] )

Run the tests from the queue, one by one.

param type default description
[wait] number 0 Wait N ms between tests
// 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', () => {
  doTest.test()
    .isObject( 'fail', 'Callback data', data )
    .done()
  ;
} );

// Or using the shortcut
doTest.add( 'App interface', 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 description
level string Either fail or warn
what string Text to prepend to check result
input mixed 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 description
level string Either fail or warn
what string Text to prepend to check result
input mixed 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 description
level string Either fail or warn
what string Text to prepend to check result
input mixed The variable to check
test()
  .isArray( 'fail', 'My data', data )
  .done()
;

test() .isString

( level, what, input )

Check if input is a string.

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

test() .isNumber

( level, what, input )

Check if input is a number.

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

test() .isUndefined

( level, what, input )

Check if input is undefined.

param type description
level string Either fail or warn
what string Text to prepend to check result
input mixed 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 description
level string Either fail or warn
what string Text to prepend to check result
input mixed 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 description
level string Either fail or warn
what string Text to prepend to check result
input mixed 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 description
level string Either fail or warn
what string Text to prepend to check result
input mixed The variable to check
test()
  .isBoolean( 'fail', 'My data', data )
  .done()
;

test() .isFunction

( level, what, input )

Check if input is an instance of Function or AsyncFunction.

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

test() .isNormalFunction

( level, what, input )

Check if input is an instance of Function.

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

test() .isAsyncFunction

( level, what, input )

Check if input is an instance of AsyncFunction.

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

test() .isDate

( level, what, input )

Check if input is an instance of Date.

param type description
level string Either fail or warn
what string Text to prepend to check result
input mixed 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 description
level string Either fail or warn
what string Text to prepend to check result
one mixed The variable to check
two mixed 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 description
level string Either fail or warn
what string Text to prepend to check result
one mixed 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 description
level string Either fail or warn
what string Text to prepend to check result
input mixed 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 description
level string Either fail or warn
what string Text to prepend to check result
input mixed 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 https://unlicense.org

Author

Franklin | Buy me a coffee

nodejs-dotest's People

Contributors

dependabot[bot] avatar fvdm avatar greenkeeper[bot] avatar greenkeeperio-bot avatar renovate[bot] avatar

Stargazers

 avatar

Watchers

 avatar  avatar  avatar

Forkers

jhartst

nodejs-dotest's Issues

An in-range update of eslint is breaking the build 🚨

☝️ Greenkeeper’s updated Terms of Service will come into effect on April 6th, 2018.

Version 4.19.0 of eslint was just published.

Branch Build failing 🚨
Dependency eslint
Current Version 4.18.2
Type dependency

This version is covered by your current version range and after updating it in your project the build failed.

eslint is a direct dependency of this project, and it is very likely causing it to break. If other packages depend on yours, this update is probably also breaking those in turn.

Status Details
  • bitHound - Code null Details
  • bitHound - Dependencies null Details
  • continuous-integration/travis-ci/push The Travis CI build failed Details
  • coverage/coveralls First build on greenkeeper/eslint-4.19.0 at 91.597% Details

Release Notes v4.19.0
  • 55a1593 Update: consecutive option for one-var (fixes #4680) (#9994) (薛定谔的猫)
  • 8d3814e Fix: false positive about ES2018 RegExp enhancements (fixes #9893) (#10062) (Toru Nagashima)
  • 935f4e4 Docs: Clarify default ignoring of node_modules (#10092) (Matijs Brinkhuis)
  • 72ed3db Docs: Wrap Buffer() in backticks in no-buffer-constructor rule description (#10084) (Stephen Edgar)
  • 3aded2f Docs: Fix lodash typos, make spacing consistent (#10073) (Josh Smith)
  • e33bb64 Chore: enable no-param-reassign on ESLint codebase (#10065) (Teddy Katz)
  • 66a1e9a Docs: fix possible typo (#10060) (Vse Mozhet Byt)
  • 2e68be6 Update: give a node at least the indentation of its parent (fixes #9995) (#10054) (Teddy Katz)
  • 72ca5b3 Update: Correctly indent JSXText with trailing linebreaks (fixes #9878) (#10055) (Teddy Katz)
  • 2a4c838 Docs: Update ECMAScript versions in FAQ (#10047) (alberto)
Commits

The new version differs by 12 commits.

  • 4f595e8 4.19.0
  • 16fc59e Build: changelog update for 4.19.0
  • 55a1593 Update: consecutive option for one-var (fixes #4680) (#9994)
  • 8d3814e Fix: false positive about ES2018 RegExp enhancements (fixes #9893) (#10062)
  • 935f4e4 Docs: Clarify default ignoring of node_modules (#10092)
  • 72ed3db Docs: Wrap Buffer() in backticks in no-buffer-constructor rule description (#10084)
  • 3aded2f Docs: Fix lodash typos, make spacing consistent (#10073)
  • e33bb64 Chore: enable no-param-reassign on ESLint codebase (#10065)
  • 66a1e9a Docs: fix possible typo (#10060)
  • 2e68be6 Update: give a node at least the indentation of its parent (fixes #9995) (#10054)
  • 72ca5b3 Update: Correctly indent JSXText with trailing linebreaks (fixes #9878) (#10055)
  • 2a4c838 Docs: Update ECMAScript versions in FAQ (#10047)

See the full diff

FAQ and help

There is a collection of frequently asked questions. If those don’t help, you can always ask the humans behind Greenkeeper.


Your Greenkeeper Bot 🌴

Feature: test shortcut

Instead of dotest.test () allow test ()

dotest.add ('Label', function (test) {
  app.method (function (err, data) {
    test (err)
      .isObject (...)
      .done ();
  });
});

Action required: Greenkeeper could not be activated 🚨

🚨 You need to enable Continuous Integration on all branches of this repository. 🚨

To enable Greenkeeper, you need to make sure that a commit status is reported on all branches. This is required by Greenkeeper because it uses your CI build statuses to figure out when to notify you about breaking changes.

Since we didn’t receive a CI status on the greenkeeper/initial branch, it’s possible that you don’t have CI set up yet. We recommend using Travis CI, but Greenkeeper will work with every other CI service as well.

If you have already set up a CI for this repository, you might need to check how it’s configured. Make sure it is set to run on all new branches. If you don’t want it to run on absolutely every branch, you can whitelist branches starting with greenkeeper/.

Once you have installed and configured CI on this repository correctly, you’ll need to re-trigger Greenkeeper’s initial pull request. To do this, please delete the greenkeeper/initial branch in this repository, and then remove and re-add this repository to the Greenkeeper integration’s white list on Github. You'll find this list on your repo or organization’s settings page, under Installed GitHub Apps.

An in-range update of nsp is breaking the build 🚨

Version 3.2.0 of nsp was just published.

Branch Build failing 🚨
Dependency nsp
Current Version 3.1.0
Type dependency

This version is covered by your current version range and after updating it in your project the build failed.

nsp is a direct dependency of this project, and it is very likely causing it to break. If other packages depend on yours, this update is probably also breaking those in turn.

Status Details
  • continuous-integration/travis-ci/push The Travis CI build failed Details
  • coverage/coveralls First build on greenkeeper/nsp-3.2.0 at 91.597% Details

Commits

The new version differs by 4 commits.

See the full diff

FAQ and help

There is a collection of frequently asked questions. If those don’t help, you can always ask the humans behind Greenkeeper.


Your Greenkeeper Bot 🌴

An in-range update of eslint is breaking the build 🚨

The dependency eslint was updated from 5.14.0 to 5.14.1.

🚨 View failing branch.

This version is covered by your current version range and after updating it in your project the build failed.

eslint is a direct dependency of this project, and it is very likely causing it to break. If other packages depend on yours, this update is probably also breaking those in turn.

Status Details
  • continuous-integration/travis-ci/push: The Travis CI build failed (Details).

Release Notes for v5.14.1
  • 1d6e639 Fix: sort-keys throws Error at SpreadElement (fixes #11402) (#11403) (Krist Wongsuphasawat)
Commits

The new version differs by 3 commits.

  • b2e94d8 5.14.1
  • ce129ed Build: changelog update for 5.14.1
  • 1d6e639 Fix: sort-keys throws Error at SpreadElement (fixes #11402) (#11403)

See the full diff

FAQ and help

There is a collection of frequently asked questions. If those don’t help, you can always ask the humans behind Greenkeeper.


Your Greenkeeper Bot 🌴

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.