Skip to content

Testing ssr (renderToString) in vitest? #211

Open
@benoitv-code

Description

@benoitv-code

I am using vitest to test files using renderToString

The vitest.config.ts file uses:

export default defineConfig({
  plugins: [solidPlugin({ ssr: true })],
  test: {
    environment: "node"
  },
});

Since [email protected], I get the following error:

Error: renderToString is not supported in the browser, returning undefined
    at throwInBrowser (.../node_modules/solid-js/web/dist/dev.js:1089:15)

As well as isServer (from solid-js/web) returning false.

I believe this is linked to this change: #173

The workarounds I have:

  • Sticking to [email protected]
  • Or using this workaround in vitest.config.ts: ssr: { target: "webworker" } (this leads to other issues)

Is it indeed a bug, or is there a better way to configure vitest to test ssr code from SolidJS?

Thanks!

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions