Skip to content
This repository was archived by the owner on Apr 15, 2023. It is now read-only.
This repository was archived by the owner on Apr 15, 2023. It is now read-only.

ES6 transformation issue when testing with jest #14

@adamchel

Description

@adamchel

Hello,

I'm writing a React Native library that communicates with a backend server with a server-sent event stream, and while I'm able to get this library to work in a React Native app, I'm not able to get this library to work when running the jest test suite for our library:

 FAIL  __tests__/StitchAppClientIntTests.ts
  ● Test suite failed to run

    /Users/adamchel/stitch/sdks/v4/stitch-js-sdk/packages/react-native/core/node_modules/react-native-event-source/index.js:1
    ({"Object.<anonymous>":function(module,exports,require,__dirname,__filename,global,jest){import EventSource from './EventSource';
                                                                                                    ^^^^^^^^^^^

    SyntaxError: Unexpected identifier

       7 | var RNAsyncStorage_1 = __importDefault(require("./internal/common/RNAsyncStorage"));
       8 | var StitchAppClientImpl_1 = __importDefault(require("./internal/StitchAppClientImpl"));
    >  9 | var react_native_event_source_1 = __importDefault(require("react-native-event-source"));
         |                                                   ^
      10 | var DEFAULT_BASE_URL = "https://stitch.mongodb.com";
      11 | var appClients = {};
      12 | var Stitch = (function () {

      at ScriptTransformer._transformAndBuildScript (../../../node_modules/jest-runtime/build/script_transformer.js:403:17)
      at Object.require (../core/dist/cjs/core/Stitch.js:9:51)

The issue appears to be due to the fact that jest does not support parsing ES6 code, and the default jest configuration for React Native does not transform dependencies. (see https://jestjs.io/docs/en/tutorial-react-native). Can you update this library to export the EventSource implementation as an ES5 commonjs module so that it can play more nicely with the default jest configuration for React Native? The RN JS bundler supports transforming commonJS modules so it shouldn't cause any compatibility issues.

I also tried to add this module to transformIgnorePatterns, but with no luck. It might be due to the fact that this our library is a multi-module lerna project that shares one node_modules directory, and jest is not looking in the right place to transform the library.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions