svelteness / svelte-jester

A Jest transformer for Svelte - compile your components before importing them into tests.
MIT License
128 stars 18 forks source link

Allow to use CJS with Svelte 4 without throwing an error #166

Open j3rem1e opened 12 months ago

j3rem1e commented 12 months ago

Today, svelte-jester throw an exception if we try to use Svelte 4 with a (classic) cjs setup.

To help with the migration path to esm and jest, it would be great to not throw an exception here but maybe add a warning to the documentation.

It works by chaining babel-jest after svelte-jester if I remove the exception, with the following config:

transform: {
    "\\.svelte$": [
      'jest-chain-transform',
      {
        transformers: [
          'svelte-jester', 'babel-jest'
        ]
      }
    ]
  }

Integrating the transformation esm->csj could be great, but I don't think it's really necessary if it's documented.

sebastianrothe commented 12 months ago

Interesting. I thought that this would be impossible.

If you start migrating your code, this should an all at once issue. I think it is not possible to mix and match.

benmccann commented 12 months ago

Svelte 4 will only output ESM, but he's setup a transformer to change that output to CJS, so that it will run with Jest. More details here: https://github.com/storybookjs/addon-svelte-csf/issues/132#issuecomment-1699885697

I think it'd be reasonable to try to support it as it'd probably make upgrading to Svelte 4 easier for folks. We can leave ESM as the default

artemkliaus commented 10 months ago

Svelte 4 will only output ESM, but he's setup a transformer to change that output to CJS, so that it will run with Jest. More details here: storybookjs/addon-svelte-csf#132 (comment)

I think it'd be reasonable to try to support it as it'd probably make upgrading to Svelte 4 easier for folks. We can leave ESM as the default

When will fix?