brillout / react-streaming

React Streaming. Full-fledged & Easy.
MIT License
216 stars 14 forks source link

Jest examples #23

Closed tbrannam closed 1 year ago

tbrannam commented 1 year ago

I am having trouble running a basic unit test that uses react-streaming/server renderToStream through jest?

I'm currently seeing a segmentation fault, and it seems isolated to utils/loadModule. when this function is called to load stream, the jest test quits with a segmentation fault.

In the jest environment it is using the CJS code, I am uncertain if that should matter.

tbrannam commented 1 year ago

If I modify the CJS code for util/loadModule, to use require instead of import, then it seems to work. I'm not certain about the comments in the code here, but in this case it seems that it is appropriate for this code to use require?

Under normal conditionals TS will not transpile code in node_modules, and in this case it would seem somewhat redundant to do so?

"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.loadModule = void 0;
/** Dynamically load module, without the module being bundled. */
function loadModule(id) {
    console.log('loadModule', id)
    // - For TypeScript to not transpile `import()` to `require()` for CJS builds, it needs to be configured with `"moduleResolution": "nodenext"`, see https://github.com/microsoft/TypeScript/issues/43329#issuecomment-1079559627
    // - Skip webpack from forcefully bunlding dynamic imports with unknown IDs: https://github.com/webpack/webpack/issues/7644#issuecomment-402123392
    return require(/*webpackIgnore: true*/ id);
}
exports.loadModule = loadModule;
brillout commented 1 year ago

What Node.js version are you using?

Closing as a segfault means there is a bug in the JavaScript runtime. Let's continue the conversation though as there may be a workaround in react-streaming land.