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

[Bug]: Svelte 4 component testing not working #30862

Open
ryanzec opened this issue May 16, 2024 · 2 comments
Open

[Bug]: Svelte 4 component testing not working #30862

ryanzec opened this issue May 16, 2024 · 2 comments

Comments

@ryanzec
Copy link

ryanzec commented May 16, 2024

Version

1.43.1

Steps to reproduce

clone this repo: https://github.com/ryanzec/edg-ui
run pnpm install
run pnpm test:components

Expected behavior

test should run

Actual behavior

error after code builds

✓ built in 8.15s

Run npm run preview to preview your production build locally.

> Using @sveltejs/adapter-auto
  Could not detect a supported production environment. See https://kit.svelte.dev/docs/adapters to learn how to configure your app to run on the platform of your choosing
Error: ENOENT: no such file or directory, open '/Users/ryanzec/repositories/edg-ui/playwright/.cache/metainfo.json'
  1 did not run

To open last HTML report run:

  pnpm exec playwright show-report

 ELIFECYCLE  Command failed with exit code 1.

Additional context

I followed the guide on the website an initially I got an error when it tried to compile code with TS:

vite v5.2.11 building for production...
✓ 4 modules transformed.
RollupError: [vite-plugin-svelte] [plugin vite-plugin-svelte] src/lib/components/core/button/button.svelte (2:9): /Users/ryanzec/repositories/edg-ui/src/lib/components/core/button/button.svelte:2:9 Unexpected token

- Did you forget to add a TypeScript preprocessor? See https://github.com/sveltejs/vite-plugin-svelte/blob/main/docs/preprocess.md for more information.
file: /Users/ryanzec/repositories/edg-ui/src/lib/components/core/button/button.svelte:2:9
 1 |  <script context="module" lang="ts">
 2 |    export enum ButtonVariant {
               ^
 3 |      FILLED = 'filled',
 4 |      WEAK = 'weak',

so I have to add in the sveltekit plugin to the playwright config but then I get this error.

Environment

System:
    OS: macOS 12.7.4
    CPU: (8) x64 Intel(R) Core(TM) i7-6820HQ CPU @ 2.70GHz
    Memory: 33.79 MB / 16.00 GB
  Binaries:
    Node: 20.12.2 - ~/.nvm/versions/node/v20.12.2/bin/node
    npm: 10.5.0 - ~/.nvm/versions/node/v20.12.2/bin/npm
    pnpm: 9.0.6 - ~/.nvm/versions/node/v20.12.2/bin/pnpm
  IDEs:
    VSCode: 1.89.0 - /usr/local/bin/code
  Languages:
    Bash: 3.2.57 - /bin/bash
  npmPackages:
    @playwright/experimental-ct-svelte: 1.44.0 => 1.44.0
    @playwright/test: 1.43.1 => 1.43.1
@ryanzec
Copy link
Author

ryanzec commented May 18, 2024

After more searching, instead of the adding the sveltekit plugin, I needed to add the svelte plugin like this:

ctViteConfig: {
  plugins: [svelte({ preprocess: vitePreprocess() })],
  resolve: { alias: { $lib: path.resolve('src/lib') } },
},

I don't know if it should work with the sveltekit plugin but since this is for component test, sveltekit really is not needed.

While there does not seems to be a bug in playwright itself, it would be helpful for this to live on the component testing page so that people don't follow the guide and have it not work and not know why.

If this should work with sveltekit too (which I guess would be good for testing that components work with SSR), I have no idea if that is a bug in Playwright and configuration that I am not able to figure out.

@ryanzec
Copy link
Author

ryanzec commented May 20, 2024

I would add that I do think being able to using sveltekit with playwright is important if possible as components will often use $app/* which is part of sveltekit.

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

No branches or pull requests

2 participants