fix(test): use async jiti import path for Node 24.13+ compatibility

Node 24.13+ sealed the require property on ESM module objects as a
read-only getter, breaking Jiti's sync CJS path when tryNative is false.
Switch to the async .import() helper which uses dynamic import() instead.
This commit is contained in:
Antonio 2026-03-20 10:00:47 -03:00
parent c33ea8e30a
commit 41a5875715
2 changed files with 8 additions and 8 deletions

View File

@ -77,9 +77,9 @@ export const copiedRuntimeMarker = {
...__testing.buildPluginLoaderJitiOptions({}),
tryNative: false,
});
// The production loader uses sync Jiti evaluation, so this regression test
// should exercise the same seam instead of Jiti's async import helper.
expect(() => withoutAlias(copiedChannelRuntime)).toThrow();
// Node 24.13+ sealed `require` on ESM module objects, breaking Jiti's sync
// CJS path when tryNative is false. Use the async `.import()` helper instead.
await expect(async () => await withoutAlias.import(copiedChannelRuntime)).rejects.toThrow();
const withAlias = createJiti(jitiBaseUrl, {
...__testing.buildPluginLoaderJitiOptions({
@ -87,7 +87,7 @@ export const copiedRuntimeMarker = {
}),
tryNative: false,
});
expect(withAlias(copiedChannelRuntime)).toMatchObject({
expect(await withAlias.import(copiedChannelRuntime)).toMatchObject({
copiedRuntimeMarker: {
PAIRING_APPROVED_MESSAGE: "paired",
resolveOutboundSendDep: expect.any(Function),

View File

@ -3595,9 +3595,9 @@ export const syntheticRuntimeMarker = {
...__testing.buildPluginLoaderJitiOptions({}),
tryNative: false,
});
// The production loader uses sync Jiti evaluation, so this boundary should
// follow the same path instead of the async import helper.
expect(() => withoutAlias(copiedChannelRuntime)).toThrow();
// Node 24.13+ sealed `require` on ESM module objects, breaking Jiti's sync
// CJS path when tryNative is false. Use the async `.import()` helper instead.
await expect(async () => await withoutAlias.import(copiedChannelRuntime)).rejects.toThrow();
const withAlias = createJiti(jitiBaseUrl, {
...__testing.buildPluginLoaderJitiOptions({
@ -3605,7 +3605,7 @@ export const syntheticRuntimeMarker = {
}),
tryNative: false,
});
expect(withAlias(copiedChannelRuntime)).toMatchObject({
expect(await withAlias.import(copiedChannelRuntime)).toMatchObject({
syntheticRuntimeMarker: {
resolveOutboundSendDep: expect.any(Function),
},