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

Does svelte-jester work with svelte 5? #299

Open
norricorp opened this issue Jan 30, 2025 · 5 comments
Open

Does svelte-jester work with svelte 5? #299

norricorp opened this issue Jan 30, 2025 · 5 comments
Assignees
Labels
enhancement New feature or request

Comments

@norricorp
Copy link

My package.json includes
"jest": "^29.7.0",
"svelte": "^5.0.0",
"svelte-jester": "^5.0.0",

For svelte 5 migration I added
import { render } from 'svelte/server';
to ssr.test.js

Result is

FAIL test/ssr/ssr.test.js
● Test suite failed to run

Jest encountered an unexpected token

Jest failed to parse a file. This happens e.g. when your code or its dependencies use non-standard JavaScript syntax, or when Jest is not configured to support such syntax.

Out of the box Jest supports Babel, which will be used to transform your files into valid JS based on your Babel configuration.

By default "node_modules" folder is ignored by transformers.

Here's what you can do:
 • If you are trying to use ECMAScript Modules, see https://jestjs.io/docs/ecmascript-modules for how to enable it.
 • If you are trying to use TypeScript, see https://jestjs.io/docs/getting-started#using-typescript
 • To have some of your "node_modules" files transformed, you can specify a custom "transformIgnorePatterns" in your config.
 • If you need a custom transformation specify a "transform" option in your config.
 • If you simply want to mock your non-JS modules (e.g. binary assets) you can stub them out with the "moduleNameMapper" config option.

You'll find more details and examples of these config options in the docs:
https://jestjs.io/docs/configuration
For information about custom transformations, see:
https://jestjs.io/docs/code-transformation

Details:

C:\GitWork\svelte4-navigator\node_modules\svelte\src\server\index.js:1
({"Object.<anonymous>":function(module,exports,require,__dirname,__filename,jest){export { render } from '../internal/server/index.js';
                                                                                  ^^^^^^

SyntaxError: Unexpected token 'export'

> 1 | import { render } from 'svelte/server';
    | ^
  2 | import cheerio from "cheerio";
  3 | // eslint-disable-next-line import/extensions, import/no-unresolved
  4 | import app from "./dist/App";

  at Runtime.createScriptFromCode (node_modules/jest-runtime/build/index.js:1505:14)
  at Object.require (test/ssr/ssr.test.js:1:1)
@sebastianrothe
Copy link
Collaborator

sebastianrothe commented Feb 4, 2025

Thanks for the question. I might have some time on the weekend to look into this.

In the meantime, you can check here, if anything resolves the problem: #121 (comment)

@sebastianrothe sebastianrothe self-assigned this Feb 4, 2025
@sebastianrothe sebastianrothe added the enhancement New feature or request label Feb 4, 2025
@sebastianrothe sebastianrothe pinned this issue Feb 4, 2025
@norricorp
Copy link
Author

norricorp commented Feb 4, 2025 via email

@norricorp
Copy link
Author

Hi @sebastianrothe,
Did you get a chance to look at this?
Regards

@sebastianrothe
Copy link
Collaborator

sebastianrothe commented Feb 11, 2025

Hi @sebastianrothe, Did you get a chance to look at this? Regards

Yeah, and to my surprise, we already have svelte5 support and tests. https://github.com/svelteness/svelte-jester/tree/master/e2e/svelte-5

I upgraded to the current svelte version and it works as well (#300). Can you provide a sample repo with your problem?

@norricorp
Copy link
Author

The repo that I have been using is https://github.com/norricorp/svelte4-navigator on the svelte5 branch.
BUT https://github.com/norricorp/svelte4-navigator/blob/main/test/ssr/ssr.test.js does not contain the changed code, which is

import { render } from 'svelte/server';
import cheerio from "cheerio";
// eslint-disable-next-line import/extensions, import/no-unresolved
import app from "./dist/App";

const createSelector = testId => `[data-testid="${testId}"]`;

render = url => {
	const { html, head } = render(app, { props: { url }});
//	const { html } = app.render({ url });
	return testId => cheerio.load(html)(createSelector(testId));
};

I made the change based on
https://svelte.dev/docs/svelte/v5-migration-guide#Components-are-no-longer-classes-Server-API-changes

The error is pointing to the import render.

I will also raise this again with the svelte forum on discord. The background is that I made changes to a fork of the original repo and (naturally) wanted to do the minimum so I would rather not have to get involved with learning jest right now.

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

No branches or pull requests

2 participants