Skip to content

Commit

Permalink
chore(auth-providers): switch to vitest (mostly) (redwoodjs#9869)
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
Josh-Walker-GM committed Jan 22, 2024
1 parent 68ed27a commit 352af62
Show file tree
Hide file tree
Showing 90 changed files with 515 additions and 576 deletions.
4 changes: 0 additions & 4 deletions packages/auth-providers/auth0/api/jest.config.js

This file was deleted.

8 changes: 4 additions & 4 deletions packages/auth-providers/auth0/api/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,8 @@
"build:types": "tsc --build --verbose",
"build:watch": "nodemon --watch src --ext \"js,jsx,ts,tsx,template\" --ignore dist --exec \"yarn build\"",
"prepublishOnly": "NODE_ENV=production yarn build",
"test": "jest src",
"test:watch": "yarn test --watch"
"test": "vitest run src",
"test:watch": "vitest watch src"
},
"dependencies": {
"@babel/runtime-corejs3": "7.23.6",
Expand All @@ -33,8 +33,8 @@
"@babel/core": "^7.22.20",
"@redwoodjs/api": "6.0.7",
"@types/jsonwebtoken": "9.0.5",
"jest": "29.7.0",
"typescript": "5.3.3"
"typescript": "5.3.3",
"vitest": "1.2.1"
},
"gitHead": "3905ed045508b861b495f8d5630d76c7a157d8f1"
}
9 changes: 6 additions & 3 deletions packages/auth-providers/auth0/api/src/__tests__/auth0.test.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,13 @@
import jwt from 'jsonwebtoken'
import { vi, test, expect } from 'vitest'

import { verifyAuth0Token } from '../decoder'

jest.mock('jsonwebtoken', () => ({
verify: jest.fn(),
decode: jest.fn(),
vi.mock('jsonwebtoken', () => ({
default: {
verify: vi.fn(),
decode: vi.fn(),
},
}))

test('verify, and not decode, should be called in production', () => {
Expand Down
7 changes: 7 additions & 0 deletions packages/auth-providers/auth0/api/vitest.config.mts
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
import { defineConfig, configDefaults } from 'vitest/config'

export default defineConfig({
test: {
exclude: [...configDefaults.exclude, '**/fixtures'],
},
})
4 changes: 0 additions & 4 deletions packages/auth-providers/auth0/setup/jest.config.js

This file was deleted.

8 changes: 4 additions & 4 deletions packages/auth-providers/auth0/setup/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,8 @@
"build:types": "tsc --build --verbose",
"build:watch": "nodemon --watch src --ext \"js,jsx,ts,tsx,template\" --ignore dist --exec \"yarn build\"",
"prepublishOnly": "NODE_ENV=production yarn build",
"test": "jest src",
"test:watch": "yarn test --watch"
"test": "vitest run src",
"test:watch": "vitest watch src"
},
"dependencies": {
"@babel/runtime-corejs3": "7.23.6",
Expand All @@ -31,8 +31,8 @@
"@babel/cli": "7.23.4",
"@babel/core": "^7.22.20",
"@types/yargs": "17.0.32",
"jest": "29.7.0",
"typescript": "5.3.3"
"typescript": "5.3.3",
"vitest": "1.2.1"
},
"gitHead": "3905ed045508b861b495f8d5630d76c7a157d8f1"
}
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
import { vi, test, expect } from 'vitest'

import { command, description, builder, handler } from '../setup'

// mock Telemetry for CLI commands so they don't try to spawn a process
jest.mock('@redwoodjs/telemetry', () => {
vi.mock('@redwoodjs/telemetry', () => {
return {
errorTelemetry: () => jest.fn(),
timedTelemetry: () => jest.fn(),
Expand Down
7 changes: 7 additions & 0 deletions packages/auth-providers/auth0/setup/vitest.config.mts
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
import { defineConfig, configDefaults } from 'vitest/config'

export default defineConfig({
test: {
exclude: [...configDefaults.exclude, '**/fixtures'],
},
})
5 changes: 0 additions & 5 deletions packages/auth-providers/auth0/web/jest.config.js

This file was deleted.

8 changes: 4 additions & 4 deletions packages/auth-providers/auth0/web/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,8 @@
"build:types": "tsc --build --verbose",
"build:watch": "nodemon --watch src --ext \"js,jsx,ts,tsx,template\" --ignore dist --exec \"yarn build\"",
"prepublishOnly": "NODE_ENV=production yarn build",
"test": "jest src",
"test:watch": "yarn test --watch"
"test": "vitest run src",
"test:watch": "vitest watch src"
},
"dependencies": {
"@babel/runtime-corejs3": "7.23.6",
Expand All @@ -32,9 +32,9 @@
"@babel/cli": "7.23.4",
"@babel/core": "^7.22.20",
"@types/react": "18.2.37",
"jest": "29.7.0",
"react": "0.0.0-experimental-e5205658f-20230913",
"typescript": "5.3.3"
"typescript": "5.3.3",
"vitest": "1.2.1"
},
"peerDependencies": {
"@auth0/auth0-spa-js": "2.1.2"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import type {
User,
} from '@auth0/auth0-spa-js'
import { renderHook, act } from '@testing-library/react'
import { vi, beforeAll, beforeEach, describe, expect, it } from 'vitest'

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

Expand Down Expand Up @@ -52,7 +53,7 @@ const auth0MockClient: Partial<Auth0Client> = {
},
}

const fetchMock = jest.fn()
const fetchMock = vi.fn()
fetchMock.mockImplementation(async (_url, options) => {
const body = options?.body ? JSON.parse(options.body) : {}

Expand Down
8 changes: 8 additions & 0 deletions packages/auth-providers/auth0/web/vitest.config.mts
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
import { defineConfig, configDefaults } from 'vitest/config'

export default defineConfig({
test: {
exclude: [...configDefaults.exclude, '**/fixtures'],
environment: 'jsdom',
},
})

This file was deleted.

8 changes: 4 additions & 4 deletions packages/auth-providers/azureActiveDirectory/api/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,8 @@
"build:types": "tsc --build --verbose",
"build:watch": "nodemon --watch src --ext \"js,jsx,ts,tsx,template\" --ignore dist --exec \"yarn build\"",
"prepublishOnly": "NODE_ENV=production yarn build",
"test": "jest src",
"test:watch": "yarn test --watch"
"test": "vitest run src",
"test:watch": "vitest watch src"
},
"dependencies": {
"@babel/runtime-corejs3": "7.23.6",
Expand All @@ -34,8 +34,8 @@
"@redwoodjs/api": "6.0.7",
"@types/aws-lambda": "8.10.126",
"@types/jsonwebtoken": "9.0.5",
"jest": "29.7.0",
"typescript": "5.3.3"
"typescript": "5.3.3",
"vitest": "1.2.1"
},
"gitHead": "3905ed045508b861b495f8d5630d76c7a157d8f1"
}
Original file line number Diff line number Diff line change
@@ -1,11 +1,14 @@
import type { APIGatewayProxyEvent, Context as LambdaContext } from 'aws-lambda'
import jwt from 'jsonwebtoken'
import { vi, test, beforeAll, afterAll, expect, describe } from 'vitest'

import { authDecoder } from '../decoder'

jest.mock('jsonwebtoken', () => ({
verify: jest.fn(),
decode: jest.fn(),
vi.mock('jsonwebtoken', () => ({
default: {
verify: vi.fn(),
decode: vi.fn(),
},
}))

const req = {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
import { defineConfig, configDefaults } from 'vitest/config'

export default defineConfig({
test: {
exclude: [...configDefaults.exclude, '**/fixtures'],
},
})

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,8 @@
"build:types": "tsc --build --verbose",
"build:watch": "nodemon --watch src --ext \"js,jsx,ts,tsx,template\" --ignore dist --exec \"yarn build\"",
"prepublishOnly": "NODE_ENV=production yarn build",
"test": "jest src",
"test:watch": "yarn test --watch"
"test": "vitest run src",
"test:watch": "vitest watch src"
},
"dependencies": {
"@babel/runtime-corejs3": "7.23.6",
Expand All @@ -31,8 +31,8 @@
"@babel/cli": "7.23.4",
"@babel/core": "^7.22.20",
"@types/yargs": "17.0.32",
"jest": "29.7.0",
"typescript": "5.3.3"
"typescript": "5.3.3",
"vitest": "1.2.1"
},
"gitHead": "3905ed045508b861b495f8d5630d76c7a157d8f1"
}
Original file line number Diff line number Diff line change
@@ -1,10 +1,12 @@
import { vi, test, expect } from 'vitest'

import { command, description, builder, handler } from '../setup'

// mock Telemetry for CLI commands so they don't try to spawn a process
jest.mock('@redwoodjs/telemetry', () => {
vi.mock('@redwoodjs/telemetry', () => {
return {
errorTelemetry: () => jest.fn(),
timedTelemetry: () => jest.fn(),
errorTelemetry: () => vi.fn(),
timedTelemetry: () => vi.fn(),
}
})

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
import { defineConfig, configDefaults } from 'vitest/config'

export default defineConfig({
test: {
exclude: [...configDefaults.exclude, '**/fixtures'],
},
})

This file was deleted.

8 changes: 4 additions & 4 deletions packages/auth-providers/azureActiveDirectory/web/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,8 @@
"build:types": "tsc --build --verbose",
"build:watch": "nodemon --watch src --ext \"js,jsx,ts,tsx,template\" --ignore dist --exec \"yarn build\"",
"prepublishOnly": "NODE_ENV=production yarn build",
"test": "jest src",
"test:watch": "yarn test --watch"
"test": "vitest run src",
"test:watch": "vitest watch src"
},
"dependencies": {
"@babel/runtime-corejs3": "7.23.6",
Expand All @@ -33,9 +33,9 @@
"@babel/core": "^7.22.20",
"@types/netlify-identity-widget": "1.9.6",
"@types/react": "18.2.37",
"jest": "29.7.0",
"react": "0.0.0-experimental-e5205658f-20230913",
"typescript": "5.3.3"
"typescript": "5.3.3",
"vitest": "1.2.1"
},
"peerDependencies": {
"@azure/msal-browser": "2.38.3"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import type {
RedirectRequest,
} from '@azure/msal-browser'
import { renderHook, act } from '@testing-library/react'
import { vi, it, expect, describe, beforeAll, beforeEach } from 'vitest'

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

Expand Down Expand Up @@ -79,7 +80,7 @@ const azureActiveDirectoryMockClient: Partial<AzureActiveDirectoryClient> = {
},
}

const fetchMock = jest.fn()
const fetchMock = vi.fn()
fetchMock.mockImplementation(async (_url, options) => {
const body = options?.body ? JSON.parse(options.body) : {}

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
import { defineConfig, configDefaults } from 'vitest/config'

export default defineConfig({
test: {
exclude: [...configDefaults.exclude, '**/fixtures'],
environment: 'jsdom',
},
})
4 changes: 0 additions & 4 deletions packages/auth-providers/clerk/api/jest.config.js

This file was deleted.

8 changes: 4 additions & 4 deletions packages/auth-providers/clerk/api/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,8 @@
"build:types": "tsc --build --verbose",
"build:watch": "nodemon --watch src --ext \"js,jsx,ts,tsx,template\" --ignore dist --exec \"yarn build\"",
"prepublishOnly": "NODE_ENV=production yarn build",
"test": "jest src",
"test:watch": "yarn test --watch"
"test": "vitest run src",
"test:watch": "vitest watch src"
},
"dependencies": {
"@babel/runtime-corejs3": "7.23.6",
Expand All @@ -32,8 +32,8 @@
"@babel/core": "^7.22.20",
"@redwoodjs/api": "6.0.7",
"@types/aws-lambda": "8.10.126",
"jest": "29.7.0",
"typescript": "5.3.3"
"typescript": "5.3.3",
"vitest": "1.2.1"
},
"gitHead": "3905ed045508b861b495f8d5630d76c7a157d8f1"
}
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import type { APIGatewayProxyEvent, Context as LambdaContext } from 'aws-lambda'
import { beforeAll, afterAll, describe, test, expect } from 'vitest'

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

Expand Down
7 changes: 7 additions & 0 deletions packages/auth-providers/clerk/api/vitest.config.mts
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
import { defineConfig, configDefaults } from 'vitest/config'

export default defineConfig({
test: {
exclude: [...configDefaults.exclude, '**/fixtures'],
},
})
4 changes: 0 additions & 4 deletions packages/auth-providers/clerk/setup/jest.config.js

This file was deleted.

5 changes: 1 addition & 4 deletions packages/auth-providers/clerk/setup/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,7 @@
"build:pack": "yarn pack -o redwoodjs-auth-clerk-setup.tgz",
"build:types": "tsc --build --verbose",
"build:watch": "nodemon --watch src --ext \"js,jsx,ts,tsx,template\" --ignore dist --exec \"yarn build\"",
"prepublishOnly": "NODE_ENV=production yarn build",
"test": "jest src --passWithNoTests",
"test:watch": "yarn test --watch"
"prepublishOnly": "NODE_ENV=production yarn build"
},
"dependencies": {
"@babel/runtime-corejs3": "7.23.6",
Expand All @@ -31,7 +29,6 @@
"@babel/cli": "7.23.4",
"@babel/core": "^7.22.20",
"@types/yargs": "17.0.32",
"jest": "29.7.0",
"typescript": "5.3.3"
},
"gitHead": "3905ed045508b861b495f8d5630d76c7a157d8f1"
Expand Down
5 changes: 0 additions & 5 deletions packages/auth-providers/clerk/web/jest.config.js

This file was deleted.

Loading

0 comments on commit 352af62

Please sign in to comment.