diff --git a/.gitignore b/.gitignore index 7a07923..29f2273 100644 --- a/.gitignore +++ b/.gitignore @@ -1,5 +1,6 @@ /node_modules /coverage +/types ############ ## Windows diff --git a/.prettierignore b/.prettierignore index cce0279..c8c9787 100644 --- a/.prettierignore +++ b/.prettierignore @@ -1,2 +1,3 @@ package.json package-lock.json +types diff --git a/eslint.config.mjs b/eslint.config.mjs index 2379219..d0426f1 100644 --- a/eslint.config.mjs +++ b/eslint.config.mjs @@ -3,7 +3,7 @@ import config from "eslint-config-webpack"; export default defineConfig([ { - ignores: [".changeset/"] + ignores: [".changeset/", "types/"] }, { extends: [config], @@ -19,6 +19,17 @@ export default defineConfig([ } } }, + { + // README code samples use `Function` and `Array<...>` to mirror the + // public `tapable.d.ts` types. Disable the strict TypeScript rules + // for README — they only activate when `typescript` is a direct + // devDependency (added for type generation in `lib/`). + files: ["**/*.md/*"], + rules: { + "@typescript-eslint/no-unsafe-function-type": "off", + "@typescript-eslint/array-type": "off" + } + }, { files: ["benchmark/**/*"], languageOptions: { @@ -32,7 +43,17 @@ export default defineConfig([ "n/hashbang": "off", "n/no-unsupported-features/es-syntax": "off", "n/no-unsupported-features/node-builtins": "off", - "n/no-process-exit": "off" + "n/no-process-exit": "off", + // Benchmark files predate strict JSDoc rules and use loose JSDoc. + // The strict rules only activate when `typescript` is a direct + // devDependency (added for type generation in `lib/`). + "jsdoc/require-jsdoc": "off", + "jsdoc/require-param-description": "off", + "jsdoc/require-returns-description": "off", + "jsdoc/no-restricted-syntax": "off", + "jsdoc/reject-function-type": "off", + "jsdoc/type-formatting": "off", + "jsdoc/tag-lines": "off" } } ]); diff --git a/lib/AsyncParallelBailHook.js b/lib/AsyncParallelBailHook.js index 5cabeaa..d5f1bad 100644 --- a/lib/AsyncParallelBailHook.js +++ b/lib/AsyncParallelBailHook.js @@ -7,10 +7,39 @@ const Hook = require("./Hook"); const HookCodeFactory = require("./HookCodeFactory"); +/** @typedef {import("./Hook").EXPECTED_ANY} EXPECTED_ANY */ +/** @typedef {import("./Hook").EXPECTED_FUNCTION} EXPECTED_FUNCTION */ +/** @typedef {import("./Hook").UnsetAdditionalOptions} UnsetAdditionalOptions */ +/** @typedef {import("./Hook").CompileOptions} CompileOptions */ +/** @typedef {import("./HookCodeFactory").ContentOptions} ContentOptions */ +/** + * @template {EXPECTED_ANY[]} T + * @typedef {import("./Hook").ArgumentNames} ArgumentNames + */ +/** + * @template T + * @typedef {import("./Hook").AsArray} AsArray + */ + +/** + * Mirror of the `AsyncParallelBailHook` class declared in `tapable.d.ts` for + * use as the factory function's return type, so `new AsyncParallelBailHook(...)` + * resolves to the specific subclass type instead of the generic `Hook`. + * @template T + * @template R + * @template [AdditionalOptions=UnsetAdditionalOptions] + * @typedef {import("../tapable").AsyncParallelBailHook} AsyncParallelBailHookType + */ + class AsyncParallelBailHookCodeFactory extends HookCodeFactory { + /** + * @param {ContentOptions} options content generation options + * @returns {string} generated body code + */ content({ onError, onResult, onDone }) { + const opts = /** @type {CompileOptions} */ (this.options); let code = ""; - code += `var _results = new Array(${this.options.taps.length});\n`; + code += `var _results = new Array(${opts.taps.length});\n`; code += "var _checkDone = function() {\n"; code += "for(var i = 0; i < _results.length; i++) {\n"; code += "var item = _results[i];\n"; @@ -68,20 +97,44 @@ class AsyncParallelBailHookCodeFactory extends HookCodeFactory { const factory = new AsyncParallelBailHookCodeFactory(); +/** + * @template T + * @template R + * @template [AdditionalOptions=UnsetAdditionalOptions] + * @this {Hook} + * @param {CompileOptions} options compile options + * @returns {EXPECTED_FUNCTION} the compiled call function + */ function COMPILE(options) { factory.setup(this, options); return factory.create(options); } -function AsyncParallelBailHook(args = [], name = undefined) { +/** + * @constructor + * @template T + * @template R + * @template [AdditionalOptions=UnsetAdditionalOptions] + * @param {ArgumentNames>=} args argument names of the hook + * @param {string=} name name of the hook + * @returns {AsyncParallelBailHookType} a new AsyncParallelBailHook instance + */ +function AsyncParallelBailHook( + args = /** @type {ArgumentNames>} */ (/** @type {unknown} */ ([])), + name = undefined +) { const hook = new Hook(args, name); hook.constructor = AsyncParallelBailHook; hook.compile = COMPILE; + // @ts-expect-error for performance reasons hook._call = undefined; hook.call = undefined; - return hook; + return /** @type {AsyncParallelBailHookType} */ ( + /** @type {unknown} */ (hook) + ); } +/** @type {EXPECTED_ANY} */ AsyncParallelBailHook.prototype = null; module.exports = AsyncParallelBailHook; diff --git a/lib/AsyncParallelHook.js b/lib/AsyncParallelHook.js index 3fa0722..34327b5 100644 --- a/lib/AsyncParallelHook.js +++ b/lib/AsyncParallelHook.js @@ -7,7 +7,34 @@ const Hook = require("./Hook"); const HookCodeFactory = require("./HookCodeFactory"); +/** @typedef {import("./Hook").EXPECTED_ANY} EXPECTED_ANY */ +/** @typedef {import("./Hook").EXPECTED_FUNCTION} EXPECTED_FUNCTION */ +/** @typedef {import("./Hook").CompileOptions} CompileOptions */ +/** @typedef {import("./Hook").UnsetAdditionalOptions} UnsetAdditionalOptions */ +/** @typedef {import("./HookCodeFactory").ContentOptions} ContentOptions */ +/** + * @template {EXPECTED_ANY[]} T + * @typedef {import("./Hook").ArgumentNames} ArgumentNames + */ +/** + * @template T + * @typedef {import("./Hook").AsArray} AsArray + */ + +/** + * Mirror of the `AsyncParallelHook` class declared in `tapable.d.ts` for use + * as the factory function's return type, so `new AsyncParallelHook(...)` + * resolves to the specific subclass type instead of the generic `Hook`. + * @template T + * @template [AdditionalOptions=UnsetAdditionalOptions] + * @typedef {import("../tapable").AsyncParallelHook} AsyncParallelHookType + */ + class AsyncParallelHookCodeFactory extends HookCodeFactory { + /** + * @param {ContentOptions} options content generation options + * @returns {string} generated body code + */ content({ onError, onDone }) { return this.callTapsParallel({ onError: (i, err, done, doneBreak) => onError(err) + doneBreak(true), @@ -18,20 +45,40 @@ class AsyncParallelHookCodeFactory extends HookCodeFactory { const factory = new AsyncParallelHookCodeFactory(); +/** + * @this {Hook} + * @param {CompileOptions} options compile options + * @returns {EXPECTED_FUNCTION} the compiled call function + */ function COMPILE(options) { factory.setup(this, options); return factory.create(options); } -function AsyncParallelHook(args = [], name = undefined) { +/** + * @constructor + * @template T + * @template [AdditionalOptions=UnsetAdditionalOptions] + * @param {ArgumentNames>=} args argument names of the hook + * @param {string=} name name of the hook + * @returns {AsyncParallelHookType} a new AsyncParallelHook instance + */ +function AsyncParallelHook( + args = /** @type {ArgumentNames>} */ (/** @type {unknown} */ ([])), + name = undefined +) { const hook = new Hook(args, name); hook.constructor = AsyncParallelHook; hook.compile = COMPILE; + // @ts-expect-error for performance reasons hook._call = undefined; hook.call = undefined; - return hook; + return /** @type {AsyncParallelHookType} */ ( + /** @type {unknown} */ (hook) + ); } +/** @type {EXPECTED_ANY} */ AsyncParallelHook.prototype = null; module.exports = AsyncParallelHook; diff --git a/lib/AsyncSeriesBailHook.js b/lib/AsyncSeriesBailHook.js index a46d3d2..f247b43 100644 --- a/lib/AsyncSeriesBailHook.js +++ b/lib/AsyncSeriesBailHook.js @@ -7,7 +7,35 @@ const Hook = require("./Hook"); const HookCodeFactory = require("./HookCodeFactory"); +/** @typedef {import("./Hook").EXPECTED_ANY} EXPECTED_ANY */ +/** @typedef {import("./Hook").EXPECTED_FUNCTION} EXPECTED_FUNCTION */ +/** @typedef {import("./Hook").CompileOptions} CompileOptions */ +/** @typedef {import("./Hook").UnsetAdditionalOptions} UnsetAdditionalOptions */ +/** @typedef {import("./HookCodeFactory").ContentOptions} ContentOptions */ +/** + * @template {EXPECTED_ANY[]} T + * @typedef {import("./Hook").ArgumentNames} ArgumentNames + */ +/** + * @template T + * @typedef {import("./Hook").AsArray} AsArray + */ + +/** + * Mirror of the `AsyncSeriesBailHook` class declared in `tapable.d.ts` for + * use as the factory function's return type, so `new AsyncSeriesBailHook(...)` + * resolves to the specific subclass type instead of the generic `Hook`. + * @template T + * @template R + * @template [AdditionalOptions=UnsetAdditionalOptions] + * @typedef {import("../tapable").AsyncSeriesBailHook} AsyncSeriesBailHookType + */ + class AsyncSeriesBailHookCodeFactory extends HookCodeFactory { + /** + * @param {ContentOptions} options content generation options + * @returns {string} generated body code + */ content({ onError, onResult, resultReturns, onDone }) { return this.callTapsSeries({ onError: (i, err, next, doneBreak) => onError(err) + doneBreak(true), @@ -23,20 +51,41 @@ class AsyncSeriesBailHookCodeFactory extends HookCodeFactory { const factory = new AsyncSeriesBailHookCodeFactory(); +/** + * @this {Hook} + * @param {CompileOptions} options compile options + * @returns {EXPECTED_FUNCTION} the compiled call function + */ function COMPILE(options) { factory.setup(this, options); return factory.create(options); } -function AsyncSeriesBailHook(args = [], name = undefined) { +/** + * @constructor + * @template T + * @template R + * @template [AdditionalOptions=UnsetAdditionalOptions] + * @param {ArgumentNames>=} args argument names of the hook + * @param {string=} name name of the hook + * @returns {AsyncSeriesBailHookType} a new AsyncSeriesBailHook instance + */ +function AsyncSeriesBailHook( + args = /** @type {ArgumentNames>} */ (/** @type {unknown} */ ([])), + name = undefined +) { const hook = new Hook(args, name); hook.constructor = AsyncSeriesBailHook; hook.compile = COMPILE; + // @ts-expect-error for performance reasons hook._call = undefined; hook.call = undefined; - return hook; + return /** @type {AsyncSeriesBailHookType} */ ( + /** @type {unknown} */ (hook) + ); } +/** @type {EXPECTED_ANY} */ AsyncSeriesBailHook.prototype = null; module.exports = AsyncSeriesBailHook; diff --git a/lib/AsyncSeriesHook.js b/lib/AsyncSeriesHook.js index 569d480..d23ff9a 100644 --- a/lib/AsyncSeriesHook.js +++ b/lib/AsyncSeriesHook.js @@ -7,7 +7,34 @@ const Hook = require("./Hook"); const HookCodeFactory = require("./HookCodeFactory"); +/** @typedef {import("./Hook").EXPECTED_ANY} EXPECTED_ANY */ +/** @typedef {import("./Hook").EXPECTED_FUNCTION} EXPECTED_FUNCTION */ +/** @typedef {import("./Hook").CompileOptions} CompileOptions */ +/** @typedef {import("./Hook").UnsetAdditionalOptions} UnsetAdditionalOptions */ +/** @typedef {import("./HookCodeFactory").ContentOptions} ContentOptions */ +/** + * @template {EXPECTED_ANY[]} T + * @typedef {import("./Hook").ArgumentNames} ArgumentNames + */ +/** + * @template T + * @typedef {import("./Hook").AsArray} AsArray + */ + +/** + * Mirror of the `AsyncSeriesHook` class declared in `tapable.d.ts` for use + * as the factory function's return type, so `new AsyncSeriesHook(...)` + * resolves to the specific subclass type instead of the generic `Hook`. + * @template T + * @template [AdditionalOptions=UnsetAdditionalOptions] + * @typedef {import("../tapable").AsyncSeriesHook} AsyncSeriesHookType + */ + class AsyncSeriesHookCodeFactory extends HookCodeFactory { + /** + * @param {ContentOptions} options content generation options + * @returns {string} generated body code + */ content({ onError, onDone }) { return this.callTapsSeries({ onError: (i, err, next, doneBreak) => onError(err) + doneBreak(true), @@ -18,20 +45,40 @@ class AsyncSeriesHookCodeFactory extends HookCodeFactory { const factory = new AsyncSeriesHookCodeFactory(); +/** + * @this {Hook} + * @param {CompileOptions} options compile options + * @returns {EXPECTED_FUNCTION} the compiled call function + */ function COMPILE(options) { factory.setup(this, options); return factory.create(options); } -function AsyncSeriesHook(args = [], name = undefined) { +/** + * @constructor + * @template T + * @template [AdditionalOptions=UnsetAdditionalOptions] + * @param {ArgumentNames>=} args argument names of the hook + * @param {string=} name name of the hook + * @returns {AsyncSeriesHookType} a new AsyncSeriesHook instance + */ +function AsyncSeriesHook( + args = /** @type {ArgumentNames>} */ (/** @type {unknown} */ ([])), + name = undefined +) { const hook = new Hook(args, name); hook.constructor = AsyncSeriesHook; hook.compile = COMPILE; + // @ts-expect-error for performance reasons hook._call = undefined; hook.call = undefined; - return hook; + return /** @type {AsyncSeriesHookType} */ ( + /** @type {unknown} */ (hook) + ); } +/** @type {EXPECTED_ANY} */ AsyncSeriesHook.prototype = null; module.exports = AsyncSeriesHook; diff --git a/lib/AsyncSeriesLoopHook.js b/lib/AsyncSeriesLoopHook.js index 5c3c21d..5765eb3 100644 --- a/lib/AsyncSeriesLoopHook.js +++ b/lib/AsyncSeriesLoopHook.js @@ -7,7 +7,34 @@ const Hook = require("./Hook"); const HookCodeFactory = require("./HookCodeFactory"); +/** @typedef {import("./Hook").EXPECTED_ANY} EXPECTED_ANY */ +/** @typedef {import("./Hook").EXPECTED_FUNCTION} EXPECTED_FUNCTION */ +/** @typedef {import("./Hook").CompileOptions} CompileOptions */ +/** @typedef {import("./Hook").UnsetAdditionalOptions} UnsetAdditionalOptions */ +/** @typedef {import("./HookCodeFactory").ContentOptions} ContentOptions */ +/** + * @template {EXPECTED_ANY[]} T + * @typedef {import("./Hook").ArgumentNames} ArgumentNames + */ +/** + * @template T + * @typedef {import("./Hook").AsArray} AsArray + */ + +/** + * Mirror of the `AsyncSeriesLoopHook` class declared in `tapable.d.ts` for + * use as the factory function's return type, so `new AsyncSeriesLoopHook(...)` + * resolves to the specific subclass type instead of the generic `Hook`. + * @template T + * @template [AdditionalOptions=UnsetAdditionalOptions] + * @typedef {import("../tapable").AsyncSeriesLoopHook} AsyncSeriesLoopHookType + */ + class AsyncSeriesLoopHookCodeFactory extends HookCodeFactory { + /** + * @param {ContentOptions} options content generation options + * @returns {string} generated body code + */ content({ onError, onDone }) { return this.callTapsLooping({ onError: (i, err, next, doneBreak) => onError(err) + doneBreak(true), @@ -18,20 +45,40 @@ class AsyncSeriesLoopHookCodeFactory extends HookCodeFactory { const factory = new AsyncSeriesLoopHookCodeFactory(); +/** + * @this {Hook} + * @param {CompileOptions} options compile options + * @returns {EXPECTED_FUNCTION} the compiled call function + */ function COMPILE(options) { factory.setup(this, options); return factory.create(options); } -function AsyncSeriesLoopHook(args = [], name = undefined) { +/** + * @constructor + * @template T + * @template [AdditionalOptions=UnsetAdditionalOptions] + * @param {ArgumentNames>=} args argument names of the hook + * @param {string=} name name of the hook + * @returns {AsyncSeriesLoopHookType} a new AsyncSeriesLoopHook instance + */ +function AsyncSeriesLoopHook( + args = /** @type {ArgumentNames>} */ (/** @type {unknown} */ ([])), + name = undefined +) { const hook = new Hook(args, name); hook.constructor = AsyncSeriesLoopHook; hook.compile = COMPILE; + // @ts-expect-error for performance reasons hook._call = undefined; hook.call = undefined; - return hook; + return /** @type {AsyncSeriesLoopHookType} */ ( + /** @type {unknown} */ (hook) + ); } +/** @type {EXPECTED_ANY} */ AsyncSeriesLoopHook.prototype = null; module.exports = AsyncSeriesLoopHook; diff --git a/lib/AsyncSeriesWaterfallHook.js b/lib/AsyncSeriesWaterfallHook.js index 21a0701..4cc48c0 100644 --- a/lib/AsyncSeriesWaterfallHook.js +++ b/lib/AsyncSeriesWaterfallHook.js @@ -7,42 +7,92 @@ const Hook = require("./Hook"); const HookCodeFactory = require("./HookCodeFactory"); +/** @typedef {import("./Hook").EXPECTED_ANY} EXPECTED_ANY */ +/** @typedef {import("./Hook").EXPECTED_FUNCTION} EXPECTED_FUNCTION */ +/** @typedef {import("./Hook").CompileOptions} CompileOptions */ +/** @typedef {import("./Hook").UnsetAdditionalOptions} UnsetAdditionalOptions */ +/** @typedef {import("./HookCodeFactory").ContentOptions} ContentOptions */ +/** + * @template {EXPECTED_ANY[]} T + * @typedef {import("./Hook").ArgumentNames} ArgumentNames + */ +/** + * @template T + * @typedef {import("./Hook").AsArray} AsArray + */ + +/** + * Mirror of the `AsyncSeriesWaterfallHook` class declared in `tapable.d.ts` + * for use as the factory function's return type, so + * `new AsyncSeriesWaterfallHook(...)` resolves to the specific subclass type + * instead of the generic `Hook`. + * @template T + * @template [R=AsArray[0]] + * @template [AdditionalOptions=UnsetAdditionalOptions] + * @typedef {import("../tapable").AsyncSeriesWaterfallHook} AsyncSeriesWaterfallHookType + */ + class AsyncSeriesWaterfallHookCodeFactory extends HookCodeFactory { - content({ onError, onResult, _onDone }) { + /** + * @param {ContentOptions} options content generation options + * @returns {string} generated body code + */ + content({ onError, onResult }) { return this.callTapsSeries({ onError: (i, err, next, doneBreak) => onError(err) + doneBreak(true), onResult: (i, result, next) => { let code = ""; code += `if(${result} !== undefined) {\n`; - code += `${this._args[0]} = ${result};\n`; + code += `${/** @type {string[]} */ (this._args)[0]} = ${result};\n`; code += "}\n"; code += next(); return code; }, - onDone: () => onResult(this._args[0]) + onDone: () => onResult(/** @type {string[]} */ (this._args)[0]) }); } } const factory = new AsyncSeriesWaterfallHookCodeFactory(); +/** + * @this {Hook} + * @param {CompileOptions} options compile options + * @returns {EXPECTED_FUNCTION} the compiled call function + */ function COMPILE(options) { factory.setup(this, options); return factory.create(options); } -function AsyncSeriesWaterfallHook(args = [], name = undefined) { +/** + * @constructor + * @template T + * @template [R=AsArray[0]] + * @template [AdditionalOptions=UnsetAdditionalOptions] + * @param {ArgumentNames>=} args argument names of the hook + * @param {string=} name name of the hook + * @returns {AsyncSeriesWaterfallHookType} a new AsyncSeriesWaterfallHook instance + */ +function AsyncSeriesWaterfallHook( + args = /** @type {ArgumentNames>} */ (/** @type {unknown} */ ([])), + name = undefined +) { if (args.length < 1) { throw new Error("Waterfall hooks must have at least one argument"); } const hook = new Hook(args, name); hook.constructor = AsyncSeriesWaterfallHook; hook.compile = COMPILE; + // @ts-expect-error for performance reasons hook._call = undefined; hook.call = undefined; - return hook; + return /** @type {AsyncSeriesWaterfallHookType} */ ( + /** @type {unknown} */ (hook) + ); } +/** @type {EXPECTED_ANY} */ AsyncSeriesWaterfallHook.prototype = null; module.exports = AsyncSeriesWaterfallHook; diff --git a/lib/Hook.js b/lib/Hook.js index 5bf7417..851fb3c 100644 --- a/lib/Hook.js +++ b/lib/Hook.js @@ -6,38 +6,222 @@ const util = require("util"); +// eslint-disable-next-line jsdoc/reject-function-type +/** @typedef {Function} EXPECTED_FUNCTION */ +// eslint-disable-next-line jsdoc/reject-any-type +/** @typedef {any} EXPECTED_ANY */ +/** @typedef {Record} EXPECTED_OBJECT */ + +/** + * @template T + * @typedef {T extends EXPECTED_ANY[] ? T : [T]} AsArray + */ + +/** + * @template {number} T + * @typedef {T extends 0 | 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 ? T : never} Measure + */ + +/** + * @template {EXPECTED_ANY[]} T + * @template U + * @typedef {{ + * 0: [U]; + * 1: [T[0], U]; + * 2: [T[0], T[1], U]; + * 3: [T[0], T[1], T[2], U]; + * 4: [T[0], T[1], T[2], T[3], U]; + * 5: [T[0], T[1], T[2], T[3], T[4], U]; + * 6: [T[0], T[1], T[2], T[3], T[4], T[5], U]; + * 7: [T[0], T[1], T[2], T[3], T[4], T[5], T[6], U]; + * 8: [T[0], T[1], T[2], T[3], T[4], T[5], T[6], T[7], U]; + * }[Measure]} Append + */ + +/* eslint-disable jsdoc/ts-no-empty-object-type */ +/** + * @template X + * @typedef {X extends UnsetAdditionalOptions ? { } : X} IfSet + */ +/* eslint-enable jsdoc/ts-no-empty-object-type */ + +/** + * @template {number} T + * @template U + * @typedef {T extends 0 ? void[] : ReadonlyArray & { 0: U, length: T }} FixedSizeArray + */ + +/** + * @template {EXPECTED_ANY[]} T + * @typedef {FixedSizeArray} ArgumentNames + */ + +/** + * @typedef {object} TapOptions + * @property {string=} before name of an earlier tap to insert this tap before + * @property {number=} stage stage to schedule the tap in (lower runs earlier) + */ + +/** + * @typedef {TapOptions & { name: string }} Tap + */ + +/** + * @typedef {Tap & { type: "sync" | "async" | "promise", fn: EXPECTED_FUNCTION }} FullTap + */ + +/** + * @template E, T + * @typedef {(error: E | null, result?: T) => void} Callback + */ + +/** + * @template E, T + * @typedef {(error?: E | null | false, result?: T) => void} InnerCallback + */ + +// TODO remove context in the next major release, deprecated +/** + * @template T + * @template R + * @template [AdditionalOptions=UnsetAdditionalOptions] + * @typedef {object} HookInterceptor + * @property {string=} name optional name of the interceptor + * @property {((tap: FullTap & IfSet) => void)=} tap called for each tap before it runs + * @property {((...args: EXPECTED_ANY[]) => void)=} call called when the hook is called + * @property {((...args: EXPECTED_ANY[]) => void)=} loop called for each loop iteration of looping hooks + * @property {((err: Error) => void)=} error called when an error occurs + * @property {((result: R) => void)=} result called with the hook's result + * @property {(() => void)=} done called when the hook is fully done + * @property {((tap: FullTap & IfSet) => FullTap & IfSet)=} register called whenever a tap is registered + * @property {boolean=} context true to pass a `_context` argument to interceptor callbacks + */ + +/** + * @typedef {object} UnsetAdditionalOptions + * @property {true} _UnsetAdditionalOptions unset + */ + +/** + * @template T + * @template R + * @template [AdditionalOptions=UnsetAdditionalOptions] + * @typedef {object} CompileOptions + * @property {FullTap[]} taps the registered taps + * @property {HookInterceptor[]} interceptors the registered interceptors + * @property {ArgumentNames>} args names of the hook arguments (used for code generation) + * @property {"sync" | "async" | "promise"} type call type + */ + const deprecateContext = util.deprecate( () => {}, "Hook.context is deprecated and will be removed" ); +/** + * @template T, R + * @callback CallDelegate + * @param {...AsArray} args + * @returns {R} + */ + +/** + * @template T, R + * @type {CallDelegate} + * @this {Hook} + */ function CALL_DELEGATE(...args) { + // @ts-expect-error for performance reasons this.call = this._createCall("sync"); + // @ts-expect-error for performance reasons return this.call(...args); } +/** + * @template T, R + * @callback CallAsyncDelegate + * @param {...Append, Callback>} args + * @returns void + */ + +/** + * @template T, R + * @type {CallAsyncDelegate} + * @this {Hook} + */ function CALL_ASYNC_DELEGATE(...args) { + // @ts-expect-error for performance reasons this.callAsync = this._createCall("async"); return this.callAsync(...args); } +/** + * @template T, R + * @callback PromiseDeledate + * @param {...AsArray} args + * @returns {Promise} + */ + +/** + * @template T, R + * @type {PromiseDeledate} + * @this {Hook} + */ function PROMISE_DELEGATE(...args) { + // @ts-expect-error for performance reasons this.promise = this._createCall("promise"); return this.promise(...args); } +/** + * @template T + * @template R + * @template [AdditionalOptions=UnsetAdditionalOptions] + */ class Hook { - constructor(args = [], name = undefined) { + /** + * @param {ArgumentNames>=} args argument names of the hook (used for code generation) + * @param {string=} name name of the hook + */ + constructor( + args = /** @type {ArgumentNames>} */ ( + /** @type {unknown} */ ([]) + ), + name = undefined + ) { + /** + * @private + * @type {ArgumentNames>} + */ this._args = args; + /** @type {string | undefined} */ this.name = name; + /** @type {FullTap[]} */ this.taps = []; + /** @type {HookInterceptor[]} */ this.interceptors = []; + /** + * @private + * @type {CallDelegate | undefined} + */ this._call = CALL_DELEGATE; + /** @type {CallDelegate | undefined} */ this.call = CALL_DELEGATE; + /** + * @private + * @type {CallAsyncDelegate} + */ this._callAsync = CALL_ASYNC_DELEGATE; + /** @type {CallAsyncDelegate} */ this.callAsync = CALL_ASYNC_DELEGATE; + /** + * @private + * @type {PromiseDeledate} + */ this._promise = PROMISE_DELEGATE; + /** @type {PromiseDeledate} */ this.promise = PROMISE_DELEGATE; + /** @type {EXPECTED_FUNCTION[] | undefined} */ this._x = undefined; // eslint-disable-next-line no-self-assign @@ -50,10 +234,20 @@ class Hook { this.tapPromise = this.tapPromise; } + /** + * @abstract + * @param {CompileOptions} _options compile options + * @returns {EXPECTED_FUNCTION} the compiled call function + */ compile(_options) { throw new Error("Abstract: should be overridden"); } + /** + * @private + * @param {"sync" | "async" | "promise"} type the call type + * @returns {EXPECTED_FUNCTION} the compiled call function + */ _createCall(type) { return this.compile({ taps: this.taps, @@ -63,6 +257,13 @@ class Hook { }); } + /** + * @private + * @param {"sync" | "async" | "promise"} type the tap type + * @param {string | (Tap & IfSet)} options name or full tap options + * @param {EXPECTED_FUNCTION} fn callback registered with the tap + * @returns {void} + */ _tap(type, options, fn) { if (typeof options === "string") { // Fast path: a string options ("name") is by far the most common @@ -72,7 +273,9 @@ class Hook { if (name === "") { throw new Error("Missing name for tap"); } - options = { type, fn, name }; + options = + /** @type {FullTap & IfSet} */ + ({ type, fn, name }); } else { if (typeof options !== "object" || options === null) { throw new Error("Invalid tap options"); @@ -84,7 +287,10 @@ class Hook { if (typeof name !== "string" || name === "") { throw new Error("Missing name for tap"); } - if (typeof options.context !== "undefined") { + if ( + typeof (/** @type {{ context?: unknown }} */ (options).context) !== + "undefined" + ) { deprecateContext(); } // Fast path: only `name` is set. Build the descriptor as a literal @@ -101,29 +307,57 @@ class Hook { } } if (onlyName) { - options = { type, fn, name }; + options = + /** @type {FullTap & IfSet} */ + ({ type, fn, name }); } else { options.name = name; // Preserve previous precedence: user-provided keys win over the internal `type`/`fn`. options = Object.assign({ type, fn }, options); } } - options = this._runRegisterInterceptors(options); - this._insert(options); + options = this._runRegisterInterceptors( + /** @type {FullTap & IfSet} */ + (options) + ); + this._insert( + /** @type {FullTap & IfSet} */ + (options) + ); } + /** + * @param {string | (Tap & IfSet)} options tap name or full tap options + * @param {(...args: AsArray) => R} fn the function to register + * @returns {void} + */ tap(options, fn) { this._tap("sync", options, fn); } + /** + * @param {string | (Tap & IfSet)} options tap name or full tap options + * @param {(...args: Append, InnerCallback>) => void} fn the function to register + * @returns {void} + */ tapAsync(options, fn) { this._tap("async", options, fn); } + /** + * @param {string | (Tap & IfSet)} options tap name or full tap options + * @param {(...args: AsArray) => Promise} fn the function to register + * @returns {void} + */ tapPromise(options, fn) { this._tap("promise", options, fn); } + /** + * @private + * @param {FullTap & IfSet} options the tap descriptor + * @returns {FullTap & IfSet} possibly transformed options + */ _runRegisterInterceptors(options) { const { interceptors } = this; const { length } = interceptors; @@ -141,11 +375,25 @@ class Hook { return options; } + /** + * @param {TapOptions & IfSet} options the options to merge into each tap + * @returns {Omit} a wrapper that pre-applies the options + */ withOptions(options) { + /** + * @param {string | (TapOptions & IfSet)} opt options + * @returns {Tap & IfSet} merged options + */ const mergeOptions = (opt) => - Object.assign({}, options, typeof opt === "string" ? { name: opt } : opt); + /** @type {Tap & IfSet} */ ( + Object.assign( + {}, + options, + typeof opt === "string" ? { name: opt } : opt + ) + ); - return { + return /** @type {Omit} */ ({ name: this.name, tap: (opt, fn) => this.tap(mergeOptions(opt), fn), tapAsync: (opt, fn) => this.tapAsync(mergeOptions(opt), fn), @@ -153,29 +401,47 @@ class Hook { intercept: (interceptor) => this.intercept(interceptor), isUsed: () => this.isUsed(), withOptions: (opt) => this.withOptions(mergeOptions(opt)) - }; + }); } + /** + * @returns {boolean} true if the hook has any taps or interceptors registered + */ isUsed() { return this.taps.length > 0 || this.interceptors.length > 0; } + /** + * @param {HookInterceptor} interceptor the interceptor to register + * @returns {void} + */ intercept(interceptor) { this._resetCompilation(); this.interceptors.push(Object.assign({}, interceptor)); if (interceptor.register) { for (let i = 0; i < this.taps.length; i++) { - this.taps[i] = interceptor.register(this.taps[i]); + this.taps[i] = interceptor.register( + /** @type {FullTap & IfSet} */ (this.taps[i]) + ); } } } + /** + * @private + * @returns {void} + */ _resetCompilation() { this.call = this._call; this.callAsync = this._callAsync; this.promise = this._promise; } + /** + * @private + * @param {FullTap & IfSet} item the tap to insert into the ordered taps list + * @returns {void} + */ _insert(item) { this._resetCompilation(); const { taps } = this; @@ -194,6 +460,7 @@ class Hook { } } + /** @type {Set | undefined} */ let before; if (typeof item.before === "string") { diff --git a/lib/HookCodeFactory.js b/lib/HookCodeFactory.js index 2e0e6c1..598ceab 100644 --- a/lib/HookCodeFactory.js +++ b/lib/HookCodeFactory.js @@ -4,15 +4,86 @@ */ "use strict"; +/** @typedef {import("./Hook").EXPECTED_ANY} EXPECTED_ANY */ +/** @typedef {import("./Hook").EXPECTED_OBJECT} EXPECTED_OBJECT */ +/** @typedef {import("./Hook").EXPECTED_FUNCTION} EXPECTED_FUNCTION */ +/** @typedef {import("./Hook").FullTap} FullTap */ +/** @typedef {import("./Hook").CompileOptions} CompileOptions */ + +/** + * @template T, R, AdditionalOptions + * @typedef {import("./Hook").HookInterceptor} HookInterceptor + */ + +/** + * @template T, R, AdditionalOptions + * @typedef {import("./Hook")} Hook + */ + +/** + * @typedef {(error: string) => string} OnErrorCallback + */ + +/** + * @typedef {(result: string) => string} OnResultCallback + */ + +/** + * @typedef {() => string} OnDoneCallback + */ + +/** + * @typedef {object} ContentOptions + * @property {OnErrorCallback} onError generates code for handling an error + * @property {OnResultCallback} onResult generates code for handling a result + * @property {OnDoneCallback} onDone generates code for completion + * @property {boolean=} resultReturns true if the generated function returns a result + * @property {boolean=} doneReturns true if the generated function returns when done + * @property {boolean=} rethrowIfPossible true to rethrow errors when safe + */ + +/** + * @typedef {object} CallTapOptions + * @property {OnErrorCallback} onError generates code for handling an error + * @property {OnResultCallback=} onResult generates code for handling a result + * @property {OnDoneCallback=} onDone generates code for completion + * @property {boolean=} rethrowIfPossible true to rethrow errors when safe + */ + +/** + * @typedef {object} CallTapsOptions + * @property {((tapIndex: number, error: string, next: () => string, doneBreak: (skipDone: boolean) => string) => string)} onError generates code for handling an error + * @property {((tapIndex: number, result: string, next: () => string, doneBreak: (skipDone: boolean) => string) => string)=} onResult generates code for handling a result + * @property {OnDoneCallback} onDone generates code for completion + * @property {boolean=} rethrowIfPossible true to rethrow errors when safe + * @property {boolean=} doneReturns true if the generated function returns when done + * @property {boolean=} resultReturns true if the generated function returns a result + */ + +/** + * @typedef {object} CallTapsParallelOptions + * @property {((tapIndex: number, error: string, next: () => string, doneBreak: (skipDone: boolean) => string) => string)} onError generates code for handling an error + * @property {((tapIndex: number, result: string, next: () => string, doneBreak: (skipDone: boolean) => string) => string)=} onResult generates code for handling a result + * @property {(tapIndex: number, run: () => string, done: () => string, doneBreak: (skipDone: boolean) => string) => string=} onTap options + * @property {OnDoneCallback=} onDone generates code for completion + * @property {boolean=} rethrowIfPossible true to rethrow errors when safe + */ + class HookCodeFactory { - constructor(config) { - this.config = config; + constructor() { + /** @type {CompileOptions | undefined} */ this.options = undefined; + /** @type {string[] | undefined} */ this._args = undefined; } + /** + * @param {CompileOptions} options compile options + * @returns {EXPECTED_FUNCTION} the compiled hook function + */ create(options) { this.init(options); + /** @type {EXPECTED_FUNCTION} */ let fn; switch (options.type) { case "sync": @@ -21,8 +92,8 @@ class HookCodeFactory { `"use strict";\n${this.header()}${this.contentWithInterceptors({ onError: (err) => `throw ${err};\n`, onResult: (result) => `return ${result};\n`, - resultReturns: true, onDone: () => "", + resultReturns: true, rethrowIfPossible: true })}` ); @@ -76,9 +147,15 @@ class HookCodeFactory { return fn; } + /** + * @param {Hook} instance the hook instance to attach the resolved tap function array to + * @param {CompileOptions} options compile options containing the taps + * @returns {void} + */ setup(instance, options) { const { taps } = options; const { length } = taps; + /** @type {EXPECTED_FUNCTION[]}} */ const fns = Array.from({ length }); for (let i = 0; i < length; i++) { fns[i] = taps[i].fn; @@ -87,107 +164,146 @@ class HookCodeFactory { } /** - * @param {{ type: "sync" | "promise" | "async", taps: Array, interceptors: Array }} options + * @param {CompileOptions} options compile options + * @returns {void} */ init(options) { this.options = options; // `_args` is only read (length / join / [0]) - never mutated - so we // can share the caller's array directly instead of paying for a copy // on every compile. - this._args = options.args; + this._args = /** @type {string[]} */ ( + /** @type {unknown} */ (options.args) + ); + /** @type {string | undefined} */ this._joinedArgs = undefined; } + /** + * @returns {void} + */ deinit() { this.options = undefined; this._args = undefined; this._joinedArgs = undefined; } + /** + * @param {ContentOptions} options content generation options + * @returns {string} generated code with interceptor calls wrapped around content + */ contentWithInterceptors(options) { - if (this.options.interceptors.length > 0) { + if (/** @type {CompileOptions} */ (this.options).interceptors.length > 0) { const { onError, onResult, onDone } = options; let code = ""; - for (let i = 0; i < this.options.interceptors.length; i++) { - const interceptor = this.options.interceptors[i]; + const opts = /** @type {CompileOptions} */ (this.options); + for (let i = 0; i < opts.interceptors.length; i++) { + const interceptor = opts.interceptors[i]; if (interceptor.call) { code += `${this.getInterceptor(i)}.call(${this.args({ before: interceptor.context ? "_context" : undefined })});\n`; } } + // `content` is intentionally not declared on the base class - it's + // abstract and provided by every subclass. Skipping the runtime + // stub keeps the prototype chain mononomorphic on the hot compile + // path: subclass `content` is the only one V8 sees, no shadowing. + // @ts-expect-error abstract method, provided by subclasses for performance reasons code += this.content( Object.assign(options, { onError: onError && - ((err) => { - let code = ""; - for (let i = 0; i < this.options.interceptors.length; i++) { - const interceptor = this.options.interceptors[i]; - if (interceptor.error) { - code += `${this.getInterceptor(i)}.error(${err});\n`; + /** @type {OnErrorCallback} */ + ( + (err) => { + let code = ""; + for (let i = 0; i < opts.interceptors.length; i++) { + const interceptor = opts.interceptors[i]; + if (interceptor.error) { + code += `${this.getInterceptor(i)}.error(${err});\n`; + } } + code += onError(err); + return code; } - code += onError(err); - return code; - }), + ), onResult: onResult && - ((result) => { - let code = ""; - for (let i = 0; i < this.options.interceptors.length; i++) { - const interceptor = this.options.interceptors[i]; - if (interceptor.result) { - code += `${this.getInterceptor(i)}.result(${result});\n`; + /** @type {OnResultCallback} */ + ( + (result) => { + let code = ""; + for (let i = 0; i < opts.interceptors.length; i++) { + const interceptor = opts.interceptors[i]; + if (interceptor.result) { + code += `${this.getInterceptor(i)}.result(${result});\n`; + } } + code += onResult(result); + return code; } - code += onResult(result); - return code; - }), + ), onDone: onDone && - (() => { - let code = ""; - for (let i = 0; i < this.options.interceptors.length; i++) { - const interceptor = this.options.interceptors[i]; - if (interceptor.done) { - code += `${this.getInterceptor(i)}.done();\n`; + /** @type {OnDoneCallback} */ + ( + () => { + let code = ""; + for (let i = 0; i < opts.interceptors.length; i++) { + const interceptor = opts.interceptors[i]; + if (interceptor.done) { + code += `${this.getInterceptor(i)}.done();\n`; + } } + code += onDone(); + return code; } - code += onDone(); - return code; - }) + ) }) ); return code; } + // @ts-expect-error abstract method, provided by subclasses for performance reasons return this.content(options); } + /** + * @returns {string} generated header preamble shared across all call types + */ header() { let code = ""; code += this.needContext() ? "var _context = {};\n" : "var _context;\n"; code += "var _x = this._x;\n"; - if (this.options.interceptors.length > 0) { + if (/** @type {CompileOptions} */ (this.options).interceptors.length > 0) { code += "var _taps = this.taps;\n"; code += "var _interceptors = this.interceptors;\n"; } return code; } + /** + * @returns {boolean} true if any tap requested a `_context` + */ needContext() { - const { taps } = this.options; + const { taps } = /** @type {CompileOptions} */ (this.options); for (let i = 0; i < taps.length; i++) { - if (taps[i].context) return true; + if (/** @type {{ context?: boolean }} */ (taps[i]).context) return true; } return false; } + /** + * @param {number} tapIndex index of the tap to call + * @param {CallTapOptions} options content generation options + * @returns {string} generated code that invokes the tap + */ callTap(tapIndex, { onError, onResult, onDone, rethrowIfPossible }) { let code = ""; let hasTapCached = false; - for (let i = 0; i < this.options.interceptors.length; i++) { - const interceptor = this.options.interceptors[i]; + const opts = /** @type {CompileOptions} */ (this.options); + for (let i = 0; i < opts.interceptors.length; i++) { + const interceptor = opts.interceptors[i]; if (interceptor.tap) { if (!hasTapCached) { code += `var _tap${tapIndex} = ${this.getTap(tapIndex)};\n`; @@ -199,7 +315,9 @@ class HookCodeFactory { } } code += `var _fn${tapIndex} = ${this.getTapFn(tapIndex)};\n`; - const tap = this.options.taps[tapIndex]; + const tap = + /** @type {FullTap & { context?: boolean }} */ + (opts.taps[tapIndex]); switch (tap.type) { case "sync": if (!rethrowIfPossible) { @@ -280,6 +398,10 @@ class HookCodeFactory { return code; } + /** + * @param {CallTapsOptions} options series-call options + * @returns {string} generated code calling all taps in series + */ callTapsSeries({ onError, onResult, @@ -288,7 +410,7 @@ class HookCodeFactory { doneReturns, rethrowIfPossible }) { - const { taps } = this.options; + const { taps } = /** @type {CompileOptions} */ (this.options); const tapsLength = taps.length; if (tapsLength === 0) return onDone(); // Inlined findIndex to avoid the callback allocation. @@ -301,6 +423,10 @@ class HookCodeFactory { } const somethingReturns = resultReturns || doneReturns; // doneBreak doesn't depend on the loop variable - hoist to allocate once. + /** + * @param {boolean} skipDone true when need to skip done, otherwise false + * @returns {string} code + */ const doneBreak = (skipDone) => { if (skipDone) return ""; return onDone(); @@ -324,7 +450,7 @@ class HookCodeFactory { onError: (error) => onError(i, error, done, doneBreak), onResult: onResult && ((result) => onResult(i, result, done, doneBreak)), - onDone: !onResult && done, + onDone: !onResult ? done : undefined, rethrowIfPossible: rethrowIfPossible && (firstAsync < 0 || i < firstAsync) }); @@ -334,9 +460,14 @@ class HookCodeFactory { return code; } + /** + * @param {CallTapsOptions} options looping-call options + * @returns {string} generated code that calls taps in a loop + */ callTapsLooping({ onError, onDone, rethrowIfPossible }) { - if (this.options.taps.length === 0) return onDone(); - const syncOnly = this.options.taps.every((t) => t.type === "sync"); + const opts = /** @type {CompileOptions} */ (this.options); + if (opts.taps.length === 0) return onDone(); + const syncOnly = opts.taps.every((t) => t.type === "sync"); let code = ""; if (!syncOnly) { code += "var _looper = (function() {\n"; @@ -345,8 +476,8 @@ class HookCodeFactory { code += "var _loop;\n"; code += "do {\n"; code += "_loop = false;\n"; - for (let i = 0; i < this.options.interceptors.length; i++) { - const interceptor = this.options.interceptors[i]; + for (let i = 0; i < opts.interceptors.length; i++) { + const interceptor = opts.interceptors[i]; if (interceptor.loop) { code += `${this.getInterceptor(i)}.loop(${this.args({ before: interceptor.context ? "_context" : undefined @@ -386,6 +517,10 @@ class HookCodeFactory { return code; } + /** + * @param {CallTapsParallelOptions} options parallel-call options + * @returns {string} generated code that calls all taps in parallel + */ callTapsParallel({ onError, onResult, @@ -393,12 +528,13 @@ class HookCodeFactory { rethrowIfPossible, onTap = (i, run) => run() }) { - const { taps } = this.options; + const { taps } = /** @type {CompileOptions} */ (this.options); const tapsLength = taps.length; if (tapsLength <= 1) { return this.callTapsSeries({ onError, onResult, + // @ts-expect-error is it a bug? onDone, rethrowIfPossible }); @@ -409,6 +545,10 @@ class HookCodeFactory { if (onDone) return "if(--_counter === 0) _done();\n"; return "--_counter;"; }; + /** + * @param {boolean} skipDone true when need to skip done, otherwise false + * @returns {string} code + */ const doneBreak = (skipDone) => { if (skipDone || !onDone) return "_counter = 0;\n"; return "_counter = 0;\n_done();\n"; @@ -443,7 +583,7 @@ class HookCodeFactory { code += "}\n"; return code; }), - onDone: !onResult && (() => done()), + onDone: !onResult ? () => done() : undefined, rethrowIfPossible }), done, @@ -454,6 +594,10 @@ class HookCodeFactory { return code; } + /** + * @param {{ before?: string, after?: string }=} options optional arguments to prepend or append + * @returns {string} comma-separated argument list as JS source + */ args({ before, after } = {}) { // Hot during code generation. Join `_args` once and cache the result, // then build the customized variants via string concat instead of @@ -461,27 +605,42 @@ class HookCodeFactory { // arrays and re-joining. let joined = this._joinedArgs; if (joined === undefined) { - joined = this._args.length === 0 ? "" : this._args.join(", "); + joined = + /** @type {string[]} */ (this._args).length === 0 + ? "" + : /** @type {string[]} */ (this._args).join(", "); this._joinedArgs = joined; } if (!before && !after) return joined; if (joined.length === 0) { if (before && after) return `${before}, ${after}`; - return before || after; + return /** @type {string} */ (before || after); } if (before && after) return `${before}, ${joined}, ${after}`; if (before) return `${before}, ${joined}`; return `${joined}, ${after}`; } + /** + * @param {number} idx tap index + * @returns {string} JS expression that resolves to the registered tap function at index `idx` + */ getTapFn(idx) { return `_x[${idx}]`; } + /** + * @param {number} idx tap index + * @returns {string} JS expression that resolves to the tap descriptor at index `idx` + */ getTap(idx) { return `_taps[${idx}]`; } + /** + * @param {number} idx interceptor index + * @returns {string} JS expression that resolves to the interceptor at index `idx` + */ getInterceptor(idx) { return `_interceptors[${idx}]`; } diff --git a/lib/HookMap.js b/lib/HookMap.js index ca91cd6..a083584 100644 --- a/lib/HookMap.js +++ b/lib/HookMap.js @@ -6,20 +6,60 @@ const util = require("util"); +/** @typedef {import("./Hook").EXPECTED_ANY} EXPECTED_ANY */ + +/** + * @template H + * @template [K=EXPECTED_ANY] + * @typedef {(key: K) => H} HookFactory + */ + +/** + * @template H + * @template [K=EXPECTED_ANY] + * @typedef {object} HookMapInterceptor + * @property {((key: K, hook: H) => H)=} factory called when a hook is created for a new key + */ + +/** + * @template H, K + * @param {K} key key passed through unchanged + * @param {H} hook hook returned unchanged + * @returns {H} the hook unchanged + */ const defaultFactory = (key, hook) => hook; +/** + * @template H + */ class HookMap { + /** + * @param {HookFactory} factory factory creating new hooks for unknown keys + * @param {string=} name name of the hook map + */ constructor(factory, name = undefined) { + /** @type {Map} */ this._map = new Map(); + /** @type {string | undefined} */ this.name = name; + /** @type {HookFactory} */ this._factory = factory; + /** @type {HookMapInterceptor[]} */ this._interceptors = []; } + /** + * @param {EXPECTED_ANY} key the key to look up + * @returns {H | undefined} the hook stored for `key`, if any + */ get(key) { return this._map.get(key); } + /** + * @param {EXPECTED_ANY} key the key to look up or create + * @returns {H} the hook stored for `key`, creating one via the factory if missing + */ for(key) { // Hot path: inline the map lookup to skip the `this.get(key)` // indirection. This gets hit on every hook access in consumers @@ -32,12 +72,18 @@ class HookMap { let newHook = this._factory(key); const interceptors = this._interceptors; for (let i = 0; i < interceptors.length; i++) { - newHook = interceptors[i].factory(key, newHook); + newHook = + /** @type {NonNullable["factory"]>} */ + (interceptors[i].factory)(key, newHook); } map.set(key, newHook); return newHook; } + /** + * @param {HookMapInterceptor} interceptor the interceptor to register + * @returns {void} + */ intercept(interceptor) { this._interceptors.push( Object.assign( @@ -50,24 +96,25 @@ class HookMap { } } -HookMap.prototype.tap = util.deprecate(function tap(key, options, fn) { - return this.for(key).tap(options, fn); -}, "HookMap#tap(key,…) is deprecated. Use HookMap#for(key).tap(…) instead."); +HookMap.prototype.tap = + // @ts-expect-error deprecated + util.deprecate(function tap(key, options, fn) { + // @ts-expect-error deprecated + return this.for(key).tap(options, fn); + }, "HookMap#tap(key,…) is deprecated. Use HookMap#for(key).tap(…) instead."); -HookMap.prototype.tapAsync = util.deprecate(function tapAsync( - key, - options, - fn -) { - return this.for(key).tapAsync(options, fn); -}, "HookMap#tapAsync(key,…) is deprecated. Use HookMap#for(key).tapAsync(…) instead."); +HookMap.prototype.tapAsync = + // @ts-expect-error deprecated + util.deprecate(function tapAsync(key, options, fn) { + // @ts-expect-error deprecated + return this.for(key).tapAsync(options, fn); + }, "HookMap#tapAsync(key,…) is deprecated. Use HookMap#for(key).tapAsync(…) instead."); -HookMap.prototype.tapPromise = util.deprecate(function tapPromise( - key, - options, - fn -) { - return this.for(key).tapPromise(options, fn); -}, "HookMap#tapPromise(key,…) is deprecated. Use HookMap#for(key).tapPromise(…) instead."); +HookMap.prototype.tapPromise = + // @ts-expect-error deprecated + util.deprecate(function tapPromise(key, options, fn) { + // @ts-expect-error deprecated + return this.for(key).tapPromise(options, fn); + }, "HookMap#tapPromise(key,…) is deprecated. Use HookMap#for(key).tapPromise(…) instead."); module.exports = HookMap; diff --git a/lib/MultiHook.js b/lib/MultiHook.js index 900abbd..051dbd9 100644 --- a/lib/MultiHook.js +++ b/lib/MultiHook.js @@ -4,12 +4,60 @@ */ "use strict"; +/** @typedef {import("./Hook").EXPECTED_ANY} EXPECTED_ANY */ +/** @typedef {import("./Hook").EXPECTED_FUNCTION} EXPECTED_FUNCTION */ +/** @typedef {import("./Hook").Tap} Tap */ +/** @typedef {import("./Hook").TapOptions} TapOptions */ + +/** + * @template T + * @typedef {import("./Hook").AsArray} AsArray + */ + +/** + * @template {EXPECTED_ANY[]} T + * @template U + * @typedef {import("./Hook").Append} Append + */ + +/** + * @template E, T + * @typedef {import("./Hook").InnerCallback} InnerCallback + */ + +/** + * @template T + * @template [R=void] + * @template [AdditionalOptions=object] + * @typedef {import("./Hook")} Hook + */ + +/** + * @template T, R, AdditionalOptions + * @typedef {import("./Hook").HookInterceptor} HookInterceptor + */ + +/** + * @template {Hook} H + */ class MultiHook { + /** + * @param {H[]} hooks the underlying hooks to multiplex tap calls across + * @param {string=} name name of the multi hook + */ constructor(hooks, name = undefined) { + /** @type {H[]} */ this.hooks = hooks; + /** @type {string | undefined} */ this.name = name; } + /** + * @template T, R + * @param {string | Tap} options tap name or full tap options + * @param {(...args: AsArray) => R} fn the function to register + * @returns {void} + */ tap(options, fn) { const { hooks } = this; for (let i = 0; i < hooks.length; i++) { @@ -17,6 +65,12 @@ class MultiHook { } } + /** + * @template T, R + * @param {string | Tap} options tap name or full tap options + * @param {(...args: Append, InnerCallback>) => void} fn the function to register + * @returns {void} + */ tapAsync(options, fn) { const { hooks } = this; for (let i = 0; i < hooks.length; i++) { @@ -24,21 +78,36 @@ class MultiHook { } } + /** + * @template T, R + * @param {string | Tap} options tap name or full tap options + * @param {(...args: AsArray) => Promise} fn the function to register + * @returns {void} + */ tapPromise(options, fn) { const { hooks } = this; for (let i = 0; i < hooks.length; i++) { - hooks[i].tapPromise(options, fn); + hooks[i].tapPromise(options, /** @type {EXPECTED_ANY} */ (fn)); } } + /** + * @returns {boolean} true if any of the underlying hooks reports usage + */ isUsed() { const { hooks } = this; for (let i = 0; i < hooks.length; i++) { - if (hooks[i].isUsed()) return true; + if (hooks[i].isUsed()) { + return true; + } } return false; } + /** + * @param {HookInterceptor} interceptor the interceptor to register + * @returns {void} + */ intercept(interceptor) { const { hooks } = this; for (let i = 0; i < hooks.length; i++) { @@ -46,10 +115,21 @@ class MultiHook { } } + /** + * @param {TapOptions} options the options to merge into each tap + * @returns {MultiHook} a new MultiHook wrapping each underlying hook with the options + */ withOptions(options) { - return new MultiHook( - this.hooks.map((hook) => hook.withOptions(options)), - this.name + return /** @type {MultiHook} */ ( + new MultiHook( + this.hooks.map( + (hook) => + /** @type {H} */ ( + /** @type {unknown} */ (hook.withOptions(options)) + ) + ), + this.name + ) ); } } diff --git a/lib/SyncBailHook.js b/lib/SyncBailHook.js index 4b538c3..4e970e9 100644 --- a/lib/SyncBailHook.js +++ b/lib/SyncBailHook.js @@ -7,7 +7,36 @@ const Hook = require("./Hook"); const HookCodeFactory = require("./HookCodeFactory"); +/** @typedef {import("./Hook").EXPECTED_ANY} EXPECTED_ANY */ +/** @typedef {import("./Hook").EXPECTED_FUNCTION} EXPECTED_FUNCTION */ +/** @typedef {import("./Hook").UnsetAdditionalOptions} UnsetAdditionalOptions */ +/** @typedef {import("./Hook").CompileOptions} CompileOptions */ +/** @typedef {import("./HookCodeFactory").ContentOptions} ContentOptions */ + +/** + * @template T + * @typedef {import("./Hook").AsArray} AsArray + */ +/** + * @template {EXPECTED_ANY[]} T + * @typedef {import("./Hook").ArgumentNames} ArgumentNames + */ + +/** + * Mirror of the `SyncBailHook` class declared in `tapable.d.ts` for use as + * the factory function's return type, so `new SyncBailHook(...)` resolves to + * the specific subclass type instead of the generic `Hook`. + * @template T + * @template R + * @template [AdditionalOptions=UnsetAdditionalOptions] + * @typedef {import("../tapable").SyncBailHook} SyncBailHookType + */ + class SyncBailHookCodeFactory extends HookCodeFactory { + /** + * @param {ContentOptions} options content generation options + * @returns {string} generated body code + */ content({ onError, onResult, resultReturns, onDone, rethrowIfPossible }) { return this.callTapsSeries({ onError: (i, err) => onError(err), @@ -32,20 +61,40 @@ const TAP_PROMISE = () => { throw new Error("tapPromise is not supported on a SyncBailHook"); }; +/** + * @this {Hook} + * @param {CompileOptions} options compile options + * @returns {EXPECTED_FUNCTION} the compiled call function + */ function COMPILE(options) { factory.setup(this, options); return factory.create(options); } -function SyncBailHook(args = [], name = undefined) { +/** + * @constructor + * @template T + * @template R + * @template [AdditionalOptions=UnsetAdditionalOptions] + * @param {ArgumentNames>=} args argument names of the hook + * @param {string=} name name of the hook + * @returns {SyncBailHookType} a new SyncBailHook instance + */ +function SyncBailHook( + args = /** @type {ArgumentNames>} */ (/** @type {unknown} */ ([])), + name = undefined +) { const hook = new Hook(args, name); hook.constructor = SyncBailHook; hook.tapAsync = TAP_ASYNC; hook.tapPromise = TAP_PROMISE; hook.compile = COMPILE; - return hook; + return /** @type {SyncBailHookType} */ ( + /** @type {unknown} */ (hook) + ); } +/** @type {EXPECTED_ANY} */ SyncBailHook.prototype = null; module.exports = SyncBailHook; diff --git a/lib/SyncHook.js b/lib/SyncHook.js index 968dea2..9260fc1 100644 --- a/lib/SyncHook.js +++ b/lib/SyncHook.js @@ -7,7 +7,36 @@ const Hook = require("./Hook"); const HookCodeFactory = require("./HookCodeFactory"); +/** @typedef {import("./Hook").EXPECTED_ANY} EXPECTED_ANY */ +/** @typedef {import("./Hook").EXPECTED_FUNCTION} EXPECTED_FUNCTION */ +/** @typedef {import("./Hook").UnsetAdditionalOptions} UnsetAdditionalOptions */ +/** @typedef {import("./Hook").CompileOptions} CompileOptions */ +/** @typedef {import("./HookCodeFactory").ContentOptions} ContentOptions */ + +/** + * @template T + * @typedef {import("./Hook").AsArray} AsArray + */ +/** + * @template {EXPECTED_ANY[]} T + * @typedef {import("./Hook").ArgumentNames} ArgumentNames + */ + +/** + * Mirror of the `SyncHook` class declared in `tapable.d.ts` for use as the + * factory function's return type, so `new SyncHook(...)` resolves to the + * specific subclass type instead of the generic `Hook`. + * @template T + * @template [R=void] + * @template [AdditionalOptions=UnsetAdditionalOptions] + * @typedef {import("../tapable").SyncHook} SyncHookType + */ + class SyncHookCodeFactory extends HookCodeFactory { + /** + * @param {ContentOptions} options content generation options + * @returns {string} generated body code + */ content({ onError, onDone, rethrowIfPossible }) { return this.callTapsSeries({ onError: (i, err) => onError(err), @@ -27,20 +56,40 @@ const TAP_PROMISE = () => { throw new Error("tapPromise is not supported on a SyncHook"); }; +/** + * @this {Hook} + * @param {CompileOptions} options compile options + * @returns {EXPECTED_FUNCTION} the compiled call function + */ function COMPILE(options) { factory.setup(this, options); return factory.create(options); } -function SyncHook(args = [], name = undefined) { +/** + * @constructor + * @template T + * @template [R=void] + * @template [AdditionalOptions=UnsetAdditionalOptions] + * @param {ArgumentNames>=} args argument names of the hook + * @param {string=} name name of the hook + * @returns {SyncHookType} a new SyncHook instance + */ +function SyncHook( + args = /** @type {ArgumentNames>} */ (/** @type {unknown} */ ([])), + name = undefined +) { const hook = new Hook(args, name); hook.constructor = SyncHook; hook.tapAsync = TAP_ASYNC; hook.tapPromise = TAP_PROMISE; hook.compile = COMPILE; - return hook; + return /** @type {SyncHookType} */ ( + /** @type {unknown} */ (hook) + ); } +/** @type {EXPECTED_ANY} */ SyncHook.prototype = null; module.exports = SyncHook; diff --git a/lib/SyncLoopHook.js b/lib/SyncLoopHook.js index da48ca1..86e769b 100644 --- a/lib/SyncLoopHook.js +++ b/lib/SyncLoopHook.js @@ -7,7 +7,34 @@ const Hook = require("./Hook"); const HookCodeFactory = require("./HookCodeFactory"); +/** @typedef {import("./Hook").EXPECTED_ANY} EXPECTED_ANY */ +/** @typedef {import("./Hook").EXPECTED_FUNCTION} EXPECTED_FUNCTION */ +/** @typedef {import("./Hook").CompileOptions} CompileOptions */ +/** @typedef {import("./Hook").UnsetAdditionalOptions} UnsetAdditionalOptions */ +/** @typedef {import("./HookCodeFactory").ContentOptions} ContentOptions */ +/** + * @template T + * @typedef {import("./Hook").AsArray} AsArray + */ +/** + * @template {EXPECTED_ANY[]} T + * @typedef {import("./Hook").ArgumentNames} ArgumentNames + */ + +/** + * Mirror of the `SyncLoopHook` class declared in `tapable.d.ts` for use as + * the factory function's return type, so `new SyncLoopHook(...)` resolves + * to the specific subclass type instead of the generic `Hook`. + * @template T + * @template [AdditionalOptions=UnsetAdditionalOptions] + * @typedef {import("../tapable").SyncLoopHook} SyncLoopHookType + */ + class SyncLoopHookCodeFactory extends HookCodeFactory { + /** + * @param {ContentOptions} options content generation options + * @returns {string} generated body code + */ content({ onError, onDone, rethrowIfPossible }) { return this.callTapsLooping({ onError: (i, err) => onError(err), @@ -27,20 +54,39 @@ const TAP_PROMISE = () => { throw new Error("tapPromise is not supported on a SyncLoopHook"); }; +/** + * @this {Hook} + * @param {CompileOptions} options compile options + * @returns {EXPECTED_FUNCTION} the compiled call function + */ function COMPILE(options) { factory.setup(this, options); return factory.create(options); } -function SyncLoopHook(args = [], name = undefined) { +/** + * @constructor + * @template T + * @template [AdditionalOptions=UnsetAdditionalOptions] + * @param {ArgumentNames>=} args argument names of the hook + * @param {string=} name name of the hook + * @returns {SyncLoopHookType} a new SyncLoopHook instance + */ +function SyncLoopHook( + args = /** @type {ArgumentNames>} */ (/** @type {unknown} */ ([])), + name = undefined +) { const hook = new Hook(args, name); hook.constructor = SyncLoopHook; hook.tapAsync = TAP_ASYNC; hook.tapPromise = TAP_PROMISE; hook.compile = COMPILE; - return hook; + return /** @type {SyncLoopHookType} */ ( + /** @type {unknown} */ (hook) + ); } +/** @type {EXPECTED_ANY} */ SyncLoopHook.prototype = null; module.exports = SyncLoopHook; diff --git a/lib/SyncWaterfallHook.js b/lib/SyncWaterfallHook.js index 8eca528..de4f2a8 100644 --- a/lib/SyncWaterfallHook.js +++ b/lib/SyncWaterfallHook.js @@ -7,19 +7,47 @@ const Hook = require("./Hook"); const HookCodeFactory = require("./HookCodeFactory"); +/** @typedef {import("./Hook").EXPECTED_ANY} EXPECTED_ANY */ +/** @typedef {import("./Hook").EXPECTED_FUNCTION} EXPECTED_FUNCTION */ +/** @typedef {import("./Hook").CompileOptions} CompileOptions */ +/** @typedef {import("./Hook").UnsetAdditionalOptions} UnsetAdditionalOptions */ +/** @typedef {import("./HookCodeFactory").ContentOptions} ContentOptions */ +/** + * @template T + * @typedef {import("./Hook").AsArray} AsArray + */ +/** + * @template {EXPECTED_ANY[]} T + * @typedef {import("./Hook").ArgumentNames} ArgumentNames + */ + +/** + * Mirror of the `SyncWaterfallHook` class declared in `tapable.d.ts` for use + * as the factory function's return type, so `new SyncWaterfallHook(...)` + * resolves to the specific subclass type instead of the generic `Hook`. + * @template T + * @template [R=AsArray[0]] + * @template [AdditionalOptions=UnsetAdditionalOptions] + * @typedef {import("../tapable").SyncWaterfallHook} SyncWaterfallHookType + */ + class SyncWaterfallHookCodeFactory extends HookCodeFactory { + /** + * @param {ContentOptions} options content generation options + * @returns {string} generated body code + */ content({ onError, onResult, resultReturns, rethrowIfPossible }) { return this.callTapsSeries({ onError: (i, err) => onError(err), onResult: (i, result, next) => { let code = ""; code += `if(${result} !== undefined) {\n`; - code += `${this._args[0]} = ${result};\n`; + code += `${/** @type {string[]} */ (this._args)[0]} = ${result};\n`; code += "}\n"; code += next(); return code; }, - onDone: () => onResult(this._args[0]), + onDone: () => onResult(/** @type {string[]} */ (this._args)[0]), doneReturns: resultReturns, rethrowIfPossible }); @@ -36,12 +64,29 @@ const TAP_PROMISE = () => { throw new Error("tapPromise is not supported on a SyncWaterfallHook"); }; +/** + * @this {Hook} + * @param {CompileOptions} options compile options + * @returns {EXPECTED_FUNCTION} the compiled call function + */ function COMPILE(options) { factory.setup(this, options); return factory.create(options); } -function SyncWaterfallHook(args = [], name = undefined) { +/** + * @constructor + * @template T + * @template [R=AsArray[0]] + * @template [AdditionalOptions=UnsetAdditionalOptions] + * @param {ArgumentNames>=} args argument names of the hook + * @param {string=} name name of the hook + * @returns {SyncWaterfallHookType} a new SyncWaterfallHook instance + */ +function SyncWaterfallHook( + args = /** @type {ArgumentNames>} */ (/** @type {unknown} */ ([])), + name = undefined +) { if (args.length < 1) { throw new Error("Waterfall hooks must have at least one argument"); } @@ -50,9 +95,12 @@ function SyncWaterfallHook(args = [], name = undefined) { hook.tapAsync = TAP_ASYNC; hook.tapPromise = TAP_PROMISE; hook.compile = COMPILE; - return hook; + return /** @type {SyncWaterfallHookType} */ ( + /** @type {unknown} */ (hook) + ); } +/** @type {EXPECTED_ANY} */ SyncWaterfallHook.prototype = null; module.exports = SyncWaterfallHook; diff --git a/lib/util-browser.js b/lib/util-browser.js index d07eb6c..9cfb733 100644 --- a/lib/util-browser.js +++ b/lib/util-browser.js @@ -4,6 +4,15 @@ */ "use strict"; +/** @typedef {import("./Hook").EXPECTED_FUNCTION} EXPECTED_FUNCTION */ + +/** + * Browser shim for `util.deprecate`. Logs the deprecation message once on the + * first call, then forwards arguments to `fn`. + * @param {EXPECTED_FUNCTION} fn the function to wrap + * @param {string} msg the deprecation message + * @returns {EXPECTED_FUNCTION} the wrapped function + */ module.exports.deprecate = (fn, msg) => { let once = true; return function deprecate() { @@ -12,6 +21,7 @@ module.exports.deprecate = (fn, msg) => { console.warn(`DeprecationWarning: ${msg}`); once = false; } + // @ts-expect-error expected // eslint-disable-next-line prefer-rest-params return fn.apply(this, arguments); }; diff --git a/package-lock.json b/package-lock.json index 6c8f4bd..3d45f75 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1,12 +1,12 @@ { "name": "tapable", - "version": "2.3.2", + "version": "2.3.3", "lockfileVersion": 3, "requires": true, "packages": { "": { "name": "tapable", - "version": "2.3.2", + "version": "2.3.3", "license": "MIT", "devDependencies": { "@babel/core": "^7.4.4", @@ -21,7 +21,8 @@ "jest": "^30.3.0", "prettier": "^3.8.3", "prettier-1": "npm:prettier@^1", - "tinybench": "^6.0.0" + "tinybench": "^6.0.0", + "typescript": "^6.0.3" }, "engines": { "node": ">=6" @@ -2955,9 +2956,9 @@ } }, "node_modules/@jest/reporters/node_modules/brace-expansion": { - "version": "2.0.2", - "resolved": "https://registry.npmjs.org/brace-expansion/-/brace-expansion-2.0.2.tgz", - "integrity": "sha512-Jt0vHyM+jmUBqojB7E1NIYadt0vI0Qxjxd2TErW94wDz+E2LAm5vKMXXwg6ZZBTHPuUlDgQHKXvjGBdfcF1ZDQ==", + "version": "2.1.0", + "resolved": "https://registry.npmjs.org/brace-expansion/-/brace-expansion-2.1.0.tgz", + "integrity": "sha512-TN1kCZAgdgweJhWWpgKYrQaMNHcDULHkWwQIspdtjV4Y5aurRdZpjAqn6yX3FPqTA9ngHCc4hJxMAMgGfve85w==", "dev": true, "license": "MIT", "dependencies": { @@ -4255,9 +4256,9 @@ } }, "node_modules/anymatch/node_modules/picomatch": { - "version": "2.3.1", - "resolved": "https://registry.npmjs.org/picomatch/-/picomatch-2.3.1.tgz", - "integrity": "sha512-JU3teHTNjmE2VCGFzuY8EXzCDVwEqB2a8fsIvwaStHhAWJEeVd1o1QD80CU6+ZdEXXSLbSsuLwJjkCBWqRQUVA==", + "version": "2.3.2", + "resolved": "https://registry.npmjs.org/picomatch/-/picomatch-2.3.2.tgz", + "integrity": "sha512-V7+vQEJ06Z+c5tSye8S+nHUfI51xoXIXjHQ99cQtKUkQqqO1kO/KCJUfZXuB47h/YBlDhah2H3hdUGXn8ie0oA==", "dev": true, "license": "MIT", "engines": { @@ -4677,9 +4678,9 @@ } }, "node_modules/brace-expansion": { - "version": "1.1.12", - "resolved": "https://registry.npmjs.org/brace-expansion/-/brace-expansion-1.1.12.tgz", - "integrity": "sha512-9T9UjW3r0UW5c1Q7GTwllptXwhvYmEzFhzMfZ9H7FQWt+uZePjZPjBP/W1ZEyZ1twGWom5/56TF4lPcqjnDHcg==", + "version": "1.1.14", + "resolved": "https://registry.npmjs.org/brace-expansion/-/brace-expansion-1.1.14.tgz", + "integrity": "sha512-MWPGfDxnyzKU7rNOW9SP/c50vi3xrmrua/+6hfPbCS2ABNWfx24vPidzvC7krjU/RTo235sV776ymlsMtGKj8g==", "dev": true, "license": "MIT", "dependencies": { @@ -8168,9 +8169,9 @@ } }, "node_modules/jest-config/node_modules/brace-expansion": { - "version": "2.0.2", - "resolved": "https://registry.npmjs.org/brace-expansion/-/brace-expansion-2.0.2.tgz", - "integrity": "sha512-Jt0vHyM+jmUBqojB7E1NIYadt0vI0Qxjxd2TErW94wDz+E2LAm5vKMXXwg6ZZBTHPuUlDgQHKXvjGBdfcF1ZDQ==", + "version": "2.1.0", + "resolved": "https://registry.npmjs.org/brace-expansion/-/brace-expansion-2.1.0.tgz", + "integrity": "sha512-TN1kCZAgdgweJhWWpgKYrQaMNHcDULHkWwQIspdtjV4Y5aurRdZpjAqn6yX3FPqTA9ngHCc4hJxMAMgGfve85w==", "dev": true, "license": "MIT", "dependencies": { @@ -8518,9 +8519,9 @@ } }, "node_modules/jest-runtime/node_modules/brace-expansion": { - "version": "2.0.2", - "resolved": "https://registry.npmjs.org/brace-expansion/-/brace-expansion-2.0.2.tgz", - "integrity": "sha512-Jt0vHyM+jmUBqojB7E1NIYadt0vI0Qxjxd2TErW94wDz+E2LAm5vKMXXwg6ZZBTHPuUlDgQHKXvjGBdfcF1ZDQ==", + "version": "2.1.0", + "resolved": "https://registry.npmjs.org/brace-expansion/-/brace-expansion-2.1.0.tgz", + "integrity": "sha512-TN1kCZAgdgweJhWWpgKYrQaMNHcDULHkWwQIspdtjV4Y5aurRdZpjAqn6yX3FPqTA9ngHCc4hJxMAMgGfve85w==", "dev": true, "license": "MIT", "dependencies": { @@ -10602,9 +10603,9 @@ "license": "ISC" }, "node_modules/picomatch": { - "version": "4.0.3", - "resolved": "https://registry.npmjs.org/picomatch/-/picomatch-4.0.3.tgz", - "integrity": "sha512-5gTmgEY/sqK6gFXLIsQNH19lWb4ebPDLA4SdLP7dsWkIXHWlG66oPuVvXSGFPppYZz8ZDZq0dYYrbHfBCVUb1Q==", + "version": "4.0.4", + "resolved": "https://registry.npmjs.org/picomatch/-/picomatch-4.0.4.tgz", + "integrity": "sha512-QP88BAKvMam/3NxH6vj2o21R6MjxZUAd6nlwAS/pnGvN9IVLocLHxGYIzFhg6fUQ+5th6P4dv4eW9jX3DSIj7A==", "dev": true, "license": "MIT", "engines": { @@ -12051,12 +12052,11 @@ } }, "node_modules/typescript": { - "version": "5.9.3", - "resolved": "https://registry.npmjs.org/typescript/-/typescript-5.9.3.tgz", - "integrity": "sha512-jl1vZzPDinLr9eUt3J/t7V6FgNEw9QjvBPdysz9KfQDD41fQrC2Y4vKQdiaUpFT4bXlb1RHhLpp8wtm6M5TgSw==", + "version": "6.0.3", + "resolved": "https://registry.npmjs.org/typescript/-/typescript-6.0.3.tgz", + "integrity": "sha512-y2TvuxSZPDyQakkFRPZHKFm+KKVqIisdg9/CZwm9ftvKXLP8NRWj38/ODjNbr43SsoXqNuAisEf1GdCxqWcdBw==", "dev": true, "license": "Apache-2.0", - "peer": true, "bin": { "tsc": "bin/tsc", "tsserver": "bin/tsserver" diff --git a/package.json b/package.json index 9d63912..2945b89 100644 --- a/package.json +++ b/package.json @@ -23,7 +23,8 @@ "tapable.d.ts" ], "scripts": { - "lint": "npm run lint:code && npm run fmt:check", + "lint": "npm run lint:code && npm run lint:types && npm run fmt:check", + "lint:types": "tsc --pretty --noEmit", "lint:code": "eslint --cache .", "fmt": "npm run fmt:base -- --log-level warn --write", "fmt:check": "npm run fmt:base -- --check", @@ -57,7 +58,8 @@ "jest": "^30.3.0", "prettier": "^3.8.3", "prettier-1": "npm:prettier@^1", - "tinybench": "^6.0.0" + "tinybench": "^6.0.0", + "typescript": "^6.0.3" }, "engines": { "node": ">=6" diff --git a/test/AsyncParallelBailHook.test.js b/test/AsyncParallelBailHook.test.js new file mode 100644 index 0000000..3613be0 --- /dev/null +++ b/test/AsyncParallelBailHook.test.js @@ -0,0 +1,18 @@ +/* + MIT License http://www.opensource.org/licenses/mit-license.php + Author Tobias Koppers @sokra +*/ +"use strict"; + +const AsyncParallelBailHook = require("../lib/AsyncParallelBailHook"); +const HookTester = require("./HookTester.test"); + +describe("AsyncParallelBailHook", () => { + it("should have to correct behavior", async () => { + const tester = new HookTester((args) => new AsyncParallelBailHook(args)); + + const result = await tester.run(); + + expect(result).toMatchSnapshot(); + }, 15000); +}); diff --git a/test/AsyncParallelHooks.test.js b/test/AsyncParallelHooks.test.js index b730cd2..3925af3 100644 --- a/test/AsyncParallelHooks.test.js +++ b/test/AsyncParallelHooks.test.js @@ -4,7 +4,6 @@ */ "use strict"; -const AsyncParallelBailHook = require("../lib/AsyncParallelBailHook"); const AsyncParallelHook = require("../lib/AsyncParallelHook"); const HookTester = require("./HookTester.test"); @@ -17,13 +16,3 @@ describe("AsyncParallelHook", () => { expect(result).toMatchSnapshot(); }, 15000); }); - -describe("AsyncParallelBailHook", () => { - it("should have to correct behavior", async () => { - const tester = new HookTester((args) => new AsyncParallelBailHook(args)); - - const result = await tester.run(); - - expect(result).toMatchSnapshot(); - }, 15000); -}); diff --git a/test/AsyncSeriesBailHook.test.js b/test/AsyncSeriesBailHook.test.js new file mode 100644 index 0000000..cbe45f2 --- /dev/null +++ b/test/AsyncSeriesBailHook.test.js @@ -0,0 +1,28 @@ +/* + MIT License http://www.opensource.org/licenses/mit-license.php + Author Tobias Koppers @sokra +*/ +"use strict"; + +const AsyncSeriesBailHook = require("../lib/AsyncSeriesBailHook"); +const HookTester = require("./HookTester.test"); + +describe("AsyncSeriesBailHook", () => { + it("should have to correct behavior", async () => { + const tester = new HookTester((args) => new AsyncSeriesBailHook(args)); + + const result = await tester.run(); + + expect(result).toMatchSnapshot(); + }); + + it("should not crash with many plugins", () => { + const hook = new AsyncSeriesBailHook(["x"]); + for (let i = 0; i < 1000; i++) { + hook.tap("Test", () => 42); + } + hook.tapAsync("Test", (x, callback) => callback(null, 42)); + hook.tapPromise("Test", (_x) => Promise.resolve(42)); + return expect(hook.promise()).resolves.toBe(42); + }); +}); diff --git a/test/AsyncSeriesHooks.test.js b/test/AsyncSeriesHooks.test.js index 8aaf12f..7ec9cd2 100644 --- a/test/AsyncSeriesHooks.test.js +++ b/test/AsyncSeriesHooks.test.js @@ -4,10 +4,7 @@ */ "use strict"; -const AsyncSeriesBailHook = require("../lib/AsyncSeriesBailHook"); const AsyncSeriesHook = require("../lib/AsyncSeriesHook"); -const AsyncSeriesLoopHook = require("../lib/AsyncSeriesLoopHook"); -const AsyncSeriesWaterfallHook = require("../lib/AsyncSeriesWaterfallHook"); const HookTester = require("./HookTester.test"); describe("AsyncSeriesHook", () => { @@ -42,79 +39,3 @@ describe("AsyncSeriesHook", () => { expect(result).toMatchSnapshot(); }); }); - -describe("AsyncSeriesBailHook", () => { - it("should have to correct behavior", async () => { - const tester = new HookTester((args) => new AsyncSeriesBailHook(args)); - - const result = await tester.run(); - - expect(result).toMatchSnapshot(); - }); - - it("should not crash with many plugins", () => { - const hook = new AsyncSeriesBailHook(["x"]); - for (let i = 0; i < 1000; i++) { - hook.tap("Test", () => 42); - } - hook.tapAsync("Test", (x, callback) => callback(null, 42)); - hook.tapPromise("Test", (_x) => Promise.resolve(42)); - return expect(hook.promise()).resolves.toBe(42); - }); -}); - -describe("AsyncSeriesWaterfallHook", () => { - it("should have to correct behavior", async () => { - const tester = new HookTester((args) => new AsyncSeriesWaterfallHook(args)); - - const result = await tester.run(); - - expect(result).toMatchSnapshot(); - }); - - it("should work with undefined", async () => { - const hook = new AsyncSeriesWaterfallHook(["x"]); - hook.tap("number", () => 42); - hook.tap("undefined", () => undefined); - return expect(hook.promise()).resolves.toBe(42); - }); - - it("should work with void", async () => { - const hook = new AsyncSeriesWaterfallHook(["x"]); - hook.tap("number", () => 42); - hook.tap("undefined", () => {}); - return expect(hook.promise()).resolves.toBe(42); - }); - - it("should work with undefined and number again", async () => { - const hook = new AsyncSeriesWaterfallHook(["x"]); - hook.tap("number", () => 42); - hook.tap("undefined", () => {}); - hook.tap("number-again", () => 43); - return expect(hook.promise()).resolves.toBe(43); - }); - - it("should work with null", async () => { - const hook = new AsyncSeriesWaterfallHook(["x"]); - hook.tap("number", () => 42); - hook.tap("undefined", () => null); - return expect(hook.promise()).resolves.toBeNull(); - }); - - it("should work with different types", async () => { - const hook = new AsyncSeriesWaterfallHook(["x"]); - hook.tap("number", () => 42); - hook.tap("string", () => "string"); - return expect(hook.promise()).resolves.toBe("string"); - }); -}); - -describe("AsyncSeriesLoopHook", () => { - it("should have to correct behavior", async () => { - const tester = new HookTester((args) => new AsyncSeriesLoopHook(args)); - - const result = await tester.runForLoop(); - - expect(result).toMatchSnapshot(); - }); -}); diff --git a/test/AsyncSeriesLoopHook.test.js b/test/AsyncSeriesLoopHook.test.js new file mode 100644 index 0000000..e963f5f --- /dev/null +++ b/test/AsyncSeriesLoopHook.test.js @@ -0,0 +1,18 @@ +/* + MIT License http://www.opensource.org/licenses/mit-license.php + Author Tobias Koppers @sokra +*/ +"use strict"; + +const AsyncSeriesLoopHook = require("../lib/AsyncSeriesLoopHook"); +const HookTester = require("./HookTester.test"); + +describe("AsyncSeriesLoopHook", () => { + it("should have to correct behavior", async () => { + const tester = new HookTester((args) => new AsyncSeriesLoopHook(args)); + + const result = await tester.runForLoop(); + + expect(result).toMatchSnapshot(); + }); +}); diff --git a/test/AsyncSeriesWaterfallHook.test.js b/test/AsyncSeriesWaterfallHook.test.js new file mode 100644 index 0000000..4687f55 --- /dev/null +++ b/test/AsyncSeriesWaterfallHook.test.js @@ -0,0 +1,54 @@ +/* + MIT License http://www.opensource.org/licenses/mit-license.php + Author Tobias Koppers @sokra +*/ +"use strict"; + +const AsyncSeriesWaterfallHook = require("../lib/AsyncSeriesWaterfallHook"); +const HookTester = require("./HookTester.test"); + +describe("AsyncSeriesWaterfallHook", () => { + it("should have to correct behavior", async () => { + const tester = new HookTester((args) => new AsyncSeriesWaterfallHook(args)); + + const result = await tester.run(); + + expect(result).toMatchSnapshot(); + }); + + it("should work with undefined", async () => { + const hook = new AsyncSeriesWaterfallHook(["x"]); + hook.tap("number", () => 42); + hook.tap("undefined", () => undefined); + return expect(hook.promise()).resolves.toBe(42); + }); + + it("should work with void", async () => { + const hook = new AsyncSeriesWaterfallHook(["x"]); + hook.tap("number", () => 42); + hook.tap("undefined", () => {}); + return expect(hook.promise()).resolves.toBe(42); + }); + + it("should work with undefined and number again", async () => { + const hook = new AsyncSeriesWaterfallHook(["x"]); + hook.tap("number", () => 42); + hook.tap("undefined", () => {}); + hook.tap("number-again", () => 43); + return expect(hook.promise()).resolves.toBe(43); + }); + + it("should work with null", async () => { + const hook = new AsyncSeriesWaterfallHook(["x"]); + hook.tap("number", () => 42); + hook.tap("undefined", () => null); + return expect(hook.promise()).resolves.toBeNull(); + }); + + it("should work with different types", async () => { + const hook = new AsyncSeriesWaterfallHook(["x"]); + hook.tap("number", () => 42); + hook.tap("string", () => "string"); + return expect(hook.promise()).resolves.toBe("string"); + }); +}); diff --git a/test/Hook.test.js b/test/Hook.test.js index 6b551d4..eb677b2 100644 --- a/test/Hook.test.js +++ b/test/Hook.test.js @@ -4,8 +4,17 @@ */ "use strict"; +const AsyncParallelBailHook = require("../lib/AsyncParallelBailHook"); +const AsyncParallelHook = require("../lib/AsyncParallelHook"); +const AsyncSeriesBailHook = require("../lib/AsyncSeriesBailHook"); +const AsyncSeriesHook = require("../lib/AsyncSeriesHook"); +const AsyncSeriesLoopHook = require("../lib/AsyncSeriesLoopHook"); +const AsyncSeriesWaterfallHook = require("../lib/AsyncSeriesWaterfallHook"); const HookTest = require("../lib/Hook"); +const SyncBailHook = require("../lib/SyncBailHook"); const SyncHook = require("../lib/SyncHook"); +const SyncLoopHook = require("../lib/SyncLoopHook"); +const SyncWaterfallHook = require("../lib/SyncWaterfallHook"); describe("Hook", () => { it("should throw when compile is not overridden", () => { @@ -200,6 +209,136 @@ describe("Hook", () => { expect(hook.taps[1].extra).toBe("value"); }); + describe("instance shape (V8 hidden-class layout)", () => { + // `Hook.js` ends with `Object.setPrototypeOf(Hook.prototype, null)` and + // the constructor does `this.compile = this.compile` etc. Both are + // load-bearing performance optimizations - the self-assignments force + // the methods that subclasses overwrite (`compile`, `tap`, `tapAsync`, + // `tapPromise`) to be own properties in a fixed insertion order, so + // every Hook/SyncHook/AsyncSeriesHook/... lands in the same V8 hidden + // class. These tests pin the contract so a future "cleanup" cannot + // silently regress it. + + // Layout produced by the base `Hook` constructor. + const baseOwnKeys = [ + "_args", + "name", + "taps", + "interceptors", + "_call", + "call", + "_callAsync", + "callAsync", + "_promise", + "promise", + "_x", + "compile", + "tap", + "tapAsync", + "tapPromise" + ]; + + // Subclass factories (`SyncHook(...)` etc.) tack `constructor` onto the + // instance *after* the base layout is established, then overwrite a + // few of the existing slots in place. So every subclass instance ends + // up with the same shape, distinct from the bare `new Hook(...)` shape + // but identical across all subclass families - which is the case that + // matters in practice (users instantiate subclasses, not Hook). + const subclassOwnKeys = [...baseOwnKeys, "constructor"]; + + it("hook.prototype has a null prototype", () => { + // `Object.setPrototypeOf(Hook.prototype, null)` keeps property + // lookup at one hop and protects against prototype pollution. + expect(Object.getPrototypeOf(HookTest.prototype)).toBeNull(); + }); + + it("makes compile/tap/tapAsync/tapPromise own properties on every Hook instance", () => { + const hook = new HookTest(["arg"]); + // Self-assignments in the constructor must produce own props, + // not inherited ones - otherwise subclass overwrites would + // trigger a hidden-class transition on every instance. + expect(Object.prototype.hasOwnProperty.call(hook, "compile")).toBe(true); + expect(Object.prototype.hasOwnProperty.call(hook, "tap")).toBe(true); + expect(Object.prototype.hasOwnProperty.call(hook, "tapAsync")).toBe(true); + expect(Object.prototype.hasOwnProperty.call(hook, "tapPromise")).toBe( + true + ); + }); + + it("makes the call/_call/callAsync/_callAsync/promise/_promise pairs own properties", () => { + const hook = new HookTest(["arg"]); + // The split is the lazy-compile reset pattern: `_xxx` is the + // delegate, `xxx` is the live slot that gets replaced with the + // compiled function on first invocation. + for (const key of [ + "_call", + "call", + "_callAsync", + "callAsync", + "_promise", + "promise" + ]) { + expect(Object.prototype.hasOwnProperty.call(hook, key)).toBe(true); + } + }); + + it("preserves the own-property insertion order on a base Hook", () => { + const hook = new HookTest(["arg"]); + expect(Object.keys(hook)).toEqual(baseOwnKeys); + }); + + it("preserves the same own-property layout across every Hook subclass", () => { + // Subclasses overwrite `compile`/`tapAsync`/`tapPromise` (and some + // wipe `_call`/`call` to undefined), but they must not introduce + // new own properties or change their order beyond the trailing + // `constructor` assignment. Otherwise instances of different + // subclasses end up in different hidden classes and shared call + // sites turn polymorphic. + const subclasses = [ + new SyncHook(["arg"]), + new SyncBailHook(["arg"]), + new SyncLoopHook(["arg"]), + new SyncWaterfallHook(["arg"]), + new AsyncParallelHook(["arg"]), + new AsyncParallelBailHook(["arg"]), + new AsyncSeriesHook(["arg"]), + new AsyncSeriesBailHook(["arg"]), + new AsyncSeriesLoopHook(["arg"]), + new AsyncSeriesWaterfallHook(["arg"]) + ]; + + for (const hook of subclasses) { + expect(Object.keys(hook)).toEqual(subclassOwnKeys); + } + }); + + it("does not change the own-property layout after taps/interceptors/calls", () => { + // Once a hook is exercised end-to-end (tap, intercept, call) the + // own-property set must still match the layout established by the + // constructor. Anything new added by `_resetCompilation`, + // `intercept`, the lazy compile, etc. would change the hidden + // class for every hook that has ever been used. + const hook = new SyncHook(["arg"]); + hook.intercept({ call: () => {} }); + hook.tap("A", () => {}); + hook.call(1); + + expect(Object.keys(hook)).toEqual(subclassOwnKeys); + }); + + it("keeps Async* hooks in the same layout even with call/_call set to undefined", () => { + // Async* hooks set `hook.call = undefined; hook._call = undefined` + // to disable the sync entrypoint. The slots must still exist as + // own properties (just holding `undefined`) so the hidden class + // matches the rest of the family. + const hook = new AsyncSeriesHook(["arg"]); + expect(Object.prototype.hasOwnProperty.call(hook, "call")).toBe(true); + expect(Object.prototype.hasOwnProperty.call(hook, "_call")).toBe(true); + expect(hook.call).toBeUndefined(); + expect(hook._call).toBeUndefined(); + }); + }); + it("should not ignore invalid before values", () => { // A plugin may use a hook that will never be executed const hook = new SyncHook(); diff --git a/test/SyncBailHook.test.js b/test/SyncBailHook.test.js index a6d93c3..b47840f 100644 --- a/test/SyncBailHook.test.js +++ b/test/SyncBailHook.test.js @@ -4,7 +4,8 @@ */ "use strict"; -const SyncBailHookTest = require("../lib/SyncBailHook"); +const SyncBailHook = require("../lib/SyncBailHook"); +const HookTester = require("./HookTester.test"); function pify(fn) { return new Promise((resolve, reject) => { @@ -16,9 +17,17 @@ function pify(fn) { } describe("SyncBailHook", () => { + it("should have to correct behavior", async () => { + const tester = new HookTester((args) => new SyncBailHook(args)); + + const result = await tester.run(true); + + expect(result).toMatchSnapshot(); + }, 15000); + it("should allow to create sync bail hooks", async () => { - const h1 = new SyncBailHookTest(["a"]); - const h2 = new SyncBailHookTest(["a", "b"]); + const h1 = new SyncBailHook(["a"]); + const h2 = new SyncBailHook(["a", "b"]); const r = h1.call(1); expect(r).toBeUndefined(); @@ -45,7 +54,7 @@ describe("SyncBailHook", () => { }); it("should bail on non-null return", async () => { - const h1 = new SyncBailHookTest(["a"]); + const h1 = new SyncBailHook(["a"]); const mockCall1 = jest.fn(); const mockCall2 = jest.fn(() => "B"); const mockCall3 = jest.fn(() => "C"); @@ -59,7 +68,7 @@ describe("SyncBailHook", () => { }); it("should allow to intercept calls", () => { - const hook = new SyncBailHookTest(["x"]); + const hook = new SyncBailHook(["x"]); const mockCall = jest.fn(); const mockTap = jest.fn((x) => x); @@ -83,17 +92,17 @@ describe("SyncBailHook", () => { }); it("should throw on tapAsync", () => { - const hook = new SyncBailHookTest(["x"]); + const hook = new SyncBailHook(["x"]); expect(() => hook.tapAsync()).toThrow(/tapAsync/); }); it("should throw on tapPromise", () => { - const hook = new SyncBailHookTest(["x"]); + const hook = new SyncBailHook(["x"]); expect(() => hook.tapPromise()).toThrow(/tapPromise/); }); it("should not crash with many plugins", () => { - const hook = new SyncBailHookTest(["x"]); + const hook = new SyncBailHook(["x"]); for (let i = 0; i < 1000; i++) { hook.tap("Test", () => 42); } diff --git a/test/SyncHooks.test.js b/test/SyncHooks.test.js index e30ee65..c9584c4 100644 --- a/test/SyncHooks.test.js +++ b/test/SyncHooks.test.js @@ -4,10 +4,7 @@ */ "use strict"; -const SyncBailHook = require("../lib/SyncBailHook"); const SyncHook = require("../lib/SyncHook"); -const SyncLoopHook = require("../lib/SyncLoopHook"); -const SyncWaterfallHook = require("../lib/SyncWaterfallHook"); const HookTester = require("./HookTester.test"); describe("SyncHook", () => { @@ -19,33 +16,3 @@ describe("SyncHook", () => { expect(result).toMatchSnapshot(); }, 15000); }); - -describe("SyncBailHook", () => { - it("should have to correct behavior", async () => { - const tester = new HookTester((args) => new SyncBailHook(args)); - - const result = await tester.run(true); - - expect(result).toMatchSnapshot(); - }, 15000); -}); - -describe("SyncWaterfallHook", () => { - it("should have to correct behavior", async () => { - const tester = new HookTester((args) => new SyncWaterfallHook(args)); - - const result = await tester.run(true); - - expect(result).toMatchSnapshot(); - }, 15000); -}); - -describe("SyncLoopHook", () => { - it("should have to correct behavior", async () => { - const tester = new HookTester((args) => new SyncLoopHook(args)); - - const result = await tester.runForLoop(true); - - expect(result).toMatchSnapshot(); - }, 15000); -}); diff --git a/test/SyncLoopHook.test.js b/test/SyncLoopHook.test.js index e742224..c7ae025 100644 --- a/test/SyncLoopHook.test.js +++ b/test/SyncLoopHook.test.js @@ -3,25 +3,34 @@ */ "use strict"; -const SyncLoopHookTest = require("../lib/SyncLoopHook"); +const SyncLoopHook = require("../lib/SyncLoopHook"); +const HookTester = require("./HookTester.test"); describe("SyncLoopHook", () => { it("should throw on tapAsync", () => { - const hook = new SyncLoopHookTest(["a"]); + const hook = new SyncLoopHook(["a"]); expect(() => hook.tapAsync("A", () => {})).toThrow( /tapAsync is not supported on a SyncLoopHook/ ); }); it("should throw on tapPromise", () => { - const hook = new SyncLoopHookTest(["a"]); + const hook = new SyncLoopHook(["a"]); expect(() => hook.tapPromise("A", () => {})).toThrow( /tapPromise is not supported on a SyncLoopHook/ ); }); + it("should have to correct behavior", async () => { + const tester = new HookTester((args) => new SyncLoopHook(args)); + + const result = await tester.runForLoop(true); + + expect(result).toMatchSnapshot(); + }, 15000); + it("should loop through taps until all return undefined", () => { - const hook = new SyncLoopHookTest(["counter"]); + const hook = new SyncLoopHook(["counter"]); let firstCalls = 0; let secondCalls = 0; hook.tap("first", () => { @@ -36,7 +45,7 @@ describe("SyncLoopHook", () => { }); it("should be callable without arguments using default args", () => { - const hook = new SyncLoopHookTest(); + const hook = new SyncLoopHook(); const mock = jest.fn(); hook.tap("A", mock); hook.call(); diff --git a/test/SyncWaterfallHook.test.js b/test/SyncWaterfallHook.test.js index 1098570..975770f 100644 --- a/test/SyncWaterfallHook.test.js +++ b/test/SyncWaterfallHook.test.js @@ -4,7 +4,8 @@ */ "use strict"; -const SyncWaterfallHookTest = require("../lib/SyncWaterfallHook"); +const SyncWaterfallHook = require("../lib/SyncWaterfallHook"); +const HookTester = require("./HookTester.test"); function pify(fn) { return new Promise((resolve, reject) => { @@ -17,13 +18,21 @@ function pify(fn) { describe("SyncWaterfallHook", () => { it("should throw an error when hook has no argument", () => { - expect(() => new SyncWaterfallHookTest()).toThrow( + expect(() => new SyncWaterfallHook()).toThrow( "Waterfall hooks must have at least one argument" ); }); + it("should have to correct behavior", async () => { + const tester = new HookTester((args) => new SyncWaterfallHook(args)); + + const result = await tester.run(true); + + expect(result).toMatchSnapshot(); + }, 15000); + it("should work", () => { - const hook = new SyncWaterfallHookTest(["x"]); + const hook = new SyncWaterfallHook(["x"]); hook.tap("number", () => 42); hook.tap("string", () => "str"); hook.tap("false", () => false); @@ -31,21 +40,21 @@ describe("SyncWaterfallHook", () => { }); it("should work with undefined", async () => { - const hook = new SyncWaterfallHookTest(["x"]); + const hook = new SyncWaterfallHook(["x"]); hook.tap("number", () => 42); hook.tap("undefined", () => undefined); return expect(hook.call()).toBe(42); }); it("should work with void", async () => { - const hook = new SyncWaterfallHookTest(["x"]); + const hook = new SyncWaterfallHook(["x"]); hook.tap("number", () => 42); hook.tap("undefined", () => {}); return expect(hook.call()).toBe(42); }); it("should work with undefined and number again", async () => { - const hook = new SyncWaterfallHookTest(["x"]); + const hook = new SyncWaterfallHook(["x"]); hook.tap("number", () => 42); hook.tap("undefined", () => {}); hook.tap("number-again", () => 43); @@ -53,21 +62,21 @@ describe("SyncWaterfallHook", () => { }); it("should work with null", async () => { - const hook = new SyncWaterfallHookTest(["x"]); + const hook = new SyncWaterfallHook(["x"]); hook.tap("number", () => 42); hook.tap("undefined", () => null); return expect(hook.call()).toBeNull(); }); it("should work with different types", async () => { - const hook = new SyncWaterfallHookTest(["x"]); + const hook = new SyncWaterfallHook(["x"]); hook.tap("number", () => 42); hook.tap("string", () => "string"); return expect(hook.call()).toBe("string"); }); it("should allow to create sync hooks", async () => { - const hook = new SyncWaterfallHookTest(["arg1", "arg2"]); + const hook = new SyncWaterfallHook(["arg1", "arg2"]); const mock0 = jest.fn((arg) => `${arg},0`); const mock1 = jest.fn((arg) => `${arg},1`); @@ -100,7 +109,7 @@ describe("SyncWaterfallHook", () => { }); it("should allow to intercept calls", () => { - const hook = new SyncWaterfallHookTest(["arg1", "arg2"]); + const hook = new SyncWaterfallHook(["arg1", "arg2"]); const mockCall = jest.fn(); const mock0 = jest.fn(() => "mock0"); @@ -139,8 +148,8 @@ describe("SyncWaterfallHook", () => { }); it("should allow to create waterfall hooks", async () => { - const h1 = new SyncWaterfallHookTest(["a"]); - const h2 = new SyncWaterfallHookTest(["a", "b"]); + const h1 = new SyncWaterfallHook(["a"]); + const h2 = new SyncWaterfallHook(["a", "b"]); expect(h1.call(1)).toBe(1); @@ -164,12 +173,12 @@ describe("SyncWaterfallHook", () => { it("should throw when args have length less than 1", () => { expect(() => { // eslint-disable-next-line no-new - new SyncWaterfallHookTest([]); + new SyncWaterfallHook([]); }).toThrow(/Waterfall/); }); it("should allow to intercept calls #2", () => { - const hook = new SyncWaterfallHookTest(["x"]); + const hook = new SyncWaterfallHook(["x"]); const mockCall = jest.fn(); const mockTap = jest.fn((x) => x); @@ -193,12 +202,12 @@ describe("SyncWaterfallHook", () => { }); it("should throw on tapAsync", () => { - const hook = new SyncWaterfallHookTest(["x"]); + const hook = new SyncWaterfallHook(["x"]); expect(() => hook.tapAsync()).toThrow(/tapAsync/); }); it("should throw on tapPromise", () => { - const hook = new SyncWaterfallHookTest(["x"]); + const hook = new SyncWaterfallHook(["x"]); expect(() => hook.tapPromise()).toThrow(/tapPromise/); }); }); diff --git a/test/__snapshots__/AsyncParallelBailHook.test.js.snap b/test/__snapshots__/AsyncParallelBailHook.test.js.snap new file mode 100644 index 0000000..ee732b7 --- /dev/null +++ b/test/__snapshots__/AsyncParallelBailHook.test.js.snap @@ -0,0 +1,798 @@ +// Jest Snapshot v1, https://jestjs.io/docs/snapshot-testing + +exports[`AsyncParallelBailHook should have to correct behavior 1`] = ` +Object { + "async": Object { + "callAsyncMultipleAsyncEarlyError": Object { + "error": "Error in async2", + "type": "async", + }, + "callAsyncMultipleAsyncEarlyErrorCalled1": true, + "callAsyncMultipleAsyncError": Object { + "error": "Error in async2", + "type": "async", + }, + "callAsyncMultipleAsyncErrorCalled1": true, + "callAsyncMultipleAsyncLateError": Object { + "error": "Error in async2", + "type": "async", + }, + "callAsyncMultipleAsyncLateErrorCalled1": true, + "callAsyncMultipleAsyncLateErrorCalled3": true, + "callAsyncMultipleAsyncLateErrorEarlyResult1": Object { + "error": "Error in async2", + "type": "async", + }, + "callAsyncMultipleAsyncLateErrorEarlyResult1Called1": true, + "callAsyncMultipleAsyncLateErrorEarlyResult1Called3": true, + "callAsyncMultipleAsyncLateErrorEarlyResult2": Object { + "type": "async", + "value": 42, + }, + "callAsyncMultipleAsyncLateErrorEarlyResult2Called1": true, + "callAsyncMultipleAsyncLateErrorEarlyResult2Called3": true, + "callAsyncMultipleAsyncWithArg": Object { + "type": "async", + "value": 43, + }, + "callAsyncMultipleAsyncWithArgCalled1": 42, + "callAsyncMultipleAsyncWithArgFirstReturn": Object { + "type": "async", + "value": 43, + }, + "callAsyncMultipleAsyncWithArgFirstReturnCalled1": 42, + "callAsyncMultipleAsyncWithArgLastReturn": Object { + "type": "async", + "value": 44, + }, + "callAsyncMultipleAsyncWithArgLastReturnCalled1": 42, + "callAsyncMultipleAsyncWithArgLastReturnCalled2": 42, + "callAsyncMultipleAsyncWithArgNoReturn": Object { + "type": "async", + "value": undefined, + }, + "callAsyncMultipleAsyncWithArgNoReturnCalled1": 42, + "callAsyncMultipleAsyncWithArgNoReturnCalled2": 42, + "callAsyncMultipleMixed1WithArg": Object { + "type": "async", + "value": 43, + }, + "callAsyncMultipleMixed1WithArgCalled1": 42, + "callAsyncMultipleMixed2WithArg": Object { + "type": "async", + "value": 43, + }, + "callAsyncMultipleMixed2WithArgCalled1": 42, + "callAsyncMultipleMixed2WithArgCalled2": 42, + "callAsyncMultipleMixed3WithArg": Object { + "type": "async", + "value": 43, + }, + "callAsyncMultipleMixed3WithArgCalled1": 42, + "callAsyncMultipleMixedError1WithArg": Object { + "type": "async", + "value": 42, + }, + "callAsyncMultipleMixedError1WithArgCalled1": 42, + "callAsyncMultipleMixedError2WithArg": Object { + "type": "async", + "value": 42, + }, + "callAsyncMultipleMixedError2WithArgCalled1": 42, + "callAsyncMultipleMixedError3WithArg": Object { + "error": "Error in async", + "type": "async", + }, + "callAsyncMultipleMixedError3WithArgCalled1": 42, + "callAsyncMultipleMixedLateError": Object { + "error": "Error in async", + "type": "async", + }, + "callAsyncMultipleMixedLateErrorCalled1": true, + "callAsyncMultipleMixedLateErrorCalled2": true, + "callAsyncMultipleMixedLateErrorCalled3": true, + "callAsyncMultiplePromiseEarlyError": Object { + "error": "Error in async2", + "type": "async", + }, + "callAsyncMultiplePromiseEarlyErrorCalled1": true, + "callAsyncMultiplePromiseEarlyErrorCalled3": true, + "callAsyncMultiplePromiseError": Object { + "error": "Error in async2", + "type": "async", + }, + "callAsyncMultiplePromiseErrorCalled1": true, + "callAsyncMultiplePromiseErrorCalled3": true, + "callAsyncMultiplePromiseLateError": Object { + "error": "Error in async2", + "type": "async", + }, + "callAsyncMultiplePromiseLateErrorCalled1": true, + "callAsyncMultiplePromiseLateErrorCalled3": true, + "callAsyncMultiplePromiseWithArg": Object { + "type": "async", + "value": 43, + }, + "callAsyncMultiplePromiseWithArgCalled1": 42, + "callAsyncMultiplePromiseWithArgCalled2": 42, + "callAsyncMultiplePromiseWithArgFirstReturn": Object { + "type": "async", + "value": 43, + }, + "callAsyncMultiplePromiseWithArgFirstReturnCalled1": 42, + "callAsyncMultiplePromiseWithArgFirstReturnCalled2": 42, + "callAsyncMultiplePromiseWithArgLastReturn": Object { + "type": "async", + "value": 44, + }, + "callAsyncMultiplePromiseWithArgLastReturnCalled1": 42, + "callAsyncMultiplePromiseWithArgLastReturnCalled2": 42, + "callAsyncMultiplePromiseWithArgNoReturn": Object { + "type": "async", + "value": undefined, + }, + "callAsyncMultiplePromiseWithArgNoReturnCalled1": 42, + "callAsyncMultiplePromiseWithArgNoReturnCalled2": 42, + "callAsyncMultipleSync": Object { + "type": "async", + "value": 42, + }, + "callAsyncMultipleSyncCalled1": true, + "callAsyncMultipleSyncError": Object { + "error": "Error in sync2", + "type": "async", + }, + "callAsyncMultipleSyncErrorCalled1": true, + "callAsyncMultipleSyncLastReturn": Object { + "type": "async", + "value": 43, + }, + "callAsyncMultipleSyncLastReturnCalled1": true, + "callAsyncMultipleSyncLastReturnCalled2": true, + "callAsyncMultipleSyncNoReturn": Object { + "type": "async", + "value": undefined, + }, + "callAsyncMultipleSyncNoReturnCalled1": true, + "callAsyncMultipleSyncNoReturnCalled2": true, + "callAsyncMultipleSyncWithArg": Object { + "type": "async", + "value": 43, + }, + "callAsyncMultipleSyncWithArgCalled1": 42, + "callAsyncMultipleSyncWithArgFirstReturn": Object { + "type": "async", + "value": 43, + }, + "callAsyncMultipleSyncWithArgFirstReturnCalled1": 42, + "callAsyncMultipleSyncWithArgLastReturn": Object { + "type": "async", + "value": 44, + }, + "callAsyncMultipleSyncWithArgLastReturnCalled1": 42, + "callAsyncMultipleSyncWithArgLastReturnCalled2": 42, + "callAsyncMultipleSyncWithArgNoReturn": Object { + "type": "async", + "value": undefined, + }, + "callAsyncMultipleSyncWithArgNoReturnCalled1": 42, + "callAsyncMultipleSyncWithArgNoReturnCalled2": 42, + "callAsyncNone": Object { + "type": "async", + "value": undefined, + }, + "callAsyncNoneWithArg": Object { + "type": "async", + "value": undefined, + }, + "callAsyncSingleAsyncWithArg": Object { + "type": "async", + "value": 42, + }, + "callAsyncSingleAsyncWithArgCalled1": 42, + "callAsyncSinglePromiseWithArg": Object { + "type": "async", + "value": 43, + }, + "callAsyncSinglePromiseWithArgCalled1": 42, + "callAsyncSinglePromiseWithEmptyReject": Object { + "error": "Tap function (tapPromise) rejects \\"\\" value", + "type": "async", + }, + "callAsyncSinglePromiseWithEmptyStringArg": Object { + "type": "async", + "value": "", + }, + "callAsyncSinglePromiseWithEmptyStringArgCalled1": 42, + "callAsyncSinglePromiseWithFalseReject": Object { + "error": "Tap function (tapPromise) rejects \\"false\\" value", + "type": "async", + }, + "callAsyncSinglePromiseWithNullArg": Object { + "type": "async", + "value": null, + }, + "callAsyncSinglePromiseWithNullArgCalled1": 42, + "callAsyncSinglePromiseWithNullReject": Object { + "error": "Tap function (tapPromise) rejects \\"null\\" value", + "type": "async", + }, + "callAsyncSinglePromiseWithUndefined": Object { + "type": "async", + "value": undefined, + }, + "callAsyncSinglePromiseWithUndefinedCalled1": 42, + "callAsyncSinglePromiseWithUndefinedReject": Object { + "error": "Tap function (tapPromise) rejects \\"undefined\\" value", + "type": "async", + }, + "callAsyncSinglePromiseWithZeroArg": Object { + "type": "async", + "value": 0, + }, + "callAsyncSinglePromiseWithZeroArgCalled1": 42, + "callAsyncSinglePromiseWithZeroReject": Object { + "error": "Tap function (tapPromise) rejects \\"0\\" value", + "type": "async", + }, + "callAsyncSingleSync": Object { + "type": "async", + "value": 42, + }, + "callAsyncSingleSyncCalled1": true, + "callAsyncSingleSyncWithArg": Object { + "type": "async", + "value": 43, + }, + "callAsyncSingleSyncWithArgCalled1": 42, + "callAsyncSingleSyncWithArgNoReturn": Object { + "type": "async", + "value": undefined, + }, + "callAsyncSingleSyncWithArgNoReturnCalled1": 42, + "promiseMultipleAsyncEarlyError": Object { + "error": "Error in async2", + "type": "promise", + }, + "promiseMultipleAsyncEarlyErrorCalled1": true, + "promiseMultipleAsyncError": Object { + "error": "Error in async2", + "type": "promise", + }, + "promiseMultipleAsyncErrorCalled1": true, + "promiseMultipleAsyncLateError": Object { + "error": "Error in async2", + "type": "promise", + }, + "promiseMultipleAsyncLateErrorCalled1": true, + "promiseMultipleAsyncLateErrorCalled3": true, + "promiseMultipleAsyncLateErrorEarlyResult1": Object { + "error": "Error in async2", + "type": "promise", + }, + "promiseMultipleAsyncLateErrorEarlyResult1Called1": true, + "promiseMultipleAsyncLateErrorEarlyResult1Called3": true, + "promiseMultipleAsyncLateErrorEarlyResult2": Object { + "type": "promise", + "value": 42, + }, + "promiseMultipleAsyncLateErrorEarlyResult2Called1": true, + "promiseMultipleAsyncLateErrorEarlyResult2Called3": true, + "promiseMultipleAsyncWithArg": Object { + "type": "promise", + "value": 43, + }, + "promiseMultipleAsyncWithArgCalled1": 42, + "promiseMultipleAsyncWithArgFirstReturn": Object { + "type": "promise", + "value": 43, + }, + "promiseMultipleAsyncWithArgFirstReturnCalled1": 42, + "promiseMultipleAsyncWithArgLastReturn": Object { + "type": "promise", + "value": 44, + }, + "promiseMultipleAsyncWithArgLastReturnCalled1": 42, + "promiseMultipleAsyncWithArgLastReturnCalled2": 42, + "promiseMultipleAsyncWithArgNoReturn": Object { + "type": "promise", + "value": undefined, + }, + "promiseMultipleAsyncWithArgNoReturnCalled1": 42, + "promiseMultipleAsyncWithArgNoReturnCalled2": 42, + "promiseMultipleMixed1WithArg": Object { + "type": "promise", + "value": 43, + }, + "promiseMultipleMixed1WithArgCalled1": 42, + "promiseMultipleMixed2WithArg": Object { + "type": "promise", + "value": 43, + }, + "promiseMultipleMixed2WithArgCalled1": 42, + "promiseMultipleMixed2WithArgCalled2": 42, + "promiseMultipleMixed3WithArg": Object { + "type": "promise", + "value": 43, + }, + "promiseMultipleMixed3WithArgCalled1": 42, + "promiseMultipleMixedError1WithArg": Object { + "type": "promise", + "value": 42, + }, + "promiseMultipleMixedError1WithArgCalled1": 42, + "promiseMultipleMixedError2WithArg": Object { + "type": "promise", + "value": 42, + }, + "promiseMultipleMixedError2WithArgCalled1": 42, + "promiseMultipleMixedError3WithArg": Object { + "error": "Error in async", + "type": "promise", + }, + "promiseMultipleMixedError3WithArgCalled1": 42, + "promiseMultipleMixedLateError": Object { + "error": "Error in async", + "type": "promise", + }, + "promiseMultipleMixedLateErrorCalled1": true, + "promiseMultipleMixedLateErrorCalled2": true, + "promiseMultipleMixedLateErrorCalled3": true, + "promiseMultiplePromiseEarlyError": Object { + "error": "Error in async2", + "type": "promise", + }, + "promiseMultiplePromiseEarlyErrorCalled1": true, + "promiseMultiplePromiseEarlyErrorCalled3": true, + "promiseMultiplePromiseError": Object { + "error": "Error in async2", + "type": "promise", + }, + "promiseMultiplePromiseErrorCalled1": true, + "promiseMultiplePromiseErrorCalled3": true, + "promiseMultiplePromiseLateError": Object { + "error": "Error in async2", + "type": "promise", + }, + "promiseMultiplePromiseLateErrorCalled1": true, + "promiseMultiplePromiseLateErrorCalled3": true, + "promiseMultiplePromiseWithArg": Object { + "type": "promise", + "value": 43, + }, + "promiseMultiplePromiseWithArgCalled1": 42, + "promiseMultiplePromiseWithArgCalled2": 42, + "promiseMultiplePromiseWithArgFirstReturn": Object { + "type": "promise", + "value": 43, + }, + "promiseMultiplePromiseWithArgFirstReturnCalled1": 42, + "promiseMultiplePromiseWithArgFirstReturnCalled2": 42, + "promiseMultiplePromiseWithArgLastReturn": Object { + "type": "promise", + "value": 44, + }, + "promiseMultiplePromiseWithArgLastReturnCalled1": 42, + "promiseMultiplePromiseWithArgLastReturnCalled2": 42, + "promiseMultiplePromiseWithArgNoReturn": Object { + "type": "promise", + "value": undefined, + }, + "promiseMultiplePromiseWithArgNoReturnCalled1": 42, + "promiseMultiplePromiseWithArgNoReturnCalled2": 42, + "promiseMultipleSync": Object { + "type": "promise", + "value": 42, + }, + "promiseMultipleSyncCalled1": true, + "promiseMultipleSyncError": Object { + "error": "Error in sync2", + "type": "promise", + }, + "promiseMultipleSyncErrorCalled1": true, + "promiseMultipleSyncLastReturn": Object { + "type": "promise", + "value": 43, + }, + "promiseMultipleSyncLastReturnCalled1": true, + "promiseMultipleSyncLastReturnCalled2": true, + "promiseMultipleSyncNoReturn": Object { + "type": "promise", + "value": undefined, + }, + "promiseMultipleSyncNoReturnCalled1": true, + "promiseMultipleSyncNoReturnCalled2": true, + "promiseMultipleSyncWithArg": Object { + "type": "promise", + "value": 43, + }, + "promiseMultipleSyncWithArgCalled1": 42, + "promiseMultipleSyncWithArgFirstReturn": Object { + "type": "promise", + "value": 43, + }, + "promiseMultipleSyncWithArgFirstReturnCalled1": 42, + "promiseMultipleSyncWithArgLastReturn": Object { + "type": "promise", + "value": 44, + }, + "promiseMultipleSyncWithArgLastReturnCalled1": 42, + "promiseMultipleSyncWithArgLastReturnCalled2": 42, + "promiseMultipleSyncWithArgNoReturn": Object { + "type": "promise", + "value": undefined, + }, + "promiseMultipleSyncWithArgNoReturnCalled1": 42, + "promiseMultipleSyncWithArgNoReturnCalled2": 42, + "promiseNone": Object { + "type": "promise", + "value": undefined, + }, + "promiseNoneWithArg": Object { + "type": "promise", + "value": undefined, + }, + "promiseSingleAsyncWithArg": Object { + "type": "promise", + "value": 42, + }, + "promiseSingleAsyncWithArgCalled1": 42, + "promiseSinglePromiseWithArg": Object { + "type": "promise", + "value": 43, + }, + "promiseSinglePromiseWithArgCalled1": 42, + "promiseSinglePromiseWithEmptyReject": Object { + "error": "Tap function (tapPromise) rejects \\"\\" value", + "type": "promise", + }, + "promiseSinglePromiseWithEmptyStringArg": Object { + "type": "promise", + "value": "", + }, + "promiseSinglePromiseWithEmptyStringArgCalled1": 42, + "promiseSinglePromiseWithFalseReject": Object { + "error": "Tap function (tapPromise) rejects \\"false\\" value", + "type": "promise", + }, + "promiseSinglePromiseWithNullArg": Object { + "type": "promise", + "value": null, + }, + "promiseSinglePromiseWithNullArgCalled1": 42, + "promiseSinglePromiseWithNullReject": Object { + "error": "Tap function (tapPromise) rejects \\"null\\" value", + "type": "promise", + }, + "promiseSinglePromiseWithUndefined": Object { + "type": "promise", + "value": undefined, + }, + "promiseSinglePromiseWithUndefinedCalled1": 42, + "promiseSinglePromiseWithUndefinedReject": Object { + "error": "Tap function (tapPromise) rejects \\"undefined\\" value", + "type": "promise", + }, + "promiseSinglePromiseWithZeroArg": Object { + "type": "promise", + "value": 0, + }, + "promiseSinglePromiseWithZeroArgCalled1": 42, + "promiseSinglePromiseWithZeroReject": Object { + "error": "Tap function (tapPromise) rejects \\"0\\" value", + "type": "promise", + }, + "promiseSingleSync": Object { + "type": "promise", + "value": 42, + }, + "promiseSingleSyncCalled1": true, + "promiseSingleSyncWithArg": Object { + "type": "promise", + "value": 43, + }, + "promiseSingleSyncWithArgCalled1": 42, + "promiseSingleSyncWithArgNoReturn": Object { + "type": "promise", + "value": undefined, + }, + "promiseSingleSyncWithArgNoReturnCalled1": 42, + }, + "intercept": Object { + "callAsyncContextIntercepted": Object { + "type": "async", + "value": 48, + }, + "callAsyncContextInterceptedCall1": Array [ + Object { + "number": 42, + }, + 1, + 2, + 3, + ], + "callAsyncContextInterceptedCall2": Array [ + 1, + 2, + 3, + ], + "callAsyncContextInterceptedTap1": Object { + "number": 42, + }, + "callAsyncIntercepted": Object { + "type": "async", + "value": 6, + }, + "callAsyncInterceptedCall1": Array [ + 1, + 2, + 3, + ], + "callAsyncInterceptedCall2": Array [ + 1, + 2, + 3, + ], + "callAsyncInterceptedResult1": 6, + "callAsyncInterceptedResult2": 6, + "callAsyncInterceptedTap1": Object { + "fn": 3, + "name": "sync", + "type": "sync", + }, + "callAsyncInterceptedTap2": Object { + "fn": 3, + "name": "sync", + "type": "sync", + }, + "callAsyncUnusedContextIntercepted": Object { + "type": "async", + "value": 6, + }, + "callAsyncUnusedContextInterceptedCall1": Array [ + undefined, + 1, + 2, + 3, + ], + "callAsyncUnusedContextInterceptedCall2": Array [ + 1, + 2, + 3, + ], + "callAsyncUnusedContextInterceptedTap1": undefined, + "promiseContextIntercepted": Object { + "type": "promise", + "value": 48, + }, + "promiseContextInterceptedCall1": Array [ + Object { + "number": 42, + }, + 1, + 2, + 3, + ], + "promiseContextInterceptedCall2": Array [ + 1, + 2, + 3, + ], + "promiseContextInterceptedTap1": Object { + "number": 42, + }, + "promiseIntercepted": Object { + "type": "promise", + "value": 6, + }, + "promiseInterceptedCall1": Array [ + 1, + 2, + 3, + ], + "promiseInterceptedCall2": Array [ + 1, + 2, + 3, + ], + "promiseInterceptedResult1": 6, + "promiseInterceptedResult2": 6, + "promiseInterceptedTap1": Object { + "fn": 3, + "name": "sync", + "type": "sync", + }, + "promiseInterceptedTap2": Object { + "fn": 3, + "name": "sync", + "type": "sync", + }, + "promiseUnusedContextIntercepted": Object { + "type": "promise", + "value": 6, + }, + "promiseUnusedContextInterceptedCall1": Array [ + undefined, + 1, + 2, + 3, + ], + "promiseUnusedContextInterceptedCall2": Array [ + 1, + 2, + 3, + ], + "promiseUnusedContextInterceptedTap1": undefined, + }, + "sync": Object { + "callAsyncIntercepted": Object { + "type": "async", + "value": 6, + }, + "callAsyncInterceptedCall1": Array [ + 1, + 2, + 3, + ], + "callAsyncInterceptedCall2": Array [ + 1, + 2, + 3, + ], + "callAsyncInterceptedTap1": Object { + "fn": 3, + "name": "sync1", + "type": "sync", + }, + "callAsyncInterceptedTap2": Object { + "fn": 3, + "name": "sync1", + "type": "sync", + }, + "callAsyncMultipleSync": Object { + "type": "async", + "value": 42, + }, + "callAsyncMultipleSyncCalled1": true, + "callAsyncMultipleSyncError": Object { + "error": "Error in sync2", + "type": "async", + }, + "callAsyncMultipleSyncErrorCalled1": true, + "callAsyncMultipleSyncErrorCalled2": true, + "callAsyncMultipleSyncWithArg": Object { + "type": "async", + "value": 84, + }, + "callAsyncMultipleSyncWithArgCalled1": 42, + "callAsyncMultipleSyncWithArgFirstReturn": Object { + "type": "async", + "value": 84, + }, + "callAsyncMultipleSyncWithArgFirstReturnCalled1": 42, + "callAsyncMultipleSyncWithArgLastReturn": Object { + "type": "async", + "value": 85, + }, + "callAsyncMultipleSyncWithArgLastReturnCalled1": 42, + "callAsyncMultipleSyncWithArgLastReturnCalled2": 42, + "callAsyncMultipleSyncWithArgNoReturn": Object { + "type": "async", + "value": undefined, + }, + "callAsyncMultipleSyncWithArgNoReturnCalled1": 42, + "callAsyncMultipleSyncWithArgNoReturnCalled2": 42, + "callAsyncMultipleSyncWithArgs": Object { + "type": "async", + "value": 129, + }, + "callAsyncMultipleSyncWithArgsCalled1": Array [ + 42, + 43, + 44, + ], + "callAsyncNone": Object { + "type": "async", + "value": undefined, + }, + "callAsyncNoneWithArg": Object { + "type": "async", + "value": undefined, + }, + "callAsyncSingleSync": Object { + "type": "async", + "value": 42, + }, + "callAsyncSingleSyncCalled": true, + "callAsyncSingleSyncWithArg": Object { + "type": "async", + "value": 42, + }, + "callAsyncSingleSyncWithArgCalled": 42, + "promiseIntercepted": Object { + "type": "promise", + "value": 6, + }, + "promiseInterceptedCall1": Array [ + 1, + 2, + 3, + ], + "promiseInterceptedCall2": Array [ + 1, + 2, + 3, + ], + "promiseInterceptedTap1": Object { + "fn": 3, + "name": "sync1", + "type": "sync", + }, + "promiseInterceptedTap2": Object { + "fn": 3, + "name": "sync1", + "type": "sync", + }, + "promiseMultipleSync": Object { + "type": "promise", + "value": 42, + }, + "promiseMultipleSyncCalled1": true, + "promiseMultipleSyncError": Object { + "error": "Error in sync2", + "type": "promise", + }, + "promiseMultipleSyncErrorCalled1": true, + "promiseMultipleSyncErrorCalled2": true, + "promiseMultipleSyncWithArg": Object { + "type": "promise", + "value": 84, + }, + "promiseMultipleSyncWithArgCalled1": 42, + "promiseMultipleSyncWithArgFirstReturn": Object { + "type": "promise", + "value": 84, + }, + "promiseMultipleSyncWithArgFirstReturnCalled1": 42, + "promiseMultipleSyncWithArgLastReturn": Object { + "type": "promise", + "value": 85, + }, + "promiseMultipleSyncWithArgLastReturnCalled1": 42, + "promiseMultipleSyncWithArgLastReturnCalled2": 42, + "promiseMultipleSyncWithArgNoReturn": Object { + "type": "promise", + "value": undefined, + }, + "promiseMultipleSyncWithArgNoReturnCalled1": 42, + "promiseMultipleSyncWithArgNoReturnCalled2": 42, + "promiseMultipleSyncWithArgs": Object { + "type": "promise", + "value": 129, + }, + "promiseMultipleSyncWithArgsCalled1": Array [ + 42, + 43, + 44, + ], + "promiseNone": Object { + "type": "promise", + "value": undefined, + }, + "promiseNoneWithArg": Object { + "type": "promise", + "value": undefined, + }, + "promiseSingleSync": Object { + "type": "promise", + "value": 42, + }, + "promiseSingleSyncCalled": true, + "promiseSingleSyncWithArg": Object { + "type": "promise", + "value": 42, + }, + "promiseSingleSyncWithArgCalled": 42, + }, +} +`; diff --git a/test/__snapshots__/AsyncParallelHooks.test.js.snap b/test/__snapshots__/AsyncParallelHooks.test.js.snap index c1c3b01..fd553b5 100644 --- a/test/__snapshots__/AsyncParallelHooks.test.js.snap +++ b/test/__snapshots__/AsyncParallelHooks.test.js.snap @@ -1,802 +1,5 @@ // Jest Snapshot v1, https://jestjs.io/docs/snapshot-testing -exports[`AsyncParallelBailHook should have to correct behavior 1`] = ` -Object { - "async": Object { - "callAsyncMultipleAsyncEarlyError": Object { - "error": "Error in async2", - "type": "async", - }, - "callAsyncMultipleAsyncEarlyErrorCalled1": true, - "callAsyncMultipleAsyncError": Object { - "error": "Error in async2", - "type": "async", - }, - "callAsyncMultipleAsyncErrorCalled1": true, - "callAsyncMultipleAsyncLateError": Object { - "error": "Error in async2", - "type": "async", - }, - "callAsyncMultipleAsyncLateErrorCalled1": true, - "callAsyncMultipleAsyncLateErrorCalled3": true, - "callAsyncMultipleAsyncLateErrorEarlyResult1": Object { - "error": "Error in async2", - "type": "async", - }, - "callAsyncMultipleAsyncLateErrorEarlyResult1Called1": true, - "callAsyncMultipleAsyncLateErrorEarlyResult1Called3": true, - "callAsyncMultipleAsyncLateErrorEarlyResult2": Object { - "type": "async", - "value": 42, - }, - "callAsyncMultipleAsyncLateErrorEarlyResult2Called1": true, - "callAsyncMultipleAsyncLateErrorEarlyResult2Called3": true, - "callAsyncMultipleAsyncWithArg": Object { - "type": "async", - "value": 43, - }, - "callAsyncMultipleAsyncWithArgCalled1": 42, - "callAsyncMultipleAsyncWithArgFirstReturn": Object { - "type": "async", - "value": 43, - }, - "callAsyncMultipleAsyncWithArgFirstReturnCalled1": 42, - "callAsyncMultipleAsyncWithArgLastReturn": Object { - "type": "async", - "value": 44, - }, - "callAsyncMultipleAsyncWithArgLastReturnCalled1": 42, - "callAsyncMultipleAsyncWithArgLastReturnCalled2": 42, - "callAsyncMultipleAsyncWithArgNoReturn": Object { - "type": "async", - "value": undefined, - }, - "callAsyncMultipleAsyncWithArgNoReturnCalled1": 42, - "callAsyncMultipleAsyncWithArgNoReturnCalled2": 42, - "callAsyncMultipleMixed1WithArg": Object { - "type": "async", - "value": 43, - }, - "callAsyncMultipleMixed1WithArgCalled1": 42, - "callAsyncMultipleMixed2WithArg": Object { - "type": "async", - "value": 43, - }, - "callAsyncMultipleMixed2WithArgCalled1": 42, - "callAsyncMultipleMixed2WithArgCalled2": 42, - "callAsyncMultipleMixed3WithArg": Object { - "type": "async", - "value": 43, - }, - "callAsyncMultipleMixed3WithArgCalled1": 42, - "callAsyncMultipleMixedError1WithArg": Object { - "type": "async", - "value": 42, - }, - "callAsyncMultipleMixedError1WithArgCalled1": 42, - "callAsyncMultipleMixedError2WithArg": Object { - "type": "async", - "value": 42, - }, - "callAsyncMultipleMixedError2WithArgCalled1": 42, - "callAsyncMultipleMixedError3WithArg": Object { - "error": "Error in async", - "type": "async", - }, - "callAsyncMultipleMixedError3WithArgCalled1": 42, - "callAsyncMultipleMixedLateError": Object { - "error": "Error in async", - "type": "async", - }, - "callAsyncMultipleMixedLateErrorCalled1": true, - "callAsyncMultipleMixedLateErrorCalled2": true, - "callAsyncMultipleMixedLateErrorCalled3": true, - "callAsyncMultiplePromiseEarlyError": Object { - "error": "Error in async2", - "type": "async", - }, - "callAsyncMultiplePromiseEarlyErrorCalled1": true, - "callAsyncMultiplePromiseEarlyErrorCalled3": true, - "callAsyncMultiplePromiseError": Object { - "error": "Error in async2", - "type": "async", - }, - "callAsyncMultiplePromiseErrorCalled1": true, - "callAsyncMultiplePromiseErrorCalled3": true, - "callAsyncMultiplePromiseLateError": Object { - "error": "Error in async2", - "type": "async", - }, - "callAsyncMultiplePromiseLateErrorCalled1": true, - "callAsyncMultiplePromiseLateErrorCalled3": true, - "callAsyncMultiplePromiseWithArg": Object { - "type": "async", - "value": 43, - }, - "callAsyncMultiplePromiseWithArgCalled1": 42, - "callAsyncMultiplePromiseWithArgCalled2": 42, - "callAsyncMultiplePromiseWithArgFirstReturn": Object { - "type": "async", - "value": 43, - }, - "callAsyncMultiplePromiseWithArgFirstReturnCalled1": 42, - "callAsyncMultiplePromiseWithArgFirstReturnCalled2": 42, - "callAsyncMultiplePromiseWithArgLastReturn": Object { - "type": "async", - "value": 44, - }, - "callAsyncMultiplePromiseWithArgLastReturnCalled1": 42, - "callAsyncMultiplePromiseWithArgLastReturnCalled2": 42, - "callAsyncMultiplePromiseWithArgNoReturn": Object { - "type": "async", - "value": undefined, - }, - "callAsyncMultiplePromiseWithArgNoReturnCalled1": 42, - "callAsyncMultiplePromiseWithArgNoReturnCalled2": 42, - "callAsyncMultipleSync": Object { - "type": "async", - "value": 42, - }, - "callAsyncMultipleSyncCalled1": true, - "callAsyncMultipleSyncError": Object { - "error": "Error in sync2", - "type": "async", - }, - "callAsyncMultipleSyncErrorCalled1": true, - "callAsyncMultipleSyncLastReturn": Object { - "type": "async", - "value": 43, - }, - "callAsyncMultipleSyncLastReturnCalled1": true, - "callAsyncMultipleSyncLastReturnCalled2": true, - "callAsyncMultipleSyncNoReturn": Object { - "type": "async", - "value": undefined, - }, - "callAsyncMultipleSyncNoReturnCalled1": true, - "callAsyncMultipleSyncNoReturnCalled2": true, - "callAsyncMultipleSyncWithArg": Object { - "type": "async", - "value": 43, - }, - "callAsyncMultipleSyncWithArgCalled1": 42, - "callAsyncMultipleSyncWithArgFirstReturn": Object { - "type": "async", - "value": 43, - }, - "callAsyncMultipleSyncWithArgFirstReturnCalled1": 42, - "callAsyncMultipleSyncWithArgLastReturn": Object { - "type": "async", - "value": 44, - }, - "callAsyncMultipleSyncWithArgLastReturnCalled1": 42, - "callAsyncMultipleSyncWithArgLastReturnCalled2": 42, - "callAsyncMultipleSyncWithArgNoReturn": Object { - "type": "async", - "value": undefined, - }, - "callAsyncMultipleSyncWithArgNoReturnCalled1": 42, - "callAsyncMultipleSyncWithArgNoReturnCalled2": 42, - "callAsyncNone": Object { - "type": "async", - "value": undefined, - }, - "callAsyncNoneWithArg": Object { - "type": "async", - "value": undefined, - }, - "callAsyncSingleAsyncWithArg": Object { - "type": "async", - "value": 42, - }, - "callAsyncSingleAsyncWithArgCalled1": 42, - "callAsyncSinglePromiseWithArg": Object { - "type": "async", - "value": 43, - }, - "callAsyncSinglePromiseWithArgCalled1": 42, - "callAsyncSinglePromiseWithEmptyReject": Object { - "error": "Tap function (tapPromise) rejects \\"\\" value", - "type": "async", - }, - "callAsyncSinglePromiseWithEmptyStringArg": Object { - "type": "async", - "value": "", - }, - "callAsyncSinglePromiseWithEmptyStringArgCalled1": 42, - "callAsyncSinglePromiseWithFalseReject": Object { - "error": "Tap function (tapPromise) rejects \\"false\\" value", - "type": "async", - }, - "callAsyncSinglePromiseWithNullArg": Object { - "type": "async", - "value": null, - }, - "callAsyncSinglePromiseWithNullArgCalled1": 42, - "callAsyncSinglePromiseWithNullReject": Object { - "error": "Tap function (tapPromise) rejects \\"null\\" value", - "type": "async", - }, - "callAsyncSinglePromiseWithUndefined": Object { - "type": "async", - "value": undefined, - }, - "callAsyncSinglePromiseWithUndefinedCalled1": 42, - "callAsyncSinglePromiseWithUndefinedReject": Object { - "error": "Tap function (tapPromise) rejects \\"undefined\\" value", - "type": "async", - }, - "callAsyncSinglePromiseWithZeroArg": Object { - "type": "async", - "value": 0, - }, - "callAsyncSinglePromiseWithZeroArgCalled1": 42, - "callAsyncSinglePromiseWithZeroReject": Object { - "error": "Tap function (tapPromise) rejects \\"0\\" value", - "type": "async", - }, - "callAsyncSingleSync": Object { - "type": "async", - "value": 42, - }, - "callAsyncSingleSyncCalled1": true, - "callAsyncSingleSyncWithArg": Object { - "type": "async", - "value": 43, - }, - "callAsyncSingleSyncWithArgCalled1": 42, - "callAsyncSingleSyncWithArgNoReturn": Object { - "type": "async", - "value": undefined, - }, - "callAsyncSingleSyncWithArgNoReturnCalled1": 42, - "promiseMultipleAsyncEarlyError": Object { - "error": "Error in async2", - "type": "promise", - }, - "promiseMultipleAsyncEarlyErrorCalled1": true, - "promiseMultipleAsyncError": Object { - "error": "Error in async2", - "type": "promise", - }, - "promiseMultipleAsyncErrorCalled1": true, - "promiseMultipleAsyncLateError": Object { - "error": "Error in async2", - "type": "promise", - }, - "promiseMultipleAsyncLateErrorCalled1": true, - "promiseMultipleAsyncLateErrorCalled3": true, - "promiseMultipleAsyncLateErrorEarlyResult1": Object { - "error": "Error in async2", - "type": "promise", - }, - "promiseMultipleAsyncLateErrorEarlyResult1Called1": true, - "promiseMultipleAsyncLateErrorEarlyResult1Called3": true, - "promiseMultipleAsyncLateErrorEarlyResult2": Object { - "type": "promise", - "value": 42, - }, - "promiseMultipleAsyncLateErrorEarlyResult2Called1": true, - "promiseMultipleAsyncLateErrorEarlyResult2Called3": true, - "promiseMultipleAsyncWithArg": Object { - "type": "promise", - "value": 43, - }, - "promiseMultipleAsyncWithArgCalled1": 42, - "promiseMultipleAsyncWithArgFirstReturn": Object { - "type": "promise", - "value": 43, - }, - "promiseMultipleAsyncWithArgFirstReturnCalled1": 42, - "promiseMultipleAsyncWithArgLastReturn": Object { - "type": "promise", - "value": 44, - }, - "promiseMultipleAsyncWithArgLastReturnCalled1": 42, - "promiseMultipleAsyncWithArgLastReturnCalled2": 42, - "promiseMultipleAsyncWithArgNoReturn": Object { - "type": "promise", - "value": undefined, - }, - "promiseMultipleAsyncWithArgNoReturnCalled1": 42, - "promiseMultipleAsyncWithArgNoReturnCalled2": 42, - "promiseMultipleMixed1WithArg": Object { - "type": "promise", - "value": 43, - }, - "promiseMultipleMixed1WithArgCalled1": 42, - "promiseMultipleMixed2WithArg": Object { - "type": "promise", - "value": 43, - }, - "promiseMultipleMixed2WithArgCalled1": 42, - "promiseMultipleMixed2WithArgCalled2": 42, - "promiseMultipleMixed3WithArg": Object { - "type": "promise", - "value": 43, - }, - "promiseMultipleMixed3WithArgCalled1": 42, - "promiseMultipleMixedError1WithArg": Object { - "type": "promise", - "value": 42, - }, - "promiseMultipleMixedError1WithArgCalled1": 42, - "promiseMultipleMixedError2WithArg": Object { - "type": "promise", - "value": 42, - }, - "promiseMultipleMixedError2WithArgCalled1": 42, - "promiseMultipleMixedError3WithArg": Object { - "error": "Error in async", - "type": "promise", - }, - "promiseMultipleMixedError3WithArgCalled1": 42, - "promiseMultipleMixedLateError": Object { - "error": "Error in async", - "type": "promise", - }, - "promiseMultipleMixedLateErrorCalled1": true, - "promiseMultipleMixedLateErrorCalled2": true, - "promiseMultipleMixedLateErrorCalled3": true, - "promiseMultiplePromiseEarlyError": Object { - "error": "Error in async2", - "type": "promise", - }, - "promiseMultiplePromiseEarlyErrorCalled1": true, - "promiseMultiplePromiseEarlyErrorCalled3": true, - "promiseMultiplePromiseError": Object { - "error": "Error in async2", - "type": "promise", - }, - "promiseMultiplePromiseErrorCalled1": true, - "promiseMultiplePromiseErrorCalled3": true, - "promiseMultiplePromiseLateError": Object { - "error": "Error in async2", - "type": "promise", - }, - "promiseMultiplePromiseLateErrorCalled1": true, - "promiseMultiplePromiseLateErrorCalled3": true, - "promiseMultiplePromiseWithArg": Object { - "type": "promise", - "value": 43, - }, - "promiseMultiplePromiseWithArgCalled1": 42, - "promiseMultiplePromiseWithArgCalled2": 42, - "promiseMultiplePromiseWithArgFirstReturn": Object { - "type": "promise", - "value": 43, - }, - "promiseMultiplePromiseWithArgFirstReturnCalled1": 42, - "promiseMultiplePromiseWithArgFirstReturnCalled2": 42, - "promiseMultiplePromiseWithArgLastReturn": Object { - "type": "promise", - "value": 44, - }, - "promiseMultiplePromiseWithArgLastReturnCalled1": 42, - "promiseMultiplePromiseWithArgLastReturnCalled2": 42, - "promiseMultiplePromiseWithArgNoReturn": Object { - "type": "promise", - "value": undefined, - }, - "promiseMultiplePromiseWithArgNoReturnCalled1": 42, - "promiseMultiplePromiseWithArgNoReturnCalled2": 42, - "promiseMultipleSync": Object { - "type": "promise", - "value": 42, - }, - "promiseMultipleSyncCalled1": true, - "promiseMultipleSyncError": Object { - "error": "Error in sync2", - "type": "promise", - }, - "promiseMultipleSyncErrorCalled1": true, - "promiseMultipleSyncLastReturn": Object { - "type": "promise", - "value": 43, - }, - "promiseMultipleSyncLastReturnCalled1": true, - "promiseMultipleSyncLastReturnCalled2": true, - "promiseMultipleSyncNoReturn": Object { - "type": "promise", - "value": undefined, - }, - "promiseMultipleSyncNoReturnCalled1": true, - "promiseMultipleSyncNoReturnCalled2": true, - "promiseMultipleSyncWithArg": Object { - "type": "promise", - "value": 43, - }, - "promiseMultipleSyncWithArgCalled1": 42, - "promiseMultipleSyncWithArgFirstReturn": Object { - "type": "promise", - "value": 43, - }, - "promiseMultipleSyncWithArgFirstReturnCalled1": 42, - "promiseMultipleSyncWithArgLastReturn": Object { - "type": "promise", - "value": 44, - }, - "promiseMultipleSyncWithArgLastReturnCalled1": 42, - "promiseMultipleSyncWithArgLastReturnCalled2": 42, - "promiseMultipleSyncWithArgNoReturn": Object { - "type": "promise", - "value": undefined, - }, - "promiseMultipleSyncWithArgNoReturnCalled1": 42, - "promiseMultipleSyncWithArgNoReturnCalled2": 42, - "promiseNone": Object { - "type": "promise", - "value": undefined, - }, - "promiseNoneWithArg": Object { - "type": "promise", - "value": undefined, - }, - "promiseSingleAsyncWithArg": Object { - "type": "promise", - "value": 42, - }, - "promiseSingleAsyncWithArgCalled1": 42, - "promiseSinglePromiseWithArg": Object { - "type": "promise", - "value": 43, - }, - "promiseSinglePromiseWithArgCalled1": 42, - "promiseSinglePromiseWithEmptyReject": Object { - "error": "Tap function (tapPromise) rejects \\"\\" value", - "type": "promise", - }, - "promiseSinglePromiseWithEmptyStringArg": Object { - "type": "promise", - "value": "", - }, - "promiseSinglePromiseWithEmptyStringArgCalled1": 42, - "promiseSinglePromiseWithFalseReject": Object { - "error": "Tap function (tapPromise) rejects \\"false\\" value", - "type": "promise", - }, - "promiseSinglePromiseWithNullArg": Object { - "type": "promise", - "value": null, - }, - "promiseSinglePromiseWithNullArgCalled1": 42, - "promiseSinglePromiseWithNullReject": Object { - "error": "Tap function (tapPromise) rejects \\"null\\" value", - "type": "promise", - }, - "promiseSinglePromiseWithUndefined": Object { - "type": "promise", - "value": undefined, - }, - "promiseSinglePromiseWithUndefinedCalled1": 42, - "promiseSinglePromiseWithUndefinedReject": Object { - "error": "Tap function (tapPromise) rejects \\"undefined\\" value", - "type": "promise", - }, - "promiseSinglePromiseWithZeroArg": Object { - "type": "promise", - "value": 0, - }, - "promiseSinglePromiseWithZeroArgCalled1": 42, - "promiseSinglePromiseWithZeroReject": Object { - "error": "Tap function (tapPromise) rejects \\"0\\" value", - "type": "promise", - }, - "promiseSingleSync": Object { - "type": "promise", - "value": 42, - }, - "promiseSingleSyncCalled1": true, - "promiseSingleSyncWithArg": Object { - "type": "promise", - "value": 43, - }, - "promiseSingleSyncWithArgCalled1": 42, - "promiseSingleSyncWithArgNoReturn": Object { - "type": "promise", - "value": undefined, - }, - "promiseSingleSyncWithArgNoReturnCalled1": 42, - }, - "intercept": Object { - "callAsyncContextIntercepted": Object { - "type": "async", - "value": 48, - }, - "callAsyncContextInterceptedCall1": Array [ - Object { - "number": 42, - }, - 1, - 2, - 3, - ], - "callAsyncContextInterceptedCall2": Array [ - 1, - 2, - 3, - ], - "callAsyncContextInterceptedTap1": Object { - "number": 42, - }, - "callAsyncIntercepted": Object { - "type": "async", - "value": 6, - }, - "callAsyncInterceptedCall1": Array [ - 1, - 2, - 3, - ], - "callAsyncInterceptedCall2": Array [ - 1, - 2, - 3, - ], - "callAsyncInterceptedResult1": 6, - "callAsyncInterceptedResult2": 6, - "callAsyncInterceptedTap1": Object { - "fn": 3, - "name": "sync", - "type": "sync", - }, - "callAsyncInterceptedTap2": Object { - "fn": 3, - "name": "sync", - "type": "sync", - }, - "callAsyncUnusedContextIntercepted": Object { - "type": "async", - "value": 6, - }, - "callAsyncUnusedContextInterceptedCall1": Array [ - undefined, - 1, - 2, - 3, - ], - "callAsyncUnusedContextInterceptedCall2": Array [ - 1, - 2, - 3, - ], - "callAsyncUnusedContextInterceptedTap1": undefined, - "promiseContextIntercepted": Object { - "type": "promise", - "value": 48, - }, - "promiseContextInterceptedCall1": Array [ - Object { - "number": 42, - }, - 1, - 2, - 3, - ], - "promiseContextInterceptedCall2": Array [ - 1, - 2, - 3, - ], - "promiseContextInterceptedTap1": Object { - "number": 42, - }, - "promiseIntercepted": Object { - "type": "promise", - "value": 6, - }, - "promiseInterceptedCall1": Array [ - 1, - 2, - 3, - ], - "promiseInterceptedCall2": Array [ - 1, - 2, - 3, - ], - "promiseInterceptedResult1": 6, - "promiseInterceptedResult2": 6, - "promiseInterceptedTap1": Object { - "fn": 3, - "name": "sync", - "type": "sync", - }, - "promiseInterceptedTap2": Object { - "fn": 3, - "name": "sync", - "type": "sync", - }, - "promiseUnusedContextIntercepted": Object { - "type": "promise", - "value": 6, - }, - "promiseUnusedContextInterceptedCall1": Array [ - undefined, - 1, - 2, - 3, - ], - "promiseUnusedContextInterceptedCall2": Array [ - 1, - 2, - 3, - ], - "promiseUnusedContextInterceptedTap1": undefined, - }, - "sync": Object { - "callAsyncIntercepted": Object { - "type": "async", - "value": 6, - }, - "callAsyncInterceptedCall1": Array [ - 1, - 2, - 3, - ], - "callAsyncInterceptedCall2": Array [ - 1, - 2, - 3, - ], - "callAsyncInterceptedTap1": Object { - "fn": 3, - "name": "sync1", - "type": "sync", - }, - "callAsyncInterceptedTap2": Object { - "fn": 3, - "name": "sync1", - "type": "sync", - }, - "callAsyncMultipleSync": Object { - "type": "async", - "value": 42, - }, - "callAsyncMultipleSyncCalled1": true, - "callAsyncMultipleSyncError": Object { - "error": "Error in sync2", - "type": "async", - }, - "callAsyncMultipleSyncErrorCalled1": true, - "callAsyncMultipleSyncErrorCalled2": true, - "callAsyncMultipleSyncWithArg": Object { - "type": "async", - "value": 84, - }, - "callAsyncMultipleSyncWithArgCalled1": 42, - "callAsyncMultipleSyncWithArgFirstReturn": Object { - "type": "async", - "value": 84, - }, - "callAsyncMultipleSyncWithArgFirstReturnCalled1": 42, - "callAsyncMultipleSyncWithArgLastReturn": Object { - "type": "async", - "value": 85, - }, - "callAsyncMultipleSyncWithArgLastReturnCalled1": 42, - "callAsyncMultipleSyncWithArgLastReturnCalled2": 42, - "callAsyncMultipleSyncWithArgNoReturn": Object { - "type": "async", - "value": undefined, - }, - "callAsyncMultipleSyncWithArgNoReturnCalled1": 42, - "callAsyncMultipleSyncWithArgNoReturnCalled2": 42, - "callAsyncMultipleSyncWithArgs": Object { - "type": "async", - "value": 129, - }, - "callAsyncMultipleSyncWithArgsCalled1": Array [ - 42, - 43, - 44, - ], - "callAsyncNone": Object { - "type": "async", - "value": undefined, - }, - "callAsyncNoneWithArg": Object { - "type": "async", - "value": undefined, - }, - "callAsyncSingleSync": Object { - "type": "async", - "value": 42, - }, - "callAsyncSingleSyncCalled": true, - "callAsyncSingleSyncWithArg": Object { - "type": "async", - "value": 42, - }, - "callAsyncSingleSyncWithArgCalled": 42, - "promiseIntercepted": Object { - "type": "promise", - "value": 6, - }, - "promiseInterceptedCall1": Array [ - 1, - 2, - 3, - ], - "promiseInterceptedCall2": Array [ - 1, - 2, - 3, - ], - "promiseInterceptedTap1": Object { - "fn": 3, - "name": "sync1", - "type": "sync", - }, - "promiseInterceptedTap2": Object { - "fn": 3, - "name": "sync1", - "type": "sync", - }, - "promiseMultipleSync": Object { - "type": "promise", - "value": 42, - }, - "promiseMultipleSyncCalled1": true, - "promiseMultipleSyncError": Object { - "error": "Error in sync2", - "type": "promise", - }, - "promiseMultipleSyncErrorCalled1": true, - "promiseMultipleSyncErrorCalled2": true, - "promiseMultipleSyncWithArg": Object { - "type": "promise", - "value": 84, - }, - "promiseMultipleSyncWithArgCalled1": 42, - "promiseMultipleSyncWithArgFirstReturn": Object { - "type": "promise", - "value": 84, - }, - "promiseMultipleSyncWithArgFirstReturnCalled1": 42, - "promiseMultipleSyncWithArgLastReturn": Object { - "type": "promise", - "value": 85, - }, - "promiseMultipleSyncWithArgLastReturnCalled1": 42, - "promiseMultipleSyncWithArgLastReturnCalled2": 42, - "promiseMultipleSyncWithArgNoReturn": Object { - "type": "promise", - "value": undefined, - }, - "promiseMultipleSyncWithArgNoReturnCalled1": 42, - "promiseMultipleSyncWithArgNoReturnCalled2": 42, - "promiseMultipleSyncWithArgs": Object { - "type": "promise", - "value": 129, - }, - "promiseMultipleSyncWithArgsCalled1": Array [ - 42, - 43, - 44, - ], - "promiseNone": Object { - "type": "promise", - "value": undefined, - }, - "promiseNoneWithArg": Object { - "type": "promise", - "value": undefined, - }, - "promiseSingleSync": Object { - "type": "promise", - "value": 42, - }, - "promiseSingleSyncCalled": true, - "promiseSingleSyncWithArg": Object { - "type": "promise", - "value": 42, - }, - "promiseSingleSyncWithArgCalled": 42, - }, -} -`; - exports[`AsyncParallelHook should have to correct behavior 1`] = ` Object { "async": Object { diff --git a/test/__snapshots__/AsyncSeriesBailHook.test.js.snap b/test/__snapshots__/AsyncSeriesBailHook.test.js.snap new file mode 100644 index 0000000..f9c4986 --- /dev/null +++ b/test/__snapshots__/AsyncSeriesBailHook.test.js.snap @@ -0,0 +1,776 @@ +// Jest Snapshot v1, https://jestjs.io/docs/snapshot-testing + +exports[`AsyncSeriesBailHook should have to correct behavior 1`] = ` +Object { + "async": Object { + "callAsyncMultipleAsyncEarlyError": Object { + "error": "Error in async2", + "type": "async", + }, + "callAsyncMultipleAsyncEarlyErrorCalled1": true, + "callAsyncMultipleAsyncError": Object { + "error": "Error in async2", + "type": "async", + }, + "callAsyncMultipleAsyncErrorCalled1": true, + "callAsyncMultipleAsyncLateError": Object { + "error": "Error in async2", + "type": "async", + }, + "callAsyncMultipleAsyncLateErrorCalled1": true, + "callAsyncMultipleAsyncLateErrorEarlyResult1": Object { + "error": "Error in async2", + "type": "async", + }, + "callAsyncMultipleAsyncLateErrorEarlyResult1Called1": true, + "callAsyncMultipleAsyncLateErrorEarlyResult2": Object { + "type": "async", + "value": 42, + }, + "callAsyncMultipleAsyncLateErrorEarlyResult2Called1": true, + "callAsyncMultipleAsyncWithArg": Object { + "type": "async", + "value": 43, + }, + "callAsyncMultipleAsyncWithArgCalled1": 42, + "callAsyncMultipleAsyncWithArgFirstReturn": Object { + "type": "async", + "value": 43, + }, + "callAsyncMultipleAsyncWithArgFirstReturnCalled1": 42, + "callAsyncMultipleAsyncWithArgLastReturn": Object { + "type": "async", + "value": 44, + }, + "callAsyncMultipleAsyncWithArgLastReturnCalled1": 42, + "callAsyncMultipleAsyncWithArgLastReturnCalled2": 42, + "callAsyncMultipleAsyncWithArgNoReturn": Object { + "type": "async", + "value": undefined, + }, + "callAsyncMultipleAsyncWithArgNoReturnCalled1": 42, + "callAsyncMultipleAsyncWithArgNoReturnCalled2": 42, + "callAsyncMultipleMixed1WithArg": Object { + "type": "async", + "value": 43, + }, + "callAsyncMultipleMixed1WithArgCalled1": 42, + "callAsyncMultipleMixed2WithArg": Object { + "type": "async", + "value": 43, + }, + "callAsyncMultipleMixed2WithArgCalled1": 42, + "callAsyncMultipleMixed3WithArg": Object { + "type": "async", + "value": 43, + }, + "callAsyncMultipleMixed3WithArgCalled1": 42, + "callAsyncMultipleMixedError1WithArg": Object { + "type": "async", + "value": 42, + }, + "callAsyncMultipleMixedError1WithArgCalled1": 42, + "callAsyncMultipleMixedError2WithArg": Object { + "type": "async", + "value": 42, + }, + "callAsyncMultipleMixedError2WithArgCalled1": 42, + "callAsyncMultipleMixedError3WithArg": Object { + "error": "Error in async", + "type": "async", + }, + "callAsyncMultipleMixedError3WithArgCalled1": 42, + "callAsyncMultipleMixedLateError": Object { + "error": "Error in async", + "type": "async", + }, + "callAsyncMultipleMixedLateErrorCalled1": true, + "callAsyncMultiplePromiseEarlyError": Object { + "error": "Error in async2", + "type": "async", + }, + "callAsyncMultiplePromiseEarlyErrorCalled1": true, + "callAsyncMultiplePromiseError": Object { + "error": "Error in async2", + "type": "async", + }, + "callAsyncMultiplePromiseErrorCalled1": true, + "callAsyncMultiplePromiseLateError": Object { + "error": "Error in async2", + "type": "async", + }, + "callAsyncMultiplePromiseLateErrorCalled1": true, + "callAsyncMultiplePromiseWithArg": Object { + "type": "async", + "value": 43, + }, + "callAsyncMultiplePromiseWithArgCalled1": 42, + "callAsyncMultiplePromiseWithArgFirstReturn": Object { + "type": "async", + "value": 43, + }, + "callAsyncMultiplePromiseWithArgFirstReturnCalled1": 42, + "callAsyncMultiplePromiseWithArgLastReturn": Object { + "type": "async", + "value": 44, + }, + "callAsyncMultiplePromiseWithArgLastReturnCalled1": 42, + "callAsyncMultiplePromiseWithArgLastReturnCalled2": 42, + "callAsyncMultiplePromiseWithArgNoReturn": Object { + "type": "async", + "value": undefined, + }, + "callAsyncMultiplePromiseWithArgNoReturnCalled1": 42, + "callAsyncMultiplePromiseWithArgNoReturnCalled2": 42, + "callAsyncMultipleSync": Object { + "type": "async", + "value": 42, + }, + "callAsyncMultipleSyncCalled1": true, + "callAsyncMultipleSyncError": Object { + "error": "Error in sync2", + "type": "async", + }, + "callAsyncMultipleSyncErrorCalled1": true, + "callAsyncMultipleSyncLastReturn": Object { + "type": "async", + "value": 43, + }, + "callAsyncMultipleSyncLastReturnCalled1": true, + "callAsyncMultipleSyncLastReturnCalled2": true, + "callAsyncMultipleSyncNoReturn": Object { + "type": "async", + "value": undefined, + }, + "callAsyncMultipleSyncNoReturnCalled1": true, + "callAsyncMultipleSyncNoReturnCalled2": true, + "callAsyncMultipleSyncWithArg": Object { + "type": "async", + "value": 43, + }, + "callAsyncMultipleSyncWithArgCalled1": 42, + "callAsyncMultipleSyncWithArgFirstReturn": Object { + "type": "async", + "value": 43, + }, + "callAsyncMultipleSyncWithArgFirstReturnCalled1": 42, + "callAsyncMultipleSyncWithArgLastReturn": Object { + "type": "async", + "value": 44, + }, + "callAsyncMultipleSyncWithArgLastReturnCalled1": 42, + "callAsyncMultipleSyncWithArgLastReturnCalled2": 42, + "callAsyncMultipleSyncWithArgNoReturn": Object { + "type": "async", + "value": undefined, + }, + "callAsyncMultipleSyncWithArgNoReturnCalled1": 42, + "callAsyncMultipleSyncWithArgNoReturnCalled2": 42, + "callAsyncNone": Object { + "type": "async", + "value": undefined, + }, + "callAsyncNoneWithArg": Object { + "type": "async", + "value": undefined, + }, + "callAsyncSingleAsyncWithArg": Object { + "type": "async", + "value": 42, + }, + "callAsyncSingleAsyncWithArgCalled1": 42, + "callAsyncSinglePromiseWithArg": Object { + "type": "async", + "value": 43, + }, + "callAsyncSinglePromiseWithArgCalled1": 42, + "callAsyncSinglePromiseWithEmptyReject": Object { + "error": "Tap function (tapPromise) rejects \\"\\" value", + "type": "async", + }, + "callAsyncSinglePromiseWithEmptyStringArg": Object { + "type": "async", + "value": "", + }, + "callAsyncSinglePromiseWithEmptyStringArgCalled1": 42, + "callAsyncSinglePromiseWithFalseReject": Object { + "error": "Tap function (tapPromise) rejects \\"false\\" value", + "type": "async", + }, + "callAsyncSinglePromiseWithNullArg": Object { + "type": "async", + "value": null, + }, + "callAsyncSinglePromiseWithNullArgCalled1": 42, + "callAsyncSinglePromiseWithNullReject": Object { + "error": "Tap function (tapPromise) rejects \\"null\\" value", + "type": "async", + }, + "callAsyncSinglePromiseWithUndefined": Object { + "type": "async", + "value": undefined, + }, + "callAsyncSinglePromiseWithUndefinedCalled1": 42, + "callAsyncSinglePromiseWithUndefinedReject": Object { + "error": "Tap function (tapPromise) rejects \\"undefined\\" value", + "type": "async", + }, + "callAsyncSinglePromiseWithZeroArg": Object { + "type": "async", + "value": 0, + }, + "callAsyncSinglePromiseWithZeroArgCalled1": 42, + "callAsyncSinglePromiseWithZeroReject": Object { + "error": "Tap function (tapPromise) rejects \\"0\\" value", + "type": "async", + }, + "callAsyncSingleSync": Object { + "type": "async", + "value": 42, + }, + "callAsyncSingleSyncCalled1": true, + "callAsyncSingleSyncWithArg": Object { + "type": "async", + "value": 43, + }, + "callAsyncSingleSyncWithArgCalled1": 42, + "callAsyncSingleSyncWithArgNoReturn": Object { + "type": "async", + "value": undefined, + }, + "callAsyncSingleSyncWithArgNoReturnCalled1": 42, + "promiseMultipleAsyncEarlyError": Object { + "error": "Error in async2", + "type": "promise", + }, + "promiseMultipleAsyncEarlyErrorCalled1": true, + "promiseMultipleAsyncError": Object { + "error": "Error in async2", + "type": "promise", + }, + "promiseMultipleAsyncErrorCalled1": true, + "promiseMultipleAsyncLateError": Object { + "error": "Error in async2", + "type": "promise", + }, + "promiseMultipleAsyncLateErrorCalled1": true, + "promiseMultipleAsyncLateErrorEarlyResult1": Object { + "error": "Error in async2", + "type": "promise", + }, + "promiseMultipleAsyncLateErrorEarlyResult1Called1": true, + "promiseMultipleAsyncLateErrorEarlyResult2": Object { + "type": "promise", + "value": 42, + }, + "promiseMultipleAsyncLateErrorEarlyResult2Called1": true, + "promiseMultipleAsyncWithArg": Object { + "type": "promise", + "value": 43, + }, + "promiseMultipleAsyncWithArgCalled1": 42, + "promiseMultipleAsyncWithArgFirstReturn": Object { + "type": "promise", + "value": 43, + }, + "promiseMultipleAsyncWithArgFirstReturnCalled1": 42, + "promiseMultipleAsyncWithArgLastReturn": Object { + "type": "promise", + "value": 44, + }, + "promiseMultipleAsyncWithArgLastReturnCalled1": 42, + "promiseMultipleAsyncWithArgLastReturnCalled2": 42, + "promiseMultipleAsyncWithArgNoReturn": Object { + "type": "promise", + "value": undefined, + }, + "promiseMultipleAsyncWithArgNoReturnCalled1": 42, + "promiseMultipleAsyncWithArgNoReturnCalled2": 42, + "promiseMultipleMixed1WithArg": Object { + "type": "promise", + "value": 43, + }, + "promiseMultipleMixed1WithArgCalled1": 42, + "promiseMultipleMixed2WithArg": Object { + "type": "promise", + "value": 43, + }, + "promiseMultipleMixed2WithArgCalled1": 42, + "promiseMultipleMixed3WithArg": Object { + "type": "promise", + "value": 43, + }, + "promiseMultipleMixed3WithArgCalled1": 42, + "promiseMultipleMixedError1WithArg": Object { + "type": "promise", + "value": 42, + }, + "promiseMultipleMixedError1WithArgCalled1": 42, + "promiseMultipleMixedError2WithArg": Object { + "type": "promise", + "value": 42, + }, + "promiseMultipleMixedError2WithArgCalled1": 42, + "promiseMultipleMixedError3WithArg": Object { + "error": "Error in async", + "type": "promise", + }, + "promiseMultipleMixedError3WithArgCalled1": 42, + "promiseMultipleMixedLateError": Object { + "error": "Error in async", + "type": "promise", + }, + "promiseMultipleMixedLateErrorCalled1": true, + "promiseMultiplePromiseEarlyError": Object { + "error": "Error in async2", + "type": "promise", + }, + "promiseMultiplePromiseEarlyErrorCalled1": true, + "promiseMultiplePromiseError": Object { + "error": "Error in async2", + "type": "promise", + }, + "promiseMultiplePromiseErrorCalled1": true, + "promiseMultiplePromiseLateError": Object { + "error": "Error in async2", + "type": "promise", + }, + "promiseMultiplePromiseLateErrorCalled1": true, + "promiseMultiplePromiseWithArg": Object { + "type": "promise", + "value": 43, + }, + "promiseMultiplePromiseWithArgCalled1": 42, + "promiseMultiplePromiseWithArgFirstReturn": Object { + "type": "promise", + "value": 43, + }, + "promiseMultiplePromiseWithArgFirstReturnCalled1": 42, + "promiseMultiplePromiseWithArgLastReturn": Object { + "type": "promise", + "value": 44, + }, + "promiseMultiplePromiseWithArgLastReturnCalled1": 42, + "promiseMultiplePromiseWithArgLastReturnCalled2": 42, + "promiseMultiplePromiseWithArgNoReturn": Object { + "type": "promise", + "value": undefined, + }, + "promiseMultiplePromiseWithArgNoReturnCalled1": 42, + "promiseMultiplePromiseWithArgNoReturnCalled2": 42, + "promiseMultipleSync": Object { + "type": "promise", + "value": 42, + }, + "promiseMultipleSyncCalled1": true, + "promiseMultipleSyncError": Object { + "error": "Error in sync2", + "type": "promise", + }, + "promiseMultipleSyncErrorCalled1": true, + "promiseMultipleSyncLastReturn": Object { + "type": "promise", + "value": 43, + }, + "promiseMultipleSyncLastReturnCalled1": true, + "promiseMultipleSyncLastReturnCalled2": true, + "promiseMultipleSyncNoReturn": Object { + "type": "promise", + "value": undefined, + }, + "promiseMultipleSyncNoReturnCalled1": true, + "promiseMultipleSyncNoReturnCalled2": true, + "promiseMultipleSyncWithArg": Object { + "type": "promise", + "value": 43, + }, + "promiseMultipleSyncWithArgCalled1": 42, + "promiseMultipleSyncWithArgFirstReturn": Object { + "type": "promise", + "value": 43, + }, + "promiseMultipleSyncWithArgFirstReturnCalled1": 42, + "promiseMultipleSyncWithArgLastReturn": Object { + "type": "promise", + "value": 44, + }, + "promiseMultipleSyncWithArgLastReturnCalled1": 42, + "promiseMultipleSyncWithArgLastReturnCalled2": 42, + "promiseMultipleSyncWithArgNoReturn": Object { + "type": "promise", + "value": undefined, + }, + "promiseMultipleSyncWithArgNoReturnCalled1": 42, + "promiseMultipleSyncWithArgNoReturnCalled2": 42, + "promiseNone": Object { + "type": "promise", + "value": undefined, + }, + "promiseNoneWithArg": Object { + "type": "promise", + "value": undefined, + }, + "promiseSingleAsyncWithArg": Object { + "type": "promise", + "value": 42, + }, + "promiseSingleAsyncWithArgCalled1": 42, + "promiseSinglePromiseWithArg": Object { + "type": "promise", + "value": 43, + }, + "promiseSinglePromiseWithArgCalled1": 42, + "promiseSinglePromiseWithEmptyReject": Object { + "error": "Tap function (tapPromise) rejects \\"\\" value", + "type": "promise", + }, + "promiseSinglePromiseWithEmptyStringArg": Object { + "type": "promise", + "value": "", + }, + "promiseSinglePromiseWithEmptyStringArgCalled1": 42, + "promiseSinglePromiseWithFalseReject": Object { + "error": "Tap function (tapPromise) rejects \\"false\\" value", + "type": "promise", + }, + "promiseSinglePromiseWithNullArg": Object { + "type": "promise", + "value": null, + }, + "promiseSinglePromiseWithNullArgCalled1": 42, + "promiseSinglePromiseWithNullReject": Object { + "error": "Tap function (tapPromise) rejects \\"null\\" value", + "type": "promise", + }, + "promiseSinglePromiseWithUndefined": Object { + "type": "promise", + "value": undefined, + }, + "promiseSinglePromiseWithUndefinedCalled1": 42, + "promiseSinglePromiseWithUndefinedReject": Object { + "error": "Tap function (tapPromise) rejects \\"undefined\\" value", + "type": "promise", + }, + "promiseSinglePromiseWithZeroArg": Object { + "type": "promise", + "value": 0, + }, + "promiseSinglePromiseWithZeroArgCalled1": 42, + "promiseSinglePromiseWithZeroReject": Object { + "error": "Tap function (tapPromise) rejects \\"0\\" value", + "type": "promise", + }, + "promiseSingleSync": Object { + "type": "promise", + "value": 42, + }, + "promiseSingleSyncCalled1": true, + "promiseSingleSyncWithArg": Object { + "type": "promise", + "value": 43, + }, + "promiseSingleSyncWithArgCalled1": 42, + "promiseSingleSyncWithArgNoReturn": Object { + "type": "promise", + "value": undefined, + }, + "promiseSingleSyncWithArgNoReturnCalled1": 42, + }, + "intercept": Object { + "callAsyncContextIntercepted": Object { + "type": "async", + "value": 48, + }, + "callAsyncContextInterceptedCall1": Array [ + Object { + "number": 42, + }, + 1, + 2, + 3, + ], + "callAsyncContextInterceptedCall2": Array [ + 1, + 2, + 3, + ], + "callAsyncContextInterceptedTap1": Object { + "number": 42, + }, + "callAsyncIntercepted": Object { + "type": "async", + "value": 6, + }, + "callAsyncInterceptedCall1": Array [ + 1, + 2, + 3, + ], + "callAsyncInterceptedCall2": Array [ + 1, + 2, + 3, + ], + "callAsyncInterceptedResult1": 6, + "callAsyncInterceptedResult2": 6, + "callAsyncInterceptedTap1": Object { + "fn": 3, + "name": "sync", + "type": "sync", + }, + "callAsyncInterceptedTap2": Object { + "fn": 3, + "name": "sync", + "type": "sync", + }, + "callAsyncUnusedContextIntercepted": Object { + "type": "async", + "value": 6, + }, + "callAsyncUnusedContextInterceptedCall1": Array [ + undefined, + 1, + 2, + 3, + ], + "callAsyncUnusedContextInterceptedCall2": Array [ + 1, + 2, + 3, + ], + "callAsyncUnusedContextInterceptedTap1": undefined, + "promiseContextIntercepted": Object { + "type": "promise", + "value": 48, + }, + "promiseContextInterceptedCall1": Array [ + Object { + "number": 42, + }, + 1, + 2, + 3, + ], + "promiseContextInterceptedCall2": Array [ + 1, + 2, + 3, + ], + "promiseContextInterceptedTap1": Object { + "number": 42, + }, + "promiseIntercepted": Object { + "type": "promise", + "value": 6, + }, + "promiseInterceptedCall1": Array [ + 1, + 2, + 3, + ], + "promiseInterceptedCall2": Array [ + 1, + 2, + 3, + ], + "promiseInterceptedResult1": 6, + "promiseInterceptedResult2": 6, + "promiseInterceptedTap1": Object { + "fn": 3, + "name": "sync", + "type": "sync", + }, + "promiseInterceptedTap2": Object { + "fn": 3, + "name": "sync", + "type": "sync", + }, + "promiseUnusedContextIntercepted": Object { + "type": "promise", + "value": 6, + }, + "promiseUnusedContextInterceptedCall1": Array [ + undefined, + 1, + 2, + 3, + ], + "promiseUnusedContextInterceptedCall2": Array [ + 1, + 2, + 3, + ], + "promiseUnusedContextInterceptedTap1": undefined, + }, + "sync": Object { + "callAsyncIntercepted": Object { + "type": "async", + "value": 6, + }, + "callAsyncInterceptedCall1": Array [ + 1, + 2, + 3, + ], + "callAsyncInterceptedCall2": Array [ + 1, + 2, + 3, + ], + "callAsyncInterceptedTap1": Object { + "fn": 3, + "name": "sync1", + "type": "sync", + }, + "callAsyncInterceptedTap2": Object { + "fn": 3, + "name": "sync1", + "type": "sync", + }, + "callAsyncMultipleSync": Object { + "type": "async", + "value": 42, + }, + "callAsyncMultipleSyncCalled1": true, + "callAsyncMultipleSyncError": Object { + "error": "Error in sync2", + "type": "async", + }, + "callAsyncMultipleSyncErrorCalled1": true, + "callAsyncMultipleSyncErrorCalled2": true, + "callAsyncMultipleSyncWithArg": Object { + "type": "async", + "value": 84, + }, + "callAsyncMultipleSyncWithArgCalled1": 42, + "callAsyncMultipleSyncWithArgFirstReturn": Object { + "type": "async", + "value": 84, + }, + "callAsyncMultipleSyncWithArgFirstReturnCalled1": 42, + "callAsyncMultipleSyncWithArgLastReturn": Object { + "type": "async", + "value": 85, + }, + "callAsyncMultipleSyncWithArgLastReturnCalled1": 42, + "callAsyncMultipleSyncWithArgLastReturnCalled2": 42, + "callAsyncMultipleSyncWithArgNoReturn": Object { + "type": "async", + "value": undefined, + }, + "callAsyncMultipleSyncWithArgNoReturnCalled1": 42, + "callAsyncMultipleSyncWithArgNoReturnCalled2": 42, + "callAsyncMultipleSyncWithArgs": Object { + "type": "async", + "value": 129, + }, + "callAsyncMultipleSyncWithArgsCalled1": Array [ + 42, + 43, + 44, + ], + "callAsyncNone": Object { + "type": "async", + "value": undefined, + }, + "callAsyncNoneWithArg": Object { + "type": "async", + "value": undefined, + }, + "callAsyncSingleSync": Object { + "type": "async", + "value": 42, + }, + "callAsyncSingleSyncCalled": true, + "callAsyncSingleSyncWithArg": Object { + "type": "async", + "value": 42, + }, + "callAsyncSingleSyncWithArgCalled": 42, + "promiseIntercepted": Object { + "type": "promise", + "value": 6, + }, + "promiseInterceptedCall1": Array [ + 1, + 2, + 3, + ], + "promiseInterceptedCall2": Array [ + 1, + 2, + 3, + ], + "promiseInterceptedTap1": Object { + "fn": 3, + "name": "sync1", + "type": "sync", + }, + "promiseInterceptedTap2": Object { + "fn": 3, + "name": "sync1", + "type": "sync", + }, + "promiseMultipleSync": Object { + "type": "promise", + "value": 42, + }, + "promiseMultipleSyncCalled1": true, + "promiseMultipleSyncError": Object { + "error": "Error in sync2", + "type": "promise", + }, + "promiseMultipleSyncErrorCalled1": true, + "promiseMultipleSyncErrorCalled2": true, + "promiseMultipleSyncWithArg": Object { + "type": "promise", + "value": 84, + }, + "promiseMultipleSyncWithArgCalled1": 42, + "promiseMultipleSyncWithArgFirstReturn": Object { + "type": "promise", + "value": 84, + }, + "promiseMultipleSyncWithArgFirstReturnCalled1": 42, + "promiseMultipleSyncWithArgLastReturn": Object { + "type": "promise", + "value": 85, + }, + "promiseMultipleSyncWithArgLastReturnCalled1": 42, + "promiseMultipleSyncWithArgLastReturnCalled2": 42, + "promiseMultipleSyncWithArgNoReturn": Object { + "type": "promise", + "value": undefined, + }, + "promiseMultipleSyncWithArgNoReturnCalled1": 42, + "promiseMultipleSyncWithArgNoReturnCalled2": 42, + "promiseMultipleSyncWithArgs": Object { + "type": "promise", + "value": 129, + }, + "promiseMultipleSyncWithArgsCalled1": Array [ + 42, + 43, + 44, + ], + "promiseNone": Object { + "type": "promise", + "value": undefined, + }, + "promiseNoneWithArg": Object { + "type": "promise", + "value": undefined, + }, + "promiseSingleSync": Object { + "type": "promise", + "value": 42, + }, + "promiseSingleSyncCalled": true, + "promiseSingleSyncWithArg": Object { + "type": "promise", + "value": 42, + }, + "promiseSingleSyncWithArgCalled": 42, + }, +} +`; diff --git a/test/__snapshots__/AsyncSeriesHooks.test.js.snap b/test/__snapshots__/AsyncSeriesHooks.test.js.snap index 8f68dc3..03a11bf 100644 --- a/test/__snapshots__/AsyncSeriesHooks.test.js.snap +++ b/test/__snapshots__/AsyncSeriesHooks.test.js.snap @@ -1,6 +1,6 @@ // Jest Snapshot v1, https://jestjs.io/docs/snapshot-testing -exports[`AsyncSeriesBailHook should have to correct behavior 1`] = ` +exports[`AsyncSeriesHook should have to correct behavior 1`] = ` Object { "async": Object { "callAsyncMultipleAsyncEarlyError": Object { @@ -24,23 +24,25 @@ Object { }, "callAsyncMultipleAsyncLateErrorEarlyResult1Called1": true, "callAsyncMultipleAsyncLateErrorEarlyResult2": Object { + "error": "Error in async2", "type": "async", - "value": 42, }, "callAsyncMultipleAsyncLateErrorEarlyResult2Called1": true, "callAsyncMultipleAsyncWithArg": Object { "type": "async", - "value": 43, + "value": undefined, }, "callAsyncMultipleAsyncWithArgCalled1": 42, + "callAsyncMultipleAsyncWithArgCalled2": 42, "callAsyncMultipleAsyncWithArgFirstReturn": Object { "type": "async", - "value": 43, + "value": undefined, }, "callAsyncMultipleAsyncWithArgFirstReturnCalled1": 42, + "callAsyncMultipleAsyncWithArgFirstReturnCalled2": 42, "callAsyncMultipleAsyncWithArgLastReturn": Object { "type": "async", - "value": 44, + "value": undefined, }, "callAsyncMultipleAsyncWithArgLastReturnCalled1": 42, "callAsyncMultipleAsyncWithArgLastReturnCalled2": 42, @@ -52,29 +54,37 @@ Object { "callAsyncMultipleAsyncWithArgNoReturnCalled2": 42, "callAsyncMultipleMixed1WithArg": Object { "type": "async", - "value": 43, + "value": undefined, }, "callAsyncMultipleMixed1WithArgCalled1": 42, + "callAsyncMultipleMixed1WithArgCalled2": 42, + "callAsyncMultipleMixed1WithArgCalled3": 42, "callAsyncMultipleMixed2WithArg": Object { "type": "async", - "value": 43, + "value": undefined, }, "callAsyncMultipleMixed2WithArgCalled1": 42, + "callAsyncMultipleMixed2WithArgCalled2": 42, "callAsyncMultipleMixed3WithArg": Object { "type": "async", - "value": 43, + "value": undefined, }, "callAsyncMultipleMixed3WithArgCalled1": 42, + "callAsyncMultipleMixed3WithArgCalled2": 42, + "callAsyncMultipleMixed3WithArgCalled3": 42, "callAsyncMultipleMixedError1WithArg": Object { + "error": "Error in sync", "type": "async", - "value": 42, }, "callAsyncMultipleMixedError1WithArgCalled1": 42, + "callAsyncMultipleMixedError1WithArgCalled2": 42, + "callAsyncMultipleMixedError1WithArgCalled3": 42, "callAsyncMultipleMixedError2WithArg": Object { + "error": "Error in promise", "type": "async", - "value": 42, }, "callAsyncMultipleMixedError2WithArgCalled1": 42, + "callAsyncMultipleMixedError2WithArgCalled2": 42, "callAsyncMultipleMixedError3WithArg": Object { "error": "Error in async", "type": "async", @@ -102,17 +112,19 @@ Object { "callAsyncMultiplePromiseLateErrorCalled1": true, "callAsyncMultiplePromiseWithArg": Object { "type": "async", - "value": 43, + "value": undefined, }, "callAsyncMultiplePromiseWithArgCalled1": 42, + "callAsyncMultiplePromiseWithArgCalled2": 42, "callAsyncMultiplePromiseWithArgFirstReturn": Object { "type": "async", - "value": 43, + "value": undefined, }, "callAsyncMultiplePromiseWithArgFirstReturnCalled1": 42, + "callAsyncMultiplePromiseWithArgFirstReturnCalled2": 42, "callAsyncMultiplePromiseWithArgLastReturn": Object { "type": "async", - "value": 44, + "value": undefined, }, "callAsyncMultiplePromiseWithArgLastReturnCalled1": 42, "callAsyncMultiplePromiseWithArgLastReturnCalled2": 42, @@ -124,9 +136,10 @@ Object { "callAsyncMultiplePromiseWithArgNoReturnCalled2": 42, "callAsyncMultipleSync": Object { "type": "async", - "value": 42, + "value": undefined, }, "callAsyncMultipleSyncCalled1": true, + "callAsyncMultipleSyncCalled2": true, "callAsyncMultipleSyncError": Object { "error": "Error in sync2", "type": "async", @@ -134,7 +147,7 @@ Object { "callAsyncMultipleSyncErrorCalled1": true, "callAsyncMultipleSyncLastReturn": Object { "type": "async", - "value": 43, + "value": undefined, }, "callAsyncMultipleSyncLastReturnCalled1": true, "callAsyncMultipleSyncLastReturnCalled2": true, @@ -146,17 +159,19 @@ Object { "callAsyncMultipleSyncNoReturnCalled2": true, "callAsyncMultipleSyncWithArg": Object { "type": "async", - "value": 43, + "value": undefined, }, "callAsyncMultipleSyncWithArgCalled1": 42, + "callAsyncMultipleSyncWithArgCalled2": 42, "callAsyncMultipleSyncWithArgFirstReturn": Object { "type": "async", - "value": 43, + "value": undefined, }, "callAsyncMultipleSyncWithArgFirstReturnCalled1": 42, + "callAsyncMultipleSyncWithArgFirstReturnCalled2": 42, "callAsyncMultipleSyncWithArgLastReturn": Object { "type": "async", - "value": 44, + "value": undefined, }, "callAsyncMultipleSyncWithArgLastReturnCalled1": 42, "callAsyncMultipleSyncWithArgLastReturnCalled2": 42, @@ -176,12 +191,12 @@ Object { }, "callAsyncSingleAsyncWithArg": Object { "type": "async", - "value": 42, + "value": undefined, }, "callAsyncSingleAsyncWithArgCalled1": 42, "callAsyncSinglePromiseWithArg": Object { "type": "async", - "value": 43, + "value": undefined, }, "callAsyncSinglePromiseWithArgCalled1": 42, "callAsyncSinglePromiseWithEmptyReject": Object { @@ -190,7 +205,7 @@ Object { }, "callAsyncSinglePromiseWithEmptyStringArg": Object { "type": "async", - "value": "", + "value": undefined, }, "callAsyncSinglePromiseWithEmptyStringArgCalled1": 42, "callAsyncSinglePromiseWithFalseReject": Object { @@ -199,7 +214,7 @@ Object { }, "callAsyncSinglePromiseWithNullArg": Object { "type": "async", - "value": null, + "value": undefined, }, "callAsyncSinglePromiseWithNullArgCalled1": 42, "callAsyncSinglePromiseWithNullReject": Object { @@ -217,7 +232,7 @@ Object { }, "callAsyncSinglePromiseWithZeroArg": Object { "type": "async", - "value": 0, + "value": undefined, }, "callAsyncSinglePromiseWithZeroArgCalled1": 42, "callAsyncSinglePromiseWithZeroReject": Object { @@ -226,12 +241,12 @@ Object { }, "callAsyncSingleSync": Object { "type": "async", - "value": 42, + "value": undefined, }, "callAsyncSingleSyncCalled1": true, "callAsyncSingleSyncWithArg": Object { "type": "async", - "value": 43, + "value": undefined, }, "callAsyncSingleSyncWithArgCalled1": 42, "callAsyncSingleSyncWithArgNoReturn": Object { @@ -260,23 +275,25 @@ Object { }, "promiseMultipleAsyncLateErrorEarlyResult1Called1": true, "promiseMultipleAsyncLateErrorEarlyResult2": Object { + "error": "Error in async2", "type": "promise", - "value": 42, }, "promiseMultipleAsyncLateErrorEarlyResult2Called1": true, "promiseMultipleAsyncWithArg": Object { "type": "promise", - "value": 43, + "value": undefined, }, "promiseMultipleAsyncWithArgCalled1": 42, + "promiseMultipleAsyncWithArgCalled2": 42, "promiseMultipleAsyncWithArgFirstReturn": Object { "type": "promise", - "value": 43, + "value": undefined, }, "promiseMultipleAsyncWithArgFirstReturnCalled1": 42, + "promiseMultipleAsyncWithArgFirstReturnCalled2": 42, "promiseMultipleAsyncWithArgLastReturn": Object { "type": "promise", - "value": 44, + "value": undefined, }, "promiseMultipleAsyncWithArgLastReturnCalled1": 42, "promiseMultipleAsyncWithArgLastReturnCalled2": 42, @@ -288,29 +305,37 @@ Object { "promiseMultipleAsyncWithArgNoReturnCalled2": 42, "promiseMultipleMixed1WithArg": Object { "type": "promise", - "value": 43, + "value": undefined, }, "promiseMultipleMixed1WithArgCalled1": 42, + "promiseMultipleMixed1WithArgCalled2": 42, + "promiseMultipleMixed1WithArgCalled3": 42, "promiseMultipleMixed2WithArg": Object { "type": "promise", - "value": 43, + "value": undefined, }, "promiseMultipleMixed2WithArgCalled1": 42, + "promiseMultipleMixed2WithArgCalled2": 42, "promiseMultipleMixed3WithArg": Object { "type": "promise", - "value": 43, + "value": undefined, }, "promiseMultipleMixed3WithArgCalled1": 42, + "promiseMultipleMixed3WithArgCalled2": 42, + "promiseMultipleMixed3WithArgCalled3": 42, "promiseMultipleMixedError1WithArg": Object { + "error": "Error in sync", "type": "promise", - "value": 42, }, "promiseMultipleMixedError1WithArgCalled1": 42, + "promiseMultipleMixedError1WithArgCalled2": 42, + "promiseMultipleMixedError1WithArgCalled3": 42, "promiseMultipleMixedError2WithArg": Object { + "error": "Error in promise", "type": "promise", - "value": 42, }, "promiseMultipleMixedError2WithArgCalled1": 42, + "promiseMultipleMixedError2WithArgCalled2": 42, "promiseMultipleMixedError3WithArg": Object { "error": "Error in async", "type": "promise", @@ -338,17 +363,19 @@ Object { "promiseMultiplePromiseLateErrorCalled1": true, "promiseMultiplePromiseWithArg": Object { "type": "promise", - "value": 43, + "value": undefined, }, "promiseMultiplePromiseWithArgCalled1": 42, + "promiseMultiplePromiseWithArgCalled2": 42, "promiseMultiplePromiseWithArgFirstReturn": Object { "type": "promise", - "value": 43, + "value": undefined, }, "promiseMultiplePromiseWithArgFirstReturnCalled1": 42, + "promiseMultiplePromiseWithArgFirstReturnCalled2": 42, "promiseMultiplePromiseWithArgLastReturn": Object { "type": "promise", - "value": 44, + "value": undefined, }, "promiseMultiplePromiseWithArgLastReturnCalled1": 42, "promiseMultiplePromiseWithArgLastReturnCalled2": 42, @@ -360,9 +387,10 @@ Object { "promiseMultiplePromiseWithArgNoReturnCalled2": 42, "promiseMultipleSync": Object { "type": "promise", - "value": 42, + "value": undefined, }, "promiseMultipleSyncCalled1": true, + "promiseMultipleSyncCalled2": true, "promiseMultipleSyncError": Object { "error": "Error in sync2", "type": "promise", @@ -370,7 +398,7 @@ Object { "promiseMultipleSyncErrorCalled1": true, "promiseMultipleSyncLastReturn": Object { "type": "promise", - "value": 43, + "value": undefined, }, "promiseMultipleSyncLastReturnCalled1": true, "promiseMultipleSyncLastReturnCalled2": true, @@ -382,17 +410,19 @@ Object { "promiseMultipleSyncNoReturnCalled2": true, "promiseMultipleSyncWithArg": Object { "type": "promise", - "value": 43, + "value": undefined, }, "promiseMultipleSyncWithArgCalled1": 42, + "promiseMultipleSyncWithArgCalled2": 42, "promiseMultipleSyncWithArgFirstReturn": Object { "type": "promise", - "value": 43, + "value": undefined, }, "promiseMultipleSyncWithArgFirstReturnCalled1": 42, + "promiseMultipleSyncWithArgFirstReturnCalled2": 42, "promiseMultipleSyncWithArgLastReturn": Object { "type": "promise", - "value": 44, + "value": undefined, }, "promiseMultipleSyncWithArgLastReturnCalled1": 42, "promiseMultipleSyncWithArgLastReturnCalled2": 42, @@ -412,12 +442,12 @@ Object { }, "promiseSingleAsyncWithArg": Object { "type": "promise", - "value": 42, + "value": undefined, }, "promiseSingleAsyncWithArgCalled1": 42, "promiseSinglePromiseWithArg": Object { "type": "promise", - "value": 43, + "value": undefined, }, "promiseSinglePromiseWithArgCalled1": 42, "promiseSinglePromiseWithEmptyReject": Object { @@ -426,7 +456,7 @@ Object { }, "promiseSinglePromiseWithEmptyStringArg": Object { "type": "promise", - "value": "", + "value": undefined, }, "promiseSinglePromiseWithEmptyStringArgCalled1": 42, "promiseSinglePromiseWithFalseReject": Object { @@ -435,7 +465,7 @@ Object { }, "promiseSinglePromiseWithNullArg": Object { "type": "promise", - "value": null, + "value": undefined, }, "promiseSinglePromiseWithNullArgCalled1": 42, "promiseSinglePromiseWithNullReject": Object { @@ -453,7 +483,7 @@ Object { }, "promiseSinglePromiseWithZeroArg": Object { "type": "promise", - "value": 0, + "value": undefined, }, "promiseSinglePromiseWithZeroArgCalled1": 42, "promiseSinglePromiseWithZeroReject": Object { @@ -462,12 +492,12 @@ Object { }, "promiseSingleSync": Object { "type": "promise", - "value": 42, + "value": undefined, }, "promiseSingleSyncCalled1": true, "promiseSingleSyncWithArg": Object { "type": "promise", - "value": 43, + "value": undefined, }, "promiseSingleSyncWithArgCalled1": 42, "promiseSingleSyncWithArgNoReturn": Object { @@ -479,7 +509,7 @@ Object { "intercept": Object { "callAsyncContextIntercepted": Object { "type": "async", - "value": 48, + "value": undefined, }, "callAsyncContextInterceptedCall1": Array [ Object { @@ -499,7 +529,7 @@ Object { }, "callAsyncIntercepted": Object { "type": "async", - "value": 6, + "value": undefined, }, "callAsyncInterceptedCall1": Array [ 1, @@ -511,12 +541,12 @@ Object { 2, 3, ], - "callAsyncInterceptedResult1": 6, - "callAsyncInterceptedResult2": 6, + "callAsyncInterceptedDone1": true, + "callAsyncInterceptedDone2": true, "callAsyncInterceptedTap1": Object { - "fn": 3, - "name": "sync", - "type": "sync", + "fn": 2, + "name": "promise", + "type": "promise", }, "callAsyncInterceptedTap2": Object { "fn": 3, @@ -525,7 +555,7 @@ Object { }, "callAsyncUnusedContextIntercepted": Object { "type": "async", - "value": 6, + "value": undefined, }, "callAsyncUnusedContextInterceptedCall1": Array [ undefined, @@ -541,7 +571,7 @@ Object { "callAsyncUnusedContextInterceptedTap1": undefined, "promiseContextIntercepted": Object { "type": "promise", - "value": 48, + "value": undefined, }, "promiseContextInterceptedCall1": Array [ Object { @@ -561,7 +591,7 @@ Object { }, "promiseIntercepted": Object { "type": "promise", - "value": 6, + "value": undefined, }, "promiseInterceptedCall1": Array [ 1, @@ -573,12 +603,12 @@ Object { 2, 3, ], - "promiseInterceptedResult1": 6, - "promiseInterceptedResult2": 6, + "promiseInterceptedDone1": true, + "promiseInterceptedDone2": true, "promiseInterceptedTap1": Object { - "fn": 3, - "name": "sync", - "type": "sync", + "fn": 2, + "name": "promise", + "type": "promise", }, "promiseInterceptedTap2": Object { "fn": 3, @@ -587,7 +617,7 @@ Object { }, "promiseUnusedContextIntercepted": Object { "type": "promise", - "value": 6, + "value": undefined, }, "promiseUnusedContextInterceptedCall1": Array [ undefined, @@ -605,7 +635,7 @@ Object { "sync": Object { "callAsyncIntercepted": Object { "type": "async", - "value": 6, + "value": undefined, }, "callAsyncInterceptedCall1": Array [ 1, @@ -618,8 +648,8 @@ Object { 3, ], "callAsyncInterceptedTap1": Object { - "fn": 3, - "name": "sync1", + "fn": 2, + "name": "sync2", "type": "sync", }, "callAsyncInterceptedTap2": Object { @@ -629,9 +659,10 @@ Object { }, "callAsyncMultipleSync": Object { "type": "async", - "value": 42, + "value": undefined, }, "callAsyncMultipleSyncCalled1": true, + "callAsyncMultipleSyncCalled2": true, "callAsyncMultipleSyncError": Object { "error": "Error in sync2", "type": "async", @@ -640,17 +671,19 @@ Object { "callAsyncMultipleSyncErrorCalled2": true, "callAsyncMultipleSyncWithArg": Object { "type": "async", - "value": 84, + "value": undefined, }, "callAsyncMultipleSyncWithArgCalled1": 42, + "callAsyncMultipleSyncWithArgCalled2": 42, "callAsyncMultipleSyncWithArgFirstReturn": Object { "type": "async", - "value": 84, + "value": undefined, }, "callAsyncMultipleSyncWithArgFirstReturnCalled1": 42, + "callAsyncMultipleSyncWithArgFirstReturnCalled2": 42, "callAsyncMultipleSyncWithArgLastReturn": Object { "type": "async", - "value": 85, + "value": undefined, }, "callAsyncMultipleSyncWithArgLastReturnCalled1": 42, "callAsyncMultipleSyncWithArgLastReturnCalled2": 42, @@ -662,13 +695,18 @@ Object { "callAsyncMultipleSyncWithArgNoReturnCalled2": 42, "callAsyncMultipleSyncWithArgs": Object { "type": "async", - "value": 129, + "value": undefined, }, "callAsyncMultipleSyncWithArgsCalled1": Array [ 42, 43, 44, ], + "callAsyncMultipleSyncWithArgsCalled2": Array [ + 42, + 43, + 44, + ], "callAsyncNone": Object { "type": "async", "value": undefined, @@ -679,17 +717,17 @@ Object { }, "callAsyncSingleSync": Object { "type": "async", - "value": 42, + "value": undefined, }, "callAsyncSingleSyncCalled": true, "callAsyncSingleSyncWithArg": Object { "type": "async", - "value": 42, + "value": undefined, }, "callAsyncSingleSyncWithArgCalled": 42, "promiseIntercepted": Object { "type": "promise", - "value": 6, + "value": undefined, }, "promiseInterceptedCall1": Array [ 1, @@ -702,8 +740,8 @@ Object { 3, ], "promiseInterceptedTap1": Object { - "fn": 3, - "name": "sync1", + "fn": 2, + "name": "sync2", "type": "sync", }, "promiseInterceptedTap2": Object { @@ -713,9 +751,10 @@ Object { }, "promiseMultipleSync": Object { "type": "promise", - "value": 42, + "value": undefined, }, "promiseMultipleSyncCalled1": true, + "promiseMultipleSyncCalled2": true, "promiseMultipleSyncError": Object { "error": "Error in sync2", "type": "promise", @@ -724,17 +763,19 @@ Object { "promiseMultipleSyncErrorCalled2": true, "promiseMultipleSyncWithArg": Object { "type": "promise", - "value": 84, + "value": undefined, }, "promiseMultipleSyncWithArgCalled1": 42, + "promiseMultipleSyncWithArgCalled2": 42, "promiseMultipleSyncWithArgFirstReturn": Object { "type": "promise", - "value": 84, + "value": undefined, }, "promiseMultipleSyncWithArgFirstReturnCalled1": 42, + "promiseMultipleSyncWithArgFirstReturnCalled2": 42, "promiseMultipleSyncWithArgLastReturn": Object { "type": "promise", - "value": 85, + "value": undefined, }, "promiseMultipleSyncWithArgLastReturnCalled1": 42, "promiseMultipleSyncWithArgLastReturnCalled2": 42, @@ -746,13 +787,18 @@ Object { "promiseMultipleSyncWithArgNoReturnCalled2": 42, "promiseMultipleSyncWithArgs": Object { "type": "promise", - "value": 129, + "value": undefined, }, "promiseMultipleSyncWithArgsCalled1": Array [ 42, 43, 44, ], + "promiseMultipleSyncWithArgsCalled2": Array [ + 42, + 43, + 44, + ], "promiseNone": Object { "type": "promise", "value": undefined, @@ -763,1703 +809,13 @@ Object { }, "promiseSingleSync": Object { "type": "promise", - "value": 42, + "value": undefined, }, "promiseSingleSyncCalled": true, "promiseSingleSyncWithArg": Object { "type": "promise", - "value": 42, - }, - "promiseSingleSyncWithArgCalled": 42, - }, -} -`; - -exports[`AsyncSeriesHook should have to correct behavior 1`] = ` -Object { - "async": Object { - "callAsyncMultipleAsyncEarlyError": Object { - "error": "Error in async2", - "type": "async", - }, - "callAsyncMultipleAsyncEarlyErrorCalled1": true, - "callAsyncMultipleAsyncError": Object { - "error": "Error in async2", - "type": "async", - }, - "callAsyncMultipleAsyncErrorCalled1": true, - "callAsyncMultipleAsyncLateError": Object { - "error": "Error in async2", - "type": "async", - }, - "callAsyncMultipleAsyncLateErrorCalled1": true, - "callAsyncMultipleAsyncLateErrorEarlyResult1": Object { - "error": "Error in async2", - "type": "async", - }, - "callAsyncMultipleAsyncLateErrorEarlyResult1Called1": true, - "callAsyncMultipleAsyncLateErrorEarlyResult2": Object { - "error": "Error in async2", - "type": "async", - }, - "callAsyncMultipleAsyncLateErrorEarlyResult2Called1": true, - "callAsyncMultipleAsyncWithArg": Object { - "type": "async", - "value": undefined, - }, - "callAsyncMultipleAsyncWithArgCalled1": 42, - "callAsyncMultipleAsyncWithArgCalled2": 42, - "callAsyncMultipleAsyncWithArgFirstReturn": Object { - "type": "async", - "value": undefined, - }, - "callAsyncMultipleAsyncWithArgFirstReturnCalled1": 42, - "callAsyncMultipleAsyncWithArgFirstReturnCalled2": 42, - "callAsyncMultipleAsyncWithArgLastReturn": Object { - "type": "async", - "value": undefined, - }, - "callAsyncMultipleAsyncWithArgLastReturnCalled1": 42, - "callAsyncMultipleAsyncWithArgLastReturnCalled2": 42, - "callAsyncMultipleAsyncWithArgNoReturn": Object { - "type": "async", - "value": undefined, - }, - "callAsyncMultipleAsyncWithArgNoReturnCalled1": 42, - "callAsyncMultipleAsyncWithArgNoReturnCalled2": 42, - "callAsyncMultipleMixed1WithArg": Object { - "type": "async", - "value": undefined, - }, - "callAsyncMultipleMixed1WithArgCalled1": 42, - "callAsyncMultipleMixed1WithArgCalled2": 42, - "callAsyncMultipleMixed1WithArgCalled3": 42, - "callAsyncMultipleMixed2WithArg": Object { - "type": "async", - "value": undefined, - }, - "callAsyncMultipleMixed2WithArgCalled1": 42, - "callAsyncMultipleMixed2WithArgCalled2": 42, - "callAsyncMultipleMixed3WithArg": Object { - "type": "async", "value": undefined, }, - "callAsyncMultipleMixed3WithArgCalled1": 42, - "callAsyncMultipleMixed3WithArgCalled2": 42, - "callAsyncMultipleMixed3WithArgCalled3": 42, - "callAsyncMultipleMixedError1WithArg": Object { - "error": "Error in sync", - "type": "async", - }, - "callAsyncMultipleMixedError1WithArgCalled1": 42, - "callAsyncMultipleMixedError1WithArgCalled2": 42, - "callAsyncMultipleMixedError1WithArgCalled3": 42, - "callAsyncMultipleMixedError2WithArg": Object { - "error": "Error in promise", - "type": "async", - }, - "callAsyncMultipleMixedError2WithArgCalled1": 42, - "callAsyncMultipleMixedError2WithArgCalled2": 42, - "callAsyncMultipleMixedError3WithArg": Object { - "error": "Error in async", - "type": "async", - }, - "callAsyncMultipleMixedError3WithArgCalled1": 42, - "callAsyncMultipleMixedLateError": Object { - "error": "Error in async", - "type": "async", - }, - "callAsyncMultipleMixedLateErrorCalled1": true, - "callAsyncMultiplePromiseEarlyError": Object { - "error": "Error in async2", - "type": "async", - }, - "callAsyncMultiplePromiseEarlyErrorCalled1": true, - "callAsyncMultiplePromiseError": Object { - "error": "Error in async2", - "type": "async", - }, - "callAsyncMultiplePromiseErrorCalled1": true, - "callAsyncMultiplePromiseLateError": Object { - "error": "Error in async2", - "type": "async", - }, - "callAsyncMultiplePromiseLateErrorCalled1": true, - "callAsyncMultiplePromiseWithArg": Object { - "type": "async", - "value": undefined, - }, - "callAsyncMultiplePromiseWithArgCalled1": 42, - "callAsyncMultiplePromiseWithArgCalled2": 42, - "callAsyncMultiplePromiseWithArgFirstReturn": Object { - "type": "async", - "value": undefined, - }, - "callAsyncMultiplePromiseWithArgFirstReturnCalled1": 42, - "callAsyncMultiplePromiseWithArgFirstReturnCalled2": 42, - "callAsyncMultiplePromiseWithArgLastReturn": Object { - "type": "async", - "value": undefined, - }, - "callAsyncMultiplePromiseWithArgLastReturnCalled1": 42, - "callAsyncMultiplePromiseWithArgLastReturnCalled2": 42, - "callAsyncMultiplePromiseWithArgNoReturn": Object { - "type": "async", - "value": undefined, - }, - "callAsyncMultiplePromiseWithArgNoReturnCalled1": 42, - "callAsyncMultiplePromiseWithArgNoReturnCalled2": 42, - "callAsyncMultipleSync": Object { - "type": "async", - "value": undefined, - }, - "callAsyncMultipleSyncCalled1": true, - "callAsyncMultipleSyncCalled2": true, - "callAsyncMultipleSyncError": Object { - "error": "Error in sync2", - "type": "async", - }, - "callAsyncMultipleSyncErrorCalled1": true, - "callAsyncMultipleSyncLastReturn": Object { - "type": "async", - "value": undefined, - }, - "callAsyncMultipleSyncLastReturnCalled1": true, - "callAsyncMultipleSyncLastReturnCalled2": true, - "callAsyncMultipleSyncNoReturn": Object { - "type": "async", - "value": undefined, - }, - "callAsyncMultipleSyncNoReturnCalled1": true, - "callAsyncMultipleSyncNoReturnCalled2": true, - "callAsyncMultipleSyncWithArg": Object { - "type": "async", - "value": undefined, - }, - "callAsyncMultipleSyncWithArgCalled1": 42, - "callAsyncMultipleSyncWithArgCalled2": 42, - "callAsyncMultipleSyncWithArgFirstReturn": Object { - "type": "async", - "value": undefined, - }, - "callAsyncMultipleSyncWithArgFirstReturnCalled1": 42, - "callAsyncMultipleSyncWithArgFirstReturnCalled2": 42, - "callAsyncMultipleSyncWithArgLastReturn": Object { - "type": "async", - "value": undefined, - }, - "callAsyncMultipleSyncWithArgLastReturnCalled1": 42, - "callAsyncMultipleSyncWithArgLastReturnCalled2": 42, - "callAsyncMultipleSyncWithArgNoReturn": Object { - "type": "async", - "value": undefined, - }, - "callAsyncMultipleSyncWithArgNoReturnCalled1": 42, - "callAsyncMultipleSyncWithArgNoReturnCalled2": 42, - "callAsyncNone": Object { - "type": "async", - "value": undefined, - }, - "callAsyncNoneWithArg": Object { - "type": "async", - "value": undefined, - }, - "callAsyncSingleAsyncWithArg": Object { - "type": "async", - "value": undefined, - }, - "callAsyncSingleAsyncWithArgCalled1": 42, - "callAsyncSinglePromiseWithArg": Object { - "type": "async", - "value": undefined, - }, - "callAsyncSinglePromiseWithArgCalled1": 42, - "callAsyncSinglePromiseWithEmptyReject": Object { - "error": "Tap function (tapPromise) rejects \\"\\" value", - "type": "async", - }, - "callAsyncSinglePromiseWithEmptyStringArg": Object { - "type": "async", - "value": undefined, - }, - "callAsyncSinglePromiseWithEmptyStringArgCalled1": 42, - "callAsyncSinglePromiseWithFalseReject": Object { - "error": "Tap function (tapPromise) rejects \\"false\\" value", - "type": "async", - }, - "callAsyncSinglePromiseWithNullArg": Object { - "type": "async", - "value": undefined, - }, - "callAsyncSinglePromiseWithNullArgCalled1": 42, - "callAsyncSinglePromiseWithNullReject": Object { - "error": "Tap function (tapPromise) rejects \\"null\\" value", - "type": "async", - }, - "callAsyncSinglePromiseWithUndefined": Object { - "type": "async", - "value": undefined, - }, - "callAsyncSinglePromiseWithUndefinedCalled1": 42, - "callAsyncSinglePromiseWithUndefinedReject": Object { - "error": "Tap function (tapPromise) rejects \\"undefined\\" value", - "type": "async", - }, - "callAsyncSinglePromiseWithZeroArg": Object { - "type": "async", - "value": undefined, - }, - "callAsyncSinglePromiseWithZeroArgCalled1": 42, - "callAsyncSinglePromiseWithZeroReject": Object { - "error": "Tap function (tapPromise) rejects \\"0\\" value", - "type": "async", - }, - "callAsyncSingleSync": Object { - "type": "async", - "value": undefined, - }, - "callAsyncSingleSyncCalled1": true, - "callAsyncSingleSyncWithArg": Object { - "type": "async", - "value": undefined, - }, - "callAsyncSingleSyncWithArgCalled1": 42, - "callAsyncSingleSyncWithArgNoReturn": Object { - "type": "async", - "value": undefined, - }, - "callAsyncSingleSyncWithArgNoReturnCalled1": 42, - "promiseMultipleAsyncEarlyError": Object { - "error": "Error in async2", - "type": "promise", - }, - "promiseMultipleAsyncEarlyErrorCalled1": true, - "promiseMultipleAsyncError": Object { - "error": "Error in async2", - "type": "promise", - }, - "promiseMultipleAsyncErrorCalled1": true, - "promiseMultipleAsyncLateError": Object { - "error": "Error in async2", - "type": "promise", - }, - "promiseMultipleAsyncLateErrorCalled1": true, - "promiseMultipleAsyncLateErrorEarlyResult1": Object { - "error": "Error in async2", - "type": "promise", - }, - "promiseMultipleAsyncLateErrorEarlyResult1Called1": true, - "promiseMultipleAsyncLateErrorEarlyResult2": Object { - "error": "Error in async2", - "type": "promise", - }, - "promiseMultipleAsyncLateErrorEarlyResult2Called1": true, - "promiseMultipleAsyncWithArg": Object { - "type": "promise", - "value": undefined, - }, - "promiseMultipleAsyncWithArgCalled1": 42, - "promiseMultipleAsyncWithArgCalled2": 42, - "promiseMultipleAsyncWithArgFirstReturn": Object { - "type": "promise", - "value": undefined, - }, - "promiseMultipleAsyncWithArgFirstReturnCalled1": 42, - "promiseMultipleAsyncWithArgFirstReturnCalled2": 42, - "promiseMultipleAsyncWithArgLastReturn": Object { - "type": "promise", - "value": undefined, - }, - "promiseMultipleAsyncWithArgLastReturnCalled1": 42, - "promiseMultipleAsyncWithArgLastReturnCalled2": 42, - "promiseMultipleAsyncWithArgNoReturn": Object { - "type": "promise", - "value": undefined, - }, - "promiseMultipleAsyncWithArgNoReturnCalled1": 42, - "promiseMultipleAsyncWithArgNoReturnCalled2": 42, - "promiseMultipleMixed1WithArg": Object { - "type": "promise", - "value": undefined, - }, - "promiseMultipleMixed1WithArgCalled1": 42, - "promiseMultipleMixed1WithArgCalled2": 42, - "promiseMultipleMixed1WithArgCalled3": 42, - "promiseMultipleMixed2WithArg": Object { - "type": "promise", - "value": undefined, - }, - "promiseMultipleMixed2WithArgCalled1": 42, - "promiseMultipleMixed2WithArgCalled2": 42, - "promiseMultipleMixed3WithArg": Object { - "type": "promise", - "value": undefined, - }, - "promiseMultipleMixed3WithArgCalled1": 42, - "promiseMultipleMixed3WithArgCalled2": 42, - "promiseMultipleMixed3WithArgCalled3": 42, - "promiseMultipleMixedError1WithArg": Object { - "error": "Error in sync", - "type": "promise", - }, - "promiseMultipleMixedError1WithArgCalled1": 42, - "promiseMultipleMixedError1WithArgCalled2": 42, - "promiseMultipleMixedError1WithArgCalled3": 42, - "promiseMultipleMixedError2WithArg": Object { - "error": "Error in promise", - "type": "promise", - }, - "promiseMultipleMixedError2WithArgCalled1": 42, - "promiseMultipleMixedError2WithArgCalled2": 42, - "promiseMultipleMixedError3WithArg": Object { - "error": "Error in async", - "type": "promise", - }, - "promiseMultipleMixedError3WithArgCalled1": 42, - "promiseMultipleMixedLateError": Object { - "error": "Error in async", - "type": "promise", - }, - "promiseMultipleMixedLateErrorCalled1": true, - "promiseMultiplePromiseEarlyError": Object { - "error": "Error in async2", - "type": "promise", - }, - "promiseMultiplePromiseEarlyErrorCalled1": true, - "promiseMultiplePromiseError": Object { - "error": "Error in async2", - "type": "promise", - }, - "promiseMultiplePromiseErrorCalled1": true, - "promiseMultiplePromiseLateError": Object { - "error": "Error in async2", - "type": "promise", - }, - "promiseMultiplePromiseLateErrorCalled1": true, - "promiseMultiplePromiseWithArg": Object { - "type": "promise", - "value": undefined, - }, - "promiseMultiplePromiseWithArgCalled1": 42, - "promiseMultiplePromiseWithArgCalled2": 42, - "promiseMultiplePromiseWithArgFirstReturn": Object { - "type": "promise", - "value": undefined, - }, - "promiseMultiplePromiseWithArgFirstReturnCalled1": 42, - "promiseMultiplePromiseWithArgFirstReturnCalled2": 42, - "promiseMultiplePromiseWithArgLastReturn": Object { - "type": "promise", - "value": undefined, - }, - "promiseMultiplePromiseWithArgLastReturnCalled1": 42, - "promiseMultiplePromiseWithArgLastReturnCalled2": 42, - "promiseMultiplePromiseWithArgNoReturn": Object { - "type": "promise", - "value": undefined, - }, - "promiseMultiplePromiseWithArgNoReturnCalled1": 42, - "promiseMultiplePromiseWithArgNoReturnCalled2": 42, - "promiseMultipleSync": Object { - "type": "promise", - "value": undefined, - }, - "promiseMultipleSyncCalled1": true, - "promiseMultipleSyncCalled2": true, - "promiseMultipleSyncError": Object { - "error": "Error in sync2", - "type": "promise", - }, - "promiseMultipleSyncErrorCalled1": true, - "promiseMultipleSyncLastReturn": Object { - "type": "promise", - "value": undefined, - }, - "promiseMultipleSyncLastReturnCalled1": true, - "promiseMultipleSyncLastReturnCalled2": true, - "promiseMultipleSyncNoReturn": Object { - "type": "promise", - "value": undefined, - }, - "promiseMultipleSyncNoReturnCalled1": true, - "promiseMultipleSyncNoReturnCalled2": true, - "promiseMultipleSyncWithArg": Object { - "type": "promise", - "value": undefined, - }, - "promiseMultipleSyncWithArgCalled1": 42, - "promiseMultipleSyncWithArgCalled2": 42, - "promiseMultipleSyncWithArgFirstReturn": Object { - "type": "promise", - "value": undefined, - }, - "promiseMultipleSyncWithArgFirstReturnCalled1": 42, - "promiseMultipleSyncWithArgFirstReturnCalled2": 42, - "promiseMultipleSyncWithArgLastReturn": Object { - "type": "promise", - "value": undefined, - }, - "promiseMultipleSyncWithArgLastReturnCalled1": 42, - "promiseMultipleSyncWithArgLastReturnCalled2": 42, - "promiseMultipleSyncWithArgNoReturn": Object { - "type": "promise", - "value": undefined, - }, - "promiseMultipleSyncWithArgNoReturnCalled1": 42, - "promiseMultipleSyncWithArgNoReturnCalled2": 42, - "promiseNone": Object { - "type": "promise", - "value": undefined, - }, - "promiseNoneWithArg": Object { - "type": "promise", - "value": undefined, - }, - "promiseSingleAsyncWithArg": Object { - "type": "promise", - "value": undefined, - }, - "promiseSingleAsyncWithArgCalled1": 42, - "promiseSinglePromiseWithArg": Object { - "type": "promise", - "value": undefined, - }, - "promiseSinglePromiseWithArgCalled1": 42, - "promiseSinglePromiseWithEmptyReject": Object { - "error": "Tap function (tapPromise) rejects \\"\\" value", - "type": "promise", - }, - "promiseSinglePromiseWithEmptyStringArg": Object { - "type": "promise", - "value": undefined, - }, - "promiseSinglePromiseWithEmptyStringArgCalled1": 42, - "promiseSinglePromiseWithFalseReject": Object { - "error": "Tap function (tapPromise) rejects \\"false\\" value", - "type": "promise", - }, - "promiseSinglePromiseWithNullArg": Object { - "type": "promise", - "value": undefined, - }, - "promiseSinglePromiseWithNullArgCalled1": 42, - "promiseSinglePromiseWithNullReject": Object { - "error": "Tap function (tapPromise) rejects \\"null\\" value", - "type": "promise", - }, - "promiseSinglePromiseWithUndefined": Object { - "type": "promise", - "value": undefined, - }, - "promiseSinglePromiseWithUndefinedCalled1": 42, - "promiseSinglePromiseWithUndefinedReject": Object { - "error": "Tap function (tapPromise) rejects \\"undefined\\" value", - "type": "promise", - }, - "promiseSinglePromiseWithZeroArg": Object { - "type": "promise", - "value": undefined, - }, - "promiseSinglePromiseWithZeroArgCalled1": 42, - "promiseSinglePromiseWithZeroReject": Object { - "error": "Tap function (tapPromise) rejects \\"0\\" value", - "type": "promise", - }, - "promiseSingleSync": Object { - "type": "promise", - "value": undefined, - }, - "promiseSingleSyncCalled1": true, - "promiseSingleSyncWithArg": Object { - "type": "promise", - "value": undefined, - }, - "promiseSingleSyncWithArgCalled1": 42, - "promiseSingleSyncWithArgNoReturn": Object { - "type": "promise", - "value": undefined, - }, - "promiseSingleSyncWithArgNoReturnCalled1": 42, - }, - "intercept": Object { - "callAsyncContextIntercepted": Object { - "type": "async", - "value": undefined, - }, - "callAsyncContextInterceptedCall1": Array [ - Object { - "number": 42, - }, - 1, - 2, - 3, - ], - "callAsyncContextInterceptedCall2": Array [ - 1, - 2, - 3, - ], - "callAsyncContextInterceptedTap1": Object { - "number": 42, - }, - "callAsyncIntercepted": Object { - "type": "async", - "value": undefined, - }, - "callAsyncInterceptedCall1": Array [ - 1, - 2, - 3, - ], - "callAsyncInterceptedCall2": Array [ - 1, - 2, - 3, - ], - "callAsyncInterceptedDone1": true, - "callAsyncInterceptedDone2": true, - "callAsyncInterceptedTap1": Object { - "fn": 2, - "name": "promise", - "type": "promise", - }, - "callAsyncInterceptedTap2": Object { - "fn": 3, - "name": "sync", - "type": "sync", - }, - "callAsyncUnusedContextIntercepted": Object { - "type": "async", - "value": undefined, - }, - "callAsyncUnusedContextInterceptedCall1": Array [ - undefined, - 1, - 2, - 3, - ], - "callAsyncUnusedContextInterceptedCall2": Array [ - 1, - 2, - 3, - ], - "callAsyncUnusedContextInterceptedTap1": undefined, - "promiseContextIntercepted": Object { - "type": "promise", - "value": undefined, - }, - "promiseContextInterceptedCall1": Array [ - Object { - "number": 42, - }, - 1, - 2, - 3, - ], - "promiseContextInterceptedCall2": Array [ - 1, - 2, - 3, - ], - "promiseContextInterceptedTap1": Object { - "number": 42, - }, - "promiseIntercepted": Object { - "type": "promise", - "value": undefined, - }, - "promiseInterceptedCall1": Array [ - 1, - 2, - 3, - ], - "promiseInterceptedCall2": Array [ - 1, - 2, - 3, - ], - "promiseInterceptedDone1": true, - "promiseInterceptedDone2": true, - "promiseInterceptedTap1": Object { - "fn": 2, - "name": "promise", - "type": "promise", - }, - "promiseInterceptedTap2": Object { - "fn": 3, - "name": "sync", - "type": "sync", - }, - "promiseUnusedContextIntercepted": Object { - "type": "promise", - "value": undefined, - }, - "promiseUnusedContextInterceptedCall1": Array [ - undefined, - 1, - 2, - 3, - ], - "promiseUnusedContextInterceptedCall2": Array [ - 1, - 2, - 3, - ], - "promiseUnusedContextInterceptedTap1": undefined, - }, - "sync": Object { - "callAsyncIntercepted": Object { - "type": "async", - "value": undefined, - }, - "callAsyncInterceptedCall1": Array [ - 1, - 2, - 3, - ], - "callAsyncInterceptedCall2": Array [ - 1, - 2, - 3, - ], - "callAsyncInterceptedTap1": Object { - "fn": 2, - "name": "sync2", - "type": "sync", - }, - "callAsyncInterceptedTap2": Object { - "fn": 3, - "name": "sync1", - "type": "sync", - }, - "callAsyncMultipleSync": Object { - "type": "async", - "value": undefined, - }, - "callAsyncMultipleSyncCalled1": true, - "callAsyncMultipleSyncCalled2": true, - "callAsyncMultipleSyncError": Object { - "error": "Error in sync2", - "type": "async", - }, - "callAsyncMultipleSyncErrorCalled1": true, - "callAsyncMultipleSyncErrorCalled2": true, - "callAsyncMultipleSyncWithArg": Object { - "type": "async", - "value": undefined, - }, - "callAsyncMultipleSyncWithArgCalled1": 42, - "callAsyncMultipleSyncWithArgCalled2": 42, - "callAsyncMultipleSyncWithArgFirstReturn": Object { - "type": "async", - "value": undefined, - }, - "callAsyncMultipleSyncWithArgFirstReturnCalled1": 42, - "callAsyncMultipleSyncWithArgFirstReturnCalled2": 42, - "callAsyncMultipleSyncWithArgLastReturn": Object { - "type": "async", - "value": undefined, - }, - "callAsyncMultipleSyncWithArgLastReturnCalled1": 42, - "callAsyncMultipleSyncWithArgLastReturnCalled2": 42, - "callAsyncMultipleSyncWithArgNoReturn": Object { - "type": "async", - "value": undefined, - }, - "callAsyncMultipleSyncWithArgNoReturnCalled1": 42, - "callAsyncMultipleSyncWithArgNoReturnCalled2": 42, - "callAsyncMultipleSyncWithArgs": Object { - "type": "async", - "value": undefined, - }, - "callAsyncMultipleSyncWithArgsCalled1": Array [ - 42, - 43, - 44, - ], - "callAsyncMultipleSyncWithArgsCalled2": Array [ - 42, - 43, - 44, - ], - "callAsyncNone": Object { - "type": "async", - "value": undefined, - }, - "callAsyncNoneWithArg": Object { - "type": "async", - "value": undefined, - }, - "callAsyncSingleSync": Object { - "type": "async", - "value": undefined, - }, - "callAsyncSingleSyncCalled": true, - "callAsyncSingleSyncWithArg": Object { - "type": "async", - "value": undefined, - }, - "callAsyncSingleSyncWithArgCalled": 42, - "promiseIntercepted": Object { - "type": "promise", - "value": undefined, - }, - "promiseInterceptedCall1": Array [ - 1, - 2, - 3, - ], - "promiseInterceptedCall2": Array [ - 1, - 2, - 3, - ], - "promiseInterceptedTap1": Object { - "fn": 2, - "name": "sync2", - "type": "sync", - }, - "promiseInterceptedTap2": Object { - "fn": 3, - "name": "sync1", - "type": "sync", - }, - "promiseMultipleSync": Object { - "type": "promise", - "value": undefined, - }, - "promiseMultipleSyncCalled1": true, - "promiseMultipleSyncCalled2": true, - "promiseMultipleSyncError": Object { - "error": "Error in sync2", - "type": "promise", - }, - "promiseMultipleSyncErrorCalled1": true, - "promiseMultipleSyncErrorCalled2": true, - "promiseMultipleSyncWithArg": Object { - "type": "promise", - "value": undefined, - }, - "promiseMultipleSyncWithArgCalled1": 42, - "promiseMultipleSyncWithArgCalled2": 42, - "promiseMultipleSyncWithArgFirstReturn": Object { - "type": "promise", - "value": undefined, - }, - "promiseMultipleSyncWithArgFirstReturnCalled1": 42, - "promiseMultipleSyncWithArgFirstReturnCalled2": 42, - "promiseMultipleSyncWithArgLastReturn": Object { - "type": "promise", - "value": undefined, - }, - "promiseMultipleSyncWithArgLastReturnCalled1": 42, - "promiseMultipleSyncWithArgLastReturnCalled2": 42, - "promiseMultipleSyncWithArgNoReturn": Object { - "type": "promise", - "value": undefined, - }, - "promiseMultipleSyncWithArgNoReturnCalled1": 42, - "promiseMultipleSyncWithArgNoReturnCalled2": 42, - "promiseMultipleSyncWithArgs": Object { - "type": "promise", - "value": undefined, - }, - "promiseMultipleSyncWithArgsCalled1": Array [ - 42, - 43, - 44, - ], - "promiseMultipleSyncWithArgsCalled2": Array [ - 42, - 43, - 44, - ], - "promiseNone": Object { - "type": "promise", - "value": undefined, - }, - "promiseNoneWithArg": Object { - "type": "promise", - "value": undefined, - }, - "promiseSingleSync": Object { - "type": "promise", - "value": undefined, - }, - "promiseSingleSyncCalled": true, - "promiseSingleSyncWithArg": Object { - "type": "promise", - "value": undefined, - }, - "promiseSingleSyncWithArgCalled": 42, - }, -} -`; - -exports[`AsyncSeriesLoopHook should have to correct behavior 1`] = ` -Object { - "async": Object { - "callAsyncBrokenPromise": Object { - "error": "Tap function (tapPromise) did not return promise (returned this is not a promise)", - }, - "callAsyncMixed": Object { - "type": "async", - "value": undefined, - }, - "callAsyncMixedCalled1": 124, - "callAsyncMixedCalled2": 83, - "callAsyncMixedCalled3": 42, - "callAsyncMultipleAsync": Object { - "type": "async", - "value": undefined, - }, - "callAsyncMultipleAsyncCalled1": 83, - "callAsyncMultipleAsyncCalled2": 42, - "callAsyncMultiplePromise": Object { - "type": "async", - "value": undefined, - }, - "callAsyncMultiplePromiseCalled1": 83, - "callAsyncMultiplePromiseCalled2": 42, - "callAsyncSingleAsync": Object { - "type": "async", - "value": undefined, - }, - "callAsyncSingleAsyncCalled": 42, - "callAsyncSinglePromise": Object { - "type": "async", - "value": undefined, - }, - "callAsyncSinglePromiseCalled": 42, - "promiseBrokenPromise": Object { - "error": "Tap function (tapPromise) did not return promise (returned this is not a promise)", - "type": "promise", - }, - "promiseMixed": Object { - "type": "promise", - "value": undefined, - }, - "promiseMixedCalled1": 124, - "promiseMixedCalled2": 83, - "promiseMixedCalled3": 42, - "promiseMultipleAsync": Object { - "type": "promise", - "value": undefined, - }, - "promiseMultipleAsyncCalled1": 83, - "promiseMultipleAsyncCalled2": 42, - "promiseMultiplePromise": Object { - "type": "promise", - "value": undefined, - }, - "promiseMultiplePromiseCalled1": 83, - "promiseMultiplePromiseCalled2": 42, - "promiseSingleAsync": Object { - "type": "promise", - "value": undefined, - }, - "promiseSingleAsyncCalled": 42, - "promiseSinglePromise": Object { - "type": "promise", - "value": undefined, - }, - "promiseSinglePromiseCalled": 42, - }, - "sync": Object { - "callAsyncInterceptedSync": Object { - "type": "async", - "value": undefined, - }, - "callAsyncInterceptedSyncCalled1": 83, - "callAsyncInterceptedSyncCalled2": 42, - "callAsyncInterceptedSyncCalledCall": 1, - "callAsyncInterceptedSyncCalledLoop": 83, - "callAsyncInterceptedSyncCalledTap": 125, - "callAsyncMultipleSync": Object { - "type": "async", - "value": undefined, - }, - "callAsyncMultipleSyncCalled1": 83, - "callAsyncMultipleSyncCalled2": 42, - "callAsyncNone": Object { - "type": "async", - "value": undefined, - }, - "callAsyncNoneWithArg": Object { - "type": "async", - "value": undefined, - }, - "callAsyncSingleSync": Object { - "type": "async", - "value": undefined, - }, - "callAsyncSingleSyncCalled": 42, - "promiseInterceptedSync": Object { - "type": "promise", - "value": undefined, - }, - "promiseInterceptedSyncCalled1": 83, - "promiseInterceptedSyncCalled2": 42, - "promiseInterceptedSyncCalledCall": 1, - "promiseInterceptedSyncCalledLoop": 83, - "promiseInterceptedSyncCalledTap": 125, - "promiseMultipleSync": Object { - "type": "promise", - "value": undefined, - }, - "promiseMultipleSyncCalled1": 83, - "promiseMultipleSyncCalled2": 42, - "promiseNone": Object { - "type": "promise", - "value": undefined, - }, - "promiseNoneWithArg": Object { - "type": "promise", - "value": undefined, - }, - "promiseSingleSync": Object { - "type": "promise", - "value": undefined, - }, - "promiseSingleSyncCalled": 42, - }, -} -`; - -exports[`AsyncSeriesWaterfallHook should have to correct behavior 1`] = ` -Object { - "async": Object { - "callAsyncMultipleAsyncEarlyError": Object { - "error": "Waterfall hooks must have at least one argument", - }, - "callAsyncMultipleAsyncError": Object { - "error": "Waterfall hooks must have at least one argument", - }, - "callAsyncMultipleAsyncLateError": Object { - "error": "Waterfall hooks must have at least one argument", - }, - "callAsyncMultipleAsyncLateErrorEarlyResult1": Object { - "error": "Waterfall hooks must have at least one argument", - }, - "callAsyncMultipleAsyncLateErrorEarlyResult2": Object { - "error": "Waterfall hooks must have at least one argument", - }, - "callAsyncMultipleAsyncWithArg": Object { - "type": "async", - "value": 45, - }, - "callAsyncMultipleAsyncWithArgCalled1": 42, - "callAsyncMultipleAsyncWithArgCalled2": 43, - "callAsyncMultipleAsyncWithArgFirstReturn": Object { - "type": "async", - "value": 43, - }, - "callAsyncMultipleAsyncWithArgFirstReturnCalled1": 42, - "callAsyncMultipleAsyncWithArgFirstReturnCalled2": 43, - "callAsyncMultipleAsyncWithArgLastReturn": Object { - "type": "async", - "value": 44, - }, - "callAsyncMultipleAsyncWithArgLastReturnCalled1": 42, - "callAsyncMultipleAsyncWithArgLastReturnCalled2": 42, - "callAsyncMultipleAsyncWithArgNoReturn": Object { - "type": "async", - "value": 42, - }, - "callAsyncMultipleAsyncWithArgNoReturnCalled1": 42, - "callAsyncMultipleAsyncWithArgNoReturnCalled2": 42, - "callAsyncMultipleMixed1WithArg": Object { - "type": "async", - "value": 48, - }, - "callAsyncMultipleMixed1WithArgCalled1": 42, - "callAsyncMultipleMixed1WithArgCalled2": 43, - "callAsyncMultipleMixed1WithArgCalled3": 45, - "callAsyncMultipleMixed2WithArg": Object { - "type": "async", - "value": 45, - }, - "callAsyncMultipleMixed2WithArgCalled1": 42, - "callAsyncMultipleMixed2WithArgCalled2": 43, - "callAsyncMultipleMixed3WithArg": Object { - "type": "async", - "value": 48, - }, - "callAsyncMultipleMixed3WithArgCalled1": 42, - "callAsyncMultipleMixed3WithArgCalled2": 43, - "callAsyncMultipleMixed3WithArgCalled3": 45, - "callAsyncMultipleMixedError1WithArg": Object { - "error": "Error in sync", - "type": "async", - }, - "callAsyncMultipleMixedError1WithArgCalled1": 42, - "callAsyncMultipleMixedError1WithArgCalled2": 42, - "callAsyncMultipleMixedError1WithArgCalled3": 43, - "callAsyncMultipleMixedError2WithArg": Object { - "error": "Error in promise", - "type": "async", - }, - "callAsyncMultipleMixedError2WithArgCalled1": 42, - "callAsyncMultipleMixedError2WithArgCalled2": 42, - "callAsyncMultipleMixedError3WithArg": Object { - "error": "Error in async", - "type": "async", - }, - "callAsyncMultipleMixedError3WithArgCalled1": 42, - "callAsyncMultipleMixedLateError": Object { - "error": "Waterfall hooks must have at least one argument", - }, - "callAsyncMultiplePromiseEarlyError": Object { - "error": "Waterfall hooks must have at least one argument", - }, - "callAsyncMultiplePromiseError": Object { - "error": "Waterfall hooks must have at least one argument", - }, - "callAsyncMultiplePromiseLateError": Object { - "error": "Waterfall hooks must have at least one argument", - }, - "callAsyncMultiplePromiseWithArg": Object { - "type": "async", - "value": 45, - }, - "callAsyncMultiplePromiseWithArgCalled1": 42, - "callAsyncMultiplePromiseWithArgCalled2": 43, - "callAsyncMultiplePromiseWithArgFirstReturn": Object { - "type": "async", - "value": 43, - }, - "callAsyncMultiplePromiseWithArgFirstReturnCalled1": 42, - "callAsyncMultiplePromiseWithArgFirstReturnCalled2": 43, - "callAsyncMultiplePromiseWithArgLastReturn": Object { - "type": "async", - "value": 44, - }, - "callAsyncMultiplePromiseWithArgLastReturnCalled1": 42, - "callAsyncMultiplePromiseWithArgLastReturnCalled2": 42, - "callAsyncMultiplePromiseWithArgNoReturn": Object { - "type": "async", - "value": 42, - }, - "callAsyncMultiplePromiseWithArgNoReturnCalled1": 42, - "callAsyncMultiplePromiseWithArgNoReturnCalled2": 42, - "callAsyncMultipleSync": Object { - "error": "Waterfall hooks must have at least one argument", - }, - "callAsyncMultipleSyncError": Object { - "error": "Waterfall hooks must have at least one argument", - }, - "callAsyncMultipleSyncLastReturn": Object { - "error": "Waterfall hooks must have at least one argument", - }, - "callAsyncMultipleSyncNoReturn": Object { - "error": "Waterfall hooks must have at least one argument", - }, - "callAsyncMultipleSyncWithArg": Object { - "type": "async", - "value": 45, - }, - "callAsyncMultipleSyncWithArgCalled1": 42, - "callAsyncMultipleSyncWithArgCalled2": 43, - "callAsyncMultipleSyncWithArgFirstReturn": Object { - "type": "async", - "value": 43, - }, - "callAsyncMultipleSyncWithArgFirstReturnCalled1": 42, - "callAsyncMultipleSyncWithArgFirstReturnCalled2": 43, - "callAsyncMultipleSyncWithArgLastReturn": Object { - "type": "async", - "value": 44, - }, - "callAsyncMultipleSyncWithArgLastReturnCalled1": 42, - "callAsyncMultipleSyncWithArgLastReturnCalled2": 42, - "callAsyncMultipleSyncWithArgNoReturn": Object { - "type": "async", - "value": 42, - }, - "callAsyncMultipleSyncWithArgNoReturnCalled1": 42, - "callAsyncMultipleSyncWithArgNoReturnCalled2": 42, - "callAsyncNone": Object { - "error": "Waterfall hooks must have at least one argument", - }, - "callAsyncNoneWithArg": Object { - "type": "async", - "value": 42, - }, - "callAsyncSingleAsyncWithArg": Object { - "type": "async", - "value": 42, - }, - "callAsyncSingleAsyncWithArgCalled1": 42, - "callAsyncSinglePromiseWithArg": Object { - "type": "async", - "value": 43, - }, - "callAsyncSinglePromiseWithArgCalled1": 42, - "callAsyncSinglePromiseWithEmptyReject": Object { - "error": "Tap function (tapPromise) rejects \\"\\" value", - "type": "async", - }, - "callAsyncSinglePromiseWithEmptyStringArg": Object { - "type": "async", - "value": "", - }, - "callAsyncSinglePromiseWithEmptyStringArgCalled1": 42, - "callAsyncSinglePromiseWithFalseReject": Object { - "error": "Tap function (tapPromise) rejects \\"false\\" value", - "type": "async", - }, - "callAsyncSinglePromiseWithNullArg": Object { - "type": "async", - "value": null, - }, - "callAsyncSinglePromiseWithNullArgCalled1": 42, - "callAsyncSinglePromiseWithNullReject": Object { - "error": "Tap function (tapPromise) rejects \\"null\\" value", - "type": "async", - }, - "callAsyncSinglePromiseWithUndefined": Object { - "type": "async", - "value": 42, - }, - "callAsyncSinglePromiseWithUndefinedCalled1": 42, - "callAsyncSinglePromiseWithUndefinedReject": Object { - "error": "Tap function (tapPromise) rejects \\"undefined\\" value", - "type": "async", - }, - "callAsyncSinglePromiseWithZeroArg": Object { - "type": "async", - "value": 0, - }, - "callAsyncSinglePromiseWithZeroArgCalled1": 42, - "callAsyncSinglePromiseWithZeroReject": Object { - "error": "Tap function (tapPromise) rejects \\"0\\" value", - "type": "async", - }, - "callAsyncSingleSync": Object { - "error": "Waterfall hooks must have at least one argument", - }, - "callAsyncSingleSyncWithArg": Object { - "type": "async", - "value": 43, - }, - "callAsyncSingleSyncWithArgCalled1": 42, - "callAsyncSingleSyncWithArgNoReturn": Object { - "type": "async", - "value": 42, - }, - "callAsyncSingleSyncWithArgNoReturnCalled1": 42, - "promiseMultipleAsyncEarlyError": Object { - "error": "Waterfall hooks must have at least one argument", - }, - "promiseMultipleAsyncError": Object { - "error": "Waterfall hooks must have at least one argument", - }, - "promiseMultipleAsyncLateError": Object { - "error": "Waterfall hooks must have at least one argument", - }, - "promiseMultipleAsyncLateErrorEarlyResult1": Object { - "error": "Waterfall hooks must have at least one argument", - }, - "promiseMultipleAsyncLateErrorEarlyResult2": Object { - "error": "Waterfall hooks must have at least one argument", - }, - "promiseMultipleAsyncWithArg": Object { - "type": "promise", - "value": 45, - }, - "promiseMultipleAsyncWithArgCalled1": 42, - "promiseMultipleAsyncWithArgCalled2": 43, - "promiseMultipleAsyncWithArgFirstReturn": Object { - "type": "promise", - "value": 43, - }, - "promiseMultipleAsyncWithArgFirstReturnCalled1": 42, - "promiseMultipleAsyncWithArgFirstReturnCalled2": 43, - "promiseMultipleAsyncWithArgLastReturn": Object { - "type": "promise", - "value": 44, - }, - "promiseMultipleAsyncWithArgLastReturnCalled1": 42, - "promiseMultipleAsyncWithArgLastReturnCalled2": 42, - "promiseMultipleAsyncWithArgNoReturn": Object { - "type": "promise", - "value": 42, - }, - "promiseMultipleAsyncWithArgNoReturnCalled1": 42, - "promiseMultipleAsyncWithArgNoReturnCalled2": 42, - "promiseMultipleMixed1WithArg": Object { - "type": "promise", - "value": 48, - }, - "promiseMultipleMixed1WithArgCalled1": 42, - "promiseMultipleMixed1WithArgCalled2": 43, - "promiseMultipleMixed1WithArgCalled3": 45, - "promiseMultipleMixed2WithArg": Object { - "type": "promise", - "value": 45, - }, - "promiseMultipleMixed2WithArgCalled1": 42, - "promiseMultipleMixed2WithArgCalled2": 43, - "promiseMultipleMixed3WithArg": Object { - "type": "promise", - "value": 48, - }, - "promiseMultipleMixed3WithArgCalled1": 42, - "promiseMultipleMixed3WithArgCalled2": 43, - "promiseMultipleMixed3WithArgCalled3": 45, - "promiseMultipleMixedError1WithArg": Object { - "error": "Error in sync", - "type": "promise", - }, - "promiseMultipleMixedError1WithArgCalled1": 42, - "promiseMultipleMixedError1WithArgCalled2": 42, - "promiseMultipleMixedError1WithArgCalled3": 43, - "promiseMultipleMixedError2WithArg": Object { - "error": "Error in promise", - "type": "promise", - }, - "promiseMultipleMixedError2WithArgCalled1": 42, - "promiseMultipleMixedError2WithArgCalled2": 42, - "promiseMultipleMixedError3WithArg": Object { - "error": "Error in async", - "type": "promise", - }, - "promiseMultipleMixedError3WithArgCalled1": 42, - "promiseMultipleMixedLateError": Object { - "error": "Waterfall hooks must have at least one argument", - }, - "promiseMultiplePromiseEarlyError": Object { - "error": "Waterfall hooks must have at least one argument", - }, - "promiseMultiplePromiseError": Object { - "error": "Waterfall hooks must have at least one argument", - }, - "promiseMultiplePromiseLateError": Object { - "error": "Waterfall hooks must have at least one argument", - }, - "promiseMultiplePromiseWithArg": Object { - "type": "promise", - "value": 45, - }, - "promiseMultiplePromiseWithArgCalled1": 42, - "promiseMultiplePromiseWithArgCalled2": 43, - "promiseMultiplePromiseWithArgFirstReturn": Object { - "type": "promise", - "value": 43, - }, - "promiseMultiplePromiseWithArgFirstReturnCalled1": 42, - "promiseMultiplePromiseWithArgFirstReturnCalled2": 43, - "promiseMultiplePromiseWithArgLastReturn": Object { - "type": "promise", - "value": 44, - }, - "promiseMultiplePromiseWithArgLastReturnCalled1": 42, - "promiseMultiplePromiseWithArgLastReturnCalled2": 42, - "promiseMultiplePromiseWithArgNoReturn": Object { - "type": "promise", - "value": 42, - }, - "promiseMultiplePromiseWithArgNoReturnCalled1": 42, - "promiseMultiplePromiseWithArgNoReturnCalled2": 42, - "promiseMultipleSync": Object { - "error": "Waterfall hooks must have at least one argument", - }, - "promiseMultipleSyncError": Object { - "error": "Waterfall hooks must have at least one argument", - }, - "promiseMultipleSyncLastReturn": Object { - "error": "Waterfall hooks must have at least one argument", - }, - "promiseMultipleSyncNoReturn": Object { - "error": "Waterfall hooks must have at least one argument", - }, - "promiseMultipleSyncWithArg": Object { - "type": "promise", - "value": 45, - }, - "promiseMultipleSyncWithArgCalled1": 42, - "promiseMultipleSyncWithArgCalled2": 43, - "promiseMultipleSyncWithArgFirstReturn": Object { - "type": "promise", - "value": 43, - }, - "promiseMultipleSyncWithArgFirstReturnCalled1": 42, - "promiseMultipleSyncWithArgFirstReturnCalled2": 43, - "promiseMultipleSyncWithArgLastReturn": Object { - "type": "promise", - "value": 44, - }, - "promiseMultipleSyncWithArgLastReturnCalled1": 42, - "promiseMultipleSyncWithArgLastReturnCalled2": 42, - "promiseMultipleSyncWithArgNoReturn": Object { - "type": "promise", - "value": 42, - }, - "promiseMultipleSyncWithArgNoReturnCalled1": 42, - "promiseMultipleSyncWithArgNoReturnCalled2": 42, - "promiseNone": Object { - "error": "Waterfall hooks must have at least one argument", - }, - "promiseNoneWithArg": Object { - "type": "promise", - "value": 42, - }, - "promiseSingleAsyncWithArg": Object { - "type": "promise", - "value": 42, - }, - "promiseSingleAsyncWithArgCalled1": 42, - "promiseSinglePromiseWithArg": Object { - "type": "promise", - "value": 43, - }, - "promiseSinglePromiseWithArgCalled1": 42, - "promiseSinglePromiseWithEmptyReject": Object { - "error": "Tap function (tapPromise) rejects \\"\\" value", - "type": "promise", - }, - "promiseSinglePromiseWithEmptyStringArg": Object { - "type": "promise", - "value": "", - }, - "promiseSinglePromiseWithEmptyStringArgCalled1": 42, - "promiseSinglePromiseWithFalseReject": Object { - "error": "Tap function (tapPromise) rejects \\"false\\" value", - "type": "promise", - }, - "promiseSinglePromiseWithNullArg": Object { - "type": "promise", - "value": null, - }, - "promiseSinglePromiseWithNullArgCalled1": 42, - "promiseSinglePromiseWithNullReject": Object { - "error": "Tap function (tapPromise) rejects \\"null\\" value", - "type": "promise", - }, - "promiseSinglePromiseWithUndefined": Object { - "type": "promise", - "value": 42, - }, - "promiseSinglePromiseWithUndefinedCalled1": 42, - "promiseSinglePromiseWithUndefinedReject": Object { - "error": "Tap function (tapPromise) rejects \\"undefined\\" value", - "type": "promise", - }, - "promiseSinglePromiseWithZeroArg": Object { - "type": "promise", - "value": 0, - }, - "promiseSinglePromiseWithZeroArgCalled1": 42, - "promiseSinglePromiseWithZeroReject": Object { - "error": "Tap function (tapPromise) rejects \\"0\\" value", - "type": "promise", - }, - "promiseSingleSync": Object { - "error": "Waterfall hooks must have at least one argument", - }, - "promiseSingleSyncWithArg": Object { - "type": "promise", - "value": 43, - }, - "promiseSingleSyncWithArgCalled1": 42, - "promiseSingleSyncWithArgNoReturn": Object { - "type": "promise", - "value": 42, - }, - "promiseSingleSyncWithArgNoReturnCalled1": 42, - }, - "intercept": Object { - "callAsyncContextIntercepted": Object { - "type": "async", - "value": 48, - }, - "callAsyncContextInterceptedCall1": Array [ - Object { - "number": 42, - }, - 1, - 2, - 3, - ], - "callAsyncContextInterceptedCall2": Array [ - 1, - 2, - 3, - ], - "callAsyncContextInterceptedTap1": Object { - "number": 42, - }, - "callAsyncIntercepted": Object { - "type": "async", - "value": 9, - }, - "callAsyncInterceptedCall1": Array [ - 1, - 2, - 3, - ], - "callAsyncInterceptedCall2": Array [ - 1, - 2, - 3, - ], - "callAsyncInterceptedResult1": 9, - "callAsyncInterceptedResult2": 9, - "callAsyncInterceptedTap1": Object { - "fn": 2, - "name": "promise", - "type": "promise", - }, - "callAsyncInterceptedTap2": Object { - "fn": 3, - "name": "sync", - "type": "sync", - }, - "callAsyncUnusedContextIntercepted": Object { - "type": "async", - "value": 6, - }, - "callAsyncUnusedContextInterceptedCall1": Array [ - undefined, - 1, - 2, - 3, - ], - "callAsyncUnusedContextInterceptedCall2": Array [ - 1, - 2, - 3, - ], - "callAsyncUnusedContextInterceptedTap1": undefined, - "promiseContextIntercepted": Object { - "type": "promise", - "value": 48, - }, - "promiseContextInterceptedCall1": Array [ - Object { - "number": 42, - }, - 1, - 2, - 3, - ], - "promiseContextInterceptedCall2": Array [ - 1, - 2, - 3, - ], - "promiseContextInterceptedTap1": Object { - "number": 42, - }, - "promiseIntercepted": Object { - "type": "promise", - "value": 9, - }, - "promiseInterceptedCall1": Array [ - 1, - 2, - 3, - ], - "promiseInterceptedCall2": Array [ - 1, - 2, - 3, - ], - "promiseInterceptedResult1": 9, - "promiseInterceptedResult2": 9, - "promiseInterceptedTap1": Object { - "fn": 2, - "name": "promise", - "type": "promise", - }, - "promiseInterceptedTap2": Object { - "fn": 3, - "name": "sync", - "type": "sync", - }, - "promiseUnusedContextIntercepted": Object { - "type": "promise", - "value": 6, - }, - "promiseUnusedContextInterceptedCall1": Array [ - undefined, - 1, - 2, - 3, - ], - "promiseUnusedContextInterceptedCall2": Array [ - 1, - 2, - 3, - ], - "promiseUnusedContextInterceptedTap1": undefined, - }, - "sync": Object { - "callAsyncIntercepted": Object { - "type": "async", - "value": 9, - }, - "callAsyncInterceptedCall1": Array [ - 1, - 2, - 3, - ], - "callAsyncInterceptedCall2": Array [ - 1, - 2, - 3, - ], - "callAsyncInterceptedTap1": Object { - "fn": 2, - "name": "sync2", - "type": "sync", - }, - "callAsyncInterceptedTap2": Object { - "fn": 3, - "name": "sync1", - "type": "sync", - }, - "callAsyncMultipleSync": Object { - "error": "Waterfall hooks must have at least one argument", - }, - "callAsyncMultipleSyncError": Object { - "error": "Waterfall hooks must have at least one argument", - }, - "callAsyncMultipleSyncWithArg": Object { - "type": "async", - "value": 127, - }, - "callAsyncMultipleSyncWithArgCalled1": 42, - "callAsyncMultipleSyncWithArgCalled2": 84, - "callAsyncMultipleSyncWithArgFirstReturn": Object { - "type": "async", - "value": 84, - }, - "callAsyncMultipleSyncWithArgFirstReturnCalled1": 42, - "callAsyncMultipleSyncWithArgFirstReturnCalled2": 84, - "callAsyncMultipleSyncWithArgLastReturn": Object { - "type": "async", - "value": 85, - }, - "callAsyncMultipleSyncWithArgLastReturnCalled1": 42, - "callAsyncMultipleSyncWithArgLastReturnCalled2": 42, - "callAsyncMultipleSyncWithArgNoReturn": Object { - "type": "async", - "value": 42, - }, - "callAsyncMultipleSyncWithArgNoReturnCalled1": 42, - "callAsyncMultipleSyncWithArgNoReturnCalled2": 42, - "callAsyncMultipleSyncWithArgs": Object { - "type": "async", - "value": 217, - }, - "callAsyncMultipleSyncWithArgsCalled1": Array [ - 42, - 43, - 44, - ], - "callAsyncMultipleSyncWithArgsCalled2": Array [ - 129, - 43, - 44, - ], - "callAsyncNone": Object { - "error": "Waterfall hooks must have at least one argument", - }, - "callAsyncNoneWithArg": Object { - "type": "async", - "value": 42, - }, - "callAsyncSingleSync": Object { - "error": "Waterfall hooks must have at least one argument", - }, - "callAsyncSingleSyncWithArg": Object { - "type": "async", - "value": 42, - }, - "callAsyncSingleSyncWithArgCalled": 42, - "promiseIntercepted": Object { - "type": "promise", - "value": 9, - }, - "promiseInterceptedCall1": Array [ - 1, - 2, - 3, - ], - "promiseInterceptedCall2": Array [ - 1, - 2, - 3, - ], - "promiseInterceptedTap1": Object { - "fn": 2, - "name": "sync2", - "type": "sync", - }, - "promiseInterceptedTap2": Object { - "fn": 3, - "name": "sync1", - "type": "sync", - }, - "promiseMultipleSync": Object { - "error": "Waterfall hooks must have at least one argument", - }, - "promiseMultipleSyncError": Object { - "error": "Waterfall hooks must have at least one argument", - }, - "promiseMultipleSyncWithArg": Object { - "type": "promise", - "value": 127, - }, - "promiseMultipleSyncWithArgCalled1": 42, - "promiseMultipleSyncWithArgCalled2": 84, - "promiseMultipleSyncWithArgFirstReturn": Object { - "type": "promise", - "value": 84, - }, - "promiseMultipleSyncWithArgFirstReturnCalled1": 42, - "promiseMultipleSyncWithArgFirstReturnCalled2": 84, - "promiseMultipleSyncWithArgLastReturn": Object { - "type": "promise", - "value": 85, - }, - "promiseMultipleSyncWithArgLastReturnCalled1": 42, - "promiseMultipleSyncWithArgLastReturnCalled2": 42, - "promiseMultipleSyncWithArgNoReturn": Object { - "type": "promise", - "value": 42, - }, - "promiseMultipleSyncWithArgNoReturnCalled1": 42, - "promiseMultipleSyncWithArgNoReturnCalled2": 42, - "promiseMultipleSyncWithArgs": Object { - "type": "promise", - "value": 217, - }, - "promiseMultipleSyncWithArgsCalled1": Array [ - 42, - 43, - 44, - ], - "promiseMultipleSyncWithArgsCalled2": Array [ - 129, - 43, - 44, - ], - "promiseNone": Object { - "error": "Waterfall hooks must have at least one argument", - }, - "promiseNoneWithArg": Object { - "type": "promise", - "value": 42, - }, - "promiseSingleSync": Object { - "error": "Waterfall hooks must have at least one argument", - }, - "promiseSingleSyncWithArg": Object { - "type": "promise", - "value": 42, - }, "promiseSingleSyncWithArgCalled": 42, }, } diff --git a/test/__snapshots__/AsyncSeriesLoopHook.test.js.snap b/test/__snapshots__/AsyncSeriesLoopHook.test.js.snap new file mode 100644 index 0000000..f7e9579 --- /dev/null +++ b/test/__snapshots__/AsyncSeriesLoopHook.test.js.snap @@ -0,0 +1,131 @@ +// Jest Snapshot v1, https://jestjs.io/docs/snapshot-testing + +exports[`AsyncSeriesLoopHook should have to correct behavior 1`] = ` +Object { + "async": Object { + "callAsyncBrokenPromise": Object { + "error": "Tap function (tapPromise) did not return promise (returned this is not a promise)", + }, + "callAsyncMixed": Object { + "type": "async", + "value": undefined, + }, + "callAsyncMixedCalled1": 124, + "callAsyncMixedCalled2": 83, + "callAsyncMixedCalled3": 42, + "callAsyncMultipleAsync": Object { + "type": "async", + "value": undefined, + }, + "callAsyncMultipleAsyncCalled1": 83, + "callAsyncMultipleAsyncCalled2": 42, + "callAsyncMultiplePromise": Object { + "type": "async", + "value": undefined, + }, + "callAsyncMultiplePromiseCalled1": 83, + "callAsyncMultiplePromiseCalled2": 42, + "callAsyncSingleAsync": Object { + "type": "async", + "value": undefined, + }, + "callAsyncSingleAsyncCalled": 42, + "callAsyncSinglePromise": Object { + "type": "async", + "value": undefined, + }, + "callAsyncSinglePromiseCalled": 42, + "promiseBrokenPromise": Object { + "error": "Tap function (tapPromise) did not return promise (returned this is not a promise)", + "type": "promise", + }, + "promiseMixed": Object { + "type": "promise", + "value": undefined, + }, + "promiseMixedCalled1": 124, + "promiseMixedCalled2": 83, + "promiseMixedCalled3": 42, + "promiseMultipleAsync": Object { + "type": "promise", + "value": undefined, + }, + "promiseMultipleAsyncCalled1": 83, + "promiseMultipleAsyncCalled2": 42, + "promiseMultiplePromise": Object { + "type": "promise", + "value": undefined, + }, + "promiseMultiplePromiseCalled1": 83, + "promiseMultiplePromiseCalled2": 42, + "promiseSingleAsync": Object { + "type": "promise", + "value": undefined, + }, + "promiseSingleAsyncCalled": 42, + "promiseSinglePromise": Object { + "type": "promise", + "value": undefined, + }, + "promiseSinglePromiseCalled": 42, + }, + "sync": Object { + "callAsyncInterceptedSync": Object { + "type": "async", + "value": undefined, + }, + "callAsyncInterceptedSyncCalled1": 83, + "callAsyncInterceptedSyncCalled2": 42, + "callAsyncInterceptedSyncCalledCall": 1, + "callAsyncInterceptedSyncCalledLoop": 83, + "callAsyncInterceptedSyncCalledTap": 125, + "callAsyncMultipleSync": Object { + "type": "async", + "value": undefined, + }, + "callAsyncMultipleSyncCalled1": 83, + "callAsyncMultipleSyncCalled2": 42, + "callAsyncNone": Object { + "type": "async", + "value": undefined, + }, + "callAsyncNoneWithArg": Object { + "type": "async", + "value": undefined, + }, + "callAsyncSingleSync": Object { + "type": "async", + "value": undefined, + }, + "callAsyncSingleSyncCalled": 42, + "promiseInterceptedSync": Object { + "type": "promise", + "value": undefined, + }, + "promiseInterceptedSyncCalled1": 83, + "promiseInterceptedSyncCalled2": 42, + "promiseInterceptedSyncCalledCall": 1, + "promiseInterceptedSyncCalledLoop": 83, + "promiseInterceptedSyncCalledTap": 125, + "promiseMultipleSync": Object { + "type": "promise", + "value": undefined, + }, + "promiseMultipleSyncCalled1": 83, + "promiseMultipleSyncCalled2": 42, + "promiseNone": Object { + "type": "promise", + "value": undefined, + }, + "promiseNoneWithArg": Object { + "type": "promise", + "value": undefined, + }, + "promiseSingleSync": Object { + "type": "promise", + "value": undefined, + }, + "promiseSingleSyncCalled": 42, + }, +} +`; diff --git a/test/__snapshots__/AsyncSeriesWaterfallHook.test.js.snap b/test/__snapshots__/AsyncSeriesWaterfallHook.test.js.snap new file mode 100644 index 0000000..7b84832 --- /dev/null +++ b/test/__snapshots__/AsyncSeriesWaterfallHook.test.js.snap @@ -0,0 +1,740 @@ +// Jest Snapshot v1, https://jestjs.io/docs/snapshot-testing + +exports[`AsyncSeriesWaterfallHook should have to correct behavior 1`] = ` +Object { + "async": Object { + "callAsyncMultipleAsyncEarlyError": Object { + "error": "Waterfall hooks must have at least one argument", + }, + "callAsyncMultipleAsyncError": Object { + "error": "Waterfall hooks must have at least one argument", + }, + "callAsyncMultipleAsyncLateError": Object { + "error": "Waterfall hooks must have at least one argument", + }, + "callAsyncMultipleAsyncLateErrorEarlyResult1": Object { + "error": "Waterfall hooks must have at least one argument", + }, + "callAsyncMultipleAsyncLateErrorEarlyResult2": Object { + "error": "Waterfall hooks must have at least one argument", + }, + "callAsyncMultipleAsyncWithArg": Object { + "type": "async", + "value": 45, + }, + "callAsyncMultipleAsyncWithArgCalled1": 42, + "callAsyncMultipleAsyncWithArgCalled2": 43, + "callAsyncMultipleAsyncWithArgFirstReturn": Object { + "type": "async", + "value": 43, + }, + "callAsyncMultipleAsyncWithArgFirstReturnCalled1": 42, + "callAsyncMultipleAsyncWithArgFirstReturnCalled2": 43, + "callAsyncMultipleAsyncWithArgLastReturn": Object { + "type": "async", + "value": 44, + }, + "callAsyncMultipleAsyncWithArgLastReturnCalled1": 42, + "callAsyncMultipleAsyncWithArgLastReturnCalled2": 42, + "callAsyncMultipleAsyncWithArgNoReturn": Object { + "type": "async", + "value": 42, + }, + "callAsyncMultipleAsyncWithArgNoReturnCalled1": 42, + "callAsyncMultipleAsyncWithArgNoReturnCalled2": 42, + "callAsyncMultipleMixed1WithArg": Object { + "type": "async", + "value": 48, + }, + "callAsyncMultipleMixed1WithArgCalled1": 42, + "callAsyncMultipleMixed1WithArgCalled2": 43, + "callAsyncMultipleMixed1WithArgCalled3": 45, + "callAsyncMultipleMixed2WithArg": Object { + "type": "async", + "value": 45, + }, + "callAsyncMultipleMixed2WithArgCalled1": 42, + "callAsyncMultipleMixed2WithArgCalled2": 43, + "callAsyncMultipleMixed3WithArg": Object { + "type": "async", + "value": 48, + }, + "callAsyncMultipleMixed3WithArgCalled1": 42, + "callAsyncMultipleMixed3WithArgCalled2": 43, + "callAsyncMultipleMixed3WithArgCalled3": 45, + "callAsyncMultipleMixedError1WithArg": Object { + "error": "Error in sync", + "type": "async", + }, + "callAsyncMultipleMixedError1WithArgCalled1": 42, + "callAsyncMultipleMixedError1WithArgCalled2": 42, + "callAsyncMultipleMixedError1WithArgCalled3": 43, + "callAsyncMultipleMixedError2WithArg": Object { + "error": "Error in promise", + "type": "async", + }, + "callAsyncMultipleMixedError2WithArgCalled1": 42, + "callAsyncMultipleMixedError2WithArgCalled2": 42, + "callAsyncMultipleMixedError3WithArg": Object { + "error": "Error in async", + "type": "async", + }, + "callAsyncMultipleMixedError3WithArgCalled1": 42, + "callAsyncMultipleMixedLateError": Object { + "error": "Waterfall hooks must have at least one argument", + }, + "callAsyncMultiplePromiseEarlyError": Object { + "error": "Waterfall hooks must have at least one argument", + }, + "callAsyncMultiplePromiseError": Object { + "error": "Waterfall hooks must have at least one argument", + }, + "callAsyncMultiplePromiseLateError": Object { + "error": "Waterfall hooks must have at least one argument", + }, + "callAsyncMultiplePromiseWithArg": Object { + "type": "async", + "value": 45, + }, + "callAsyncMultiplePromiseWithArgCalled1": 42, + "callAsyncMultiplePromiseWithArgCalled2": 43, + "callAsyncMultiplePromiseWithArgFirstReturn": Object { + "type": "async", + "value": 43, + }, + "callAsyncMultiplePromiseWithArgFirstReturnCalled1": 42, + "callAsyncMultiplePromiseWithArgFirstReturnCalled2": 43, + "callAsyncMultiplePromiseWithArgLastReturn": Object { + "type": "async", + "value": 44, + }, + "callAsyncMultiplePromiseWithArgLastReturnCalled1": 42, + "callAsyncMultiplePromiseWithArgLastReturnCalled2": 42, + "callAsyncMultiplePromiseWithArgNoReturn": Object { + "type": "async", + "value": 42, + }, + "callAsyncMultiplePromiseWithArgNoReturnCalled1": 42, + "callAsyncMultiplePromiseWithArgNoReturnCalled2": 42, + "callAsyncMultipleSync": Object { + "error": "Waterfall hooks must have at least one argument", + }, + "callAsyncMultipleSyncError": Object { + "error": "Waterfall hooks must have at least one argument", + }, + "callAsyncMultipleSyncLastReturn": Object { + "error": "Waterfall hooks must have at least one argument", + }, + "callAsyncMultipleSyncNoReturn": Object { + "error": "Waterfall hooks must have at least one argument", + }, + "callAsyncMultipleSyncWithArg": Object { + "type": "async", + "value": 45, + }, + "callAsyncMultipleSyncWithArgCalled1": 42, + "callAsyncMultipleSyncWithArgCalled2": 43, + "callAsyncMultipleSyncWithArgFirstReturn": Object { + "type": "async", + "value": 43, + }, + "callAsyncMultipleSyncWithArgFirstReturnCalled1": 42, + "callAsyncMultipleSyncWithArgFirstReturnCalled2": 43, + "callAsyncMultipleSyncWithArgLastReturn": Object { + "type": "async", + "value": 44, + }, + "callAsyncMultipleSyncWithArgLastReturnCalled1": 42, + "callAsyncMultipleSyncWithArgLastReturnCalled2": 42, + "callAsyncMultipleSyncWithArgNoReturn": Object { + "type": "async", + "value": 42, + }, + "callAsyncMultipleSyncWithArgNoReturnCalled1": 42, + "callAsyncMultipleSyncWithArgNoReturnCalled2": 42, + "callAsyncNone": Object { + "error": "Waterfall hooks must have at least one argument", + }, + "callAsyncNoneWithArg": Object { + "type": "async", + "value": 42, + }, + "callAsyncSingleAsyncWithArg": Object { + "type": "async", + "value": 42, + }, + "callAsyncSingleAsyncWithArgCalled1": 42, + "callAsyncSinglePromiseWithArg": Object { + "type": "async", + "value": 43, + }, + "callAsyncSinglePromiseWithArgCalled1": 42, + "callAsyncSinglePromiseWithEmptyReject": Object { + "error": "Tap function (tapPromise) rejects \\"\\" value", + "type": "async", + }, + "callAsyncSinglePromiseWithEmptyStringArg": Object { + "type": "async", + "value": "", + }, + "callAsyncSinglePromiseWithEmptyStringArgCalled1": 42, + "callAsyncSinglePromiseWithFalseReject": Object { + "error": "Tap function (tapPromise) rejects \\"false\\" value", + "type": "async", + }, + "callAsyncSinglePromiseWithNullArg": Object { + "type": "async", + "value": null, + }, + "callAsyncSinglePromiseWithNullArgCalled1": 42, + "callAsyncSinglePromiseWithNullReject": Object { + "error": "Tap function (tapPromise) rejects \\"null\\" value", + "type": "async", + }, + "callAsyncSinglePromiseWithUndefined": Object { + "type": "async", + "value": 42, + }, + "callAsyncSinglePromiseWithUndefinedCalled1": 42, + "callAsyncSinglePromiseWithUndefinedReject": Object { + "error": "Tap function (tapPromise) rejects \\"undefined\\" value", + "type": "async", + }, + "callAsyncSinglePromiseWithZeroArg": Object { + "type": "async", + "value": 0, + }, + "callAsyncSinglePromiseWithZeroArgCalled1": 42, + "callAsyncSinglePromiseWithZeroReject": Object { + "error": "Tap function (tapPromise) rejects \\"0\\" value", + "type": "async", + }, + "callAsyncSingleSync": Object { + "error": "Waterfall hooks must have at least one argument", + }, + "callAsyncSingleSyncWithArg": Object { + "type": "async", + "value": 43, + }, + "callAsyncSingleSyncWithArgCalled1": 42, + "callAsyncSingleSyncWithArgNoReturn": Object { + "type": "async", + "value": 42, + }, + "callAsyncSingleSyncWithArgNoReturnCalled1": 42, + "promiseMultipleAsyncEarlyError": Object { + "error": "Waterfall hooks must have at least one argument", + }, + "promiseMultipleAsyncError": Object { + "error": "Waterfall hooks must have at least one argument", + }, + "promiseMultipleAsyncLateError": Object { + "error": "Waterfall hooks must have at least one argument", + }, + "promiseMultipleAsyncLateErrorEarlyResult1": Object { + "error": "Waterfall hooks must have at least one argument", + }, + "promiseMultipleAsyncLateErrorEarlyResult2": Object { + "error": "Waterfall hooks must have at least one argument", + }, + "promiseMultipleAsyncWithArg": Object { + "type": "promise", + "value": 45, + }, + "promiseMultipleAsyncWithArgCalled1": 42, + "promiseMultipleAsyncWithArgCalled2": 43, + "promiseMultipleAsyncWithArgFirstReturn": Object { + "type": "promise", + "value": 43, + }, + "promiseMultipleAsyncWithArgFirstReturnCalled1": 42, + "promiseMultipleAsyncWithArgFirstReturnCalled2": 43, + "promiseMultipleAsyncWithArgLastReturn": Object { + "type": "promise", + "value": 44, + }, + "promiseMultipleAsyncWithArgLastReturnCalled1": 42, + "promiseMultipleAsyncWithArgLastReturnCalled2": 42, + "promiseMultipleAsyncWithArgNoReturn": Object { + "type": "promise", + "value": 42, + }, + "promiseMultipleAsyncWithArgNoReturnCalled1": 42, + "promiseMultipleAsyncWithArgNoReturnCalled2": 42, + "promiseMultipleMixed1WithArg": Object { + "type": "promise", + "value": 48, + }, + "promiseMultipleMixed1WithArgCalled1": 42, + "promiseMultipleMixed1WithArgCalled2": 43, + "promiseMultipleMixed1WithArgCalled3": 45, + "promiseMultipleMixed2WithArg": Object { + "type": "promise", + "value": 45, + }, + "promiseMultipleMixed2WithArgCalled1": 42, + "promiseMultipleMixed2WithArgCalled2": 43, + "promiseMultipleMixed3WithArg": Object { + "type": "promise", + "value": 48, + }, + "promiseMultipleMixed3WithArgCalled1": 42, + "promiseMultipleMixed3WithArgCalled2": 43, + "promiseMultipleMixed3WithArgCalled3": 45, + "promiseMultipleMixedError1WithArg": Object { + "error": "Error in sync", + "type": "promise", + }, + "promiseMultipleMixedError1WithArgCalled1": 42, + "promiseMultipleMixedError1WithArgCalled2": 42, + "promiseMultipleMixedError1WithArgCalled3": 43, + "promiseMultipleMixedError2WithArg": Object { + "error": "Error in promise", + "type": "promise", + }, + "promiseMultipleMixedError2WithArgCalled1": 42, + "promiseMultipleMixedError2WithArgCalled2": 42, + "promiseMultipleMixedError3WithArg": Object { + "error": "Error in async", + "type": "promise", + }, + "promiseMultipleMixedError3WithArgCalled1": 42, + "promiseMultipleMixedLateError": Object { + "error": "Waterfall hooks must have at least one argument", + }, + "promiseMultiplePromiseEarlyError": Object { + "error": "Waterfall hooks must have at least one argument", + }, + "promiseMultiplePromiseError": Object { + "error": "Waterfall hooks must have at least one argument", + }, + "promiseMultiplePromiseLateError": Object { + "error": "Waterfall hooks must have at least one argument", + }, + "promiseMultiplePromiseWithArg": Object { + "type": "promise", + "value": 45, + }, + "promiseMultiplePromiseWithArgCalled1": 42, + "promiseMultiplePromiseWithArgCalled2": 43, + "promiseMultiplePromiseWithArgFirstReturn": Object { + "type": "promise", + "value": 43, + }, + "promiseMultiplePromiseWithArgFirstReturnCalled1": 42, + "promiseMultiplePromiseWithArgFirstReturnCalled2": 43, + "promiseMultiplePromiseWithArgLastReturn": Object { + "type": "promise", + "value": 44, + }, + "promiseMultiplePromiseWithArgLastReturnCalled1": 42, + "promiseMultiplePromiseWithArgLastReturnCalled2": 42, + "promiseMultiplePromiseWithArgNoReturn": Object { + "type": "promise", + "value": 42, + }, + "promiseMultiplePromiseWithArgNoReturnCalled1": 42, + "promiseMultiplePromiseWithArgNoReturnCalled2": 42, + "promiseMultipleSync": Object { + "error": "Waterfall hooks must have at least one argument", + }, + "promiseMultipleSyncError": Object { + "error": "Waterfall hooks must have at least one argument", + }, + "promiseMultipleSyncLastReturn": Object { + "error": "Waterfall hooks must have at least one argument", + }, + "promiseMultipleSyncNoReturn": Object { + "error": "Waterfall hooks must have at least one argument", + }, + "promiseMultipleSyncWithArg": Object { + "type": "promise", + "value": 45, + }, + "promiseMultipleSyncWithArgCalled1": 42, + "promiseMultipleSyncWithArgCalled2": 43, + "promiseMultipleSyncWithArgFirstReturn": Object { + "type": "promise", + "value": 43, + }, + "promiseMultipleSyncWithArgFirstReturnCalled1": 42, + "promiseMultipleSyncWithArgFirstReturnCalled2": 43, + "promiseMultipleSyncWithArgLastReturn": Object { + "type": "promise", + "value": 44, + }, + "promiseMultipleSyncWithArgLastReturnCalled1": 42, + "promiseMultipleSyncWithArgLastReturnCalled2": 42, + "promiseMultipleSyncWithArgNoReturn": Object { + "type": "promise", + "value": 42, + }, + "promiseMultipleSyncWithArgNoReturnCalled1": 42, + "promiseMultipleSyncWithArgNoReturnCalled2": 42, + "promiseNone": Object { + "error": "Waterfall hooks must have at least one argument", + }, + "promiseNoneWithArg": Object { + "type": "promise", + "value": 42, + }, + "promiseSingleAsyncWithArg": Object { + "type": "promise", + "value": 42, + }, + "promiseSingleAsyncWithArgCalled1": 42, + "promiseSinglePromiseWithArg": Object { + "type": "promise", + "value": 43, + }, + "promiseSinglePromiseWithArgCalled1": 42, + "promiseSinglePromiseWithEmptyReject": Object { + "error": "Tap function (tapPromise) rejects \\"\\" value", + "type": "promise", + }, + "promiseSinglePromiseWithEmptyStringArg": Object { + "type": "promise", + "value": "", + }, + "promiseSinglePromiseWithEmptyStringArgCalled1": 42, + "promiseSinglePromiseWithFalseReject": Object { + "error": "Tap function (tapPromise) rejects \\"false\\" value", + "type": "promise", + }, + "promiseSinglePromiseWithNullArg": Object { + "type": "promise", + "value": null, + }, + "promiseSinglePromiseWithNullArgCalled1": 42, + "promiseSinglePromiseWithNullReject": Object { + "error": "Tap function (tapPromise) rejects \\"null\\" value", + "type": "promise", + }, + "promiseSinglePromiseWithUndefined": Object { + "type": "promise", + "value": 42, + }, + "promiseSinglePromiseWithUndefinedCalled1": 42, + "promiseSinglePromiseWithUndefinedReject": Object { + "error": "Tap function (tapPromise) rejects \\"undefined\\" value", + "type": "promise", + }, + "promiseSinglePromiseWithZeroArg": Object { + "type": "promise", + "value": 0, + }, + "promiseSinglePromiseWithZeroArgCalled1": 42, + "promiseSinglePromiseWithZeroReject": Object { + "error": "Tap function (tapPromise) rejects \\"0\\" value", + "type": "promise", + }, + "promiseSingleSync": Object { + "error": "Waterfall hooks must have at least one argument", + }, + "promiseSingleSyncWithArg": Object { + "type": "promise", + "value": 43, + }, + "promiseSingleSyncWithArgCalled1": 42, + "promiseSingleSyncWithArgNoReturn": Object { + "type": "promise", + "value": 42, + }, + "promiseSingleSyncWithArgNoReturnCalled1": 42, + }, + "intercept": Object { + "callAsyncContextIntercepted": Object { + "type": "async", + "value": 48, + }, + "callAsyncContextInterceptedCall1": Array [ + Object { + "number": 42, + }, + 1, + 2, + 3, + ], + "callAsyncContextInterceptedCall2": Array [ + 1, + 2, + 3, + ], + "callAsyncContextInterceptedTap1": Object { + "number": 42, + }, + "callAsyncIntercepted": Object { + "type": "async", + "value": 9, + }, + "callAsyncInterceptedCall1": Array [ + 1, + 2, + 3, + ], + "callAsyncInterceptedCall2": Array [ + 1, + 2, + 3, + ], + "callAsyncInterceptedResult1": 9, + "callAsyncInterceptedResult2": 9, + "callAsyncInterceptedTap1": Object { + "fn": 2, + "name": "promise", + "type": "promise", + }, + "callAsyncInterceptedTap2": Object { + "fn": 3, + "name": "sync", + "type": "sync", + }, + "callAsyncUnusedContextIntercepted": Object { + "type": "async", + "value": 6, + }, + "callAsyncUnusedContextInterceptedCall1": Array [ + undefined, + 1, + 2, + 3, + ], + "callAsyncUnusedContextInterceptedCall2": Array [ + 1, + 2, + 3, + ], + "callAsyncUnusedContextInterceptedTap1": undefined, + "promiseContextIntercepted": Object { + "type": "promise", + "value": 48, + }, + "promiseContextInterceptedCall1": Array [ + Object { + "number": 42, + }, + 1, + 2, + 3, + ], + "promiseContextInterceptedCall2": Array [ + 1, + 2, + 3, + ], + "promiseContextInterceptedTap1": Object { + "number": 42, + }, + "promiseIntercepted": Object { + "type": "promise", + "value": 9, + }, + "promiseInterceptedCall1": Array [ + 1, + 2, + 3, + ], + "promiseInterceptedCall2": Array [ + 1, + 2, + 3, + ], + "promiseInterceptedResult1": 9, + "promiseInterceptedResult2": 9, + "promiseInterceptedTap1": Object { + "fn": 2, + "name": "promise", + "type": "promise", + }, + "promiseInterceptedTap2": Object { + "fn": 3, + "name": "sync", + "type": "sync", + }, + "promiseUnusedContextIntercepted": Object { + "type": "promise", + "value": 6, + }, + "promiseUnusedContextInterceptedCall1": Array [ + undefined, + 1, + 2, + 3, + ], + "promiseUnusedContextInterceptedCall2": Array [ + 1, + 2, + 3, + ], + "promiseUnusedContextInterceptedTap1": undefined, + }, + "sync": Object { + "callAsyncIntercepted": Object { + "type": "async", + "value": 9, + }, + "callAsyncInterceptedCall1": Array [ + 1, + 2, + 3, + ], + "callAsyncInterceptedCall2": Array [ + 1, + 2, + 3, + ], + "callAsyncInterceptedTap1": Object { + "fn": 2, + "name": "sync2", + "type": "sync", + }, + "callAsyncInterceptedTap2": Object { + "fn": 3, + "name": "sync1", + "type": "sync", + }, + "callAsyncMultipleSync": Object { + "error": "Waterfall hooks must have at least one argument", + }, + "callAsyncMultipleSyncError": Object { + "error": "Waterfall hooks must have at least one argument", + }, + "callAsyncMultipleSyncWithArg": Object { + "type": "async", + "value": 127, + }, + "callAsyncMultipleSyncWithArgCalled1": 42, + "callAsyncMultipleSyncWithArgCalled2": 84, + "callAsyncMultipleSyncWithArgFirstReturn": Object { + "type": "async", + "value": 84, + }, + "callAsyncMultipleSyncWithArgFirstReturnCalled1": 42, + "callAsyncMultipleSyncWithArgFirstReturnCalled2": 84, + "callAsyncMultipleSyncWithArgLastReturn": Object { + "type": "async", + "value": 85, + }, + "callAsyncMultipleSyncWithArgLastReturnCalled1": 42, + "callAsyncMultipleSyncWithArgLastReturnCalled2": 42, + "callAsyncMultipleSyncWithArgNoReturn": Object { + "type": "async", + "value": 42, + }, + "callAsyncMultipleSyncWithArgNoReturnCalled1": 42, + "callAsyncMultipleSyncWithArgNoReturnCalled2": 42, + "callAsyncMultipleSyncWithArgs": Object { + "type": "async", + "value": 217, + }, + "callAsyncMultipleSyncWithArgsCalled1": Array [ + 42, + 43, + 44, + ], + "callAsyncMultipleSyncWithArgsCalled2": Array [ + 129, + 43, + 44, + ], + "callAsyncNone": Object { + "error": "Waterfall hooks must have at least one argument", + }, + "callAsyncNoneWithArg": Object { + "type": "async", + "value": 42, + }, + "callAsyncSingleSync": Object { + "error": "Waterfall hooks must have at least one argument", + }, + "callAsyncSingleSyncWithArg": Object { + "type": "async", + "value": 42, + }, + "callAsyncSingleSyncWithArgCalled": 42, + "promiseIntercepted": Object { + "type": "promise", + "value": 9, + }, + "promiseInterceptedCall1": Array [ + 1, + 2, + 3, + ], + "promiseInterceptedCall2": Array [ + 1, + 2, + 3, + ], + "promiseInterceptedTap1": Object { + "fn": 2, + "name": "sync2", + "type": "sync", + }, + "promiseInterceptedTap2": Object { + "fn": 3, + "name": "sync1", + "type": "sync", + }, + "promiseMultipleSync": Object { + "error": "Waterfall hooks must have at least one argument", + }, + "promiseMultipleSyncError": Object { + "error": "Waterfall hooks must have at least one argument", + }, + "promiseMultipleSyncWithArg": Object { + "type": "promise", + "value": 127, + }, + "promiseMultipleSyncWithArgCalled1": 42, + "promiseMultipleSyncWithArgCalled2": 84, + "promiseMultipleSyncWithArgFirstReturn": Object { + "type": "promise", + "value": 84, + }, + "promiseMultipleSyncWithArgFirstReturnCalled1": 42, + "promiseMultipleSyncWithArgFirstReturnCalled2": 84, + "promiseMultipleSyncWithArgLastReturn": Object { + "type": "promise", + "value": 85, + }, + "promiseMultipleSyncWithArgLastReturnCalled1": 42, + "promiseMultipleSyncWithArgLastReturnCalled2": 42, + "promiseMultipleSyncWithArgNoReturn": Object { + "type": "promise", + "value": 42, + }, + "promiseMultipleSyncWithArgNoReturnCalled1": 42, + "promiseMultipleSyncWithArgNoReturnCalled2": 42, + "promiseMultipleSyncWithArgs": Object { + "type": "promise", + "value": 217, + }, + "promiseMultipleSyncWithArgsCalled1": Array [ + 42, + 43, + 44, + ], + "promiseMultipleSyncWithArgsCalled2": Array [ + 129, + 43, + 44, + ], + "promiseNone": Object { + "error": "Waterfall hooks must have at least one argument", + }, + "promiseNoneWithArg": Object { + "type": "promise", + "value": 42, + }, + "promiseSingleSync": Object { + "error": "Waterfall hooks must have at least one argument", + }, + "promiseSingleSyncWithArg": Object { + "type": "promise", + "value": 42, + }, + "promiseSingleSyncWithArgCalled": 42, + }, +} +`; diff --git a/test/__snapshots__/SyncBailHook.test.js.snap b/test/__snapshots__/SyncBailHook.test.js.snap new file mode 100644 index 0000000..e614d36 --- /dev/null +++ b/test/__snapshots__/SyncBailHook.test.js.snap @@ -0,0 +1,258 @@ +// Jest Snapshot v1, https://jestjs.io/docs/snapshot-testing + +exports[`SyncBailHook should have to correct behavior 1`] = ` +Object { + "async": Object {}, + "intercept": Object {}, + "sync": Object { + "callAsyncIntercepted": Object { + "type": "async", + "value": 6, + }, + "callAsyncInterceptedCall1": Array [ + 1, + 2, + 3, + ], + "callAsyncInterceptedCall2": Array [ + 1, + 2, + 3, + ], + "callAsyncInterceptedTap1": Object { + "fn": 3, + "name": "sync1", + "type": "sync", + }, + "callAsyncInterceptedTap2": Object { + "fn": 3, + "name": "sync1", + "type": "sync", + }, + "callAsyncMultipleSync": Object { + "type": "async", + "value": 42, + }, + "callAsyncMultipleSyncCalled1": true, + "callAsyncMultipleSyncError": Object { + "error": "Error in sync2", + "type": "async", + }, + "callAsyncMultipleSyncErrorCalled1": true, + "callAsyncMultipleSyncErrorCalled2": true, + "callAsyncMultipleSyncWithArg": Object { + "type": "async", + "value": 84, + }, + "callAsyncMultipleSyncWithArgCalled1": 42, + "callAsyncMultipleSyncWithArgFirstReturn": Object { + "type": "async", + "value": 84, + }, + "callAsyncMultipleSyncWithArgFirstReturnCalled1": 42, + "callAsyncMultipleSyncWithArgLastReturn": Object { + "type": "async", + "value": 85, + }, + "callAsyncMultipleSyncWithArgLastReturnCalled1": 42, + "callAsyncMultipleSyncWithArgLastReturnCalled2": 42, + "callAsyncMultipleSyncWithArgNoReturn": Object { + "type": "async", + "value": undefined, + }, + "callAsyncMultipleSyncWithArgNoReturnCalled1": 42, + "callAsyncMultipleSyncWithArgNoReturnCalled2": 42, + "callAsyncMultipleSyncWithArgs": Object { + "type": "async", + "value": 129, + }, + "callAsyncMultipleSyncWithArgsCalled1": Array [ + 42, + 43, + 44, + ], + "callAsyncNone": Object { + "type": "async", + "value": undefined, + }, + "callAsyncNoneWithArg": Object { + "type": "async", + "value": undefined, + }, + "callAsyncSingleSync": Object { + "type": "async", + "value": 42, + }, + "callAsyncSingleSyncCalled": true, + "callAsyncSingleSyncWithArg": Object { + "type": "async", + "value": 42, + }, + "callAsyncSingleSyncWithArgCalled": 42, + "callIntercepted": Object { + "type": "return", + "value": 6, + }, + "callInterceptedCall1": Array [ + 1, + 2, + 3, + ], + "callInterceptedCall2": Array [ + 1, + 2, + 3, + ], + "callInterceptedTap1": Object { + "fn": 3, + "name": "sync1", + "type": "sync", + }, + "callInterceptedTap2": Object { + "fn": 3, + "name": "sync1", + "type": "sync", + }, + "callMultipleSync": Object { + "type": "return", + "value": 42, + }, + "callMultipleSyncCalled1": true, + "callMultipleSyncError": Object { + "error": "Error in sync2", + }, + "callMultipleSyncErrorCalled1": true, + "callMultipleSyncErrorCalled2": true, + "callMultipleSyncWithArg": Object { + "type": "return", + "value": 84, + }, + "callMultipleSyncWithArgCalled1": 42, + "callMultipleSyncWithArgFirstReturn": Object { + "type": "return", + "value": 84, + }, + "callMultipleSyncWithArgFirstReturnCalled1": 42, + "callMultipleSyncWithArgLastReturn": Object { + "type": "return", + "value": 85, + }, + "callMultipleSyncWithArgLastReturnCalled1": 42, + "callMultipleSyncWithArgLastReturnCalled2": 42, + "callMultipleSyncWithArgNoReturn": Object { + "type": "no result", + }, + "callMultipleSyncWithArgNoReturnCalled1": 42, + "callMultipleSyncWithArgNoReturnCalled2": 42, + "callMultipleSyncWithArgs": Object { + "type": "return", + "value": 129, + }, + "callMultipleSyncWithArgsCalled1": Array [ + 42, + 43, + 44, + ], + "callNone": Object { + "type": "no result", + }, + "callNoneWithArg": Object { + "type": "no result", + }, + "callSingleSync": Object { + "type": "return", + "value": 42, + }, + "callSingleSyncCalled": true, + "callSingleSyncWithArg": Object { + "type": "return", + "value": 42, + }, + "callSingleSyncWithArgCalled": 42, + "promiseIntercepted": Object { + "type": "promise", + "value": 6, + }, + "promiseInterceptedCall1": Array [ + 1, + 2, + 3, + ], + "promiseInterceptedCall2": Array [ + 1, + 2, + 3, + ], + "promiseInterceptedTap1": Object { + "fn": 3, + "name": "sync1", + "type": "sync", + }, + "promiseInterceptedTap2": Object { + "fn": 3, + "name": "sync1", + "type": "sync", + }, + "promiseMultipleSync": Object { + "type": "promise", + "value": 42, + }, + "promiseMultipleSyncCalled1": true, + "promiseMultipleSyncError": Object { + "error": "Error in sync2", + "type": "promise", + }, + "promiseMultipleSyncErrorCalled1": true, + "promiseMultipleSyncErrorCalled2": true, + "promiseMultipleSyncWithArg": Object { + "type": "promise", + "value": 84, + }, + "promiseMultipleSyncWithArgCalled1": 42, + "promiseMultipleSyncWithArgFirstReturn": Object { + "type": "promise", + "value": 84, + }, + "promiseMultipleSyncWithArgFirstReturnCalled1": 42, + "promiseMultipleSyncWithArgLastReturn": Object { + "type": "promise", + "value": 85, + }, + "promiseMultipleSyncWithArgLastReturnCalled1": 42, + "promiseMultipleSyncWithArgLastReturnCalled2": 42, + "promiseMultipleSyncWithArgNoReturn": Object { + "type": "promise", + "value": undefined, + }, + "promiseMultipleSyncWithArgNoReturnCalled1": 42, + "promiseMultipleSyncWithArgNoReturnCalled2": 42, + "promiseMultipleSyncWithArgs": Object { + "type": "promise", + "value": 129, + }, + "promiseMultipleSyncWithArgsCalled1": Array [ + 42, + 43, + 44, + ], + "promiseNone": Object { + "type": "promise", + "value": undefined, + }, + "promiseNoneWithArg": Object { + "type": "promise", + "value": undefined, + }, + "promiseSingleSync": Object { + "type": "promise", + "value": 42, + }, + "promiseSingleSyncCalled": true, + "promiseSingleSyncWithArg": Object { + "type": "promise", + "value": 42, + }, + "promiseSingleSyncWithArgCalled": 42, + }, +} +`; diff --git a/test/__snapshots__/SyncHooks.test.js.snap b/test/__snapshots__/SyncHooks.test.js.snap index 5a2bac5..c182098 100644 --- a/test/__snapshots__/SyncHooks.test.js.snap +++ b/test/__snapshots__/SyncHooks.test.js.snap @@ -1,262 +1,5 @@ // Jest Snapshot v1, https://jestjs.io/docs/snapshot-testing -exports[`SyncBailHook should have to correct behavior 1`] = ` -Object { - "async": Object {}, - "intercept": Object {}, - "sync": Object { - "callAsyncIntercepted": Object { - "type": "async", - "value": 6, - }, - "callAsyncInterceptedCall1": Array [ - 1, - 2, - 3, - ], - "callAsyncInterceptedCall2": Array [ - 1, - 2, - 3, - ], - "callAsyncInterceptedTap1": Object { - "fn": 3, - "name": "sync1", - "type": "sync", - }, - "callAsyncInterceptedTap2": Object { - "fn": 3, - "name": "sync1", - "type": "sync", - }, - "callAsyncMultipleSync": Object { - "type": "async", - "value": 42, - }, - "callAsyncMultipleSyncCalled1": true, - "callAsyncMultipleSyncError": Object { - "error": "Error in sync2", - "type": "async", - }, - "callAsyncMultipleSyncErrorCalled1": true, - "callAsyncMultipleSyncErrorCalled2": true, - "callAsyncMultipleSyncWithArg": Object { - "type": "async", - "value": 84, - }, - "callAsyncMultipleSyncWithArgCalled1": 42, - "callAsyncMultipleSyncWithArgFirstReturn": Object { - "type": "async", - "value": 84, - }, - "callAsyncMultipleSyncWithArgFirstReturnCalled1": 42, - "callAsyncMultipleSyncWithArgLastReturn": Object { - "type": "async", - "value": 85, - }, - "callAsyncMultipleSyncWithArgLastReturnCalled1": 42, - "callAsyncMultipleSyncWithArgLastReturnCalled2": 42, - "callAsyncMultipleSyncWithArgNoReturn": Object { - "type": "async", - "value": undefined, - }, - "callAsyncMultipleSyncWithArgNoReturnCalled1": 42, - "callAsyncMultipleSyncWithArgNoReturnCalled2": 42, - "callAsyncMultipleSyncWithArgs": Object { - "type": "async", - "value": 129, - }, - "callAsyncMultipleSyncWithArgsCalled1": Array [ - 42, - 43, - 44, - ], - "callAsyncNone": Object { - "type": "async", - "value": undefined, - }, - "callAsyncNoneWithArg": Object { - "type": "async", - "value": undefined, - }, - "callAsyncSingleSync": Object { - "type": "async", - "value": 42, - }, - "callAsyncSingleSyncCalled": true, - "callAsyncSingleSyncWithArg": Object { - "type": "async", - "value": 42, - }, - "callAsyncSingleSyncWithArgCalled": 42, - "callIntercepted": Object { - "type": "return", - "value": 6, - }, - "callInterceptedCall1": Array [ - 1, - 2, - 3, - ], - "callInterceptedCall2": Array [ - 1, - 2, - 3, - ], - "callInterceptedTap1": Object { - "fn": 3, - "name": "sync1", - "type": "sync", - }, - "callInterceptedTap2": Object { - "fn": 3, - "name": "sync1", - "type": "sync", - }, - "callMultipleSync": Object { - "type": "return", - "value": 42, - }, - "callMultipleSyncCalled1": true, - "callMultipleSyncError": Object { - "error": "Error in sync2", - }, - "callMultipleSyncErrorCalled1": true, - "callMultipleSyncErrorCalled2": true, - "callMultipleSyncWithArg": Object { - "type": "return", - "value": 84, - }, - "callMultipleSyncWithArgCalled1": 42, - "callMultipleSyncWithArgFirstReturn": Object { - "type": "return", - "value": 84, - }, - "callMultipleSyncWithArgFirstReturnCalled1": 42, - "callMultipleSyncWithArgLastReturn": Object { - "type": "return", - "value": 85, - }, - "callMultipleSyncWithArgLastReturnCalled1": 42, - "callMultipleSyncWithArgLastReturnCalled2": 42, - "callMultipleSyncWithArgNoReturn": Object { - "type": "no result", - }, - "callMultipleSyncWithArgNoReturnCalled1": 42, - "callMultipleSyncWithArgNoReturnCalled2": 42, - "callMultipleSyncWithArgs": Object { - "type": "return", - "value": 129, - }, - "callMultipleSyncWithArgsCalled1": Array [ - 42, - 43, - 44, - ], - "callNone": Object { - "type": "no result", - }, - "callNoneWithArg": Object { - "type": "no result", - }, - "callSingleSync": Object { - "type": "return", - "value": 42, - }, - "callSingleSyncCalled": true, - "callSingleSyncWithArg": Object { - "type": "return", - "value": 42, - }, - "callSingleSyncWithArgCalled": 42, - "promiseIntercepted": Object { - "type": "promise", - "value": 6, - }, - "promiseInterceptedCall1": Array [ - 1, - 2, - 3, - ], - "promiseInterceptedCall2": Array [ - 1, - 2, - 3, - ], - "promiseInterceptedTap1": Object { - "fn": 3, - "name": "sync1", - "type": "sync", - }, - "promiseInterceptedTap2": Object { - "fn": 3, - "name": "sync1", - "type": "sync", - }, - "promiseMultipleSync": Object { - "type": "promise", - "value": 42, - }, - "promiseMultipleSyncCalled1": true, - "promiseMultipleSyncError": Object { - "error": "Error in sync2", - "type": "promise", - }, - "promiseMultipleSyncErrorCalled1": true, - "promiseMultipleSyncErrorCalled2": true, - "promiseMultipleSyncWithArg": Object { - "type": "promise", - "value": 84, - }, - "promiseMultipleSyncWithArgCalled1": 42, - "promiseMultipleSyncWithArgFirstReturn": Object { - "type": "promise", - "value": 84, - }, - "promiseMultipleSyncWithArgFirstReturnCalled1": 42, - "promiseMultipleSyncWithArgLastReturn": Object { - "type": "promise", - "value": 85, - }, - "promiseMultipleSyncWithArgLastReturnCalled1": 42, - "promiseMultipleSyncWithArgLastReturnCalled2": 42, - "promiseMultipleSyncWithArgNoReturn": Object { - "type": "promise", - "value": undefined, - }, - "promiseMultipleSyncWithArgNoReturnCalled1": 42, - "promiseMultipleSyncWithArgNoReturnCalled2": 42, - "promiseMultipleSyncWithArgs": Object { - "type": "promise", - "value": 129, - }, - "promiseMultipleSyncWithArgsCalled1": Array [ - 42, - 43, - 44, - ], - "promiseNone": Object { - "type": "promise", - "value": undefined, - }, - "promiseNoneWithArg": Object { - "type": "promise", - "value": undefined, - }, - "promiseSingleSync": Object { - "type": "promise", - "value": 42, - }, - "promiseSingleSyncCalled": true, - "promiseSingleSyncWithArg": Object { - "type": "promise", - "value": 42, - }, - "promiseSingleSyncWithArgCalled": 42, - }, -} -`; - exports[`SyncHook should have to correct behavior 1`] = ` Object { "async": Object {}, @@ -529,348 +272,3 @@ Object { }, } `; - -exports[`SyncLoopHook should have to correct behavior 1`] = ` -Object { - "async": Object {}, - "sync": Object { - "callAsyncInterceptedSync": Object { - "type": "async", - "value": undefined, - }, - "callAsyncInterceptedSyncCalled1": 83, - "callAsyncInterceptedSyncCalled2": 42, - "callAsyncInterceptedSyncCalledCall": 1, - "callAsyncInterceptedSyncCalledLoop": 83, - "callAsyncInterceptedSyncCalledTap": 125, - "callAsyncMultipleSync": Object { - "type": "async", - "value": undefined, - }, - "callAsyncMultipleSyncCalled1": 83, - "callAsyncMultipleSyncCalled2": 42, - "callAsyncNone": Object { - "type": "async", - "value": undefined, - }, - "callAsyncNoneWithArg": Object { - "type": "async", - "value": undefined, - }, - "callAsyncSingleSync": Object { - "type": "async", - "value": undefined, - }, - "callAsyncSingleSyncCalled": 42, - "callInterceptedSync": Object { - "type": "no result", - }, - "callInterceptedSyncCalled1": 83, - "callInterceptedSyncCalled2": 42, - "callInterceptedSyncCalledCall": 1, - "callInterceptedSyncCalledLoop": 83, - "callInterceptedSyncCalledTap": 125, - "callMultipleSync": Object { - "type": "no result", - }, - "callMultipleSyncCalled1": 83, - "callMultipleSyncCalled2": 42, - "callNone": Object { - "type": "no result", - }, - "callNoneWithArg": Object { - "type": "no result", - }, - "callSingleSync": Object { - "type": "no result", - }, - "callSingleSyncCalled": 42, - "promiseInterceptedSync": Object { - "type": "promise", - "value": undefined, - }, - "promiseInterceptedSyncCalled1": 83, - "promiseInterceptedSyncCalled2": 42, - "promiseInterceptedSyncCalledCall": 1, - "promiseInterceptedSyncCalledLoop": 83, - "promiseInterceptedSyncCalledTap": 125, - "promiseMultipleSync": Object { - "type": "promise", - "value": undefined, - }, - "promiseMultipleSyncCalled1": 83, - "promiseMultipleSyncCalled2": 42, - "promiseNone": Object { - "type": "promise", - "value": undefined, - }, - "promiseNoneWithArg": Object { - "type": "promise", - "value": undefined, - }, - "promiseSingleSync": Object { - "type": "promise", - "value": undefined, - }, - "promiseSingleSyncCalled": 42, - }, -} -`; - -exports[`SyncWaterfallHook should have to correct behavior 1`] = ` -Object { - "async": Object {}, - "intercept": Object {}, - "sync": Object { - "callAsyncIntercepted": Object { - "type": "async", - "value": 9, - }, - "callAsyncInterceptedCall1": Array [ - 1, - 2, - 3, - ], - "callAsyncInterceptedCall2": Array [ - 1, - 2, - 3, - ], - "callAsyncInterceptedTap1": Object { - "fn": 2, - "name": "sync2", - "type": "sync", - }, - "callAsyncInterceptedTap2": Object { - "fn": 3, - "name": "sync1", - "type": "sync", - }, - "callAsyncMultipleSync": Object { - "error": "Waterfall hooks must have at least one argument", - }, - "callAsyncMultipleSyncError": Object { - "error": "Waterfall hooks must have at least one argument", - }, - "callAsyncMultipleSyncWithArg": Object { - "type": "async", - "value": 127, - }, - "callAsyncMultipleSyncWithArgCalled1": 42, - "callAsyncMultipleSyncWithArgCalled2": 84, - "callAsyncMultipleSyncWithArgFirstReturn": Object { - "type": "async", - "value": 84, - }, - "callAsyncMultipleSyncWithArgFirstReturnCalled1": 42, - "callAsyncMultipleSyncWithArgFirstReturnCalled2": 84, - "callAsyncMultipleSyncWithArgLastReturn": Object { - "type": "async", - "value": 85, - }, - "callAsyncMultipleSyncWithArgLastReturnCalled1": 42, - "callAsyncMultipleSyncWithArgLastReturnCalled2": 42, - "callAsyncMultipleSyncWithArgNoReturn": Object { - "type": "async", - "value": 42, - }, - "callAsyncMultipleSyncWithArgNoReturnCalled1": 42, - "callAsyncMultipleSyncWithArgNoReturnCalled2": 42, - "callAsyncMultipleSyncWithArgs": Object { - "type": "async", - "value": 217, - }, - "callAsyncMultipleSyncWithArgsCalled1": Array [ - 42, - 43, - 44, - ], - "callAsyncMultipleSyncWithArgsCalled2": Array [ - 129, - 43, - 44, - ], - "callAsyncNone": Object { - "error": "Waterfall hooks must have at least one argument", - }, - "callAsyncNoneWithArg": Object { - "type": "async", - "value": 42, - }, - "callAsyncSingleSync": Object { - "error": "Waterfall hooks must have at least one argument", - }, - "callAsyncSingleSyncWithArg": Object { - "type": "async", - "value": 42, - }, - "callAsyncSingleSyncWithArgCalled": 42, - "callIntercepted": Object { - "type": "return", - "value": 9, - }, - "callInterceptedCall1": Array [ - 1, - 2, - 3, - ], - "callInterceptedCall2": Array [ - 1, - 2, - 3, - ], - "callInterceptedTap1": Object { - "fn": 2, - "name": "sync2", - "type": "sync", - }, - "callInterceptedTap2": Object { - "fn": 3, - "name": "sync1", - "type": "sync", - }, - "callMultipleSync": Object { - "error": "Waterfall hooks must have at least one argument", - }, - "callMultipleSyncError": Object { - "error": "Waterfall hooks must have at least one argument", - }, - "callMultipleSyncWithArg": Object { - "type": "return", - "value": 127, - }, - "callMultipleSyncWithArgCalled1": 42, - "callMultipleSyncWithArgCalled2": 84, - "callMultipleSyncWithArgFirstReturn": Object { - "type": "return", - "value": 84, - }, - "callMultipleSyncWithArgFirstReturnCalled1": 42, - "callMultipleSyncWithArgFirstReturnCalled2": 84, - "callMultipleSyncWithArgLastReturn": Object { - "type": "return", - "value": 85, - }, - "callMultipleSyncWithArgLastReturnCalled1": 42, - "callMultipleSyncWithArgLastReturnCalled2": 42, - "callMultipleSyncWithArgNoReturn": Object { - "type": "return", - "value": 42, - }, - "callMultipleSyncWithArgNoReturnCalled1": 42, - "callMultipleSyncWithArgNoReturnCalled2": 42, - "callMultipleSyncWithArgs": Object { - "type": "return", - "value": 217, - }, - "callMultipleSyncWithArgsCalled1": Array [ - 42, - 43, - 44, - ], - "callMultipleSyncWithArgsCalled2": Array [ - 129, - 43, - 44, - ], - "callNone": Object { - "error": "Waterfall hooks must have at least one argument", - }, - "callNoneWithArg": Object { - "type": "return", - "value": 42, - }, - "callSingleSync": Object { - "error": "Waterfall hooks must have at least one argument", - }, - "callSingleSyncWithArg": Object { - "type": "return", - "value": 42, - }, - "callSingleSyncWithArgCalled": 42, - "promiseIntercepted": Object { - "type": "promise", - "value": 9, - }, - "promiseInterceptedCall1": Array [ - 1, - 2, - 3, - ], - "promiseInterceptedCall2": Array [ - 1, - 2, - 3, - ], - "promiseInterceptedTap1": Object { - "fn": 2, - "name": "sync2", - "type": "sync", - }, - "promiseInterceptedTap2": Object { - "fn": 3, - "name": "sync1", - "type": "sync", - }, - "promiseMultipleSync": Object { - "error": "Waterfall hooks must have at least one argument", - }, - "promiseMultipleSyncError": Object { - "error": "Waterfall hooks must have at least one argument", - }, - "promiseMultipleSyncWithArg": Object { - "type": "promise", - "value": 127, - }, - "promiseMultipleSyncWithArgCalled1": 42, - "promiseMultipleSyncWithArgCalled2": 84, - "promiseMultipleSyncWithArgFirstReturn": Object { - "type": "promise", - "value": 84, - }, - "promiseMultipleSyncWithArgFirstReturnCalled1": 42, - "promiseMultipleSyncWithArgFirstReturnCalled2": 84, - "promiseMultipleSyncWithArgLastReturn": Object { - "type": "promise", - "value": 85, - }, - "promiseMultipleSyncWithArgLastReturnCalled1": 42, - "promiseMultipleSyncWithArgLastReturnCalled2": 42, - "promiseMultipleSyncWithArgNoReturn": Object { - "type": "promise", - "value": 42, - }, - "promiseMultipleSyncWithArgNoReturnCalled1": 42, - "promiseMultipleSyncWithArgNoReturnCalled2": 42, - "promiseMultipleSyncWithArgs": Object { - "type": "promise", - "value": 217, - }, - "promiseMultipleSyncWithArgsCalled1": Array [ - 42, - 43, - 44, - ], - "promiseMultipleSyncWithArgsCalled2": Array [ - 129, - 43, - 44, - ], - "promiseNone": Object { - "error": "Waterfall hooks must have at least one argument", - }, - "promiseNoneWithArg": Object { - "type": "promise", - "value": 42, - }, - "promiseSingleSync": Object { - "error": "Waterfall hooks must have at least one argument", - }, - "promiseSingleSyncWithArg": Object { - "type": "promise", - "value": 42, - }, - "promiseSingleSyncWithArgCalled": 42, - }, -} -`; diff --git a/test/__snapshots__/SyncLoopHook.test.js.snap b/test/__snapshots__/SyncLoopHook.test.js.snap new file mode 100644 index 0000000..7f8d61b --- /dev/null +++ b/test/__snapshots__/SyncLoopHook.test.js.snap @@ -0,0 +1,88 @@ +// Jest Snapshot v1, https://jestjs.io/docs/snapshot-testing + +exports[`SyncLoopHook should have to correct behavior 1`] = ` +Object { + "async": Object {}, + "sync": Object { + "callAsyncInterceptedSync": Object { + "type": "async", + "value": undefined, + }, + "callAsyncInterceptedSyncCalled1": 83, + "callAsyncInterceptedSyncCalled2": 42, + "callAsyncInterceptedSyncCalledCall": 1, + "callAsyncInterceptedSyncCalledLoop": 83, + "callAsyncInterceptedSyncCalledTap": 125, + "callAsyncMultipleSync": Object { + "type": "async", + "value": undefined, + }, + "callAsyncMultipleSyncCalled1": 83, + "callAsyncMultipleSyncCalled2": 42, + "callAsyncNone": Object { + "type": "async", + "value": undefined, + }, + "callAsyncNoneWithArg": Object { + "type": "async", + "value": undefined, + }, + "callAsyncSingleSync": Object { + "type": "async", + "value": undefined, + }, + "callAsyncSingleSyncCalled": 42, + "callInterceptedSync": Object { + "type": "no result", + }, + "callInterceptedSyncCalled1": 83, + "callInterceptedSyncCalled2": 42, + "callInterceptedSyncCalledCall": 1, + "callInterceptedSyncCalledLoop": 83, + "callInterceptedSyncCalledTap": 125, + "callMultipleSync": Object { + "type": "no result", + }, + "callMultipleSyncCalled1": 83, + "callMultipleSyncCalled2": 42, + "callNone": Object { + "type": "no result", + }, + "callNoneWithArg": Object { + "type": "no result", + }, + "callSingleSync": Object { + "type": "no result", + }, + "callSingleSyncCalled": 42, + "promiseInterceptedSync": Object { + "type": "promise", + "value": undefined, + }, + "promiseInterceptedSyncCalled1": 83, + "promiseInterceptedSyncCalled2": 42, + "promiseInterceptedSyncCalledCall": 1, + "promiseInterceptedSyncCalledLoop": 83, + "promiseInterceptedSyncCalledTap": 125, + "promiseMultipleSync": Object { + "type": "promise", + "value": undefined, + }, + "promiseMultipleSyncCalled1": 83, + "promiseMultipleSyncCalled2": 42, + "promiseNone": Object { + "type": "promise", + "value": undefined, + }, + "promiseNoneWithArg": Object { + "type": "promise", + "value": undefined, + }, + "promiseSingleSync": Object { + "type": "promise", + "value": undefined, + }, + "promiseSingleSyncCalled": 42, + }, +} +`; diff --git a/test/__snapshots__/SyncWaterfallHook.test.js.snap b/test/__snapshots__/SyncWaterfallHook.test.js.snap new file mode 100644 index 0000000..fa5240a --- /dev/null +++ b/test/__snapshots__/SyncWaterfallHook.test.js.snap @@ -0,0 +1,259 @@ +// Jest Snapshot v1, https://jestjs.io/docs/snapshot-testing + +exports[`SyncWaterfallHook should have to correct behavior 1`] = ` +Object { + "async": Object {}, + "intercept": Object {}, + "sync": Object { + "callAsyncIntercepted": Object { + "type": "async", + "value": 9, + }, + "callAsyncInterceptedCall1": Array [ + 1, + 2, + 3, + ], + "callAsyncInterceptedCall2": Array [ + 1, + 2, + 3, + ], + "callAsyncInterceptedTap1": Object { + "fn": 2, + "name": "sync2", + "type": "sync", + }, + "callAsyncInterceptedTap2": Object { + "fn": 3, + "name": "sync1", + "type": "sync", + }, + "callAsyncMultipleSync": Object { + "error": "Waterfall hooks must have at least one argument", + }, + "callAsyncMultipleSyncError": Object { + "error": "Waterfall hooks must have at least one argument", + }, + "callAsyncMultipleSyncWithArg": Object { + "type": "async", + "value": 127, + }, + "callAsyncMultipleSyncWithArgCalled1": 42, + "callAsyncMultipleSyncWithArgCalled2": 84, + "callAsyncMultipleSyncWithArgFirstReturn": Object { + "type": "async", + "value": 84, + }, + "callAsyncMultipleSyncWithArgFirstReturnCalled1": 42, + "callAsyncMultipleSyncWithArgFirstReturnCalled2": 84, + "callAsyncMultipleSyncWithArgLastReturn": Object { + "type": "async", + "value": 85, + }, + "callAsyncMultipleSyncWithArgLastReturnCalled1": 42, + "callAsyncMultipleSyncWithArgLastReturnCalled2": 42, + "callAsyncMultipleSyncWithArgNoReturn": Object { + "type": "async", + "value": 42, + }, + "callAsyncMultipleSyncWithArgNoReturnCalled1": 42, + "callAsyncMultipleSyncWithArgNoReturnCalled2": 42, + "callAsyncMultipleSyncWithArgs": Object { + "type": "async", + "value": 217, + }, + "callAsyncMultipleSyncWithArgsCalled1": Array [ + 42, + 43, + 44, + ], + "callAsyncMultipleSyncWithArgsCalled2": Array [ + 129, + 43, + 44, + ], + "callAsyncNone": Object { + "error": "Waterfall hooks must have at least one argument", + }, + "callAsyncNoneWithArg": Object { + "type": "async", + "value": 42, + }, + "callAsyncSingleSync": Object { + "error": "Waterfall hooks must have at least one argument", + }, + "callAsyncSingleSyncWithArg": Object { + "type": "async", + "value": 42, + }, + "callAsyncSingleSyncWithArgCalled": 42, + "callIntercepted": Object { + "type": "return", + "value": 9, + }, + "callInterceptedCall1": Array [ + 1, + 2, + 3, + ], + "callInterceptedCall2": Array [ + 1, + 2, + 3, + ], + "callInterceptedTap1": Object { + "fn": 2, + "name": "sync2", + "type": "sync", + }, + "callInterceptedTap2": Object { + "fn": 3, + "name": "sync1", + "type": "sync", + }, + "callMultipleSync": Object { + "error": "Waterfall hooks must have at least one argument", + }, + "callMultipleSyncError": Object { + "error": "Waterfall hooks must have at least one argument", + }, + "callMultipleSyncWithArg": Object { + "type": "return", + "value": 127, + }, + "callMultipleSyncWithArgCalled1": 42, + "callMultipleSyncWithArgCalled2": 84, + "callMultipleSyncWithArgFirstReturn": Object { + "type": "return", + "value": 84, + }, + "callMultipleSyncWithArgFirstReturnCalled1": 42, + "callMultipleSyncWithArgFirstReturnCalled2": 84, + "callMultipleSyncWithArgLastReturn": Object { + "type": "return", + "value": 85, + }, + "callMultipleSyncWithArgLastReturnCalled1": 42, + "callMultipleSyncWithArgLastReturnCalled2": 42, + "callMultipleSyncWithArgNoReturn": Object { + "type": "return", + "value": 42, + }, + "callMultipleSyncWithArgNoReturnCalled1": 42, + "callMultipleSyncWithArgNoReturnCalled2": 42, + "callMultipleSyncWithArgs": Object { + "type": "return", + "value": 217, + }, + "callMultipleSyncWithArgsCalled1": Array [ + 42, + 43, + 44, + ], + "callMultipleSyncWithArgsCalled2": Array [ + 129, + 43, + 44, + ], + "callNone": Object { + "error": "Waterfall hooks must have at least one argument", + }, + "callNoneWithArg": Object { + "type": "return", + "value": 42, + }, + "callSingleSync": Object { + "error": "Waterfall hooks must have at least one argument", + }, + "callSingleSyncWithArg": Object { + "type": "return", + "value": 42, + }, + "callSingleSyncWithArgCalled": 42, + "promiseIntercepted": Object { + "type": "promise", + "value": 9, + }, + "promiseInterceptedCall1": Array [ + 1, + 2, + 3, + ], + "promiseInterceptedCall2": Array [ + 1, + 2, + 3, + ], + "promiseInterceptedTap1": Object { + "fn": 2, + "name": "sync2", + "type": "sync", + }, + "promiseInterceptedTap2": Object { + "fn": 3, + "name": "sync1", + "type": "sync", + }, + "promiseMultipleSync": Object { + "error": "Waterfall hooks must have at least one argument", + }, + "promiseMultipleSyncError": Object { + "error": "Waterfall hooks must have at least one argument", + }, + "promiseMultipleSyncWithArg": Object { + "type": "promise", + "value": 127, + }, + "promiseMultipleSyncWithArgCalled1": 42, + "promiseMultipleSyncWithArgCalled2": 84, + "promiseMultipleSyncWithArgFirstReturn": Object { + "type": "promise", + "value": 84, + }, + "promiseMultipleSyncWithArgFirstReturnCalled1": 42, + "promiseMultipleSyncWithArgFirstReturnCalled2": 84, + "promiseMultipleSyncWithArgLastReturn": Object { + "type": "promise", + "value": 85, + }, + "promiseMultipleSyncWithArgLastReturnCalled1": 42, + "promiseMultipleSyncWithArgLastReturnCalled2": 42, + "promiseMultipleSyncWithArgNoReturn": Object { + "type": "promise", + "value": 42, + }, + "promiseMultipleSyncWithArgNoReturnCalled1": 42, + "promiseMultipleSyncWithArgNoReturnCalled2": 42, + "promiseMultipleSyncWithArgs": Object { + "type": "promise", + "value": 217, + }, + "promiseMultipleSyncWithArgsCalled1": Array [ + 42, + 43, + 44, + ], + "promiseMultipleSyncWithArgsCalled2": Array [ + 129, + 43, + 44, + ], + "promiseNone": Object { + "error": "Waterfall hooks must have at least one argument", + }, + "promiseNoneWithArg": Object { + "type": "promise", + "value": 42, + }, + "promiseSingleSync": Object { + "error": "Waterfall hooks must have at least one argument", + }, + "promiseSingleSyncWithArg": Object { + "type": "promise", + "value": 42, + }, + "promiseSingleSyncWithArgCalled": 42, + }, +} +`; diff --git a/tsconfig.json b/tsconfig.json new file mode 100644 index 0000000..e14b866 --- /dev/null +++ b/tsconfig.json @@ -0,0 +1,26 @@ +{ + "compilerOptions": { + "target": "esnext", + "module": "nodenext", + + "resolveJsonModule": true, + "allowSyntheticDefaultImports": true, + + "erasableSyntaxOnly": true, + "verbatimModuleSyntax": true, + "rewriteRelativeImportExtensions": true, + + "types": ["node"], + + "rootDir": "./lib", + "outDir": "./types", + + "allowJs": true, + "checkJs": true, + "strict": true, + + "declaration": true, + "emitDeclarationOnly": true + }, + "include": ["./lib/**/*"] +}