-
Notifications
You must be signed in to change notification settings - Fork 32
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Bump the npm-development group across 1 directory with 8 updates (#589)
- Loading branch information
1 parent
06eca57
commit 7bc09a8
Showing
14 changed files
with
1,347 additions
and
245 deletions.
There are no files selected for viewing
Large diffs are not rendered by default.
Oops, something went wrong.
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,52 @@ | ||
import { afterAll, beforeAll, describe, expect, test } from 'vitest' | ||
import fetchMock from '@fetch-mock/vitest' | ||
import { APIErrorCommon } from './errors' | ||
import { Client } from './client' | ||
|
||
beforeAll(() => fetchMock.mockGlobal()) | ||
afterAll(() => fetchMock.mockRestore()) | ||
|
||
const baseUrl = 'http://localhost' | ||
|
||
/** A quick way to test if an error is thrown is to check it. */ | ||
const expectError = async (fn: () => Promise<unknown> | unknown, checkErrorFn: (e: TypeError) => void) => { | ||
try { | ||
await fn() | ||
|
||
expect(true).toBe(false) // fail the test if the error is not thrown | ||
} catch (e: TypeError | unknown) { | ||
expect(e).toBeInstanceOf(Error) | ||
|
||
checkErrorFn(e as Error) | ||
} | ||
} | ||
|
||
describe('currentVersion', () => { | ||
const mockUrlMatcher = /\/api\/version$/ | ||
|
||
test('pass', async () => { | ||
fetchMock.getOnce(mockUrlMatcher, { status: 200, body: { version: 'v1.2.3' } }) | ||
|
||
const client = new Client({ baseUrl }) | ||
|
||
expect((await client.currentVersion()).toString()).equals('1.2.3') | ||
expect((await client.currentVersion()).toString()).equals('1.2.3') // the second call should use the cache | ||
|
||
fetchMock.getOnce(mockUrlMatcher, { status: 200, body: { version: 'V3.2.1' } }) | ||
|
||
expect((await client.currentVersion(true)).toString()).equals('3.2.1') // the cache should be updated | ||
expect((await client.currentVersion()).toString()).equals('3.2.1') // the second call should use the cache | ||
}) | ||
|
||
test('throws', async () => { | ||
fetchMock.getOnce(mockUrlMatcher, { status: 501, body: '"error"' }) | ||
|
||
await expectError( | ||
async () => await new Client({ baseUrl }).currentVersion(), | ||
(e) => { | ||
expect(e).toBeInstanceOf(APIErrorCommon) | ||
expect(e.message).toBe('Not Implemented') | ||
} | ||
) | ||
}) | ||
}) |
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,2 +1,2 @@ | ||
export { default as apiClient, type Client } from './client' | ||
export { Client } from './client' | ||
export { type APIError, APIErrorNotFound, APIErrorCommon, APIErrorUnknown } from './errors' |
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 +1 @@ | ||
export { routes, pathTo, RouteIDs } from './routing' | ||
export { createRoutes, pathTo, RouteIDs } from './routing' |
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,40 @@ | ||
import { MantineProvider } from '@mantine/core' | ||
import { SemVer } from 'semver' | ||
import { describe, afterEach, expect, test, vi } from 'vitest' | ||
import { render, cleanup } from '~/test-utils' | ||
import { MemoryRouter, Route, Routes } from 'react-router-dom' | ||
import { default as Layout } from './layout' | ||
import { Client } from '~/api' | ||
|
||
afterEach(() => cleanup()) | ||
|
||
/** @jest-environment jsdom */ | ||
describe('layout', () => { | ||
test('common', () => { | ||
const apiClient = new Client({ baseUrl: 'http://unit/test' }) | ||
const FakeComponent = () => <div>fake text</div> | ||
|
||
vi.spyOn(apiClient, 'currentVersion').mockResolvedValueOnce(new SemVer('0.0.0-unit-test')) | ||
vi.spyOn(apiClient, 'latestVersion').mockResolvedValueOnce(new SemVer('99.0.0-unit-test')) | ||
vi.spyOn(apiClient, 'getSettings').mockResolvedValueOnce({ | ||
limits: { maxRequests: 1000, sessionTTL: 60, maxRequestBodySize: 1000 }, | ||
}) | ||
|
||
const { unmount } = render( | ||
<MantineProvider> | ||
<MemoryRouter initialEntries={['/']}> | ||
<Routes> | ||
<Route element={<Layout apiClient={apiClient} />}> | ||
<Route path="/" element={<FakeComponent />} /> | ||
</Route> | ||
</Routes> | ||
</MemoryRouter> | ||
</MantineProvider> | ||
) | ||
|
||
expect(apiClient.currentVersion).toHaveBeenCalledTimes(1) | ||
expect(apiClient.latestVersion).toHaveBeenCalledTimes(1) | ||
|
||
unmount() | ||
}) | ||
}) |
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 userEvent from '@testing-library/user-event' | ||
|
||
export * from '@testing-library/react' | ||
export { render } from './render' | ||
export { userEvent } |
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,9 @@ | ||
import { render as testingLibraryRender } from '@testing-library/react' | ||
import { MantineProvider } from '@mantine/core' | ||
|
||
/** @link https://mantine.dev/guides/vitest/#custom-render */ | ||
export function render(ui: React.ReactNode) { | ||
return testingLibraryRender(<>{ui}</>, { | ||
wrapper: ({ children }: { children: React.ReactNode }) => <MantineProvider>{children}</MantineProvider>, | ||
}) | ||
} |
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
Oops, something went wrong.