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

2.7.1 breaks vitest config #120

Open
jtmueller opened this issue Oct 10, 2023 · 7 comments
Open

2.7.1 breaks vitest config #120

jtmueller opened this issue Oct 10, 2023 · 7 comments

Comments

@jtmueller
Copy link

I have a project that uses vitest with happy-dom in conjunction with vite-plugin-solid. Switching from 2.7.0 of vite-plugin-solid to 2.7.1 breaks my unit tests.

Here's a relevant part of the test section of vite.config.mts:

  test: {
    environment: 'happy-dom',
    globals: true,
    server: {
      deps: {
        // fixes: You appear to have multiple instances of Solid. This can lead to unexpected behavior.
        inline: [/solid-js/, /solid-testing-library/],
      },
    },
    deps: {
      // fixes: Vitest "deps.registerNodeLoader" is deprecated. If you rely on aliases inside external packages, use "deps.optimizer.web.include" instead.
      optimizer: {
        web: {
          enabled: true,
        },
      },
    },

When I run vitest with vite-plugin-solid 2.7.0, everything works fine. When I run it with 2.7.1, I get:

 Vitest  "deps.registerNodeLoader" is deprecated.If you rely on aliases inside external packages, use "deps.optimizer.web.include" instead.
 MISSING DEP  Can not find dependency 'jsdom'

? Do you want to install jsdom? › (y/N)

The fact that it's not honoring either the environment: 'happy-dom' setting or the setting that suppresses the registerNodeLoader warning makes me think that something about 2.7.1 is preventing the test config from being loaded at all.

@ryansolid
Copy link
Member

Is it related to this PR perhaps: #101

@Akiyamka
Copy link

Akiyamka commented Nov 5, 2023

I have same issue. With vite config

defineConfig({
  plugins: [solid()],
  test: {
    environment: 'happy-dom',
    globals: true,
    includeSource: ['src/**/*.ts', 'src/**/*.tsx'],
    deps: {
      optimizer: {
        web: {
          include: ['src/**/*.ts', 'src/**/*.tsx'],
        },
      },
    },
  },
});

package.json

{
  "private": true,
  "version": "0.0.0",
  "type": "module",
  "scripts": {
    "test": "vitest"
  },
  "dependencies": {
    "happy-dom": "^12.10.3",
    "solid-js": "^1.8.5",
  },
  "devDependencies": {
    "typescript": "^5.2.2",
    "vite": "^4.5.0",
    "vite-plugin-solid": "^2.7.2",
    "vitest": "^0.34.6"
  }
}

Steps

$ pnpm run test --config ./vite.config.ts

Result

> vitest "--config" "./vite.config.ts"

 Vitest  "deps.registerNodeLoader" is deprecated.If you rely on aliases inside external packages, use "deps.optimizer.web.include" instead.
 MISSING DEP  Can not find dependency 'jsdom'

? Do you want to install jsdom? › (y/N)

Rollback to 2.7.0 fix problem

@jtmueller
Copy link
Author

FWIW, this issue also appears in 2.8.0

@jtmueller
Copy link
Author

jtmueller commented Jan 1, 2024

Is it related to this PR perhaps: #101

@ryansolid That seems plausible, but it's not clear what the work-around might be. So far I've been unable to get Vitest to load my test config at all when using vite-plugin-solid 2.7.1 or 2.8.0, which is blocking updates to Vite 5.x. Do you have any suggestions?

Update: Confirmed, that PR is indeed the cause. Applying the following patch to 2.8.0 fixes the issue for me:

diff --git a/dist/cjs/index.cjs b/dist/cjs/index.cjs
index a1fb81f39868f27809df7f87405edcf3259f1a0b..5cc5c29df3434235f8392e06a5697fdaea1d3d79 100644
--- a/dist/cjs/index.cjs
+++ b/dist/cjs/index.cjs
@@ -80,7 +80,8 @@ function solidPlugin(options = {}) {
           },
           ...(isJestDomInstalled() ? {
             setupFiles: [require$1.resolve('@testing-library/jest-dom/extend-expect.js')]
-          } : {})
+          } : {}),
+          ...userConfig.test
         }
       } : {};
       return {
diff --git a/dist/esm/index.mjs b/dist/esm/index.mjs
index 830a8ab7acdcbcba70510a1b9d166e0a01aeb885..406921f9091636e14da2d48d9220da52d727425f 100644
--- a/dist/esm/index.mjs
+++ b/dist/esm/index.mjs
@@ -77,7 +77,8 @@ function solidPlugin(options = {}) {
           },
           ...(isJestDomInstalled() ? {
             setupFiles: [require.resolve('@testing-library/jest-dom/extend-expect.js')]
-          } : {})
+          } : {}),
+          ...userConfig.test
         }
       } : {};
       return {

@ryansolid
Copy link
Member

We've fixed some stuff around testing config in the latest. Can anyone confirm if this is still an issue?

@jtmueller
Copy link
Author

@ryansolid With 2.8.3 the unit tests are running to completion and they all pass, without the patch I was using for 2.8.0.

However, I'm seeing dozens of instances of these two error messages in the logs:

You appear to have multiple instances of Solid. This can lead to unexpected behavior.

computations created outside a createRoot or render will never be disposed

This is the relevant bit of my config that previously had solved these error messages, but maybe there's a better way?

  test: {
    environment: 'happy-dom',
    globals: true,
    deps: {
      optimizer: {
        web: {
          enabled: true,
          include: ['robot3', 'robot-solid'],
          // avoids "multiple instances of SolidJS" error
          exclude: ['solid-js', '@solidjs/router', 'solid-testing-library'],
        },
      },
    },

@Lucianod28
Copy link

Here's a minimal example of the "multiple instances of SolidJS" error: https://stackblitz.com/edit/vitest-dev-vitest-xs9lkq?file=package.json

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

No branches or pull requests

4 participants