Research
Security News
Malicious npm Packages Inject SSH Backdoors via Typosquatted Libraries
Socket’s threat research team has detected six malicious npm packages typosquatting popular libraries to insert SSH backdoors.
All problems in computer science can be solved by another level of indirection
TIMER-SHIM is a simple wrapper around standard timer functions which allows you to stub / test / fake their call and timing function without resorting to tricky global setTimeout/setInterval override.
If you have trouble getting mocha and sinon fake timers to behave, you might find this simple module useful.
Additionally, TIMER-SHIM also provides a few niceties over standard timer functions, including:
At its core, it simply delegates the calls to setTimeout/setInterval internally but by calling those function via TIMER-SHIM you can more easily test your time-dependent code.
$ npm install timer-shim --save
var timer = require('timer-shim')
, count = 0
, handle = null;
timer.timeout(50, function() { console.log('hello!'); });
handle = timer.interval(100, function() {
console.log(count++);
if (count === 10) timer.clear(handle);
});
Write your code using the timer module like this:
var timer = require('timer-shim');
function testWithTimeout() {
// complicated timeout code
internalState = false
timer.timeout(100, function() {
// more complicated code
internalState = true
});
}
Then write your test like this:
var timer = require('timer-shim');
describe('timer functionality', function() {
it('should works', function() {
sinon.stub(timer, 'timeout').callsArg(1)
testWithTimeout();
timer.timeout.should.have.been.calledWith(100);
interalState.should.be.true
timer.timeout.restore();
});
});
timer.c
timer.ct
timer.cto
timer.clear
timer.clearTimeout
Clears the timeout handle given.
timer.t
timer.to
timer.timeout
timer.setTimeout
Sets a function to run after the specified timeout
timer.i
timer.in
timer.iv
timer.interval
timer.setInterval
Sets a function to repeatedly every set interval.
Both timer.timeout
and timer.interval
can be called in either of the following ways:
timer.timeout(100, function() { }); // both works
timer.timeout(function() { }, 100);
timer.interval(100, function() { }); // also works
timer.interval(function() { }, 100);
Test with:
$ npm install -d && make test
Compiles with:
$ npm install -d && make lib/timer-shim.js
BSD
Just open a GitHub issue or ping me @chakrit on Twitter.
FAQs
Test-friendly timer function replacements.
The npm package timer-shim receives a total of 2,944 weekly downloads. As such, timer-shim popularity was classified as popular.
We found that timer-shim 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.
Research
Security News
Socket’s threat research team has detected six malicious npm packages typosquatting popular libraries to insert SSH backdoors.
Security News
MITRE's 2024 CWE Top 25 highlights critical software vulnerabilities like XSS, SQL Injection, and CSRF, reflecting shifts due to a refined ranking methodology.
Security News
In this segment of the Risky Business podcast, Feross Aboukhadijeh and Patrick Gray discuss the challenges of tracking malware discovered in open source softare.