Comparing version 2.0.1 to 2.0.3
@@ -1,6 +0,13 @@ | ||
var Future = require('async-future') | ||
// built in test formatting helper | ||
module.exports = function(unitTest, printOnTheFly, hangingTimeout, format) { | ||
module.exports = function(unitTest, printOnTheFly/*, [printLateEvents,] format*/) { | ||
if(arguments.length === 4) { | ||
var format = arguments[3] | ||
var printLateEvents = true | ||
} else /* if(arguments.length > 4) */{ | ||
var printLateEvents = arguments[3] | ||
var format = arguments[4] | ||
} | ||
var result = new Future | ||
@@ -10,10 +17,4 @@ | ||
end: function(e) { | ||
var results = unitTest.results() | ||
var results = unitTest.results(printLateEvents) | ||
result.return(formatGroup(results, format, 0).result) | ||
if(hangingTimeout !== 0) { | ||
setTimeout(function() { | ||
console.log(("Script is hanging (lasted more than "+hangingTimeout+"ms after test \""+results.name+"\" finished printing)").red) | ||
}, hangingTimeout).unref() // note: unref is only available in node.js | ||
} | ||
} | ||
@@ -20,0 +21,0 @@ } |
@@ -12,3 +12,4 @@ var util = require("util") | ||
// returns a future containing a string with the final results | ||
exports.text = function textOutput(unitTest, consoleColoring, printOnTheFly, hangingTimeout) { | ||
exports.text = function textOutput(unitTest, consoleColoring, printOnTheFly, printLateEvents) { | ||
if(printLateEvents === undefined) printLateEvents = true | ||
if(consoleColoring) require('colors') | ||
@@ -23,3 +24,3 @@ | ||
return formatBasic(unitTest, printOnTheFly, hangingTimeout, { | ||
return formatBasic(unitTest, printOnTheFly, printLateEvents, { | ||
group: function(name, totalSyncDuration, totalDuration, testSuccesses, testFailures, | ||
@@ -156,3 +157,4 @@ assertSuccesses, assertFailures, exceptions, | ||
exports.html = function(unitTest) { | ||
exports.html = function(unitTest, printLateEvents) { | ||
if(printLateEvents === undefined) printLateEvents = true | ||
@@ -191,3 +193,3 @@ var getTestDisplayer = function() { | ||
var formattedTestHtml = formatBasic(unitTest, false, 0, { | ||
var formattedTestHtml = formatBasic(unitTest, false, 0, printLateEvents, { | ||
group: function(name, totalSyncDuration, totalDuration, testSuccesses, testFailures, | ||
@@ -304,3 +306,3 @@ assertSuccesses, assertFailures, exceptions, | ||
var linesDisplay = "<i>"+htmlEscape(result.sourceLines).replace(/\n/g, "<br>\n")+"</i>"; | ||
var linesDisplay = "<i>"+textToHtml(result.sourceLines)+"</i>"; | ||
if(result.sourceLines.indexOf("\n") !== -1) { | ||
@@ -310,2 +312,13 @@ linesDisplay = "<br>\n"+linesDisplay; | ||
var expectations = "" | ||
if(!result.success && (result.actual !== undefined || result.expected !== undefined)) { | ||
var things = [] | ||
if(result.expected !== undefined) | ||
things.push("Expected "+textToHtml(valueToMessage(result.expected))) | ||
if(result.actual !== undefined) | ||
things.push("Got "+textToHtml(valueToMessage(result.actual))) | ||
expectations = " - "+things.join(', ') | ||
} | ||
return '<div style="color:'+color+';"><span >'+word+'</span>'+ | ||
@@ -316,3 +329,5 @@ " <span class='locationOuter'>[<span class='locationInner'>" | ||
+"</span> " | ||
+linesDisplay+"</div>" | ||
+linesDisplay | ||
+' <span class="expectations">'+expectations+'</span>' | ||
+"</div>" | ||
}, | ||
@@ -326,9 +341,11 @@ exception: function(exception) { | ||
var formattedException = htmlEscape(displayError).replace(/ /g, ' ').replace(/\n/g, "<br>\n") | ||
var formattedException = textToHtml(displayError) | ||
return '<span style="color:'+purple+';">Exception: '+formattedException+'</span>' | ||
}, | ||
log: function(values) { | ||
return values.map(function(v) { | ||
return htmlEscape(valueToString(v)).replace("\n", "<br>\n") | ||
}).join('<br>\n') | ||
return '<div>' | ||
+values.map(function(v) { | ||
return textToHtml(valueToString(v)) | ||
}).join(', ') | ||
+'</div>' | ||
@@ -389,3 +406,3 @@ } | ||
}\ | ||
.locationInner{\ | ||
.locationInner, .expectations {\ | ||
color:'+gray+';\ | ||
@@ -435,2 +452,9 @@ }\ | ||
function textToHtml(text) { | ||
return htmlEscape(text) | ||
.replace(/ /g, ' ') | ||
.replace(/\n/g, "<br>\n") | ||
.replace(/\t/g, " ") | ||
} | ||
function timeText(ms) { | ||
@@ -437,0 +461,0 @@ if(ms < 2000) |
{"name":"deadunit", | ||
"description": "A dead-simple nestable unit testing library for javascript and node.js.", | ||
"keywords": ["unit", "test", "testing", "javascript", "node"], | ||
"version":"2.0.1", | ||
"version":"2.0.3", | ||
"dependencies":{ | ||
"colors":"", | ||
"deadunit-core":"2.0.0", | ||
"proto":"", | ||
"async-future":"" | ||
"deadunit-core":"2.0.2", | ||
"proto":"1.0.8", | ||
"async-future":"0.1.7", | ||
"build-modules":"1.0.6" | ||
}, | ||
"devDependencies": { | ||
"requirejs":"" | ||
}, | ||
"author": "Billy Tetrud <bitetrudpublic@gmail.com> (https://github.com/fresheneesz/)", | ||
@@ -12,0 +16,0 @@ "license": { |
@@ -6,14 +6,13 @@ **Status**: API finalized, needs testing | ||
A *dead*-simple nesting unit testing module for node.js (and someday the browser!). | ||
A *dead*-simple nesting unit testing module for node.js and in-browser!. | ||
This repository provides default visual representations for the output of [deadunit-core](https://github.com/fresheneesz/deadunitCore), | ||
as well as a formatter that can be used to easily create custom test visualizations. | ||
'*Now with both console and HTML output!*' | ||
'*Now with browser output!*' | ||
Why use it over... | ||
Why use it over [Jasmine](http://pivotal.github.io/jasmine/) / [Node-Unit](https://github.com/caolan/nodeunit) / [Wizek's Tree](https://github.com/Wizek/Tree) | ||
================== | ||
* [Jasmine](http://pivotal.github.io/jasmine/) / [Node-Unit](https://github.com/caolan/nodeunit) / [Wizek's Tree](https://github.com/Wizek/Tree) | ||
* deadunit's *dead*-simple API only has two major ways to assert behavior (`ok` and `count`) making it easy to learn. | ||
* deadunit prints the lines of code of asserts in the test results! | ||
* deadunit prints the lines of code of asserts in the test results! So your output makes sense even if you don't spend a lot of time writing test commentary. | ||
* deadunit just uses javascript! It doesn't have an awkward sentence-like api. | ||
@@ -24,8 +23,8 @@ * deadunit's `count` method elegantly solves various issues like expecting exceptions and asynchronous asserts - just `count` up the number of `ok`s! | ||
* deadunit is simpler to use because it doesn't provide needless sugar (e.g. Tree's always-pass/always-fail asserts) | ||
* deadunit doesn't proscribe synchronization for you - it only expects that you tell it when all the tests are complete (using `this.done()`). | ||
* deadunit doesn't proscribe synchronization for you - it only expects that you tell it how many `ok`s you expect (with `count`) when you have asynchronous assertions. | ||
* it prints out exception *and* any attached data they have | ||
* it'll let you know if your code is hanging (something you don't want, but usually goes unnoticed) | ||
* deadunit supports testing code that uses [node fibers](https://github.com/laverdet/node-fibers) | ||
* deadunit's output is easier to visually parse than jasmine, or wizek's tree, and much easier than node-unit | ||
Deadunit doesn't work in the browser yet tho, whereas Jasmine and Tree do. | ||
Example | ||
@@ -84,7 +83,7 @@ ======= | ||
`Unit.format(<unitTest>, <format>)` - creates custom formatted output for test results according to the passed in `<format>`. | ||
`Unit.format(<unitTest>, <printOnTheFly>, <printLateEvents>, <format>)` - creates custom formatted output for test results according to the passed in `<format>`. | ||
`Unit.string(<results>, <colorize>)` - returns a string containing formatted test results for the passed in. The format of the results is the format returned by [deadunit-core](https://github.com/fresheneesz/deadunitCore#usage)'s `results` method. *See below for screenshots.* | ||
* `<unitTest>` is a `UnitTest` (or `ExtendedUnitTest`) object | ||
* `<printOnTheFly>` - if true, events will be printed to the console as they come in | ||
* `<printLateEvents>` - (optional - default true) if true, a warning will be printed when events come in after the results have been written. | ||
* `<format>` - an object containing functions that format the various types of results. Each formater function should return a `String`. | ||
@@ -119,10 +118,13 @@ * `format.assert(result, testName)` | ||
`test.string(<colorize>)` - returns a future that resolves to a string containing formatted test results. *See below for screenshots.* | ||
`test.writeConsole(<hangingTimeout>)` - writes colorized text output to the console. Returns a [future](https://github.com/fresheneesz/asyncFuture) that resolves when the console writing is complete. `<hangingTimeout>` (optional - default 100) is the number of milliseconds to wait for the script to exit after the results have been written. If the script hasn't exited in that amount of time, a warning will be written. If zero, no warning happens. This only applies to node.js. *See below for screenshots.* | ||
`test.writeConsole(<hangingTimeout>)` - writes colorized text output to the console. Returns a [future](https://github.com/fresheneesz/asyncFuture) that resolves when the console writing is complete. `<hangingTimeout>` is optional (default 100), and if non-zero, a warning will be displayed if the script doesn't exit before `<hangingTimeout>` number of milliseconds has passed. If zero, no warning happens. *See below for screenshots.* | ||
`test.writeHtml(<domElement>)` - writes test output to the dom element who's reference was passed to writeHtml. Returns a [future](https://github.com/fresheneesz/asyncFuture) that resolves when the console writing is complete. *See below for screenshots.* | ||
`test.html()` - returns a string containing html-formatted test results. *See below for screenshots.* | ||
`test.string(<colorize>)` - returns a future that resolves to a string containing formatted test results. `<colorize>` should only be set to true if it will be printed to a command-line console. *See below for screenshots.* | ||
`test.results()` - see [deadunit-core](https://github.com/fresheneesz/deadunitCore#usage) | ||
`test.html(<printLateEvents>)` - returns a string containing html-formatted test results. *See below for screenshots.* | ||
* `<printLateEvents>` - (optional - default true) if true, a warning will be printed when events come in after the results have been written. | ||
`test.results(<printLateEvents>)` - see [deadunit-core](https://github.com/fresheneesz/deadunitCore#usage). When called from deadunit, doesn't print a warning for late events, use the `events` method if you need to detect that. | ||
### Screenshots ### | ||
@@ -152,8 +154,23 @@ | ||
On browsers, since there is nothing as nice as node.js Domains, the`window.onerror` handler is used. The `onerror` handler has [many limitations](http://blog.meldium.com/home/2013/9/30/so-youre-thinking-of-tracking-your-js-errors), one of which is that it doesn't currently return an exception object with a stacktrace. If you want to see a more detailed stacktrace for these kinds of errors, check your browser's console (ahem, if you have one - I'm looking at you older versions of IE) because deadunit will not be able to capture and display a stacktrace in its normal output. One goal for most any code is to have 0 unhandled asyncronous exceptions. | ||
Environment/Browser Support | ||
============= | ||
* node.js | ||
* Browsers - note, on browsers, the source is not yet displayed in the output | ||
* Chrome 31 | ||
* Firefox 26 | ||
* IE 10 | ||
This needs more testing! Please help by testing and reporting bugs in other browsers or browser versions! | ||
Todo | ||
==== | ||
* Test deadunit on more browsers and browser versions | ||
* change time display so it displays full time (with asynchronous parts) as the primary time | ||
* add the ability to stream test results to a browser | ||
* make deadunit work on browsers (standalone) | ||
* Once `colors` supports a safe mode (where it doesn't modify the String prototype), use that. *Modifying builtins is dangerous*. | ||
* Ability to use a sourcemap file to correct line/column numbers | ||
* Also see [the todos for deadunit-core](https://github.com/fresheneesz/deadunitCore#to-do) | ||
@@ -160,0 +177,0 @@ |
// this is a workaround for a v8 bug: https://code.google.com/p/v8/issues/detail?id=2825 | ||
require('./test/testDeadunit.js') | ||
require('./test/testDeadunit.node') |
Sorry, the diff of this file is not supported yet
Major refactor
Supply chain riskPackage has recently undergone a major refactor. It may be unstable or indicate significant internal changes. Use caution when updating to versions that include significant changes.
Found 1 instance in 1 package
NPM Shrinkwrap
Supply chain riskPackage contains a shrinkwrap file. This may allow the package to bypass normal install procedures.
Found 1 instance in 1 package
Wildcard dependency
QualityPackage has a dependency with a floating version range. This can cause issues if the dependency publishes a new major version.
Found 2 instances in 1 package
327156
21
2
215
0
5
1
962
1
+ Addedbuild-modules@1.0.6
+ AddedJSONStream@1.3.5(transitive)
+ Addedacorn@7.4.1(transitive)
+ Addedacorn-node@1.8.2(transitive)
+ Addedacorn-walk@7.2.0(transitive)
+ Addedalign-text@0.1.4(transitive)
+ Addedarray-differ@1.0.0(transitive)
+ Addedarray-union@1.0.2(transitive)
+ Addedarray-uniq@1.0.3(transitive)
+ Addedarrify@1.0.1(transitive)
+ Addedasn1.js@4.10.1(transitive)
+ Addedassert@1.5.1(transitive)
+ Addedasync-future@0.1.7(transitive)
+ Addedavailable-typed-arrays@1.0.7(transitive)
+ Addedbalanced-match@1.0.2(transitive)
+ Addedbase64-js@1.5.1(transitive)
+ Addedbn.js@4.12.15.2.1(transitive)
+ Addedbrace-expansion@1.1.11(transitive)
+ Addedbrorand@1.1.0(transitive)
+ Addedbrowser-pack@6.1.0(transitive)
+ Addedbrowser-resolve@2.0.0(transitive)
+ Addedbrowserify@17.0.1(transitive)
+ Addedbrowserify-aes@1.2.0(transitive)
+ Addedbrowserify-cipher@1.0.1(transitive)
+ Addedbrowserify-des@1.0.2(transitive)
+ Addedbrowserify-rsa@4.1.1(transitive)
+ Addedbrowserify-sign@4.2.3(transitive)
+ Addedbrowserify-zlib@0.2.0(transitive)
+ Addedbuffer@5.2.1(transitive)
+ Addedbuffer-from@1.1.2(transitive)
+ Addedbuffer-xor@1.0.3(transitive)
+ Addedbuild-modules@1.0.6(transitive)
+ Addedbuiltin-status-codes@3.0.0(transitive)
+ Addedcached-path-relative@1.1.0(transitive)
+ Addedcall-bind@1.0.8(transitive)
+ Addedcall-bind-apply-helpers@1.0.2(transitive)
+ Addedcall-bound@1.0.3(transitive)
+ Addedcamelcase@1.2.1(transitive)
+ Addedcenter-align@0.1.3(transitive)
+ Addedcipher-base@1.0.6(transitive)
+ Addedcliui@2.1.0(transitive)
+ Addedcombine-source-map@0.8.0(transitive)
+ Addedconcat-map@0.0.1(transitive)
+ Addedconcat-stream@1.6.2(transitive)
+ Addedconsole-browserify@1.2.0(transitive)
+ Addedconstants-browserify@1.0.0(transitive)
+ Addedconvert-source-map@1.1.3(transitive)
+ Addedcore-util-is@1.0.3(transitive)
+ Addedcreate-ecdh@4.0.4(transitive)
+ Addedcreate-hash@1.2.0(transitive)
+ Addedcreate-hmac@1.1.7(transitive)
+ Addedcrypto-browserify@3.12.1(transitive)
+ Addeddash-ast@1.0.0(transitive)
+ Addeddeadunit-core@2.0.2(transitive)
+ Addeddecamelize@1.2.0(transitive)
+ Addeddefine-data-property@1.1.4(transitive)
+ Addeddefine-properties@1.2.1(transitive)
+ Addeddefined@1.0.1(transitive)
+ Addeddeps-sort@2.0.1(transitive)
+ Addeddes.js@1.1.0(transitive)
+ Addeddetective@5.2.1(transitive)
+ Addeddiffie-hellman@5.0.3(transitive)
+ Addeddomain-browser@1.2.0(transitive)
+ Addeddunder-proto@1.0.1(transitive)
+ Addedduplexer2@0.1.4(transitive)
+ Addedelliptic@6.6.1(transitive)
+ Addedes-define-property@1.0.1(transitive)
+ Addedes-errors@1.3.0(transitive)
+ Addedes-object-atoms@1.1.1(transitive)
+ Addedevents@3.3.0(transitive)
+ Addedevp_bytestokey@1.0.3(transitive)
+ Addedfast-safe-stringify@2.1.1(transitive)
+ Addedfor-each@0.3.5(transitive)
+ Addedfs.realpath@1.0.0(transitive)
+ Addedfunction-bind@1.1.2(transitive)
+ Addedget-assigned-identifiers@1.2.0(transitive)
+ Addedget-intrinsic@1.2.7(transitive)
+ Addedget-proto@1.0.1(transitive)
+ Addedglob@7.2.3(transitive)
+ Addedgopd@1.2.0(transitive)
+ Addedhas-property-descriptors@1.0.2(transitive)
+ Addedhas-symbols@1.1.0(transitive)
+ Addedhas-tostringtag@1.0.2(transitive)
+ Addedhash-base@3.0.5(transitive)
+ Addedhash.js@1.1.7(transitive)
+ Addedhasown@2.0.2(transitive)
+ Addedhmac-drbg@1.0.1(transitive)
+ Addedhtmlescape@1.1.1(transitive)
+ Addedhttps-browserify@1.0.0(transitive)
+ Addedieee754@1.2.1(transitive)
+ Addedinflight@1.0.6(transitive)
+ Addedinherits@2.0.32.0.4(transitive)
+ Addedinline-source-map@0.6.3(transitive)
+ Addedinsert-module-globals@7.2.1(transitive)
+ Addedis-arguments@1.2.0(transitive)
+ Addedis-buffer@1.1.6(transitive)
+ Addedis-callable@1.2.7(transitive)
+ Addedis-core-module@2.16.1(transitive)
+ Addedis-generator-function@1.1.0(transitive)
+ Addedis-regex@1.2.1(transitive)
+ Addedis-typed-array@1.1.15(transitive)
+ Addedisarray@1.0.0(transitive)
+ Addedjsonparse@1.3.1(transitive)
+ Addedkind-of@3.2.2(transitive)
+ Addedlabeled-stream-splicer@2.0.2(transitive)
+ Addedlazy-cache@1.0.4(transitive)
+ Addedlodash.assign@4.2.0(transitive)
+ Addedlodash.bind@4.2.1(transitive)
+ Addedlodash.defaults@4.2.0(transitive)
+ Addedlodash.foreach@4.5.0(transitive)
+ Addedlodash.memoize@3.0.4(transitive)
+ Addedlongest@1.0.1(transitive)
+ Addedmath-intrinsics@1.1.0(transitive)
+ Addedmd5.js@1.3.5(transitive)
+ Addedmiller-rabin@4.0.1(transitive)
+ Addedminifyify@7.3.5(transitive)
+ Addedminimalistic-assert@1.0.1(transitive)
+ Addedminimalistic-crypto-utils@1.0.1(transitive)
+ Addedminimatch@3.1.2(transitive)
+ Addedminimist@1.2.8(transitive)
+ Addedmkdirp@0.5.6(transitive)
+ Addedmkdirp-classic@0.5.3(transitive)
+ Addedmodule-deps@6.2.3(transitive)
+ Addedmultimatch@2.1.0(transitive)
+ Addedobject-inspect@1.13.4(transitive)
+ Addedobject-keys@1.1.1(transitive)
+ Addedobject.assign@4.1.7(transitive)
+ Addedonce@1.4.0(transitive)
+ Addedos-browserify@0.3.0(transitive)
+ Addedos-tmpdir@1.0.2(transitive)
+ Addedpako@1.0.11(transitive)
+ Addedparents@1.0.1(transitive)
+ Addedparse-asn1@5.1.7(transitive)
+ Addedpath-browserify@1.0.1(transitive)
+ Addedpath-is-absolute@1.0.1(transitive)
+ Addedpath-parse@1.0.7(transitive)
+ Addedpath-platform@0.11.15(transitive)
+ Addedpbkdf2@3.1.2(transitive)
+ Addedpossible-typed-array-names@1.1.0(transitive)
+ Addedprocess@0.11.10(transitive)
+ Addedprocess-nextick-args@2.0.1(transitive)
+ Addedproto@1.0.8(transitive)
+ Addedpublic-encrypt@4.0.3(transitive)
+ Addedpunycode@1.4.1(transitive)
+ Addedqs@6.14.0(transitive)
+ Addedquerystring-es3@0.2.1(transitive)
+ Addedrandombytes@2.1.0(transitive)
+ Addedrandomfill@1.0.4(transitive)
+ Addedread-only-stream@2.0.0(transitive)
+ Addedreadable-stream@2.3.83.6.2(transitive)
+ Addedrepeat-string@1.6.1(transitive)
+ Addedresolve@1.22.10(transitive)
+ Addedright-align@0.1.3(transitive)
+ Addedripemd160@2.0.2(transitive)
+ Addedsafe-buffer@5.1.25.2.1(transitive)
+ Addedsafe-regex-test@1.1.0(transitive)
+ Addedset-function-length@1.2.2(transitive)
+ Addedsha.js@2.4.11(transitive)
+ Addedshasum-object@1.0.0(transitive)
+ Addedshell-quote@1.8.2(transitive)
+ Addedside-channel@1.1.0(transitive)
+ Addedside-channel-list@1.0.0(transitive)
+ Addedside-channel-map@1.0.1(transitive)
+ Addedside-channel-weakmap@1.0.2(transitive)
+ Addedsimple-concat@1.0.1(transitive)
+ Addedsource-map@0.5.7(transitive)
+ Addedstack-trace@0.0.7(transitive)
+ Addedstackinfo@1.0.0(transitive)
+ Addedstream-browserify@3.0.0(transitive)
+ Addedstream-combiner2@1.1.1(transitive)
+ Addedstream-http@3.2.0(transitive)
+ Addedstream-splicer@2.0.1(transitive)
+ Addedstring_decoder@1.1.11.3.0(transitive)
+ Addedsubarg@1.0.0(transitive)
+ Addedsupports-preserve-symlinks-flag@1.0.0(transitive)
+ Addedsyntax-error@1.4.0(transitive)
+ Addedthrough@2.3.8(transitive)
+ Addedthrough2@2.0.5(transitive)
+ Addedtimers-browserify@1.4.2(transitive)
+ Addedtmp@0.0.28(transitive)
+ Addedtransform-filter@0.1.1(transitive)
+ Addedtty-browserify@0.0.1(transitive)
+ Addedtypedarray@0.0.6(transitive)
+ Addeduglify-js@2.8.29(transitive)
+ Addeduglify-to-browserify@1.0.2(transitive)
+ Addedumd@3.0.3(transitive)
+ Addedundeclared-identifiers@1.1.3(transitive)
+ Addedurl@0.11.4(transitive)
+ Addedutil@0.10.40.12.5(transitive)
+ Addedutil-deprecate@1.0.2(transitive)
+ Addedvm-browserify@1.1.2(transitive)
+ Addedwhich-typed-array@1.1.18(transitive)
+ Addedwindow-size@0.1.0(transitive)
+ Addedwordwrap@0.0.2(transitive)
+ Addedwrappy@1.0.2(transitive)
+ Addedxtend@4.0.2(transitive)
+ Addedyargs@3.10.0(transitive)
- Removedasync-future@1.0.6(transitive)
- Removeddeadunit-core@2.0.0(transitive)
- Removedproto@1.0.19(transitive)
- Removedstack-trace@0.0.10(transitive)
Updatedasync-future@0.1.7
Updateddeadunit-core@2.0.2
Updatedproto@1.0.8