![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-core
Advanced tools
The core for deadunit - a dead-simple nestable unit testing library for javascript in node.js and the browser.
deadunitCore
The core functionality for deadunit. Has a dead-simple, flexible unit testing api that outputs unit-testing results as simple javascript objects that can be accessed programmatically for display or inspection.
Simple output
var Unit = require('deadunit-core')
var test = Unit.test('some test name', function() {
var obj = someFunctionToTest()
this.ok(obj.x === 5)
this.ok(obj.y === 'y')
this.test('nested test', function() {
this.ok(obj.go() > 4)
})
this.done()
}).events({
end: function() {
console.dir(test.results())
}
})
Event driven output
Unit.test('another test', function() {
var obj = someFunctionToTest()
this.ok(obj.msg.indexof("hi") !== -1)
this.done()
}).events({
group: function(g) {
console.log(g.name +" started at "+g.time)
},
assert: function(e) {
console.log(e.success +" - "+e.sourceLines)
},
log: function(log) {
console.dir(log.values)
},
end: function() {
console.log("Done!")
}
})
npm install deadunit-core
var Unit = require('deadunit-core')
var Unit = require('deadunit-core/deadunitCore.browser')
require(['node_modules/deadunitCore.browser.gen.umd'], function(Unit) {
// ...
}
<script src='node_modules/deadunitCore.browser.gen.umd'></script>
Unit.test([<name>, ]<testFunction>)
- runs a suite of unit tests. Returns a UnitTest
object. Returns without having run the tests first - the tests are scheduled to run asynchronously soon thereafter.
<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.this.ok(<success>, [<actualValue>, [expectedValue]])
- makes an assertion about some data. Usually this can be used with just the first parameter.
<success>
- a value that the test expects to be true.<actualValue>
- (optional) the "actual value" being tested. The test results will contain information about the actual value. Example: this.ok(num === 5, num)
<expectedValue>
- (optional) the "expected value". The test results will contain information on the expected value. Example: `this.ok(obj.x === 5, obj.x, 5)this.eq(<actualValue>, <expectedValue>])
- shorthand for this.ok(<actualValue> === <expectedValue>, <actualValue>, <expectedValue>)
.
<actualValue>
- the "actual value" being tested. The test results will contain this information about the actual value.<expectedValue>
- the "expected value". The test results will contain this information on the expected value.this.count(<number>)
- Declares that a test contains a certain <number>
of test groups and asserts (the ok
method call). Does not count asserts in subtests. This should only be called once per group, and shouldn't be called asynchronously. This is also used to determine when tests are complete. If count
is not called in a test, that test completes when all of its subtests complete. If count
is called, then the test completes when the count is reached.
this.test([<name>, ]<testFunction>)
- runs a subtest. Has the same behavior as Unit.test
. Any number of subtests can be nested inside eachother.
this.log(<value>, <value2>, ...)
- Records a concatenated list of values that can be accessed in the test results. This will probably normally be used to record informational string messages.
this.timeout(<milliseconds>)
- adds a timeout of <milliseconds>
from the time at which its called. The test will only time out when all added timeouts expire. When Unit.test
is called, a timeout of 3000ms
is set, and the first time this.timeout
is called, it will override this default instead of just adding an extra timeout - so you can reduce the timeout from this default. Note that this is a timeout for the entire test, not just the specific test-group.
this.before(<function>)
- Runs the passed <function>
once before each subtest in the test.
this.after(<function>)
- Runs the passed <function>
once after each subtest in the test.
this.error(<function(e)>)
- Overrides the unhandled exception handler (that catches errors and records them in the test results) specifically for unhandled errors that happen inside this
test (not child tests). Unhandled exceptions will come through this function instead of being recorded in the test results.
this.warning(<function(e)>)
- Overrides the warning handler (which takes an exception as its parameter). Warning exceptions will come through this function instead of being recorded in the test results.
this.sourcemap(<enable>)
- enables (true
) or disables (false
) source mapping of printed exceptions with a given test. Source mapping of exceptions is enabled by default.
test.results()
- access the test results. Should only be accessed after the entire test has been completed (an asynchronous error will be thrown if more test results happen after the test results have been accessed).
test.events(<handlers>)
- sets up handlers that are called as test results come through. Test results are buffered, so event handlers will always get 100% of the test results, even tho it is called after the unit tests have started. <handlers>
is an object of handler Function
s with the following properties - note that the parameter name of the handler indicates an Event Object type below:
group(<groupStartEvent>)
- called when a new test group is started.assert(<assertEvent>
- called when an assert (ok
method) happens.count(<countEvent>)
- called when a count
happens.exception(<exceptionEvent>)
- called when an exception happens inside a test group.log(<logEvent>)
- called when a log
happens.end(<endEvent>)
- called either when the done
method is called, or when the tests time out.groupEnd(<groupEvent>)
- called when a test group is done (all expected assertions have happened and all its subtests are complete or the whole test has timed out)before(<groupEvent>)
- called when a before
handler is startedafter(<groupEvent>)
- called when a before
handler is startedbeforeEnd(<groupEvent>)
- called when a before
handler is finishedafterEnd(<groupEvent>)
- called when a before
handler is finished{ id: _, // a unique id for the test group
parent: _, // the id of the parent group (undefined if it is the top-level test group)
name: _, // the name of the test
time: _ // a Unix Timestamp of when the test group started.
}
{ id: _, // the id of the test group
time: _ // a Unix Timestamp of when the test group event happened.
}
{ parent: _, // the id of the group this assert is part of
success: _, // true or false, whether the assert passed or failed
time: _, // a Unix Timestamp of the time when the assert happened
sourceLines: _, // the text of the actual line of code for the assert
file: _, // the filename of the file containing the test
line: _, // line number of the assert
column: _, // column number of the assert (not sure this is totally accurate)
expected: _, // (optional) the value expected in the assert (third parameter to `ok`)
actual: _ // (optional) the actual value gotten (second parameter to `ok`)
}
{ parent: _, // the id of the group this assert is part of
success: _, // true or false, whether the assert passed or failed
time: _, // a Unix Timestamp of the time when the assert happened
sourceLines: _, // the text of the actual line of code for the assert
file: _, // the filename of the file containing the test
line: _, // line number of the assert
column: _, // column number of the assert (not sure this is totally accurate)
expected: _ // the number of asserts and tests expected
}
{ parent: _, // the id of the group this assert is part of
time: _, // a Unix Timestamp of the time when the assert happened
error: _ // the thrown object
}
{ parent: _, // the id of the group this log is part of
time: _, // a Unix Timestamp of the time when the log happened
values: _ // the logged values
}
{ type: _, // will either be "timeout" if a the test timed out, or "normal" otherwise
time: _ // a Unix Timestamp of the time when the test ended
}
{ id: _, // a unique id for the test group
type: 'group', // indicates a test group (either a `Unit.test` call or `this.test`)
name: _, // the name of the test
results: _, // An array of test results, which can be of an `UnitTest` Result Types
exceptions: _, // An array of uncaught exceptions thrown in the test,
duration: _, // the duration of the test from its start til the last test action (assert, log, timeout, etc)
// including asynchronous parts and including subtests
timeout: _ // Set to true if the test times out. This key is only available on the top-level group object.
}
{ parent: _, // the id of the group this assert is part of
type: 'assert', // indicates an assert (either an `ok` or `count` call)
success: _, // true or false, whether the assert passed or failed
time: _, // a Unix Timestamp of the time when the assert happened
sourceLines: _, // the text of the actual line of code for the assert (Note that sourceLines are only available if the script is allowed to download the source, which might not be the case if the source is from your filesystem [ie file://] or from another domain)
file: _, // the filename of the file containing the test
line: _, // line number of the assert
column: _, // column number of the assert (not sure this is totally accurate)
expected: _, // (optional) the value expected in the assert (third parameter to `ok`)
actual: _ // (optional) the actual value gotten (second parameter to `ok`)
}
{ parent: _, // the id of the group this log is part of
type: 'log', // indicates a test log - this is so you can log something in-line with the test results
time: _, // a Unix Timestamp of the time when the log happened
values: _ // the logged values
}
This needs more testing! Please help by testing and reporting bugs in other browsers or browser versions!
this.timeout
call)###Anything 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 testsresolve-url
as a dependency once source-map-resolver
Unit.error
string
method introduced in the last versionthis.count
to determine when tests are donelog
interface to be able to pass in multiple valuesReleased under the MIT license: http://opensource.org/licenses/MIT
FAQs
The core for deadunit - a dead-simple nestable unit testing library for javascript in node.js and the browser.
The npm package deadunit-core receives a total of 0 weekly downloads. As such, deadunit-core popularity was classified as not popular.
We found that deadunit-core 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.