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

Noodle: run actual job code in tests #296

Closed
wants to merge 2 commits into from
Closed

Conversation

josephjclark
Copy link
Collaborator

@josephjclark josephjclark commented Jun 27, 2023

Imagine if our unit tests looked like this:

  it('executes each operation in sequence', async () => {
    const job = `
      fn(() => ({ counter: 1 }))
      fn(() => ({ counter: 2 }))
      fn(() => ({ counter: 3 }))
    `

    const finalState = await execute(job, Adaptor)
    expect(finalState).to.eql({ counter: 3 });
  });

It would be so much easier to write tests and properly compose operations.

I've tested this in template just to get a vibe for how it works. So far so good.

This depends on changes in kit. I expect it to fail on local machines right now.

How it works

I've added a helped function in tools which calls @openfn/compile and @openfn/execute.

Usually the compiler will inject an import statement for the adaptor, and the runtime's linker will load it. But because we want to unit test from source, not the built adaptor, this doesn't really work.

So instead, we inject the adaptor function's exports into the runtime as globals. This is good enough to run adaptor code through the actual runtime pipeline.

I've added support to the runtime to:
a) accept globals injected into the runtime context.
b) use globals.execute, if available, instead of the default execute function

Still to do

This is just an initial spike/noodle into what a solution might be.

We need to think about and merge the changes in kit. I am having some problems pushing to kit from this laptop (??) so this ma need to wait until I get back.

Aside from adding/rewriting tests, I'm not sure much else is needed here

@josephjclark
Copy link
Collaborator Author

Superceded by #482

josephjclark added a commit that referenced this pull request Jun 11, 2024
…-types/yargs-17.7.2

build(deps): bump yargs and @types/yargs
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
Status: Done
Development

Successfully merging this pull request may close these issues.

3 participants