Openfn compile for unit tests#1443
Conversation
- Add --test flag: compiles job expressions for unit testing, writing output to tests/ by default (reads dirs.tests from openfn.yaml) - Add --strip (default on with --test): tree-shakes compiled output, keeping only export const/function declarations and their transitive dependencies; use --no-strip to keep all compiled code - Add --watch flag: watches source files and recompiles on change (uses chokidar) - Strip mode removes injected _defer import when operations are stripped - Skip writing files with no exportable code after stripping; log when skipping - Auto-clean stale step files in tests/ that were skipped in the current run without touching user-added files at other paths - Fix --test --no-strip skipping pure-operation jobs (hasExportableCode guard now only applies when strip is active) Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
- remove export default [] from strip mode output (not needed for unit testing) - add --no-strip flag to keep full compiled output including operations - remove --strip standalone flag (stripping is always on with --test by default) - auto-derive output path for single-file --test using tests/ dir - skip writing files with no exportable code in strip mode - auto-clean stale step files in tests/ after project-wide strip runs - fix --test --no-strip skipping pure-operation jobs - update help examples and option descriptions Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
|
@mtuchi I'm not liking the When you do When you do When you do I'd also suggest that So drop the |
| wrap: boolean; // TODO | ||
| wrap?: boolean; // TODO | ||
| // Strip operations instead of moving them into the export array (for test compilation) | ||
| strip?: boolean; |
There was a problem hiding this comment.
I am not sold that this is the correct implementation
This transformer's one job is to identify operations in the code.
What we need to add here is a different transformer which strips all non-exported lines from code. It's a totally unrelated thing really (OK, as it goes, all operations would be removed - but that's fine). The compiler is simply looking for export statements and removing everything else. The logic would be a lot simpler.
So this would be new transformer which runs probably before all the others
Short Description
Adds
openfn compile --testfor unit testing job code. Compiles job expressions to standard JavaScript, writing output totests/by default.Fixes #1424
Implementation Details
--testflag (packages/cli): writes output totests/by default; override with-o <dir>ordirs.testsinopenfn.yaml. Supports single-file and project-wide compilation.--test): tree-shakes the AST in top-level-operations transformer — only exportconst/exportfunction declarations and their transitive dependencies are kept. Operation calls, non-exported helpers,export default [], and the injected_deferimport are all removed.--no-strip: opt-out flag to keep the full compiled output including operations inexport default [...].--watchflag: useschokidarto watch source files and recompile on change.tests/if they exist from a previous run. Only exact step paths (tests/<workflow-id>/<step-id>.js) are touched — user-added files at other paths are never removed.packages/compiler): top-level-operations transformer extended withcollectRefs,buildDeclMap, andcollectDepshelpers for the tree-shaking logic.QA Notes
Verify
openfnx compile --helpshows--test,--no-strip, and--watchwith correct descriptions and examples.AI Usage
Please disclose whether you've used AI anywhere in this PR (it's cool, we just
want to know!):
You can read more details in our
Responsible AI Policy
Release branch checklist
Delete this section if this is not a release PR.
If this IS a release branch:
pnpm changeset versionfrom root to bump versionspnpm installpnpm changeset tagto generate tagsgit push --tagsTags may need updating if commits come in after the tags are first generated.