anycable / anycable-client

AnyCable / Action Cable JavaScript client for web, Node.js & React Native
MIT License
97 stars 15 forks source link

Jest #40

Open calderon opened 6 months ago

calderon commented 6 months ago

Hi! I have included @anycable/web (lastest version) and running Jest I am getting:

    Details:

    /Users/dani/code/project/node_modules/@anycable/web/index.js:1
    ({"Object.<anonymous>":function(module,exports,require,__dirname,__filename,jest){import {
                                                                                      ^^^^^^

    SyntaxError: Cannot use import statement outside a module

       7 |   useState,
       8 | } from 'react';
    >  9 | import {
         | ^
      10 |   Cable,
      11 |   createCable,
      12 | } from '@anycable/web';

Is there anything to add in jest config or such? What am I missing?

palkan commented 6 months ago

I suggest trying --experimental-vm-modules to the jest command (like we do here). See also: https://jestjs.io/docs/ecmascript-modules

calderon commented 6 months ago

@palkan I tried it:

NODE_OPTIONS=--experimental-vm-modules jest --coverage

The error is different but it is still in there:

    Must use import to load ES Module: /Users/dani/code/project/node_modules/@anycable/web/index.js

       7 |   useState
       8 | } from 'react';
    >  9 | import {
         | ^
      10 |   Cable,
      11 |   createCable,
      12 | } from '@anycable/web';

Using it in a project:

For now I am disabling it in my test environment as a desperate measure

jest.mock('@anycable/web', () => ({}));