Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Svelte-kit support #44

Closed
Drevoed opened this issue May 5, 2021 · 11 comments · Fixed by #46
Closed

Svelte-kit support #44

Drevoed opened this issue May 5, 2021 · 11 comments · Fixed by #46

Comments

@Drevoed
Copy link

Drevoed commented May 5, 2021

Currently svelte-kit requires "type": "module" to be present in package.json. This does not work with current version of svelte-jester because it uses require under the hood and requires are prohibited with ES modules

@sebastianrothe
Copy link
Collaborator

sebastianrothe commented May 7, 2021

Hm, we have type: module in package.json and it works without problems. What is the error you get?

The adapters dont work in the latest next-version. Thats true. You could downgrade them to the version before their switch to ESM.

@navneetsharmaui
Copy link

@sebastianrothe why would you downgrade the adapter, when sevltekit is moving entirely in the es module direction.
And the second point is this issue is not related to the adapter. The issue is that the sveltekit is using esmodule and svelte-jester is not written in esmodule. It can't be used with seveltekit moving forward if the svelte-jester is not modified to support the esmodule.

@sebastianrothe
Copy link
Collaborator

sebastianrothe commented May 10, 2021

I wanted to show, how to get it to work with sveltekit. SInce SvelteKit is transitioning to ESM, this repo should do the same, I agree.

There is another feature from Jest v27 (not released yet, but which supports ESM) #25 which might be implemented together.

@Drevoed
Copy link
Author

Drevoed commented May 10, 2021

> jest src

Uncaught Error: Must use import to load ES Module: /home/.../svelte.config.js
require() of ES modules is not supported.
require() of /home/.../svelte.config.js from /home/.../node_modules/.pnpm/cosmiconfig@7.0.0/node_modules/cosmiconfig/dist/loaders.js is an ES module file as it is a .js file whose nearest parent package.json contains "type": "module" which defines all .js files in that package scope as ES modules.
Instead rename svelte.config.js to end in .cjs, change the requiring code to use import(), or remove "type": "module" from /home/.../package.json.


FROM
Illegal instruction
 FAIL  src/tests/test.ts
  ● Test suite failed to run

    Command failed: node --unhandled-rejections=strict --abort-on-uncaught-exception "/home/.../node_modules/.pnpm/svelte-jester@1.5.0_svelte@3.38.2/node_modules/svelte-jester/src/preprocess.js"
    Uncaught Error: Must use import to load ES Module: /home/.../svelte.config.js
    require() of ES modules is not supported.
    require() of /home/.../svelte.config.js from /home/.../.pnpm/cosmiconfig@7.0.0/node_modules/cosmiconfig/dist/loaders.js is an ES module file as it is a .js file whose nearest parent package.json contains "type": "module" which defines all .js files in that package scope as ES modules.
    Instead rename svelte.config.js to end in .cjs, change the requiring code to use import(), or remove "type": "module" from /home/.../package.json.


    FROM
    Illegal instruction

      at Object.process (node_modules/.pnpm/svelte-jester@1.5.0_svelte@3.38.2/node_modules/svelte-jester/src/transformer.js:16:30)
      at ScriptTransformer.transformSource (node_modules/.pnpm/@jest+transform@26.6.2/node_modules/@jest/transform/build/ScriptTransformer.js:464:35)
      at ScriptTransformer._transformAndBuildScript (node_modules/.pnpm/@jest+transform@26.6.2/node_modules/@jest/transform/build/ScriptTransformer.js:569:40)
      at ScriptTransformer.transform (node_modules/.pnpm/@jest+transform@26.6.2/node_modules/@jest/transform/build/ScriptTransformer.js:607:25)

Test Suites: 1 failed, 1 total
Tests:       0 total
Snapshots:   0 total
Time:        2.668 s
Ran all test suites 
 ERROR  Test failed. See above for more details.

This is the exact error.

@sebastianrothe
Copy link
Collaborator

Might be a duplicate of #6

@sebastianrothe
Copy link
Collaborator

I'll give it a try, because we need it for our current project as well.

@geoidesic
Copy link

So... how does one make it work with Sveltekit? I mean what does one import in your test? With standard svelte it would be import App from '../App.svelte'; what is it for SvelteKit? Could you provide a sample test that works with the default "demo-app" installation of Sveltekit?

@navneetsharmaui
Copy link

@geoidesic see the tests in the https://github.com/navneetsharmaui/sveltkit-starter
I've not updated the project with latest svelte-jester but it will provide you base for you how to setup your project.

@geoidesic
Copy link

geoidesic commented May 30, 2021

@navneetsharmaui thx, I checked that out –– couldn't get it to build and also didn't see any tests in there? [UPDATE: found the tests but they don't run for me, I get an error sh: cross-env: command not found]

@navneetsharmaui
Copy link

navneetsharmaui commented May 30, 2021

@geoidesic I will be updating the project with the latest svelte-jester, as the test working previously since the sveltekit moved to esmodule, and by that time svelte-jester didn't had the support for the esmodule.

Wait an hour I will update the project to support the latest svelte-jester.

@navneetsharmaui
Copy link

@geoidesic You can check the project now, I've checked in some changes.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants