-
Notifications
You must be signed in to change notification settings - Fork 271
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(nextjs): Replace jest with vitest for unit tests (#4298)
Co-authored-by: Bryce Kalow <[email protected]>
- Loading branch information
1 parent
188bf40
commit 18545c7
Showing
23 changed files
with
1,705 additions
and
3,203 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,2 @@ | ||
--- | ||
--- |
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 |
---|---|---|
|
@@ -16,3 +16,4 @@ packages/*/examples | |
package-lock.json | ||
**/integration/templates/**/* | ||
commitlint.config.ts | ||
vitest.workspace.mjs |
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 was deleted.
Oops, something went wrong.
This file was deleted.
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
4 changes: 2 additions & 2 deletions
4
packages/nextjs/src/pages/__tests__/__snapshots__/exports.test.ts.snap
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
4 changes: 2 additions & 2 deletions
4
packages/nextjs/src/server/__tests__/__snapshots__/exports.test.ts.snap
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,18 +1,24 @@ | ||
global.fetch = jest.fn(() => Promise.resolve(new Response(null))); | ||
import { createClerkClient } from '@clerk/backend'; | ||
import type { Mock } from 'vitest'; | ||
import { describe, expect, it, vi } from 'vitest'; | ||
|
||
import { clerkClient } from '../clerkClient'; | ||
|
||
describe('clerkClient', () => { | ||
it('should pass version package to userAgent', async () => { | ||
const resolvedClerkClient = await clerkClient(); | ||
vi.mock('@clerk/backend', async importOriginal => { | ||
const mod: any = await importOriginal(); | ||
return { | ||
...mod, | ||
// replace some exports | ||
createClerkClient: vi.fn().mockReturnValue({ users: { getUser: vi.fn() } }), | ||
}; | ||
}); | ||
|
||
await resolvedClerkClient.users.getUser('user_test'); | ||
describe('clerkClient', () => { | ||
it('should pass package-specific userAgent', async () => { | ||
await clerkClient(); | ||
|
||
expect(global.fetch).toBeCalled(); | ||
expect((global.fetch as any).mock.calls[0][1].headers).toMatchObject({ | ||
Authorization: 'Bearer TEST_SECRET_KEY', | ||
'Content-Type': 'application/json', | ||
'User-Agent': '@clerk/[email protected]', | ||
expect((createClerkClient as Mock).mock.lastCall?.[0]).toMatchObject({ | ||
userAgent: '@clerk/[email protected]', | ||
}); | ||
}); | ||
}); |
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 |
---|---|---|
@@ -0,0 +1,13 @@ | ||
import { defineConfig } from 'vitest/config'; | ||
|
||
export default defineConfig({ | ||
plugins: [], | ||
test: { | ||
env: { | ||
CLERK_SECRET_KEY: 'TEST_SECRET_KEY', | ||
}, | ||
environment: 'jsdom', | ||
includeSource: ['**/*.{js,ts,jsx,tsx}'], | ||
setupFiles: './vitest.setup.mts', | ||
}, | ||
}); |
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 { beforeAll } from 'vitest'; | ||
|
||
globalThis.PACKAGE_NAME = '@clerk/nextjs'; | ||
globalThis.PACKAGE_VERSION = '0.0.0-test'; | ||
|
||
beforeAll(() => {}); |
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 |
---|---|---|
@@ -0,0 +1,3 @@ | ||
import { defineWorkspace } from 'vitest/config'; | ||
|
||
export default defineWorkspace(['./packages/*/vitest.config.{mts,mjs,js,ts}']); |