UNPKG

@bredele/reconcile

Version:

Reconcile data from multiple async sources.

129 lines (128 loc) 3.36 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); const _nodetest = /*#__PURE__*/ _interop_require_default(require("node:test")); const _nodeassert = /*#__PURE__*/ _interop_require_default(require("node:assert")); const _index = /*#__PURE__*/ _interop_require_default(require("./index.js")); function _interop_require_default(obj) { return obj && obj.__esModule ? obj : { default: obj }; } (0, _nodetest.default)('basic reconciliation - README example', async ()=>{ const result = await (0, _index.default)([ async ()=>({ name: 'jane', age: null }), async ()=>({ name: 'john', city: 'toronto' }), async ()=>({ city: 'paris', gender: 'female', age: 29 }) ]); _nodeassert.default.deepStrictEqual(result, { name: 'jane', age: 29, city: 'toronto', gender: 'female' }); }); (0, _nodetest.default)('null value filtering', async ()=>{ const result = await (0, _index.default)([ async ()=>({ a: null, b: 1 }), async ()=>({ a: 2, c: null }), async ()=>({ a: 3, b: 4, c: 5 }) ]); _nodeassert.default.deepStrictEqual(result, { a: 2, b: 1, c: 5 }); }); (0, _nodetest.default)('error handling - failed callbacks are ignored', async ()=>{ const result = await (0, _index.default)([ async ()=>({ a: 1 }), async ()=>{ throw new Error('fail'); }, async ()=>({ b: 2 }) ]); _nodeassert.default.deepStrictEqual(result, { a: 1, b: 2 }); }); (0, _nodetest.default)('empty input array', async ()=>{ const result = await (0, _index.default)([]); _nodeassert.default.deepStrictEqual(result, {}); }); (0, _nodetest.default)('all callbacks fail', async ()=>{ const result = await (0, _index.default)([ async ()=>{ throw new Error('fail1'); }, async ()=>{ throw new Error('fail2'); } ]); _nodeassert.default.deepStrictEqual(result, {}); }); (0, _nodetest.default)('first-wins priority', async ()=>{ const result = await (0, _index.default)([ async ()=>({ x: 'first', y: 'first' }), async ()=>({ x: 'second', z: 'second' }), async ()=>({ x: 'third', y: 'third', z: 'third' }) ]); _nodeassert.default.deepStrictEqual(result, { x: 'first', y: 'first', z: 'second' }); }); (0, _nodetest.default)('non-object results are ignored', async ()=>{ const result = await (0, _index.default)([ async ()=>({ a: 1 }), async ()=>'string', async ()=>null, async ()=>({ b: 2 }) ]); _nodeassert.default.deepStrictEqual(result, { a: 1, b: 2 }); }); //# sourceMappingURL=index.test.js.map