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] Tests not recognizing the typescript in .svelte files #187

Closed
DiogoVCS opened this issue Mar 4, 2021 · 1 comment
Closed

[Svelte] Tests not recognizing the typescript in .svelte files #187

DiogoVCS opened this issue Mar 4, 2021 · 1 comment
Assignees
Labels
bug Something isn't working Svelte

Comments

@DiogoVCS
Copy link
Contributor

DiogoVCS commented Mar 4, 2021

Created a stackoverflow question regarding this issue here, with more code snippets.
Clean project, using the nx empty workspace (or with an angular one, its the same), added a svelte project using the command line nx g @nxext/svelte:app my-app, then added a component using nx g @nxext/svelte:c my-comp and after inserting this line in the MyComponent.svelte file:

let name: string;

the tests stop working, giving the following error:

 FAIL   my-app  apps/my-app/src/components/my-comp/my-comp.spec.ts
  ● Test suite failed to run

    ParseError: Unexpected token

      at error (../../node_modules/svelte/src/compiler/utils/error.ts:25:16)
      at Parser$1.error (../../node_modules/svelte/src/compiler/parse/index.ts:100:3)
      at Parser$1.acorn_error (../../node_modules/svelte/src/compiler/parse/index.ts:93:8)
      at Object.read_script [as read] (../../node_modules/svelte/src/compiler/parse/read/script.ts:51:10)
      at tag (../../node_modules/svelte/src/compiler/parse/state/tag.ts:205:27)
      at new Parser$1 (../../node_modules/svelte/src/compiler/parse/index.ts:52:12)
      at parse (../../node_modules/svelte/src/compiler/parse/index.ts:216:17)
      at Object.compile (../../node_modules/svelte/src/compiler/compile/index.ts:91:14)
      at Object.process (../../node_modules/svelte-jester/src/transformer.js:21:25)
      at ScriptTransformer.transformSource (../../node_modules/@jest/transform/build/ScriptTransformer.js:464:35)

if I insert instead just:

let name;

it works again.

Unfortunately the TypeScript usage is a dealbreaker for us.

@DominikPieper DominikPieper self-assigned this Mar 4, 2021
@DominikPieper
Copy link
Member

Hi,
thanks for your issue. I added some changes which will come with the next release and simplify this. For now for you to add for the tests:
For the jest.config.js change the svelte transformer to this (with a path in your application directory)

'^.+\\.svelte$': ['svelte-jester', {
  'preprocess': 'apps/<project>/svelte.config.js'
}

and add a svelte.config.js in the dir with the following.

const sveltePreprocess = require('svelte-preprocess');

module.exports = {
	// Consult https://github.com/sveltejs/svelte-preprocess
	// for more information about preprocessors
	preprocess: sveltePreprocess()
};

I'll add the files and paths as a default in the next release and add a option for the build to read in the config file as well to simplify the custom configs

@DominikPieper DominikPieper added bug Something isn't working Svelte labels Mar 4, 2021
@DiogoVCS DiogoVCS closed this as completed Mar 5, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working Svelte
Projects
None yet
Development

No branches or pull requests

2 participants