Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion js/core/src/flow.ts
Original file line number Diff line number Diff line change
Expand Up @@ -156,10 +156,12 @@ export function run<T>(
let func;
let input;
let registry: Registry | undefined;
let hasInput = false;
if (typeof funcOrInput === 'function') {
func = funcOrInput;
} else {
input = funcOrInput;
hasInput = true;
}
if (typeof fnOrRegistry === 'function') {
func = fnOrRegistry;
Expand Down Expand Up @@ -199,7 +201,7 @@ export function run<T>(
},
async (meta) => {
meta.input = input;
const output = arguments.length === 3 ? await func(input) : await func();
const output = hasInput ? await func(input) : await func();
meta.output = JSON.stringify(output);
return output;
}
Expand Down
18 changes: 18 additions & 0 deletions js/core/tests/flow_test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -337,6 +337,24 @@ describe('flow', () => {
});
});

describe('run', () => {
it('should run the action', async () => {
const act = async () => 'bar';

const result = await run('action', act, registry);

assert.equal(result, 'bar');
});

it('should run the action with input', async () => {
const act = async (input: string) => `${input} bar`;

const result = await run('action', 'foo', act, registry);

assert.equal(result, 'foo bar');
});
});

describe('telemetry', async () => {
beforeEach(() => {
spanExporter.exportedSpans = [];
Expand Down