Skip to content

Commit 352af62

Browse files
chore(auth-providers): switch to vitest (mostly) (redwoodjs#9869)
This PR updates the auth providers with the exception of two: 1. `@redwoodjs/auth-firebase-web` It contains jest specific code for specifically resolving uuid to CJS. I'm sure it's possible to switch it over but I have not yet tried. 3. `@redwoodjs/auth-dbauth-web` I encountered errors that WebAuthn was not supported within the test environment. Even with the `jsdom` environment set.
1 parent 68ed27a commit 352af62

File tree

90 files changed

+515
-576
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

90 files changed

+515
-576
lines changed

packages/auth-providers/auth0/api/jest.config.js

-4
This file was deleted.

packages/auth-providers/auth0/api/package.json

+4-4
Original file line numberDiff line numberDiff line change
@@ -19,8 +19,8 @@
1919
"build:types": "tsc --build --verbose",
2020
"build:watch": "nodemon --watch src --ext \"js,jsx,ts,tsx,template\" --ignore dist --exec \"yarn build\"",
2121
"prepublishOnly": "NODE_ENV=production yarn build",
22-
"test": "jest src",
23-
"test:watch": "yarn test --watch"
22+
"test": "vitest run src",
23+
"test:watch": "vitest watch src"
2424
},
2525
"dependencies": {
2626
"@babel/runtime-corejs3": "7.23.6",
@@ -33,8 +33,8 @@
3333
"@babel/core": "^7.22.20",
3434
"@redwoodjs/api": "6.0.7",
3535
"@types/jsonwebtoken": "9.0.5",
36-
"jest": "29.7.0",
37-
"typescript": "5.3.3"
36+
"typescript": "5.3.3",
37+
"vitest": "1.2.1"
3838
},
3939
"gitHead": "3905ed045508b861b495f8d5630d76c7a157d8f1"
4040
}

packages/auth-providers/auth0/api/src/__tests__/auth0.test.ts

+6-3
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,13 @@
11
import jwt from 'jsonwebtoken'
2+
import { vi, test, expect } from 'vitest'
23

34
import { verifyAuth0Token } from '../decoder'
45

5-
jest.mock('jsonwebtoken', () => ({
6-
verify: jest.fn(),
7-
decode: jest.fn(),
6+
vi.mock('jsonwebtoken', () => ({
7+
default: {
8+
verify: vi.fn(),
9+
decode: vi.fn(),
10+
},
811
}))
912

1013
test('verify, and not decode, should be called in production', () => {
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
import { defineConfig, configDefaults } from 'vitest/config'
2+
3+
export default defineConfig({
4+
test: {
5+
exclude: [...configDefaults.exclude, '**/fixtures'],
6+
},
7+
})

packages/auth-providers/auth0/setup/jest.config.js

-4
This file was deleted.

packages/auth-providers/auth0/setup/package.json

+4-4
Original file line numberDiff line numberDiff line change
@@ -19,8 +19,8 @@
1919
"build:types": "tsc --build --verbose",
2020
"build:watch": "nodemon --watch src --ext \"js,jsx,ts,tsx,template\" --ignore dist --exec \"yarn build\"",
2121
"prepublishOnly": "NODE_ENV=production yarn build",
22-
"test": "jest src",
23-
"test:watch": "yarn test --watch"
22+
"test": "vitest run src",
23+
"test:watch": "vitest watch src"
2424
},
2525
"dependencies": {
2626
"@babel/runtime-corejs3": "7.23.6",
@@ -31,8 +31,8 @@
3131
"@babel/cli": "7.23.4",
3232
"@babel/core": "^7.22.20",
3333
"@types/yargs": "17.0.32",
34-
"jest": "29.7.0",
35-
"typescript": "5.3.3"
34+
"typescript": "5.3.3",
35+
"vitest": "1.2.1"
3636
},
3737
"gitHead": "3905ed045508b861b495f8d5630d76c7a157d8f1"
3838
}

packages/auth-providers/auth0/setup/src/__tests__/setup.test.ts

+3-1
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,9 @@
1+
import { vi, test, expect } from 'vitest'
2+
13
import { command, description, builder, handler } from '../setup'
24

35
// mock Telemetry for CLI commands so they don't try to spawn a process
4-
jest.mock('@redwoodjs/telemetry', () => {
6+
vi.mock('@redwoodjs/telemetry', () => {
57
return {
68
errorTelemetry: () => jest.fn(),
79
timedTelemetry: () => jest.fn(),
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
import { defineConfig, configDefaults } from 'vitest/config'
2+
3+
export default defineConfig({
4+
test: {
5+
exclude: [...configDefaults.exclude, '**/fixtures'],
6+
},
7+
})

packages/auth-providers/auth0/web/jest.config.js

-5
This file was deleted.

packages/auth-providers/auth0/web/package.json

+4-4
Original file line numberDiff line numberDiff line change
@@ -19,8 +19,8 @@
1919
"build:types": "tsc --build --verbose",
2020
"build:watch": "nodemon --watch src --ext \"js,jsx,ts,tsx,template\" --ignore dist --exec \"yarn build\"",
2121
"prepublishOnly": "NODE_ENV=production yarn build",
22-
"test": "jest src",
23-
"test:watch": "yarn test --watch"
22+
"test": "vitest run src",
23+
"test:watch": "vitest watch src"
2424
},
2525
"dependencies": {
2626
"@babel/runtime-corejs3": "7.23.6",
@@ -32,9 +32,9 @@
3232
"@babel/cli": "7.23.4",
3333
"@babel/core": "^7.22.20",
3434
"@types/react": "18.2.37",
35-
"jest": "29.7.0",
3635
"react": "0.0.0-experimental-e5205658f-20230913",
37-
"typescript": "5.3.3"
36+
"typescript": "5.3.3",
37+
"vitest": "1.2.1"
3838
},
3939
"peerDependencies": {
4040
"@auth0/auth0-spa-js": "2.1.2"

packages/auth-providers/auth0/web/src/__tests__/auth0.test.tsx

+2-1
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ import type {
55
User,
66
} from '@auth0/auth0-spa-js'
77
import { renderHook, act } from '@testing-library/react'
8+
import { vi, beforeAll, beforeEach, describe, expect, it } from 'vitest'
89

910
import type { CurrentUser } from '@redwoodjs/auth'
1011

@@ -52,7 +53,7 @@ const auth0MockClient: Partial<Auth0Client> = {
5253
},
5354
}
5455

55-
const fetchMock = jest.fn()
56+
const fetchMock = vi.fn()
5657
fetchMock.mockImplementation(async (_url, options) => {
5758
const body = options?.body ? JSON.parse(options.body) : {}
5859

Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
import { defineConfig, configDefaults } from 'vitest/config'
2+
3+
export default defineConfig({
4+
test: {
5+
exclude: [...configDefaults.exclude, '**/fixtures'],
6+
environment: 'jsdom',
7+
},
8+
})

packages/auth-providers/azureActiveDirectory/api/jest.config.js

-4
This file was deleted.

packages/auth-providers/azureActiveDirectory/api/package.json

+4-4
Original file line numberDiff line numberDiff line change
@@ -19,8 +19,8 @@
1919
"build:types": "tsc --build --verbose",
2020
"build:watch": "nodemon --watch src --ext \"js,jsx,ts,tsx,template\" --ignore dist --exec \"yarn build\"",
2121
"prepublishOnly": "NODE_ENV=production yarn build",
22-
"test": "jest src",
23-
"test:watch": "yarn test --watch"
22+
"test": "vitest run src",
23+
"test:watch": "vitest watch src"
2424
},
2525
"dependencies": {
2626
"@babel/runtime-corejs3": "7.23.6",
@@ -34,8 +34,8 @@
3434
"@redwoodjs/api": "6.0.7",
3535
"@types/aws-lambda": "8.10.126",
3636
"@types/jsonwebtoken": "9.0.5",
37-
"jest": "29.7.0",
38-
"typescript": "5.3.3"
37+
"typescript": "5.3.3",
38+
"vitest": "1.2.1"
3939
},
4040
"gitHead": "3905ed045508b861b495f8d5630d76c7a157d8f1"
4141
}

packages/auth-providers/azureActiveDirectory/api/src/__tests__/azureActiveDirectory.test.ts

+6-3
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,14 @@
11
import type { APIGatewayProxyEvent, Context as LambdaContext } from 'aws-lambda'
22
import jwt from 'jsonwebtoken'
3+
import { vi, test, beforeAll, afterAll, expect, describe } from 'vitest'
34

45
import { authDecoder } from '../decoder'
56

6-
jest.mock('jsonwebtoken', () => ({
7-
verify: jest.fn(),
8-
decode: jest.fn(),
7+
vi.mock('jsonwebtoken', () => ({
8+
default: {
9+
verify: vi.fn(),
10+
decode: vi.fn(),
11+
},
912
}))
1013

1114
const req = {
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
import { defineConfig, configDefaults } from 'vitest/config'
2+
3+
export default defineConfig({
4+
test: {
5+
exclude: [...configDefaults.exclude, '**/fixtures'],
6+
},
7+
})

packages/auth-providers/azureActiveDirectory/setup/jest.config.js

-4
This file was deleted.

packages/auth-providers/azureActiveDirectory/setup/package.json

+4-4
Original file line numberDiff line numberDiff line change
@@ -19,8 +19,8 @@
1919
"build:types": "tsc --build --verbose",
2020
"build:watch": "nodemon --watch src --ext \"js,jsx,ts,tsx,template\" --ignore dist --exec \"yarn build\"",
2121
"prepublishOnly": "NODE_ENV=production yarn build",
22-
"test": "jest src",
23-
"test:watch": "yarn test --watch"
22+
"test": "vitest run src",
23+
"test:watch": "vitest watch src"
2424
},
2525
"dependencies": {
2626
"@babel/runtime-corejs3": "7.23.6",
@@ -31,8 +31,8 @@
3131
"@babel/cli": "7.23.4",
3232
"@babel/core": "^7.22.20",
3333
"@types/yargs": "17.0.32",
34-
"jest": "29.7.0",
35-
"typescript": "5.3.3"
34+
"typescript": "5.3.3",
35+
"vitest": "1.2.1"
3636
},
3737
"gitHead": "3905ed045508b861b495f8d5630d76c7a157d8f1"
3838
}

packages/auth-providers/azureActiveDirectory/setup/src/__tests__/setup.test.ts

+5-3
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,12 @@
1+
import { vi, test, expect } from 'vitest'
2+
13
import { command, description, builder, handler } from '../setup'
24

35
// mock Telemetry for CLI commands so they don't try to spawn a process
4-
jest.mock('@redwoodjs/telemetry', () => {
6+
vi.mock('@redwoodjs/telemetry', () => {
57
return {
6-
errorTelemetry: () => jest.fn(),
7-
timedTelemetry: () => jest.fn(),
8+
errorTelemetry: () => vi.fn(),
9+
timedTelemetry: () => vi.fn(),
810
}
911
})
1012

Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
import { defineConfig, configDefaults } from 'vitest/config'
2+
3+
export default defineConfig({
4+
test: {
5+
exclude: [...configDefaults.exclude, '**/fixtures'],
6+
},
7+
})

packages/auth-providers/azureActiveDirectory/web/jest.config.js

-5
This file was deleted.

packages/auth-providers/azureActiveDirectory/web/package.json

+4-4
Original file line numberDiff line numberDiff line change
@@ -19,8 +19,8 @@
1919
"build:types": "tsc --build --verbose",
2020
"build:watch": "nodemon --watch src --ext \"js,jsx,ts,tsx,template\" --ignore dist --exec \"yarn build\"",
2121
"prepublishOnly": "NODE_ENV=production yarn build",
22-
"test": "jest src",
23-
"test:watch": "yarn test --watch"
22+
"test": "vitest run src",
23+
"test:watch": "vitest watch src"
2424
},
2525
"dependencies": {
2626
"@babel/runtime-corejs3": "7.23.6",
@@ -33,9 +33,9 @@
3333
"@babel/core": "^7.22.20",
3434
"@types/netlify-identity-widget": "1.9.6",
3535
"@types/react": "18.2.37",
36-
"jest": "29.7.0",
3736
"react": "0.0.0-experimental-e5205658f-20230913",
38-
"typescript": "5.3.3"
37+
"typescript": "5.3.3",
38+
"vitest": "1.2.1"
3939
},
4040
"peerDependencies": {
4141
"@azure/msal-browser": "2.38.3"

packages/auth-providers/azureActiveDirectory/web/src/__tests__/azureActiveDirectory.test.tsx

+2-1
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import type {
44
RedirectRequest,
55
} from '@azure/msal-browser'
66
import { renderHook, act } from '@testing-library/react'
7+
import { vi, it, expect, describe, beforeAll, beforeEach } from 'vitest'
78

89
import type { CurrentUser } from '@redwoodjs/auth'
910

@@ -79,7 +80,7 @@ const azureActiveDirectoryMockClient: Partial<AzureActiveDirectoryClient> = {
7980
},
8081
}
8182

82-
const fetchMock = jest.fn()
83+
const fetchMock = vi.fn()
8384
fetchMock.mockImplementation(async (_url, options) => {
8485
const body = options?.body ? JSON.parse(options.body) : {}
8586

Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
import { defineConfig, configDefaults } from 'vitest/config'
2+
3+
export default defineConfig({
4+
test: {
5+
exclude: [...configDefaults.exclude, '**/fixtures'],
6+
environment: 'jsdom',
7+
},
8+
})

packages/auth-providers/clerk/api/jest.config.js

-4
This file was deleted.

packages/auth-providers/clerk/api/package.json

+4-4
Original file line numberDiff line numberDiff line change
@@ -19,8 +19,8 @@
1919
"build:types": "tsc --build --verbose",
2020
"build:watch": "nodemon --watch src --ext \"js,jsx,ts,tsx,template\" --ignore dist --exec \"yarn build\"",
2121
"prepublishOnly": "NODE_ENV=production yarn build",
22-
"test": "jest src",
23-
"test:watch": "yarn test --watch"
22+
"test": "vitest run src",
23+
"test:watch": "vitest watch src"
2424
},
2525
"dependencies": {
2626
"@babel/runtime-corejs3": "7.23.6",
@@ -32,8 +32,8 @@
3232
"@babel/core": "^7.22.20",
3333
"@redwoodjs/api": "6.0.7",
3434
"@types/aws-lambda": "8.10.126",
35-
"jest": "29.7.0",
36-
"typescript": "5.3.3"
35+
"typescript": "5.3.3",
36+
"vitest": "1.2.1"
3737
},
3838
"gitHead": "3905ed045508b861b495f8d5630d76c7a157d8f1"
3939
}

packages/auth-providers/clerk/api/src/__tests__/clerk.test.ts

+1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import type { APIGatewayProxyEvent, Context as LambdaContext } from 'aws-lambda'
2+
import { beforeAll, afterAll, describe, test, expect } from 'vitest'
23

34
import { authDecoder, clerkAuthDecoder } from '../decoder'
45

Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
import { defineConfig, configDefaults } from 'vitest/config'
2+
3+
export default defineConfig({
4+
test: {
5+
exclude: [...configDefaults.exclude, '**/fixtures'],
6+
},
7+
})

packages/auth-providers/clerk/setup/jest.config.js

-4
This file was deleted.

packages/auth-providers/clerk/setup/package.json

+1-4
Original file line numberDiff line numberDiff line change
@@ -18,9 +18,7 @@
1818
"build:pack": "yarn pack -o redwoodjs-auth-clerk-setup.tgz",
1919
"build:types": "tsc --build --verbose",
2020
"build:watch": "nodemon --watch src --ext \"js,jsx,ts,tsx,template\" --ignore dist --exec \"yarn build\"",
21-
"prepublishOnly": "NODE_ENV=production yarn build",
22-
"test": "jest src --passWithNoTests",
23-
"test:watch": "yarn test --watch"
21+
"prepublishOnly": "NODE_ENV=production yarn build"
2422
},
2523
"dependencies": {
2624
"@babel/runtime-corejs3": "7.23.6",
@@ -31,7 +29,6 @@
3129
"@babel/cli": "7.23.4",
3230
"@babel/core": "^7.22.20",
3331
"@types/yargs": "17.0.32",
34-
"jest": "29.7.0",
3532
"typescript": "5.3.3"
3633
},
3734
"gitHead": "3905ed045508b861b495f8d5630d76c7a157d8f1"

packages/auth-providers/clerk/web/jest.config.js

-5
This file was deleted.

0 commit comments

Comments
 (0)