mirror of
https://github.com/vercel/workflow.git
synced 2026-09-14 19:59:43 +08:00
4ca9a3edbd
build durable, resilient, and observable workflows. Co-authored-by: Nathan Rajlich <n@n8.io> Co-authored-by: Pranay Prakash <pranay.gp@gmail.com> Co-authored-by: Adrian <me@adriandlam.com> Co-authored-by: JJ Kasper <jj@jjsweb.site> Co-authored-by: Vercel Release Bot <88769842+vercel-release-bot@users.noreply.github.com> Co-authored-by: Peter Wielander <mittgfu@gmail.com> Co-authored-by: Hayden Bleasel <hello@haydenbleasel.com> Co-authored-by: Gal Schlezinger <gal@spitfire.co.il> Co-authored-by: Manuel Muñoz Solera <mamuso@mamuso.net> Co-authored-by: Garrett <garrett.tolbert@vercel.com> Co-authored-by: Lars Grammel <lars.grammel@gmail.com> Co-authored-by: Pooya Parsa <pyapar@gmail.com> Co-authored-by: Tom Dale <tom@tomdale.net> Co-authored-by: Vishal Yathish <135551666+visyat@users.noreply.github.com> Co-authored-by: josh <144584931+dancer@users.noreply.github.com>
50 lines
1.1 KiB
TypeScript
50 lines
1.1 KiB
TypeScript
import { setTimeout } from 'node:timers/promises';
|
|
import { describe, expect, expectTypeOf, it } from 'vitest';
|
|
import { compact, Mutex } from './util.js';
|
|
|
|
describe('compact', () => {
|
|
it('removes null values and keeps other values', () => {
|
|
const result = compact({
|
|
a: 1,
|
|
b: null,
|
|
c: 'test',
|
|
d: null,
|
|
e: undefined,
|
|
f: false,
|
|
});
|
|
|
|
expectTypeOf(result).toEqualTypeOf<{
|
|
a: number;
|
|
b: undefined;
|
|
c: string;
|
|
d: undefined;
|
|
e: undefined;
|
|
f: boolean;
|
|
}>();
|
|
|
|
expect(result).toEqual({
|
|
a: 1,
|
|
c: 'test',
|
|
f: false,
|
|
});
|
|
});
|
|
});
|
|
|
|
describe('Mutex', () => {
|
|
it(`can register andThen to sync`, async () => {
|
|
const mutex = new Mutex();
|
|
const results: string[] = [];
|
|
mutex.andThen(async () => {
|
|
results.push('<1>');
|
|
await setTimeout(10);
|
|
results.push('</1>');
|
|
});
|
|
await mutex.andThen(async () => {
|
|
results.push('<2>');
|
|
await setTimeout(10);
|
|
results.push('</2>');
|
|
});
|
|
expect(results).toEqual(['<1>', '</1>', '<2>', '</2>']);
|
|
});
|
|
});
|