S
SolidJS•2y 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
NathanOP•2y ago
Any guidance you can offer, @lexlohr ?
Alex Lohr
Alex Lohr•2y ago
Sorry, I need to test the newest solid start myself. I am terribly busy, so I cannot promise a fast answer.
Nathan
NathanOP•2y ago
Understood. I'm happy for whatever help I can get.
Alex Lohr
Alex Lohr•2y ago
Have you tried to update all dependencies?
Nathan
NathanOP•2y ago
Just tried that. It had no effect.
Alex Lohr
Alex Lohr•2y ago
I might have some time on Saturday or Sunday later in the evening for a pair debugging session.
Nathan
NathanOP•2y ago
Just saw this now. I can't tonight, unfortunately. But I appreciate the offer.
Alex Lohr
Alex Lohr•2y ago
Maybe we can find another date. I have tried to recreate the issue, but could not get the same error.
Nathan
NathanOP•2y ago
I'm occupied tonight and tomorrow evening, but my schedule is otherwise pretty open
Alex Lohr
Alex Lohr•2y ago
Maybe Tuesday 9pm CEST works for you?
Nathan
NathanOP•2y ago
Yeah, that would work CEST = Central European Standard?
Alex Lohr
Alex Lohr•2y ago
central european summer time = UTC+2 might be a few minutes later, depending on when my kids fall asleep
Nathan
NathanOP•2y ago
Got it. See you then.
Alex Lohr
Alex Lohr•2y ago
okay, I'm here
Nathan
NathanOP•2y ago
cool How should we do this?
Alex Lohr
Alex Lohr•2y ago
Should I open a GotoMeeting so you can share your screen?
Nathan
NathanOP•2y ago
Sure Do I need to install anything for that?
Alex Lohr
Alex Lohr•2y 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
NathanOP•2y ago
I just put all changes into a testing_problems branch and pushed it

Did you find this page helpful?