![Deno 2.2 Improves Dependency Management and Expands Node.js Compatibility](https://cdn.sanity.io/images/cgdhsj6q/production/97774ea8c88cc8f4bed2766c31994ebc38116948-1664x1366.png?w=400&fit=max&auto=format)
Security News
Deno 2.2 Improves Dependency Management and Expands Node.js Compatibility
Deno 2.2 enhances Node.js compatibility, improves dependency management, adds OpenTelemetry support, and expands linting and task automation for developers.
[![build status](https://secure.travis-ci.org/dominictarr/macgyver.png)](http://travis-ci.org/dominictarr/macgyver)
declarative assertion framework for invocation ordering.
when evented code really gets mission critical there is one man you send in...
useful for testing streams, and other complex evented modules.
var macgyver = require('macgyver')
//create a context
var mac = macgyver()
//wrap a function...
function hello () {
console.log('hello')
}
function goodbye () {
console.log('goodbye')
}
var hi = mac(hello)
//declare it's behaviours
hi.isCalled(1, 7) //must be called between 1 and 7 times.
var bye = mac(goodbye).once() //must be called strictly once.
hi.before(bye) //hi must be called strictly before bye is called
hi(); hi(); bye()
/*
//this will produce an error!
hi(); hi(); bye(); hi()
*/
mac.validate()
here is a real life example: dominictarr/event-stream/test/spec.js
create a maggyver
context.
var macgyver = require('macgyver')
var mac = macgyver()
wrap a function
function doSomething() {}
var _doSomething = mac(doSomething)
now, we can make declairations about how the wrapped function must be called.
assert that the function is called at least min
times, and at most max
times.
if min
, or max
is null, then that bound is not checked. i.e. mac(fun).isCalled(null, 10)
will assert that fun
is called not more than 10 times.
alias for isCalled (1, 1)
alias for isCalled (n, n)
alias for isCalled (null, 1)
alias for isCalled (0, 0)
alias for isCalled (null, 1)
alias for isCalled (null, max)
alias for isCalled (min, null)
increments the number of times a function may be called. (inc may be negative)
assert that a function is called before another function.
the other
must also be a wrapped function.
mac(first).before(second = mac(second))
before
does not check wether the second function is eventually called or not. use isCalled
or an alias.
just like before
but checks that the function is called before the other function returns, so that it is possible for the first function to be called by the other.
assert that a function returns a value. if value is a function, it will be called with the return value.
//assert that fun returns a string.
mac(fun).returns(function (val) {
assert.equal(typeof val, 'string')
})
the function should throw if the return value was not valid.
assert that a function is passed the correct arguments.
if args
is a function, that function is called as in returns.
assert that a function throws. test may be a value or a function. test
is optional.
if supplyed test
is called on every call.
mac(fun).throws(function (err, threw) {
if(threw) {
assert.equal(err.code,'ERRCODE') //check correct error
} else {
//what to do if there was no error?
}
})
this is useful for checking conditions about when the error should be thrown. example stream#write
check all rules passed. must be called once you are sure all calls are finished.
for example process.on('exit', mac.validate)
is a good time. validate
in necessary
to check that lower bounds of isCalled
and aliases where met.
MIT / Apachce2
FAQs
[![build status](https://secure.travis-ci.org/dominictarr/macgyver.png)](http://travis-ci.org/dominictarr/macgyver) [![browser status](http://ci.testling.com/dominictarr/macgyver.png)](http://ci.testling.com/dominictarr/macgyver) declarative assertion framework for invocation ordering.
The npm package macgyver receives a total of 986 weekly downloads. As such, macgyver popularity was classified as not popular.
We found that macgyver 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
Deno 2.2 enhances Node.js compatibility, improves dependency management, adds OpenTelemetry support, and expands linting and task automation for developers.
Security News
React's CRA deprecation announcement sparked community criticism over framework recommendations, leading to quick updates acknowledging build tools like Vite as valid alternatives.
Security News
Ransomware payment rates hit an all-time low in 2024 as law enforcement crackdowns, stronger defenses, and shifting policies make attacks riskier and less profitable.