-
-
Notifications
You must be signed in to change notification settings - Fork 1.2k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Migrating vitest
to SDK
#1672
Migrating vitest
to SDK
#1672
Changes from 6 commits
c07dba8
80bee93
f0f82ec
0d36295
6af28e5
5eb6e53
e2efa42
dc83123
ba3e9bf
317eedf
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,8 @@ | ||
import matchers from '@testing-library/jest-dom/matchers' | ||
import { expect } from 'vitest' | ||
import { afterEach } from 'vitest' | ||
import { cleanup } from '@testing-library/react' | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I've updated the There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Running with the latest versions seems to work fine 👍 |
||
import '@testing-library/jest-dom/vitest' | ||
|
||
expect.extend(matchers) | ||
// runs a clean after each test case (e.g. clearing jsdom) | ||
afterEach(() => { | ||
cleanup(); | ||
}) |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2,6 +2,7 @@ | |
/// <reference types="vitest" /> | ||
import { mergeConfig } from "vite"; | ||
import react from "@vitejs/plugin-react"; | ||
import { defaultExclude } from "vitest/config" | ||
|
||
{=# customViteConfig.isDefined =} | ||
// Ignoring the TS error because we are importing a file outside of TS root dir. | ||
|
@@ -29,8 +30,12 @@ const defaultViteConfig = { | |
outDir: "build", | ||
}, | ||
test: { | ||
globals: true, | ||
environment: "jsdom", | ||
setupFiles: ["./src/test/vitest/setup.ts"], | ||
setupFiles: ["./.wasp/out/web-app/src/test/vitest/setup.ts"], | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This file is already templated, so let's use the knowledge we have about this folder instead of hardcoding it. |
||
// This is a hack to make Vite's test runner work with user files living | ||
// outside of the web app root dir. | ||
exclude: [...defaultExclude, ".wasp/**/*"] | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Same story as with setup files, There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Good call, I've now changed the template 👍 |
||
}, | ||
// resolve: { | ||
// dedupe: ["react", "react-dom"], | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -20,7 +20,8 @@ | |
"esModuleInterop": true, | ||
"moduleResolution": "node", | ||
"outDir": "dist", | ||
"allowJs": true | ||
"allowJs": true, | ||
"types": ["@testing-library/jest-dom"], | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. There were type errors related to the unit test matchers e.g. |
||
// todo(filip): Only works with common js, see https://www.typescriptlang.org/tsconfig#paths and daily-article. | ||
// "paths": { | ||
// "@wasp/*": [ | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,4 @@ | ||
/.wasp/ | ||
/.env.server | ||
/.env.client | ||
/node_modules/ | ||
node_modules/ | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Vitest creates some cache files in the |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Instead of running from the
.wasp/out
dir, it now runs from the Wasp project root dir.