Noodle: run actual job code in tests #296
Closed
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Imagine if our unit tests looked like this:
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 functionStill 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