-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
move from cra to vite Closes #157
- Loading branch information
Showing
12 changed files
with
1,682 additions
and
7,334 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
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
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,28 +1,29 @@ | ||
import { renderHook } from "@testing-library/react-hooks"; | ||
import useFetchData from "./useFetchData" | ||
import useFetchData from "./useFetchData"; | ||
|
||
beforeEach(() => { | ||
jest.spyOn(global, 'fetch').mockResolvedValue({ | ||
json: jest.fn().mockResolvedValue([{nm: 'vova'}]) | ||
}) | ||
vi.spyOn(global, "fetch").mockResolvedValue({ | ||
json: vi.fn().mockResolvedValue([{ nm: "vova" }]), | ||
}); | ||
}); | ||
|
||
afterEach(() => { | ||
jest.restoreAllMocks(); | ||
vi.restoreAllMocks(); | ||
}); | ||
//import { rest } from "msw"; | ||
test("should return error if 'url' params not passed", () => { | ||
const {result} = renderHook(() => useFetchData()) | ||
expect(result.current.error).toBe('must pass url param!'); | ||
const { result } = renderHook(() => useFetchData()); | ||
expect(result.current.error).toBe("must pass url param!"); | ||
}); | ||
test("should return loading set to 'true' if 'url' params passed", async () => { | ||
const {result, waitForNextUpdate} = renderHook(() => useFetchData('zzz')) | ||
const { result, waitForNextUpdate } = renderHook(() => useFetchData("zzz")); | ||
expect(result.current.loading).toBeTruthy(); | ||
expect(result.current.error).toBeNull() | ||
expect(result.current.data).toEqual([]) | ||
await waitForNextUpdate() | ||
expect(result.current.error).toBeNull(); | ||
expect(result.current.data).toEqual([]); | ||
await waitForNextUpdate(); | ||
}); | ||
test("should return data", async () => { | ||
const {result, waitForNextUpdate} = renderHook(() => useFetchData('zzz')) | ||
await waitForNextUpdate() | ||
expect(result.current.data).toEqual([{nm: 'vova'}]) | ||
}); | ||
const { result, waitForNextUpdate } = renderHook(() => useFetchData("zzz")); | ||
await waitForNextUpdate(); | ||
expect(result.current.data).toEqual([{ nm: "vova" }]); | ||
}); |
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 @@ | ||
/// <reference types="vite/client" /> |
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,11 @@ | ||
import { expect, afterEach } from 'vitest'; | ||
import { cleanup } from '@testing-library/react'; | ||
import matchers from '@testing-library/jest-dom/matchers'; | ||
|
||
// extends Vitest's expect method with methods from react-testing-library | ||
expect.extend(matchers); | ||
|
||
// runs a cleanup after each test case (e.g. clearing jsdom) | ||
afterEach(() => { | ||
cleanup(); | ||
}); |
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 |
---|---|---|
@@ -0,0 +1,39 @@ | ||
import { defineConfig, transformWithEsbuild } from "vite"; | ||
import react from "@vitejs/plugin-react"; | ||
|
||
// https://vitejs.dev/config/ | ||
export default defineConfig({ | ||
plugins: [ | ||
react(), | ||
{ | ||
name: "load+transform-js-files-as-jsx", | ||
async transform(code, id) { | ||
if (!id.match(/src\/.*\.js$/)) { | ||
return null; | ||
} | ||
|
||
// Use the exposed transform from vite, instead of directly | ||
// transforming with esbuild | ||
return transformWithEsbuild(code, id, { | ||
loader: "jsx", | ||
jsx: "automatic", // 👈 this is important | ||
}); | ||
}, | ||
}, | ||
// End workaround | ||
], | ||
test: { | ||
globals: true, | ||
environment: 'jsdom', | ||
setupFiles: './tests/setup.js', | ||
}, | ||
// Workaround before renaming .js to .jsx | ||
optimizeDeps: { | ||
esbuildOptions: { | ||
loader: { | ||
".js": "jsx", | ||
}, | ||
}, | ||
}, | ||
// End workaround | ||
}); |
Oops, something went wrong.