Skip to content

test(node): Add esm/cjs specific test runner utils#21729

Merged
mydea merged 2 commits into
developfrom
fn/node-runner
Jun 24, 2026
Merged

test(node): Add esm/cjs specific test runner utils#21729
mydea merged 2 commits into
developfrom
fn/node-runner

Conversation

@mydea

@mydea mydea commented Jun 24, 2026

Copy link
Copy Markdown
Member

This make some small adjustments to the node test runner, as well as exposing two new methods for faster tests:

  • Make sure that cleanup steps are also kept in the global space, so if something fails with cleanup of one specific runner, it will still be cleaned up by the global cleanup.
  • Removed some unneeded failsOnEsm: false definitions

Two new methods now exist for faster tests:

  • createEsmTests
  • createCjsTests

This works the same as createEsmAndCjsTests, but does... only run a single set. For now, I did not change the code to actually generate both variants in the tmp dir (as the file i/o is actually super fast so not really the bottleneck, but may be cleaned up later). However, we can use this in places where we do not need to run things in both environments.

In this PR, I have rewritten to the new methods in the following places only:

  • Where we deliberately only test one way because we use syntax that does not work in the other (e.g. langchain)
  • For libraries that do not work in ESM, where we now only have a single test with failsOnEsm: true to ensure we find out if that stops failing, but we do not need to run every single scenario in failure mode, only one.

In follow ups, we can think about only running one or two tests per integration in esm&cjs mode to verify it generally works in both, and run other scenarios only in esm or cjs, for faster test execution times.

@mydea mydea self-assigned this Jun 24, 2026

@cursor cursor Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Cursor Bugbot has reviewed your changes and found 2 potential issues.

Fix All in Cursor

❌ Bugbot Autofix is OFF. To automatically fix reported issues with cloud agents, enable autofix in the Cursor dashboard.

Reviewed by Cursor Bugbot for commit 9cbddb5. Configure here.

Comment thread dev-packages/node-integration-tests/utils/runner/createEsmAndCjsTests.ts Outdated
Comment thread dev-packages/node-integration-tests/utils/runner/createEsmAndCjsTests.ts Outdated
Comment on lines +72 to +125
export function createEsmTests(
cwd: string,
scenarioPath: string,
instrumentPath: string,
callback: (createTestRunner: () => ReturnType<typeof createRunner>, testFn: typeof test, cwd: string) => void,
options?: {
/**
* `additionalDependencies` to install in the tmp dir.
*/
additionalDependencies?: Record<string, string>;
/** Copy these files/dirs into the tmp dir. */
copyPaths?: string[];
},
) {
const [tmpDirPath, createTmpDir, paths] = prepareTmpDir(cwd, scenarioPath, instrumentPath, options);
const createdRunners = new Set<ReturnType<typeof createRunner>>();

callback(
() => trackRunner(createdRunners, createRunner(paths.esm.scenario).withFlags('--import', paths.esm.instrument)),
test,
tmpDirPath,
);

setupAndCleanup(createTmpDir, createdRunners, tmpDirPath);
}

/**
* Run one or multiple tests in CJS only for a given scenario and instrument file.
*/
export function createCjsTests(
cwd: string,
scenarioPath: string,
instrumentPath: string,
callback: (createTestRunner: () => ReturnType<typeof createRunner>, testFn: typeof test, cwd: string) => void,
options?: {
/**
* `additionalDependencies` to install in the tmp dir.
*/
additionalDependencies?: Record<string, string>;
/** Copy these files/dirs into the tmp dir. */
copyPaths?: string[];
},
) {
const [tmpDirPath, createTmpDir, paths] = prepareTmpDir(cwd, scenarioPath, instrumentPath, options);
const createdRunners = new Set<ReturnType<typeof createRunner>>();

callback(
() => trackRunner(createdRunners, createRunner(paths.cjs.scenario).withFlags('--require', paths.cjs.instrument)),
test,
tmpDirPath,
);

setupAndCleanup(createTmpDir, createdRunners, tmpDirPath);
}

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

l: I'd have extracted the core out into a createTest function and then call that within createCjsTests and createEsmTests as they are identical except of flag and scenario passed. Seems like a bunch of duplicated code.

But this is just a test helper so feel free to disregard.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

the problem with this is that most of the actual code/work would then be duplicated as the setup stuff is the same for both 🤔 but we can def. refactor this around some more.

@mydea mydea marked this pull request as ready for review June 24, 2026 10:30
@mydea mydea requested a review from a team as a code owner June 24, 2026 10:30
@mydea mydea requested review from JPeer264 and removed request for a team June 24, 2026 10:30
/**
* Run one or multiple tests in ESM only for a given scenario and instrument file.
*/
export function createEsmTests(

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Bug: The new functions createEsmTests and createCjsTests are not exported from the main index.ts file, making them inconsistent with the module's public API.
Severity: LOW

Suggested Fix

Re-export the createEsmTests and createCjsTests functions from the dev-packages/node-integration-tests/utils/runner/index.ts file to ensure they are part of the module's public API, consistent with other exported utilities.

Prompt for AI Agent
Review the code at the location below. A potential bug has been identified by an AI
agent. Verify if this is a real issue. If it is, propose a fix; if not, explain why it's
not valid.

Location: dev-packages/node-integration-tests/utils/runner/createEsmAndCjsTests.ts#L72

Potential issue: The new utility functions `createEsmTests` and `createCjsTests` are
defined with `export` in their source file, `createEsmAndCjsTests.ts`, but are not
re-exported from the module's public entry point, `index.ts`. While the tests updated in
this pull request work by importing directly from the source file, this creates an
inconsistent API. Other public utilities from this module are exported via `index.ts`.
Future developers will likely expect to import these new functions from the main entry
point and will find they are unavailable, leading to confusion. This represents an
incomplete refactoring that violates the principle of a single public interface for the
module.

Also affects:

  • dev-packages/node-integration-tests/utils/runner/createEsmAndCjsTests.ts:101~101

Did we get this right? 👍 / 👎 to inform future reviews.

@mydea mydea merged commit 20c04fc into develop Jun 24, 2026
84 of 86 checks passed
@mydea mydea deleted the fn/node-runner branch June 24, 2026 11:06
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants