diff options
Diffstat (limited to 'deps/npm/node_modules/util-promisify/test')
-rw-r--r-- | deps/npm/node_modules/util-promisify/test/common.js | 56 | ||||
-rw-r--r-- | deps/npm/node_modules/util-promisify/test/index.js | 194 | ||||
-rw-r--r-- | deps/npm/node_modules/util-promisify/test/timers.js | 38 |
3 files changed, 0 insertions, 288 deletions
diff --git a/deps/npm/node_modules/util-promisify/test/common.js b/deps/npm/node_modules/util-promisify/test/common.js deleted file mode 100644 index 72262b7feb..0000000000 --- a/deps/npm/node_modules/util-promisify/test/common.js +++ /dev/null @@ -1,56 +0,0 @@ -const mustCallChecks = []; - -function runCallChecks(exitCode) { - if (exitCode !== 0) return; - - const failed = mustCallChecks.filter(function(context) { - return context.actual !== context.expected; - }); - - failed.forEach(function(context) { - console.log('Mismatched %s function calls. Expected %d, actual %d.', - context.name, - context.expected, - context.actual); - console.log(context.stack.split('\n').slice(2).join('\n')); - }); - - if (failed.length) process.exit(1); -} - -exports.mustCall = function(fn, expected) { - if (typeof fn === 'number') { - expected = fn; - fn = noop; - } else if (fn === undefined) { - fn = noop; - } - - if (expected === undefined) - expected = 1; - else if (typeof expected !== 'number') - throw new TypeError(`Invalid expected value: ${expected}`); - - const context = { - expected: expected, - actual: 0, - stack: (new Error()).stack, - name: fn.name || '<anonymous>' - }; - - // add the exit listener only once to avoid listener leak warnings - if (mustCallChecks.length === 0) process.on('exit', runCallChecks); - - mustCallChecks.push(context); - - return function() { - context.actual++; - return fn.apply(this, arguments); - }; -}; - -// Crash the process on unhandled rejections. -exports.crashOnUnhandledRejection = function() { - process.on('unhandledRejection', - (err) => process.nextTick(() => { throw err; })); -}; diff --git a/deps/npm/node_modules/util-promisify/test/index.js b/deps/npm/node_modules/util-promisify/test/index.js deleted file mode 100644 index a8e8491628..0000000000 --- a/deps/npm/node_modules/util-promisify/test/index.js +++ /dev/null @@ -1,194 +0,0 @@ -'use strict'; - -const common = require('./common'); -const assert = require('assert'); -const fs = require('fs'); -const vm = require('vm'); -const promisify = require('..'); -//const customPromisifyArgs = require('..').customPromisifyArgs; - -const stat = promisify(fs.stat); - -{ - const promise = stat(__filename); - assert(promise instanceof Promise); - promise.then(common.mustCall((value) => { - assert.deepStrictEqual(value, fs.statSync(__filename)); - })); -} - -{ - const promise = stat('/dontexist'); - promise.catch(common.mustCall((error) => { - assert(error.message.includes('ENOENT: no such file or directory, stat')); - })); -} - -{ - function fn() {} - function promisifedFn() {} - fn[promisify.custom] = promisifedFn; - assert.strictEqual(promisify(fn), promisifedFn); - assert.strictEqual(promisify(promisify(fn)), promisifedFn); -} - -{ - function fn() {} - fn[promisify.custom] = 42; - assert.throws( - () => promisify(fn), - (err) => err instanceof TypeError && - err.message === 'The [util.promisify.custom] property must ' + - 'be a function'); -} - -/*{ - const firstValue = 5; - const secondValue = 17; - - function fn(callback) { - callback(null, firstValue, secondValue); - } - - fn[customPromisifyArgs] = ['first', 'second']; - - promisify(fn)().then(common.mustCall((obj) => { - assert.deepStrictEqual(obj, {first: firstValue, second: secondValue}); - })); -}*/ - -{ - const fn = vm.runInNewContext('(function() {})'); - assert.notStrictEqual(Object.getPrototypeOf(promisify(fn)), - Function.prototype); -} - -{ - function fn(callback) { - callback(null, 'foo', 'bar'); - } - promisify(fn)().then(common.mustCall((value) => { - assert.deepStrictEqual(value, 'foo'); - })); -} - -{ - function fn(callback) { - callback(null); - } - promisify(fn)().then(common.mustCall((value) => { - assert.strictEqual(value, undefined); - })); -} - -{ - function fn(callback) { - callback(); - } - promisify(fn)().then(common.mustCall((value) => { - assert.strictEqual(value, undefined); - })); -} - -{ - function fn(err, val, callback) { - callback(err, val); - } - promisify(fn)(null, 42).then(common.mustCall((value) => { - assert.strictEqual(value, 42); - })); -} - -{ - function fn(err, val, callback) { - callback(err, val); - } - promisify(fn)(new Error('oops'), null).catch(common.mustCall((err) => { - assert.strictEqual(err.message, 'oops'); - })); -} - -if (Number(process.version[1]) >= 7) eval` -{ - - function fn(err, val, callback) { - callback(err, val); - } - - (async () => { - const value = await promisify(fn)(null, 42); - assert.strictEqual(value, 42); - })(); -}` - -{ - const o = {}; - const fn = promisify(function(cb) { - - cb(null, this === o); - }); - - o.fn = fn; - - o.fn().then(common.mustCall(function(val) { - assert(val); - })); -} - -if (Number(process.version[1]) >= 7) eval` -{ - const err = new Error('Should not have called the callback with the error.'); - const stack = err.stack; - - const fn = promisify(function(cb) { - cb(null); - cb(err); - }); - - (async () => { - await fn(); - await Promise.resolve(); - return assert.strictEqual(stack, err.stack); - })(); -}` - -{ - function c() { } - const a = promisify(function() { }); - const b = promisify(a); - assert.notStrictEqual(c, a); - assert.strictEqual(a, b); -} - -{ - let errToThrow; - const thrower = promisify(function(a, b, c, cb) { - errToThrow = new Error(); - throw errToThrow; - }); - thrower(1, 2, 3) - .then(assert.fail) - .then(assert.fail, (e) => assert.strictEqual(e, errToThrow)); -} - -{ - const err = new Error(); - - const a = promisify((cb) => cb(err))(); - const b = promisify(() => { throw err; })(); - - Promise.all([ - a.then(assert.fail, function(e) { - assert.strictEqual(err, e); - }), - b.then(assert.fail, function(e) { - assert.strictEqual(err, e); - }) - ]); -} - -if (Number(process.version[1]) >= 8) -{ - const coreUtil = require('util'); - assert.strictEqual(coreUtil.promisify.custom, promisify.custom); -} diff --git a/deps/npm/node_modules/util-promisify/test/timers.js b/deps/npm/node_modules/util-promisify/test/timers.js deleted file mode 100644 index de12be034d..0000000000 --- a/deps/npm/node_modules/util-promisify/test/timers.js +++ /dev/null @@ -1,38 +0,0 @@ -'use strict'; -const common = require('./common'); -const assert = require('assert'); -const timers = require('timers'); -const promisify = require('..'); - -common.crashOnUnhandledRejection(); - -const setTimeout = promisify(timers.setTimeout); -const setImmediate = promisify(timers.setImmediate); - -{ - const promise = setTimeout(1); - promise.then(common.mustCall((value) => { - assert.strictEqual(value, undefined); - })); -} - -{ - const promise = setTimeout(1, 'foobar'); - promise.then(common.mustCall((value) => { - assert.strictEqual(value, 'foobar'); - })); -} - -{ - const promise = setImmediate(); - promise.then(common.mustCall((value) => { - assert.strictEqual(value, undefined); - })); -} - -{ - const promise = setImmediate('foobar'); - promise.then(common.mustCall((value) => { - assert.strictEqual(value, 'foobar'); - })); -} |