UNPKG

shift-interpreter

Version:

Shift-interpreter is an experimental JavaScript meta-interpreter useful for reverse engineering and analysis. One notable difference from other projects is that shift-interpreter retains state over an entire script but can be fed expressions and statement

30 lines (26 loc) 931 B
import chai from 'chai'; import { waterfallMap } from '../src/waterfall'; describe('waterfall', () => { it('should run a series of promises in order', async function() { const array = ['something', 1, { other: 'this' }]; const arrayIndex: any[] = []; function promiseGenerator(el: any, i: number) { return new Promise((res, rej) => { setTimeout(() => res(el), Math.random() * 200); }); } function promiseGeneratorIndex(el: any, i: number) { return new Promise((res, rej) => { setTimeout(() => { arrayIndex[i] = el; res(); }, Math.random() * 200); }); } const newArray = await waterfallMap(array, promiseGenerator); chai.expect(newArray).to.deep.equal(array); await waterfallMap(array, promiseGeneratorIndex); chai.expect(arrayIndex).to.deep.equal(array); chai.expect(arrayIndex).to.deep.equal(newArray); }); });