New Case Study:See how Anthropic automated 95% of dependency reviews with Socket.Learn More
Socket
Sign inDemoInstall
Socket

deadunit

Package Overview
Dependencies
Maintainers
1
Versions
50
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

deadunit - npm Package Compare versions

Comparing version 2.0.1 to 2.0.3

build.js

19

basicFormatter.js

@@ -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, '&nbsp;').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, '&nbsp;')
.replace(/\n/g, "<br>\n")
.replace(/\t/g, "&nbsp;&nbsp;&nbsp;&nbsp;")
}
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

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc