dialogflow / dialogflow-javascript-client

JavaScript Web SDK for Dialogflow
Apache License 2.0
412 stars 173 forks source link

Testing with jest causes Syntax error on "export" at api-ai-javascript/index.js:1 #92

Open dtodo1paco opened 6 years ago

dtodo1paco commented 6 years ago

Hi! I'm working in a React application which uses api-ai-client to integrate dialogflow features. Everything works as espected when I manually test the application, but when I try to create some automated tests (with jest), I get the following error, just trying to render the component (which includes api-ai-client)

 FAIL  __tests__/unit/App.test.js
  ● Test suite failed to run

    /BAR/WORKSPACE/TMP/react-api-ai-poc/node_modules/api-ai-javascript/index.js:1
    ({"Object.<anonymous>":function(module,exports,require,__dirname,__filename,global,jest){export * from "./es6/ApiAiClient";
                                                                                             ^^^^^^
    SyntaxError: Unexpected token export

      4 | const doSendMessage = async (message, token) => {
      5 |     let ret = null;
    > 6 |     try {
      8 |         const client = new ApiAiClient({accessToken: token});

Can anybody please tell me the steps to integrate this api (and to mock it if possible) ?

// .babelrc

{
  "presets": [
    "env",
    "react",
    "latest",
    "stage-2"
  ],
  "plugins": ["transform-remove-strict-mode"]

}

Also tried in jest.config

transform: {
        "^.+\\.jsx?$": "babel-jest"
 },

Regards,

lnm8910 commented 4 years ago

Hey, did you get an solution to this issue?

dtodo1paco commented 4 years ago

Yes, you can take a look here