Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

a_mock

Package Overview
Dependencies
Maintainers
2
Versions
22
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

a_mock - npm Package Compare versions

Comparing version 1.0.1 to 1.0.2

29

newThen.js
var newPromise = require('deferred');
var _setTimeout = setTimeout;
var _clearTimeout = clearTimeout;
function newThen() {
var def = newPromise();
var def = newPromise();
var parentFilename = getRequiringModulePath();
var timeout = 10;
var timerId = _setTimeout(function() {
console.error('aborting a promise in ' + parentFilename + ' that took more than ' + timeout + 's to fulfill');
throw new Error();
}, 10*1000);

@@ -9,3 +17,3 @@ function promise(success, error) {

return def.resolve();
if (success !== null )
if (success !== null )
return def.resolve(success);

@@ -15,3 +23,3 @@ return def.reject(error);

promise.then = function(success,error) {
promise.then = function(success, error) {
return def.promise.apply(def,arguments);

@@ -21,2 +29,3 @@ };

promise.resolve = function() {
_clearTimeout(timerId);
return def.resolve.apply(def,arguments);

@@ -26,2 +35,3 @@ };

promise.reject = function() {
_clearTimeout(timerId);
return def.reject.apply(def,arguments);

@@ -31,5 +41,16 @@ };

return promise;
}
function getRequiringModulePath() {
var path;
var mod = module;
//3 levels up: this file -> a_mock/index -> a/index -> requiring module
for(var i = 0; i < 4; i++) {
if(!mod.parent) return path;
mod = mod.parent;
path = mod.filename;
}
return path;
}
module.exports = newThen;
module.exports = newThen;

10

newThenSpec/test.js

@@ -8,3 +8,3 @@ var assert = require('assert');

console.log('then');
var newResolver = requireMock('deferred');

@@ -24,5 +24,5 @@ var resolve = mock();

var arg = {};
var sut = require('../newThen')();
var sut = require('../index').then();
test('then should return promiseResult',function() {

@@ -38,3 +38,3 @@ var expected = {};

assert.equal(sut.resolve(arg),expected);
});
});

@@ -51,3 +51,3 @@ test('then reject should invoke resolver.reject',function() {

assert.equal(sut(arg),expected);
});
});

@@ -54,0 +54,0 @@ test('then implicit reject should invoke resolver.reject',function() {

{
"name": "a_mock",
"version": "1.0.1",
"version": "1.0.2",
"main": "index.js",

@@ -8,3 +8,3 @@ "title": "a_mock",

"keywords": ["mock","mocking","partial mock","strict mock","tdd","stub","stubbing","mock require","verify"],
"dependencies": {
"dependencies": {
"deferred" : "0.7.1"

@@ -15,3 +15,3 @@ },

"url" : "git@github.com:alfateam/a_mock.git"
}
}
}
SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc