TritonDataCenter / node-assert-plus

Extra assertions on top of node's assert module
MIT License
122 stars 25 forks source link

add tests and refactor #16

Closed bahamas10 closed 8 years ago

bahamas10 commented 9 years ago
$ npm test

> assert-plus@0.1.5 test /Users/dave.eddy/dev/node-assert-plus
> for f in ./tests/*.js; do echo "$f"; node "$f" || exit 1; done

./tests/all.test.js
./tests/exports.test.js
./tests/ndebug.test.js

Currently (meaning in master and npm right now), arrayOf{Date,Regexp} are broken. They check typeof (...) each member, but Date objects and Regexps will be of type "object", so they fail this check. The change proposed in this pr will ensure that, for arrays, each member will be tested against module.exports[type] method for the given type.

In current master/npm

> a.arrayOfDate([new Date()])
AssertionError: date (date) is required
    at Object.module.exports.(anonymous function) [as arrayOfDate] (/Users/dave.eddy/temp/node_modules/assert-plus/assert.js:205:17)
    at repl:1:4
    at REPLServer.self.eval (repl.js:110:21)
    at Interface.<anonymous> (repl.js:239:12)
    at Interface.emit (events.js:95:17)
    at Interface._onLine (readline.js:203:10)
    at Interface._line (readline.js:532:8)
    at Interface._ttyWrite (readline.js:761:14)
    at ReadStream.onkeypress (readline.js:100:10)
    at ReadStream.emit (events.js:98:17)

> a.arrayOfRegexp([/foo/])
AssertionError: regexp (regexp) is required
    at Object.module.exports.(anonymous function) [as arrayOfRegexp] (/Users/dave.eddy/temp/node_modules/assert-plus/assert.js:205:17)
    at repl:1:4
    at REPLServer.self.eval (repl.js:110:21)
    at Interface.<anonymous> (repl.js:239:12)
    at Interface.emit (events.js:95:17)
    at Interface._onLine (readline.js:203:10)
    at Interface._line (readline.js:532:8)
    at Interface._ttyWrite (readline.js:761:14)
    at ReadStream.onkeypress (readline.js:100:10)
    at ReadStream.emit (events.js:98:17)

Also, NDEBUG doesn't work for some methods (like assert.buffer)... this change moves all NDEBUG logic to be done to the exported functions to ensure it works 100% of the time (tests added)

pfmooney commented 9 years ago
  1. Could the difference pieces be split up instead of being merged as one big wad? (bug fixes, new tests, added functionality, etc)
  2. It would probably be best to do the tests with something like node-tape instead of bespoke assert logic
bahamas10 commented 9 years ago

breaking into separate prs

  1. add tests (some broken currently) using tape https://github.com/mcavage/node-assert-plus/pull/17
  2. fix and cleanup NDEBUG logic https://github.com/mcavage/node-assert-plus/pull/18