Skip to content

Commit

Permalink
runtime: Unit test on state serialisation
Browse files Browse the repository at this point in the history
  • Loading branch information
josephjclark committed Nov 13, 2023
1 parent c448a23 commit 251dc23
Showing 1 changed file with 22 additions and 0 deletions.
22 changes: 22 additions & 0 deletions packages/runtime/test/execute/expression.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,7 @@ test(`notify ${NOTIFY_JOB_COMPLETE}`, async (t) => {
const { state, duration, jobId } = payload;
didCallCallback = true;
t.truthy(state);
t.deepEqual(state, state);
t.assert(!isNaN(duration));
t.is(jobId, 'j');
}
Expand All @@ -108,6 +109,27 @@ test(`notify ${NOTIFY_JOB_COMPLETE}`, async (t) => {
t.true(didCallCallback);
});

test(`notify ${NOTIFY_JOB_COMPLETE} should publish serializable state`, async (t) => {
// Promises will trigger an exception if you try to serialize them
// If we don't return finalState in execute/expression, this test will fail
const resultState = { x: new Promise((r) => r), y: 22 };
const expression = [(s: State) => resultState];
const state = createState();

const notify = (event: string, payload: any) => {
if (event === NOTIFY_JOB_COMPLETE) {
const { state, duration, jobId } = payload;
t.truthy(state);
t.assert(!isNaN(duration));
t.is(jobId, 'j');
}
};

const context = createContext({ notify });

await execute(context, expression, state, 'j');
});

test('jobs can handle a promise', async (t) => {
const job = [async (s: State) => s];
const state = createState();
Expand Down

0 comments on commit 251dc23

Please sign in to comment.