S
SolidJS•11mo ago
Nathan

Testing difficulties in solid-start

I'm running into some perplexing errors with Vitest in my SSR-enabled Solid Start app. In the imports two files, I get Cannot set properties of undefined (setting 'modhash'). In one, it's caused by import { isBefore, parseISO } from "date-fns". In the other, by import { CentralStoreContext } from "../root".
In at least one of the test files, I've done my best to abstract the component being tested away from the routing, but I'm still getting this error. My root.tsx:
...

export const CentralStoreContext =
createContext<ReturnType<typeof useCentralStore>>()

export default function Root() {
const ctx = useCentralStore()
const location = useLocation()
return (
<Html lang="en">
<Head>
<Title>SolidStart - With TailwindCSS</Title>
<Meta charset="utf-8" />
<Meta name="viewport" content="width=device-width, initial-scale=1" />
</Head>
<Body>
<Suspense>
<SessionProvider>
<Sidebar />
<CentralStoreContext.Provider value={ctx}>
<Routes>
<FileRoutes />
</Routes>
</CentralStoreContext.Provider>
<Scripts />
</SessionProvider>
</Suspense>
</Body>
</Html>
)
}
...

export const CentralStoreContext =
createContext<ReturnType<typeof useCentralStore>>()

export default function Root() {
const ctx = useCentralStore()
const location = useLocation()
return (
<Html lang="en">
<Head>
<Title>SolidStart - With TailwindCSS</Title>
<Meta charset="utf-8" />
<Meta name="viewport" content="width=device-width, initial-scale=1" />
</Head>
<Body>
<Suspense>
<SessionProvider>
<Sidebar />
<CentralStoreContext.Provider value={ctx}>
<Routes>
<FileRoutes />
</Routes>
</CentralStoreContext.Provider>
<Scripts />
</SessionProvider>
</Suspense>
</Body>
</Html>
)
}
And my vitest.config.ts:
/// <reference types="vitest" />
/// <reference types="vite/client" />
// 👆 do not forget to add the references above
import { defineConfig } from "vite"
import solid from "solid-start/vite"
export default defineConfig({
plugins: [solid()],
server: {
port: 3000,
},
build: {
target: "esnext",
},
test: {
environment: "jsdom",
globals: true,
transformMode: { web: [/\.[jt]sx?$/] },
},
resolve: { conditions: ["development", "browser"] },
})
/// <reference types="vitest" />
/// <reference types="vite/client" />
// 👆 do not forget to add the references above
import { defineConfig } from "vite"
import solid from "solid-start/vite"
export default defineConfig({
plugins: [solid()],
server: {
port: 3000,
},
build: {
target: "esnext",
},
test: {
environment: "jsdom",
globals: true,
transformMode: { web: [/\.[jt]sx?$/] },
},
resolve: { conditions: ["development", "browser"] },
})
19 Replies
Nathan
Nathan•11mo ago
Any guidance you can offer, @lexlohr ?
Alex Lohr
Alex Lohr•11mo ago
Sorry, I need to test the newest solid start myself. I am terribly busy, so I cannot promise a fast answer.
Nathan
Nathan•11mo ago
Understood. I'm happy for whatever help I can get.
Alex Lohr
Alex Lohr•11mo ago
Have you tried to update all dependencies?
Nathan
Nathan•11mo ago
Just tried that. It had no effect.
Alex Lohr
Alex Lohr•11mo ago
I might have some time on Saturday or Sunday later in the evening for a pair debugging session.
Nathan
Nathan•11mo ago
Just saw this now. I can't tonight, unfortunately. But I appreciate the offer.
Alex Lohr
Alex Lohr•11mo ago
Maybe we can find another date. I have tried to recreate the issue, but could not get the same error.
Nathan
Nathan•11mo ago
I'm occupied tonight and tomorrow evening, but my schedule is otherwise pretty open
Alex Lohr
Alex Lohr•11mo ago
Maybe Tuesday 9pm CEST works for you?
Nathan
Nathan•11mo ago
Yeah, that would work CEST = Central European Standard?
Alex Lohr
Alex Lohr•11mo ago
central european summer time = UTC+2 might be a few minutes later, depending on when my kids fall asleep
Nathan
Nathan•11mo ago
Got it. See you then.
Alex Lohr
Alex Lohr•11mo ago
okay, I'm here
Nathan
Nathan•11mo ago
cool How should we do this?
Alex Lohr
Alex Lohr•11mo ago
Should I open a GotoMeeting so you can share your screen?
Nathan
Nathan•11mo ago
Sure Do I need to install anything for that?
Alex Lohr
Alex Lohr•11mo ago
Just a browser (preferably not firefox, because it's media capabilities are notoriously bad). https://app.goto.com/meeting/779414933 Thank you for your time.
Nathan
Nathan•11mo ago
I just put all changes into a testing_problems branch and pushed it