Skip to content

Commit

Permalink
test: allow test for undefined at step level
Browse files Browse the repository at this point in the history
  • Loading branch information
doc-han committed Dec 2, 2024
1 parent afbf771 commit 406926e
Show file tree
Hide file tree
Showing 7 changed files with 12 additions and 25 deletions.
2 changes: 1 addition & 1 deletion packages/cli/test/commands.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -185,7 +185,7 @@ test.serial('run a job with defaults: openfn job.js', async (t) => {
test.serial('run a job which does not return state', async (t) => {
const result = await run('openfn job.js', 'export default [s => {}]');

t.deepEqual(result, {});
t.falsy(result);
});

test.serial('run a workflow', async (t) => {
Expand Down
2 changes: 1 addition & 1 deletion packages/cli/test/execute/execute.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -441,7 +441,7 @@ test.serial('run a job which does not return state', async (t) => {
expressionPath: '/job.js',
};
const result = await handler(options, logger);
t.deepEqual(result, {});
t.falsy(result);

// Check that no error messages have been logged
t.is(logger._history.length, 0);
Expand Down
2 changes: 1 addition & 1 deletion packages/engine-multi/test/integration.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -261,7 +261,7 @@ test.serial('run without error if no state is returned', (t) => {
]);

api.execute(plan, emptyState).on('workflow-complete', ({ state }) => {
t.deepEqual(state, {});
t.falsy(state);

// Ensure there are no error logs
const err = logger._find('error', /./);
Expand Down
6 changes: 3 additions & 3 deletions packages/runtime/src/execute/step.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ import {
NOTIFY_JOB_ERROR,
NOTIFY_JOB_START,
} from '../events';
import stringify from 'fast-safe-stringify';
import { isNullState } from '../util/null-state';

const loadCredentials = async (
job: Job,
Expand Down Expand Up @@ -99,8 +99,8 @@ const prepareFinalState = (
`Cleaning up state. Removing keys: ${removedProps.join(', ')}`
);

const cleanState = stringify(state);
return JSON.parse(cleanState);
if (isNullState(state)) return undefined;
return clone(state);
}
return state;
};
Expand Down
6 changes: 1 addition & 5 deletions packages/runtime/test/execute/plan.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -713,11 +713,7 @@ test('ignore leaf nodes with no result', async (t) => {
const state = { data: { x: 0 } };

const result: any = await executePlan(plan, state, {}, mockLogger);
t.deepEqual(result, {
a: { data: { x: 1 } },
b: {},
c: {},
});
t.deepEqual(result, { data: { x: 1 } });
});

test('isolate state in "parallel" execution', async (t) => {
Expand Down
15 changes: 3 additions & 12 deletions packages/runtime/test/execute/step.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -285,10 +285,10 @@ test.serial('log memory usage', async (t) => {
t.regex(memory?.message, /\d+mb(.+)\d+mb/i);
});

test.serial("warn if a previous step don't return state", async (t) => {
test.serial('warn if a non-leaf step does not return state', async (t) => {
const step = {
id: 'k',
expression: [(s: State) => {}, (s: State) => {}],
expression: [(s: State) => {}],
next: { l: true },
};

Expand All @@ -297,17 +297,8 @@ test.serial("warn if a previous step don't return state", async (t) => {

// @ts-ignore ts complains that the step does not return state
const result = await execute(context, step, state);
const warn = logger._find(
'warn',
/WARNING: No state was passed into operation/
);
const warn = logger._find('warn', /did not return a state object/);
t.truthy(warn);

const warnPrev = logger._find(
'warn',
/WARNING: No state was passed into operation/
);
t.truthy(warnPrev);
});

test.serial('do not warn if a leaf step does not return state', async (t) => {
Expand Down
4 changes: 2 additions & 2 deletions packages/runtime/test/runtime.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -477,15 +477,15 @@ test('prefer initial state to inline state', async (t) => {
t.is(result.data.y, 20);
});

test('Allow a job to return a null-state instead of undefined', async (t) => {
test('Allow a job to return undefined', async (t) => {
const plan: ExecutionPlan = {
workflow: {
steps: [{ expression: 'export default [() => {}]' }],
},
};

const result: any = await run(plan);
t.deepEqual(result, {});
t.falsy(result);
});

test('log errors, write to state, and continue', async (t) => {
Expand Down

0 comments on commit 406926e

Please sign in to comment.