Skip to content

Commit

Permalink
tests: integration tests for lazy-state
Browse files Browse the repository at this point in the history
  • Loading branch information
doc-han committed Dec 6, 2024
1 parent ef34204 commit 17d32e2
Show file tree
Hide file tree
Showing 2 changed files with 64 additions and 0 deletions.
13 changes: 13 additions & 0 deletions integration-tests/execute/ava.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
export default {
extensions: {
ts: 'module',
},

environmentVariables: {
TS_NODE_TRANSPILE_ONLY: 'true',
},

nodeArguments: ['--loader=ts-node/esm', '--no-warnings', '--experimental-vm-modules'],

files: ['test/**/*test.ts'],
};
51 changes: 51 additions & 0 deletions integration-tests/execute/test/lazy-state.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
import test from 'ava';
import execute from '../src/execute';

test.serial(
'use lazy-state in template literal & property access',
async (t) => {
const state = {
keyName: 'someKey',
firstName: 'John',
lastName: 'Doe',
};
const job = `
fnIf(\`$\{$.keyName\}\` === 'someKey', state => {
state.literal = true;
return state;
})
fnIf($.firstName + $['lastName'] === 'JohnDoe', state=> {
state.concat = true;
return state;
})`;

const result = await execute(job, state);
t.is(result.literal, true);
t.is(result.concat, true);
}
);

test.serial('state function called with lazy-state', async (t) => {
const state = { data: {} };

const job = `
fn((state) => {
state.callMeMaybe = (value) => {
state.data.greetings = "Hello " + value
return state;
}
return state
});
fn(state => {
state.data.name = "John"
return state;
})
fn($.callMeMaybe($.data.name))`;

const result = await execute(job, state);

t.deepEqual(result, { data: { name: 'John', greetings: 'Hello John' } });
});

0 comments on commit 17d32e2

Please sign in to comment.