-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Browse files
Browse the repository at this point in the history
…testing Set up Testing
- Loading branch information
Showing
10 changed files
with
859 additions
and
22 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
name: Atlas 3.0 CI | ||
|
||
on: | ||
pull_request: | ||
branches: | ||
- main | ||
- epic/* | ||
|
||
jobs: | ||
build: | ||
runs-on: ubuntu-latest | ||
if: github.event.pull_request.draft == false | ||
|
||
env: | ||
VITE_IGNORE_MSW: false | ||
|
||
steps: | ||
- name: Checkout code | ||
uses: actions/checkout@v4 | ||
|
||
- name: Setup NodeJS | ||
uses: actions/setup-node@v4 | ||
with: | ||
node-version: 20 | ||
cache: 'yarn' | ||
|
||
- name: Install dependencies | ||
run: yarn | ||
|
||
- name: Run Vitest | ||
run: yarn vitest |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,20 +1,14 @@ | ||
//src/mocks/browser.js | ||
|
||
import { setupWorker } from "msw/browser" | ||
import { http, HttpResponse } from "msw" | ||
import resolveURL from "../api/fetch.ts"; | ||
|
||
|
||
const handlers = [ | ||
export const handlers = [ | ||
http.get(resolveURL('/resource'), () => { | ||
return HttpResponse.json({ | ||
result: "Hello World!" | ||
}) | ||
}) | ||
] | ||
|
||
export const worker = setupWorker(...handlers) | ||
|
||
worker.events.on("request:start", ({ request }) => { | ||
console.log('MSW intercepted: ', request.method, request.url) | ||
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
import { setupServer } from 'msw/node' | ||
import { handlers } from "./handlers"; | ||
|
||
|
||
export const server = setupServer(...handlers) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
import { setupWorker, SetupWorker } from "msw/browser" | ||
import { handlers } from "./handlers.ts" | ||
|
||
export const worker: SetupWorker = setupWorker(...handlers) | ||
|
||
worker.events.on("request:start", ({ request }) => { | ||
console.log('MSW intercepted: ', request.method, request.url) | ||
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
import {beforeEach, describe, expect, test } from "vitest" | ||
import {render, screen} from "@testing-library/react" | ||
import { QueryClient, QueryClientProvider } from "@tanstack/react-query" | ||
import App from "../src/App" | ||
|
||
const queryClient = new QueryClient() | ||
|
||
describe("Vitest Test", () => { | ||
|
||
beforeEach(() => { | ||
render(<QueryClientProvider client={queryClient}><App></App></QueryClientProvider>) | ||
}) | ||
|
||
test("Should show Hello World!", async () => { | ||
expect(await screen.findByText(/Hello World!/)).toBeDefined() | ||
}) | ||
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,7 +1,15 @@ | ||
/// <reference types="vitest" /> | ||
/// <reference types="vite/client" /> | ||
|
||
import { defineConfig } from 'vite' | ||
import react from '@vitejs/plugin-react' | ||
|
||
// https://vitejs.dev/config/ | ||
export default defineConfig({ | ||
plugins: [react()], | ||
test: { | ||
globals: true, | ||
environment: "jsdom", | ||
setupFiles: ["./vitest.setup.ts"] | ||
} | ||
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
import { afterAll, afterEach, beforeAll } from 'vitest' | ||
import { server } from "./src/mocks/server" | ||
|
||
beforeAll(() => server.listen({ onUnhandledRequest: 'error' })) | ||
afterAll(() => server.close()) | ||
afterEach(() => server.resetHandlers()) |
Oops, something went wrong.