
Security News
/Research
Wallet-Draining npm Package Impersonates Nodemailer to Hijack Crypto Transactions
Malicious npm package impersonates Nodemailer and drains wallets by hijacking crypto transactions across multiple blockchains.
promise-to-test
Advanced tools
simple set of tools for making things you probably shouldn't do in tests seem nicer. Such as waiting (setInterval) for things to complete, and waiting before continuing actions (setTimeout). Very promise focused, depends on Q.
Simple set of utils for making async tests more sane using promises.
I found myself writing some really awful code because I wanted to wait for something to happen, but I did not want to hook into the particular methods causing it. I.e., I wanted my test to act like a user, just keep checking and give up after a certain amount of time. It looked like this :
var it = setInterval(function(){
if($('myCondition').length>0) {
clearInterval(it)
// carry on testing
done()
}
}, 10)
This didn't make me happy, and it was actually nested two or three levels deep, which I'll let you imagine. Apart from aesthetics, this approach also doesn't give much information when it does time out, and we're abandoning all the lovely assertion techniques at our disposal for the condition.
If we rewrite this code using my new tools (ok, just waitFor), it looks like this :
waitFor(function(){
assert.ok($('myCondition').length>0)
})
.then(function(){
// carry on testing
})
.then(function(){done()}, done)
So this is actually a similar amount of code, but...
waitFor(condition, timeout, frequency)
condition
: a function using assertions to test for somethingtimeout
: optional, the amount of time to wait before failing, defaults to 1000 millisecondsfrequency
: optional, the amount of time to wait before checking again, defaults to 10 millisecondsRuns the condition
function every frequency
milliseconds until either condition
runs without errors or timeout
milliseconds have passed. Returns a promise that resolves if condition
runs without errors and rejects with the last error thrown by condition
if timeout
is reached.
justWait(timeout)
timeout
: the amount of time to wait for (duh)Returns a promise which will resolve in timeout
milliseconds.
chai-as-promised and mocha-as-promised are both wonderful ways to clean up async tests with promises, you can even avoid the nasty .then(function(){done()}, done)
at the end of your promise chain!
FAQs
simple set of tools for making things you probably shouldn't do in tests seem nicer. Such as waiting (setInterval) for things to complete, and waiting before continuing actions (setTimeout). Very promise focused, depends on Q.
The npm package promise-to-test receives a total of 0 weekly downloads. As such, promise-to-test popularity was classified as not popular.
We found that promise-to-test 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
/Research
Malicious npm package impersonates Nodemailer and drains wallets by hijacking crypto transactions across multiple blockchains.
Security News
This episode explores the hard problem of reachability analysis, from static analysis limits to handling dynamic languages and massive dependency trees.
Security News
/Research
Malicious Nx npm versions stole secrets and wallet info using AI CLI tools; Socket’s AI scanner detected the supply chain attack and flagged the malware.