![Oracle Drags Its Feet in the JavaScript Trademark Dispute](https://cdn.sanity.io/images/cgdhsj6q/production/919c3b22c24f93884c548d60cbb338e819ff2435-1024x1024.webp?w=400&fit=max&auto=format)
Security News
Oracle Drags Its Feet in the JavaScript Trademark Dispute
Oracle seeks to dismiss fraud claims in the JavaScript trademark dispute, delaying the case and avoiding questions about its right to the name.
deadunit
A dead-simple nesting unit testing module for testing in node.js and the browser!. This repository provides default visual representations for the output of deadunit-core, as well as a formatter that can be used to easily create custom test visualizations.
ok
and count
) making it easy to learn.count
method elegantly solves various issues like expecting exceptions and asynchronous asserts - just count
up the number of ok
s!ok
s you expect (with count
) when you have asynchronous assertions.var Unit = require('deadunit')
var test = Unit.test('some test name', function() {
this.count(5) // expect all 5 `ok` assertions
var obj = {x:5, y: 'noty?'}
this.ok(obj.x === 5)
this.ok(obj.y === 'y')
this.test('nested test', function() {
this.ok(obj.go() > 4)
})
try {
throw new Error("oops") // exceptions
} catch(e) {
this.ok(true) // expect an exception
}
setTimeout(function(result) { // do something asynchronous
this.ok(result === 'good')
}, 10)
})
test.writeConsole() // writes colorful output!
test.html() // returns pretty html!
test.writeHtml(document.body) // writes pretty html to the current page (if you're testing in a browser)!
npm install deadunit
var Unit = require('deadunit')
var Unit = require('deadunit/deadunit.browser')
require(['node_modules/browserPackage/deadunit.browser.gen.umd'], function(Unit) {
<script src="/node_modules/deadunit/browserPackage/deadunit.browser.gen.umd.js"></script>
<script>
var Unit = deadunit
</script>
Unit.test([<name>, ]<testFunction>)
- runs a suite of unit tests. Returns an ExtendedUnitTest object.
<name>
- (optional) names the test<testFunction>
- a function that contains the asserts and sub-tests to be run. Both its only parameter and its bound this
is given the same UnitTester
object.Unit.format(<unitTest>, <printOnTheFly>, <printLateEvents>, <format>)
- creates custom formatted output for test results according to the passed in <format>
.
<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
.
format.assert(result, testName)
result
is a deadunit-core assert result objecttestName
is the name of the test the assert is underformat.exception(exception)
exception
is an exception object (could be any object that was thrown)format.group(name, totalDuration, totalSynchronousDuration, testCaseSuccesses, testCaseFailures,
assertSuccesses, assertFailures, exceptions, results, exceptionResults, nestingLevel)
name
is the test group nametotalDuration
- the total duration the test took from start to the last test-actiontestCaseSuccesses
- the number of successful asserts (the ok
method) and groups in this test group. Does not count asserts and test-groups inside subtest groupstestCaseFailures
- the number of failed asserts and groups in this test group. Does not count asserts and test-groups inside subtest groupsassertSuccesses
- the number of successful asserts in this test group and all subgroups.assertFailures
- the number of failed asserts in this test group and all subgroups.exceptions
- the number of exceptions in this test group and all subgroups.results
- an array of already-formatted test results.exceptionResults
- an array of already-formatted exceptions.nestingLevel
is what level of test group this is. The top-level test is at level 0.format.log(values)
values
is an array of logged valuesFor documentation on how to write unit tests using the following methods, see deadunit-core.
this.ok(<success>, [<actualValue>, [expectedValue]])
this.ok(<actualValue>, <expectedValue>)
this.count(<number>)
this.test([<name>, ]<testFunction>)
this.log(<value>, <value2>, ...)
this.timeout(<milliseconds>)
this.before(<function>)
this.after(<function>)
this.error(<function>)
this.sourcemap(<enable>)
This object extends UnitTest from deadunit-core. Also has the following methods:
test.writeConsole(<hangingTimeout>)
- writes colorized text output to the console. Returns a future 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.writeHtml(<domElement>)
- writes test output to the dom element who's reference was passed to writeHtml. Returns a future that resolves when the console writing is complete. See below for screenshots.
test.string(<colorize>)
- returns a future that resolves to a string containing formatted test results. <colorize>
(default false) should only be set to true if it will be printed to a command-line console. See below for screenshots.
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()
- see deadunit-core. When called from deadunit, doesn't print a warning for late events, use the events
method if you need to detect that.
Passing tests are closed and failling tests are open by default. Clicking on the bars toggles sections open or closed.
Javascript (and node.js especially) has a lot of asynchronous parts. Deadunit allows your tests to run asychronously/concurrently, but you have to manage that concurrency.
I recommend that you use either:
fibers/future
s,On browsers, since there is nothing as nice as node.js Domains, thewindow.onerror
handler is used. The onerror
handler has many limitations, 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.
This needs more testing! Please help by testing and reporting bugs in other browsers or browser versions!
Make it so that when run without a server, it emits a small note that explains that you can't get source files with the file:// protocol
Add tap output http://testanything.org/
Add karma integration
Test deadunit on more browsers and browser versions
add the ability to stream test results to a browser
Also see the todos for deadunit-core
fibers/future
s can cause deadunit to fail to catch errors thrown from a fiber, which can lead to the process to crash prematurely (before printing test results). See https://github.com/laverdet/node-fibers/issues/172Anything helps:
How to submit pull requests:
npm install
at its rootnode build.js
to build the browser packages (browserPackage/deadunitCore.browser.gen.umd.js and test/deadunitTests.browser.umd.js) before running the browser testsnode testServer
and open http://localhost:8000/ in browserscolors
that supports a safe mode (where it doesn't modify the String prototype). Modifying builtins is dangerous.test.writeConsole
prints out the testtest.results
test.writeConsole
and test.html
only return when the test is done (or times out)test.writeConsole
outputs test results as they happen in addition to outputting the final outputtest.toString
test.string
and test.html
now return futuresReleased under the MIT license: http://opensource.org/licenses/MIT
FAQs
A dead-simple nestable unit testing library for javascript and node.js.
The npm package deadunit receives a total of 29 weekly downloads. As such, deadunit popularity was classified as not popular.
We found that deadunit demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Security News
Oracle seeks to dismiss fraud claims in the JavaScript trademark dispute, delaying the case and avoiding questions about its right to the name.
Security News
The Linux Foundation is warning open source developers that compliance with global sanctions is mandatory, highlighting legal risks and restrictions on contributions.
Security News
Maven Central now validates Sigstore signatures, making it easier for developers to verify the provenance of Java packages.