Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Runtime: warn when an expression doesn't return state #832

Merged
merged 8 commits into from
Dec 3, 2024
Prev Previous commit
Next Next commit
test: warn when an operation does not return state
doc-han committed Dec 2, 2024

Unverified

This user has not yet uploaded their public signing key.
commit 13993e946bc4a48272a9f8af72a2833dcaebd731
24 changes: 24 additions & 0 deletions packages/runtime/test/execute/expression.test.ts
Original file line number Diff line number Diff line change
@@ -155,6 +155,30 @@ test.serial(
}
);

test.serial('warn when an operation does not return state', async (t) => {
// @ts-ignore violating the operation contract here
const job = [
(s) => s,
() => {},
(s) => {
s.data = { a: 'a' };
return s;
},
] as Operation[];

const state = createState() as TestState;
const context = createContext();

const result = (await execute(context, job, state, {})) as TestState;
t.deepEqual(result, { data: { a: 'a' } });

const debugLog = logger._find('debug', /did not return state/);
t.truthy(debugLog);

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

test.serial('jobs can mutate the original state', async (t) => {
const job = [
(s: TestState) => {