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

promise-wtf

Package Overview
Dependencies
Maintainers
1
Versions
22
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

promise-wtf - npm Package Compare versions

Comparing version 1.2.2 to 1.2.4

dist/promise-wtf.min.map

5

.eslintrc.json
{
"extends": "eslint-config-ggc"
"extends": "eslint-config-ggc",
"rules": {
"no-console": 0
}
}

325

dist/promise-wtf.js
/**
* promise-wtf
* v1.2.2
* built: Fri, 18 Nov 2016 08:26:17 GMT
* git: https://github.com/ndaidong/promise-wtf
* author: @ndaidong
* promise-wtf@1.2.4
* built on: Fri, 23 Jun 2017 09:41:50 GMT
* repository: https://github.com/ndaidong/promise-wtf
* maintainer: @ndaidong
* License: MIT
**/
var _createClass = function () { function defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } } return function (Constructor, protoProps, staticProps) { if (protoProps) defineProperties(Constructor.prototype, protoProps); if (staticProps) defineProperties(Constructor, staticProps); return Constructor; }; }();
function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
;(function (name, factory) {
if (typeof module !== 'undefined' && module.exports) {
module.exports = factory();
} else {
var root = window || {};
if (root.define && root.define.amd) {
root.define([], factory);
} else if (root.exports) {
root.exports = factory();
} else {
root[name] = factory();
}
}
})('Promise', function () {
var ENV = typeof module !== 'undefined' && module.exports ? 'node' : 'browser';
var PENDING = 0;
var REJECTED = 1;
var RESOLVED = 2;
var isFunction = function isFunction(v) {
return v && {}.toString.call(v) === '[object Function]';
};
var P = function () {
function P(fn) {
_classCallCheck(this, P);
var _state = PENDING;
var _deferred = null;
var _value = void 0;
var self = this;
var handle = function handle(instance) {
if (_state === PENDING) {
_deferred = instance;
return false;
}
var cb = _state === RESOLVED ? instance.onResolved : instance.onRejected;
if (!cb) {
return _state === RESOLVED ? instance.resolve(_value) : instance.reject(_value);
}
return instance.resolve(cb(_value));
};
var reject = function reject(reason) {
_state = REJECTED;
_value = reason;
if (_deferred) {
handle(_deferred);
}
};
var resolve = function resolve(instance) {
if (instance && isFunction(instance.then)) {
instance.then(resolve, reject);
return;
}
_state = RESOLVED;
_value = instance;
if (_deferred) {
handle(_deferred);
}
};
self.then = function (onResolved, onRejected) {
return new P(function (_resolve, _reject) {
return handle({
onResolved: onResolved,
onRejected: onRejected,
resolve: _resolve,
reject: _reject
});
});
};
self['catch'] = function (onRejected) {
return self.then(null, onRejected);
};
return fn(resolve, reject);
}
_createClass(P, null, [{
key: 'resolve',
value: function resolve(value) {
return new P(function (resolve) {
return resolve(value);
});
}
}, {
key: 'reject',
value: function reject(value) {
return new P(function (resolve, reject) {
return reject(value);
});
}
}, {
key: 'all',
value: function all(promises) {
var results = [];
var done = P.resolve(null);
promises.forEach(function (promise) {
done = done.then(function () {
return promise;
}).then(function (value) {
results.push(value);
});
});
return done.then(function () {
return results;
});
}
}]);
return P;
}();
var root = ENV === 'node' ? global : window;
var $P = root.Promise || P;
$P.prototype['finally'] = function (func) {
return this.then(function (value) {
return $P.resolve(func()).then(function () {
return value;
});
});
};
$P.series = function (tasks) {
return new $P(function (resolve, reject) {
var t = tasks.length;
var exec = function exec(k) {
tasks[k](function (err) {
if (err) {
return reject(err);
}
if (k < t - 1) {
return exec(k + 1);
}
return resolve();
});
};
return exec(0);
});
};
return $P;
});
(function (global, factory) {
typeof exports === 'object' && typeof module !== 'undefined' ? module.exports = factory() :
typeof define === 'function' && define.amd ? define(factory) :
(global.Promise = factory());
}(this, (function () { 'use strict';
var commonjsGlobal = typeof window !== 'undefined' ? window : typeof global !== 'undefined' ? global : typeof self !== 'undefined' ? self : {};
function createCommonjsModule(fn, module) {
return module = { exports: {} }, fn(module, module.exports), module.exports;
}
var classCallCheck = function (instance, Constructor) {
if (!(instance instanceof Constructor)) {
throw new TypeError("Cannot call a class as a function");
}
};
var createClass = function () {
function defineProperties(target, props) {
for (var i = 0; i < props.length; i++) {
var descriptor = props[i];
descriptor.enumerable = descriptor.enumerable || false;
descriptor.configurable = true;
if ("value" in descriptor) descriptor.writable = true;
Object.defineProperty(target, descriptor.key, descriptor);
}
}
return function (Constructor, protoProps, staticProps) {
if (protoProps) defineProperties(Constructor.prototype, protoProps);
if (staticProps) defineProperties(Constructor, staticProps);
return Constructor;
};
}();
var main = createCommonjsModule(function (module) {
var ENV = 'object' !== 'undefined' && module.exports ? 'node' : 'browser';
var PENDING = 0;
var REJECTED = 1;
var RESOLVED = 2;
var isFunction = function isFunction(v) {
return v && {}.toString.call(v) === '[object Function]';
};
var P = function () {
function P(fn) {
classCallCheck(this, P);
var _state = PENDING;
var _deferred = null;
var _value = void 0;
var self = this;
var handle = function handle(instance) {
if (_state === PENDING) {
_deferred = instance;
return false;
}
var cb = _state === RESOLVED ? instance.onResolved : instance.onRejected;
if (!cb) {
return _state === RESOLVED ? instance.resolve(_value) : instance.reject(_value);
}
return instance.resolve(cb(_value));
};
var reject = function reject(reason) {
_state = REJECTED;
_value = reason;
if (_deferred) {
handle(_deferred);
}
};
var resolve = function resolve(instance) {
if (instance && isFunction(instance.then)) {
instance.then(resolve, reject);
return;
}
_state = RESOLVED;
_value = instance;
if (_deferred) {
handle(_deferred);
}
};
self.then = function (onResolved, onRejected) {
return new P(function (_resolve, _reject) {
return handle({
onResolved: onResolved,
onRejected: onRejected,
resolve: _resolve,
reject: _reject
});
});
};
self['catch'] = function (onRejected) {
return self.then(null, onRejected);
};
return fn(resolve, reject);
}
createClass(P, null, [{
key: 'resolve',
value: function resolve(value) {
return new P(function (resolve) {
return resolve(value);
});
}
}, {
key: 'reject',
value: function reject(value) {
return new P(function (resolve, reject) {
return reject(value);
});
}
}, {
key: 'all',
value: function all(promises) {
var results = [];
var done = P.resolve(null);
promises.forEach(function (promise) {
done = done.then(function () {
return promise;
}).then(function (value) {
results.push(value);
});
});
return done.then(function () {
return results;
});
}
}]);
return P;
}();
var root = ENV === 'node' ? commonjsGlobal : window;
var $P = root.Promise || P;
$P.prototype['finally'] = function (func) {
return this.then(function (value) {
return $P.resolve(func()).then(function () {
return value;
});
});
};
$P.series = function (tasks) {
return new $P(function (resolve, reject) {
var t = tasks.length;
var exec = function exec(k) {
tasks[k](function (err) {
if (err) {
return reject(err);
}
if (k < t - 1) {
return exec(k + 1);
}
return resolve();
});
};
return exec(0);
});
};
module.exports = $P;
});
return main;
})));

@@ -1,2 +0,2 @@

// promise-wtf@1.2.2, by @ndaidong - built on Fri, 18 Nov 2016 08:26:17 GMT - published under MIT license
;var _createClass=function(){function defineProperties(target,props){for(var i=0;i<props.length;i++){var descriptor=props[i];descriptor.enumerable=descriptor.enumerable||false;descriptor.configurable=true;if("value"in descriptor)descriptor.writable=true;Object.defineProperty(target,descriptor.key,descriptor)}}return function(Constructor,protoProps,staticProps){if(protoProps)defineProperties(Constructor.prototype,protoProps);if(staticProps)defineProperties(Constructor,staticProps);return Constructor}}();function _classCallCheck(instance,Constructor){if(!(instance instanceof Constructor)){throw new TypeError("Cannot call a class as a function")}};(function(name,factory){if(typeof module!=="undefined"&&module.exports){module.exports=factory()}else{var root=window||{};if(root.define&&root.define.amd){root.define([],factory)}else if(root.exports){root.exports=factory()}else{root[name]=factory()}}}("Promise",function(){var ENV=typeof module!=="undefined"&&module.exports?"node":"browser";var PENDING=0;var REJECTED=1;var RESOLVED=2;var isFunction=function isFunction(v){return v&&{}.toString.call(v)==="[object Function]"};var P=function(){function P(fn){_classCallCheck(this,P);var _state=PENDING;var _deferred=null;var _value=void 0;var self=this;var handle=function handle(instance){if(_state===PENDING){_deferred=instance;return false}var cb=_state===RESOLVED?instance.onResolved:instance.onRejected;if(!cb){return _state===RESOLVED?instance.resolve(_value):instance.reject(_value)}return instance.resolve(cb(_value))};var reject=function reject(reason){_state=REJECTED;_value=reason;if(_deferred){handle(_deferred)}};var resolve=function resolve(instance){if(instance&&isFunction(instance.then)){instance.then(resolve,reject);return}_state=RESOLVED;_value=instance;if(_deferred){handle(_deferred)}};self.then=function(onResolved,onRejected){return new P(function(_resolve,_reject){return handle({onResolved:onResolved,onRejected:onRejected,resolve:_resolve,reject:_reject})})};self["catch"]=function(onRejected){return self.then(null,onRejected)};return fn(resolve,reject)}_createClass(P,null,[{key:"resolve",value:function resolve(value){return new P(function(resolve){return resolve(value)})}},{key:"reject",value:function reject(value){return new P(function(resolve,reject){return reject(value)})}},{key:"all",value:function all(promises){var results=[];var done=P.resolve(null);promises.forEach(function(promise){done=done.then(function(){return promise}).then(function(value){results.push(value)})});return done.then(function(){return results})}}]);return P}();var root=ENV==="node"?global:window;var $P=root.Promise||P;$P.prototype["finally"]=function(func){return this.then(function(value){return $P.resolve(func()).then(function(){return value})})};$P.series=function(tasks){return new $P(function(resolve,reject){var t=tasks.length;var exec=function exec(k){tasks[k](function(err){if(err){return reject(err)}if(k<t-1){return exec(k+1)}return resolve()})};return exec(0)})};return $P}));
// promise-wtf@1.2.4, by @ndaidong - built on Fri, 23 Jun 2017 09:41:50 GMT - published under MIT license
!function(n,e){"object"==typeof exports&&"undefined"!=typeof module?module.exports=e():"function"==typeof define&&define.amd?define(e):n.Promise=e()}(this,function(){"use strict";var n="undefined"!=typeof window?window:"undefined"!=typeof global?global:"undefined"!=typeof self?self:{},e=function(n,e){if(!(n instanceof e))throw new TypeError("Cannot call a class as a function")},t=function(){function n(n,e){for(var t=0;t<e.length;t++){var r=e[t];r.enumerable=r.enumerable||!1,r.configurable=!0,"value"in r&&(r.writable=!0),Object.defineProperty(n,r.key,r)}}return function(e,t,r){return t&&n(e.prototype,t),r&&n(e,r),e}}();return function(n,e){return e={exports:{}},n(e,e.exports),e.exports}(function(r){var o=r.exports?"node":"browser",u=0,i=1,f=2,c=function(n){return n&&"[object Function]"==={}.toString.call(n)},l=function(){function n(t){e(this,n);var r=u,o=null,l=void 0,s=this,a=function(n){if(r===u)return o=n,!1;var e=r===f?n.onResolved:n.onRejected;return e?n.resolve(e(l)):r===f?n.resolve(l):n.reject(l)},d=function(n){r=i,l=n,o&&a(o)};return s.then=function(e,t){return new n(function(n,r){return a({onResolved:e,onRejected:t,resolve:n,reject:r})})},s.catch=function(n){return s.then(null,n)},t(function n(e){e&&c(e.then)?e.then(n,d):(r=f,l=e,o&&a(o))},d)}return t(n,null,[{key:"resolve",value:function(e){return new n(function(n){return n(e)})}},{key:"reject",value:function(e){return new n(function(n,t){return t(e)})}},{key:"all",value:function(e){var t=[],r=n.resolve(null);return e.forEach(function(n){r=r.then(function(){return n}).then(function(n){t.push(n)})}),r.then(function(){return t})}}]),n}(),s=("node"===o?n:window).Promise||l;s.prototype.finally=function(n){return this.then(function(e){return s.resolve(n()).then(function(){return e})})},s.series=function(n){return new s(function(e,t){var r=n.length;return function o(u){n[u](function(n){return n?t(n):u<r-1?o(u+1):e()})}(0)})},r.exports=s})});
{
"version": "1.2.2",
"version": "1.2.4",
"name": "promise-wtf",

@@ -11,3 +11,6 @@ "description": "Lightweight Promise implementation with the 'finally' method",

"author": "@ndaidong",
"main": "./index.js",
"main": "./dist/promise-wtf.js",
"module": "./src/main",
"jsnext:main": "./src/main",
"browser": "./dist/promise-wtf.min.js",
"engines": {

@@ -18,30 +21,25 @@ "node": ">= 6.0"

"lint": "eslint .",
"snyk": "snyk test",
"nsp": "nsp check --output checkstyle",
"tape": "nyc tape test/start.js | tap-spec",
"report": "nyc report --reporter=lcov",
"pretest": "npm run lint && npm run snyk",
"test": "npm run aplus && npm run tape",
"posttest": "npm run report",
"coveralls": "npm test && cat ./coverage/lcov.info | coveralls",
"report": "nyc report --reporter=lcov > coverage.lcov && codecov",
"pretest": "npm run lint && npm run nsp",
"test": "npm run tape",
"posttest": "CODECOV_TOKEN=2841f57e-9a88-4f96-b44d-44f083a8fda9 npm run report && npm run aplus",
"aplus": "node ./test/aplus/index.js",
"build": "gccmin"
"start": "node src/main",
"build": "gccmin -e src/main.js -n Promise -f promise-wtf -o dist -p package.json",
"reset": "node reset"
},
"devDependencies": {
"coveralls": "latest",
"eslint": "latest",
"gcc-min": "latest",
"eslint-config-ggc": "latest",
"mocha": "latest",
"nyc": "latest",
"codecov": "2.x.x",
"eslint": "4.x.x",
"eslint-config-ggc": "1.x.x",
"gcc-min": "6.x.x",
"mocha": "3.x.x",
"nsp": "2.x.x",
"nyc": "11.x.x",
"promises-tests": "latest",
"snyk": "latest",
"tap-spec": "latest",
"tape": "latest"
"tap-spec": "4.x.x",
"tape": "4.x.x"
},
"gccmin": {
"source": "src",
"target": "dist",
"filename": "promise-wtf",
"globalVar": "Promise"
},
"keywords": [

@@ -48,0 +46,0 @@ "library",

@@ -6,5 +6,5 @@ # promise-wtf

[![Build Status](https://travis-ci.org/ndaidong/promise-wtf.svg?branch=master)](https://travis-ci.org/ndaidong/promise-wtf)
[![Coverage Status](https://coveralls.io/repos/github/ndaidong/promise-wtf/badge.svg?branch=master)](https://coveralls.io/github/ndaidong/promise-wtf?branch=master)
[![codecov](https://codecov.io/gh/ndaidong/promise-wtf/branch/master/graph/badge.svg)](https://codecov.io/gh/ndaidong/promise-wtf)
[![Dependency Status](https://gemnasium.com/badges/github.com/ndaidong/promise-wtf.svg)](https://gemnasium.com/github.com/ndaidong/promise-wtf)
[![Known Vulnerabilities](https://snyk.io/test/npm/promise-wtf/badge.svg)](https://snyk.io/test/npm/promise-wtf)
[![NSP Status](https://nodesecurity.io/orgs/techpush/projects/057d6386-964c-4d64-abe8-79845fa56f9d/badge)](https://nodesecurity.io/orgs/techpush/projects/057d6386-964c-4d64-abe8-79845fa56f9d)

@@ -113,7 +113,7 @@

- [promise-wtf.min.js](https://cdn.rawgit.com/ndaidong/promise-wtf/master/dist/promise-wtf.min.js)
- [promise-wtf.min.map](https://cdn.rawgit.com/ndaidong/promise-wtf/master/dist/promise-wtf.min.map)
- This library also supports ES6 Module, AMD and UMD style.
- Also supports ES6 Module, CommonJS, AMD and UMD style.
## Test

@@ -120,0 +120,0 @@

@@ -114,5 +114,6 @@ /**

var root = ENV === 'node' ? global : window;
var $P = root.Promise || P;
$P.prototype['finally'] = function(func) { // eslint-disable-line
$P.prototype['finally'] = function (func) {
return this.then((value) => {

@@ -119,0 +120,0 @@ return $P.resolve(func()).then(() => {

@@ -1,2 +0,1 @@

var Promise = require('../../src/main');

@@ -3,0 +2,0 @@

@@ -20,8 +20,7 @@ /**

assert.ok(a[1] === ` * ${pkgFake.name}`, 'Package name must be correct');
assert.ok(a[2] === ` * v${pkgFake.version}`, 'Package version must be correct');
assert.ok(a[3].startsWith(' * built:'), 'Package built time must be showed');
assert.ok(a[4] === ` * git: ${pkgFake.repository.url}`, 'Package repository must be correct');
assert.ok(a[5] === ` * author: ${pkgFake.author}`, 'Package author must be correct');
assert.ok(a[6] === ` * License: ${pkgFake.license}`, 'Package license must be correct');
assert.ok(a[1] === ` * ${pkgFake.name}@${pkgFake.version}`, 'Package name must be correct');
assert.ok(a[2].startsWith(' * built on:'), 'Package built time must be showed');
assert.ok(a[3] === ` * repository: ${pkgFake.repository.url}`, 'Package repository must be correct');
assert.ok(a[4] === ` * maintainer: ${pkgFake.author}`, 'Package author must be correct');
assert.ok(a[5] === ` * License: ${pkgFake.license}`, 'Package license must be correct');

@@ -28,0 +27,0 @@ assert.end();

@@ -11,260 +11,266 @@ /**

var Promise = require('../../src/main');
var PromiseMain = require('../../src/main');
var PromiseFull = require('../../dist/promise-wtf');
var PromiseMin = require('../../dist/promise-wtf.min');
var hasMethod = (ob, m) => {
return ob[m] && typeof ob[m] === 'function';
};
var promiseTest = (_Promise) => {
var hasMethod = (ob, m) => {
return ob[m] && typeof ob[m] === 'function';
};
var fakeAsyncRead = (text, callback) => {
let t = Math.random() * 1000;
setTimeout(() => {
if (!text) {
return callback(new Error('Expected a string'));
}
return callback(null, text);
}, 200 + t);
};
var fakeAsyncRead = (text, callback) => {
let t = Math.random() * 1000;
setTimeout(() => {
if (!text) {
return callback(new Error('Expected a string'));
}
return callback(null, text);
}, 200 + t);
};
var fakePromiseRead = (text) => {
return new Promise((resolve, reject) => {
return fakeAsyncRead(text, (err, content) => {
if (err) {
return reject(err);
}
return resolve(content);
var fakePromiseRead = (text) => {
return new _Promise((resolve, reject) => {
return fakeAsyncRead(text, (err, content) => {
if (err) {
return reject(err);
}
return resolve(content);
});
});
});
};
};
test('Testing Promise constructor', (assert) => {
test('Testing Promise constructor', (assert) => {
let instance = fakePromiseRead('Hello world');
let instance = fakePromiseRead('Hello world');
assert.ok(hasMethod(instance, 'then'), 'Promise instance must have "then" method');
assert.ok(hasMethod(instance, 'catch'), 'Promise instance must have "catch" method');
assert.ok(hasMethod(instance, 'finally'), 'Promise instance must have "finally" method');
assert.end();
});
assert.ok(hasMethod(instance, 'then'), 'Promise instance must have "then" method');
assert.ok(hasMethod(instance, 'catch'), 'Promise instance must have "catch" method');
assert.ok(hasMethod(instance, 'finally'), 'Promise instance must have "finally" method');
assert.end();
});
test('Testing Promise result after then', (assert) => {
test('Testing Promise result after then', (assert) => {
let instance = fakePromiseRead('Hello');
let instance = fakePromiseRead('Hello');
instance.then((s) => {
assert.deepEquals(s, 'Hello', 'It must return content');
}).catch((e) => {
console.log(e);
}).finally(() => {
assert.end();
instance.then((s) => {
assert.deepEquals(s, 'Hello', 'It must return content');
}).catch((e) => {
console.log(e);
}).finally(() => {
assert.end();
});
});
});
test('Testing Promise.all', (assert) => {
Promise.all([
fakePromiseRead('One'),
fakePromiseRead('Two'),
fakePromiseRead('Three'),
fakePromiseRead('Four'),
fakePromiseRead('Five'),
fakePromiseRead('Six'),
fakePromiseRead('Seven'),
fakePromiseRead('Eight'),
fakePromiseRead('Nine'),
fakePromiseRead('Ten')
]).then((results) => {
let s = results.join(' ');
let r = 'One Two Three Four Five Six Seven Eight Nine Ten';
assert.deepEquals(s, r, `It must return ${r}`);
assert.end();
test('Testing Promise.all', (assert) => {
_Promise.all([
fakePromiseRead('One'),
fakePromiseRead('Two'),
fakePromiseRead('Three'),
fakePromiseRead('Four'),
fakePromiseRead('Five'),
fakePromiseRead('Six'),
fakePromiseRead('Seven'),
fakePromiseRead('Eight'),
fakePromiseRead('Nine'),
fakePromiseRead('Ten')
]).then((results) => {
let s = results.join(' ');
let r = 'One Two Three Four Five Six Seven Eight Nine Ten';
assert.deepEquals(s, r, `It must return ${r}`);
assert.end();
});
});
});
test('Testing Promise.series', (assert) => {
let arr = [];
Promise.series([
(next) => {
let t = 'One';
fakeAsyncRead(t, (err, content) => {
if (!err && content) {
arr.push(content);
}
next(err, content);
});
},
(next) => {
let t = 'Two';
fakeAsyncRead(t, (err, content) => {
if (!err && content) {
arr.push(content);
}
next(err, content);
});
},
(next) => {
let t = 'Three';
fakeAsyncRead(t, (err, content) => {
if (!err && content) {
arr.push(content);
}
next(err, content);
});
},
(next) => {
let t = 'Four';
fakeAsyncRead(t, (err, content) => {
if (!err && content) {
arr.push(content);
}
next(err, content);
});
},
(next) => {
let t = 'Five';
fakeAsyncRead(t, (err, content) => {
if (!err && content) {
arr.push(content);
}
next(err, content);
});
},
(next) => {
let t = 'Six';
fakeAsyncRead(t, (err, content) => {
if (!err && content) {
arr.push(content);
}
next(err, content);
});
},
(next) => {
let t = 'Seven';
fakeAsyncRead(t, (err, content) => {
if (!err && content) {
arr.push(content);
}
next(err, content);
});
},
(next) => {
let t = 'Eight';
fakeAsyncRead(t, (err, content) => {
if (!err && content) {
arr.push(content);
}
next(err, content);
});
},
(next) => {
let t = 'Nine';
fakeAsyncRead(t, (err, content) => {
if (!err && content) {
arr.push(content);
}
next(err, content);
});
},
(next) => {
let t = 'Ten';
fakeAsyncRead(t, (err, content) => {
if (!err && content) {
arr.push(content);
}
next(err, content);
});
}
]).then(() => {
let s = arr.join(' ');
let r = 'One Two Three Four Five Six Seven Eight Nine Ten';
assert.deepEquals(s, r, `It must return ${r}`);
}).catch((err) => {
console.log(err);
}).finally(() => {
assert.end();
test('Testing Promise.series', (assert) => {
let arr = [];
_Promise.series([
(next) => {
let t = 'One';
fakeAsyncRead(t, (err, content) => {
if (!err && content) {
arr.push(content);
}
next(err, content);
});
},
(next) => {
let t = 'Two';
fakeAsyncRead(t, (err, content) => {
if (!err && content) {
arr.push(content);
}
next(err, content);
});
},
(next) => {
let t = 'Three';
fakeAsyncRead(t, (err, content) => {
if (!err && content) {
arr.push(content);
}
next(err, content);
});
},
(next) => {
let t = 'Four';
fakeAsyncRead(t, (err, content) => {
if (!err && content) {
arr.push(content);
}
next(err, content);
});
},
(next) => {
let t = 'Five';
fakeAsyncRead(t, (err, content) => {
if (!err && content) {
arr.push(content);
}
next(err, content);
});
},
(next) => {
let t = 'Six';
fakeAsyncRead(t, (err, content) => {
if (!err && content) {
arr.push(content);
}
next(err, content);
});
},
(next) => {
let t = 'Seven';
fakeAsyncRead(t, (err, content) => {
if (!err && content) {
arr.push(content);
}
next(err, content);
});
},
(next) => {
let t = 'Eight';
fakeAsyncRead(t, (err, content) => {
if (!err && content) {
arr.push(content);
}
next(err, content);
});
},
(next) => {
let t = 'Nine';
fakeAsyncRead(t, (err, content) => {
if (!err && content) {
arr.push(content);
}
next(err, content);
});
},
(next) => {
let t = 'Ten';
fakeAsyncRead(t, (err, content) => {
if (!err && content) {
arr.push(content);
}
next(err, content);
});
}
]).then(() => {
let s = arr.join(' ');
let r = 'One Two Three Four Five Six Seven Eight Nine Ten';
assert.deepEquals(s, r, `It must return ${r}`);
}).catch((err) => {
console.log(err);
}).finally(() => {
assert.end();
});
});
});
test('Testing Promise.series fail', (assert) => {
let arr = [];
Promise.series([
(next) => {
let t = 'One';
fakeAsyncRead(t, (err, content) => {
if (!err && content) {
arr.push(content);
}
next(err, content);
});
},
(next) => {
let t = 'Two';
fakeAsyncRead(t, (err, content) => {
if (!err && content) {
arr.push(content);
}
next(err, content);
});
},
(next) => {
let t = 'Three';
fakeAsyncRead(t, (err, content) => {
if (!err && content) {
arr.push(content);
}
next(err, content);
});
},
(next) => {
let t = null;
fakeAsyncRead(t, (err, content) => {
if (!err && content) {
arr.push(content);
}
next(err, content);
});
},
(next) => {
let t = 'Five';
fakeAsyncRead(t, (err, content) => {
if (!err && content) {
arr.push(content);
}
next(err, content);
});
}
]).then(() => {
assert.deepEquals(null, null, 'Nothing here');
}).catch((error) => {
assert.deepEquals(error, new Error('Expected a string'), 'It must return error here');
}).finally(() => {
assert.end();
test('Testing Promise.series fail', (assert) => {
let arr = [];
_Promise.series([
(next) => {
let t = 'One';
fakeAsyncRead(t, (err, content) => {
if (!err && content) {
arr.push(content);
}
next(err, content);
});
},
(next) => {
let t = 'Two';
fakeAsyncRead(t, (err, content) => {
if (!err && content) {
arr.push(content);
}
next(err, content);
});
},
(next) => {
let t = 'Three';
fakeAsyncRead(t, (err, content) => {
if (!err && content) {
arr.push(content);
}
next(err, content);
});
},
(next) => {
let t = null;
fakeAsyncRead(t, (err, content) => {
if (!err && content) {
arr.push(content);
}
next(err, content);
});
},
(next) => {
let t = 'Five';
fakeAsyncRead(t, (err, content) => {
if (!err && content) {
arr.push(content);
}
next(err, content);
});
}
]).then(() => {
assert.deepEquals(null, null, 'Nothing here');
}).catch((error) => {
assert.deepEquals(error, new Error('Expected a string'), 'It must return error here');
}).finally(() => {
assert.end();
});
});
});
test('Testing Promise.reject', (assert) => {
Promise.reject(new Error('fail')).then((data) => {
assert.deepEquals(data, null, 'Nothing here');
}, (error) => {
assert.deepEquals(error, new Error('[Error: fail]'), 'It must return error here');
assert.end();
test('Testing Promise.reject', (assert) => {
_Promise.reject(new Error('fail')).then((data) => {
assert.deepEquals(data, null, 'Nothing here');
}, (error) => {
assert.deepEquals(error, new Error('[Error: fail]'), 'It must return error here');
assert.end();
});
});
});
test('Testing Promise.resolve', (assert) => {
Promise.resolve('Success').then((value) => {
assert.deepEquals(value, 'Success', 'It must return "Success"');
}, (data) => {
assert.deepEquals(data, null, 'Nothing here');
});
test('Testing Promise.resolve', (assert) => {
_Promise.resolve('Success').then((value) => {
assert.deepEquals(value, 'Success', 'It must return "Success"');
}, (data) => {
assert.deepEquals(data, null, 'Nothing here');
});
var p = Promise.resolve([1, 2, 3]);
p.then((v) => {
assert.deepEquals(v[0], 1, 'It must return 1 here');
var p = _Promise.resolve([1, 2, 3]);
p.then((v) => {
assert.deepEquals(v[0], 1, 'It must return 1 here');
});
var original = _Promise.resolve(true);
var cast = _Promise.resolve(original);
cast.then((v) => {
assert.deepEquals(v, true, 'It must return true here');
});
assert.end();
});
var original = Promise.resolve(true);
var cast = Promise.resolve(original);
cast.then((v) => {
assert.deepEquals(v, true, 'It must return true here');
});
};
assert.end();
});
[PromiseMain, PromiseFull, PromiseMin].map(promiseTest);

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

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