vite-plugin-solid icon indicating copy to clipboard operation
vite-plugin-solid copied to clipboard

2.7.1 breaks vitest config

Open jtmueller opened this issue 2 years ago • 7 comments

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.

jtmueller avatar Oct 10 '23 23:10 jtmueller

Is it related to this PR perhaps: https://github.com/solidjs/vite-plugin-solid/pull/101

ryansolid avatar Oct 17 '23 20:10 ryansolid

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

Akiyamka avatar Nov 05 '23 16:11 Akiyamka

FWIW, this issue also appears in 2.8.0

jtmueller avatar Jan 01 '24 17:01 jtmueller

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 {

jtmueller avatar Jan 01 '24 17:01 jtmueller

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

ryansolid avatar Jan 22 '24 16:01 ryansolid

@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'],
        },
      },
    },

jtmueller avatar Jan 22 '24 18:01 jtmueller

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

Lucianod28 avatar Jan 27 '24 18:01 Lucianod28