cristianbote / goober

🥜 goober, a less than 1KB 🎉 css-in-js alternative with a familiar API
https://goober.rocks
MIT License
3.14k stars 119 forks source link

Fix goober running in vitest #589

Open hpinkos opened 2 months ago

hpinkos commented 2 months ago

Prevents an error when importing a component using goober into a vitest unit test

TypeError: Cannot add property p, object is not extensible
 ❯ a node_modules/goober/dist/goober.modern.js:1:2084

The error is happening because this is equivalent to module.exports

console.log(this);

[Module: null prototype] {
  css: [Function: u],
  extractCss: [Function: r],
  glob: [Function: bound u],
  keyframes: [Function: bound u],
  setup: [Function: m],
  styled: [Function: j]
}

Reproducible example of the error: https://github.com/hpinkos/vitest-goober

vercel[bot] commented 2 months ago

The latest updates on your projects. Learn more about Vercel for Git ↗︎

Name Status Preview Comments Updated (UTC)
goober-rocks ✅ Ready (Inspect) Visit Preview 💬 Add feedback Aug 29, 2024 3:18pm
codesandbox-ci[bot] commented 2 months ago

This pull request is automatically built and testable in CodeSandbox.

To see build info of the built libraries, click here or the icon next to each commit SHA.

cristianbote commented 2 months ago

heya @hpinkos thanks for looking into this. Adding that check adds +17B and wondering if this https://github.com/cristianbote/goober/pull/562 could also fix what you are seeing but with a smaller footprint?

hpinkos commented 2 months ago

@cristianbote unfortunately no. I did check that out and try it first, but in this environment globalThis is set up to be a mocked version of window so it's not equivalent to this