diff --git a/packages/graphql-server/.babelrc.js b/packages/graphql-server/.babelrc.js deleted file mode 100644 index 3b2c815712d9..000000000000 --- a/packages/graphql-server/.babelrc.js +++ /dev/null @@ -1 +0,0 @@ -module.exports = { extends: '../../babel.config.js' } diff --git a/packages/graphql-server/jest.config.js b/packages/graphql-server/jest.config.js deleted file mode 100644 index 278ea692b7d4..000000000000 --- a/packages/graphql-server/jest.config.js +++ /dev/null @@ -1,8 +0,0 @@ -module.exports = { - testMatch: ['**/__tests__/**/*.[jt]s?(x)', '**/*.test.[jt]s?(x)'], - testPathIgnorePatterns: ['fixtures', 'dist'], -} - -process.env = Object.assign(process.env, { - WEBHOOK_SECRET: 'MY_VOICE_IS_MY_PASSPORT_VERIFY_ME', -}) diff --git a/packages/graphql-server/package.json b/packages/graphql-server/package.json index 60bef2528c71..a9472d9d5b3e 100644 --- a/packages/graphql-server/package.json +++ b/packages/graphql-server/package.json @@ -18,8 +18,8 @@ "build:types": "tsc --build --verbose ./tsconfig.json", "build:watch": "nodemon --watch src --ext \"js,jsx,ts,tsx\" --ignore dist --exec \"yarn build\"", "prepublishOnly": "NODE_ENV=production yarn build", - "test": "jest src", - "test:watch": "yarn test --watch" + "test": "vitest run", + "test:watch": "vitest" }, "dependencies": { "@babel/runtime-corejs3": "7.25.0", @@ -57,10 +57,10 @@ "@types/lodash": "4.17.7", "@types/uuid": "10.0.0", "@whatwg-node/fetch": "0.9.20", - "jest": "29.7.0", "jsonwebtoken": "9.0.2", "tsx": "4.17.0", - "typescript": "5.5.4" + "typescript": "5.5.4", + "vitest": "2.0.5" }, "gitHead": "3905ed045508b861b495f8d5630d76c7a157d8f1" } diff --git a/packages/graphql-server/src/__tests__/__snapshots__/graphiql.test.ts.snap b/packages/graphql-server/src/__tests__/__snapshots__/graphiql.test.ts.snap index 407806882a52..759bd8736a5f 100644 --- a/packages/graphql-server/src/__tests__/__snapshots__/graphiql.test.ts.snap +++ b/packages/graphql-server/src/__tests__/__snapshots__/graphiql.test.ts.snap @@ -1,6 +1,6 @@ -// Jest Snapshot v1, https://goo.gl/fbAQLP +// Vitest Snapshot v1, https://vitest.dev/guide/snapshot.html -exports[`configureGraphiQLPlayground when in development should configure the GraphiQL Playground when allowGraphiQL is not provided 1`] = ` +exports[`configureGraphiQLPlayground > when in development > should configure the GraphiQL Playground when allowGraphiQL is not provided 1`] = ` { "defaultQuery": "query Redwood { redwood { @@ -13,7 +13,7 @@ exports[`configureGraphiQLPlayground when in development should configure the Gr } `; -exports[`configureGraphiQLPlayground when in development should configure the GraphiQL Playground when allowGraphiQL is null 1`] = ` +exports[`configureGraphiQLPlayground > when in development > should configure the GraphiQL Playground when allowGraphiQL is null 1`] = ` { "defaultQuery": "query Redwood { redwood { @@ -26,7 +26,7 @@ exports[`configureGraphiQLPlayground when in development should configure the Gr } `; -exports[`configureGraphiQLPlayground when in development should configure the GraphiQL Playground when allowGraphiQL is true 1`] = ` +exports[`configureGraphiQLPlayground > when in development > should configure the GraphiQL Playground when allowGraphiQL is true 1`] = ` { "defaultQuery": "query Redwood { redwood { @@ -39,7 +39,7 @@ exports[`configureGraphiQLPlayground when in development should configure the Gr } `; -exports[`configureGraphiQLPlayground when in development should configure the GraphiQL Playground when allowGraphiQL is undefined 1`] = ` +exports[`configureGraphiQLPlayground > when in development > should configure the GraphiQL Playground when allowGraphiQL is undefined 1`] = ` { "defaultQuery": "query Redwood { redwood { @@ -52,7 +52,7 @@ exports[`configureGraphiQLPlayground when in development should configure the Gr } `; -exports[`configureGraphiQLPlayground when in development should configure the GraphiQL Playground when no config is provided 1`] = ` +exports[`configureGraphiQLPlayground > when in development > should configure the GraphiQL Playground when no config is provided 1`] = ` { "defaultQuery": "query Redwood { redwood { @@ -65,7 +65,7 @@ exports[`configureGraphiQLPlayground when in development should configure the Gr } `; -exports[`configureGraphiQLPlayground when not in development environment should configure the GraphiQL Playground when allowGraphiQL is true 1`] = ` +exports[`configureGraphiQLPlayground > when not in development environment > should configure the GraphiQL Playground when allowGraphiQL is true 1`] = ` { "defaultQuery": "query Redwood { redwood { diff --git a/packages/graphql-server/src/__tests__/cors.test.ts b/packages/graphql-server/src/__tests__/cors.test.ts index 7bbd936277cd..93574504dcae 100644 --- a/packages/graphql-server/src/__tests__/cors.test.ts +++ b/packages/graphql-server/src/__tests__/cors.test.ts @@ -1,11 +1,12 @@ import type { APIGatewayProxyEvent, Context } from 'aws-lambda' +import { vi, describe, it, expect } from 'vitest' import { createLogger } from '@redwoodjs/api/logger' import { createGraphQLHandler } from '../functions/graphql' -jest.mock('../makeMergedSchema', () => { - const { makeExecutableSchema } = require('@graphql-tools/schema') +vi.mock('../makeMergedSchema', async () => { + const { makeExecutableSchema } = await import('@graphql-tools/schema') // Return executable schema return { makeMergedSchema: () => @@ -46,7 +47,7 @@ jest.mock('../makeMergedSchema', () => { } }) -jest.mock('../directives/makeDirectives', () => { +vi.mock('../directives/makeDirectives', () => { return { makeDirectivesForPlugin: () => [], } diff --git a/packages/graphql-server/src/__tests__/graphiql.test.ts b/packages/graphql-server/src/__tests__/graphiql.test.ts index e3cc52ae6b67..9a60bb6d81ca 100644 --- a/packages/graphql-server/src/__tests__/graphiql.test.ts +++ b/packages/graphql-server/src/__tests__/graphiql.test.ts @@ -1,3 +1,5 @@ +import { describe, beforeAll, afterAll, it, expect } from 'vitest' + import { configureGraphiQLPlayground } from '../graphiql' describe('configureGraphiQLPlayground', () => { diff --git a/packages/graphql-server/src/__tests__/introspection.test.ts b/packages/graphql-server/src/__tests__/introspection.test.ts index 25fb83604275..e547f6612fe0 100644 --- a/packages/graphql-server/src/__tests__/introspection.test.ts +++ b/packages/graphql-server/src/__tests__/introspection.test.ts @@ -1,3 +1,5 @@ +import { describe, beforeAll, afterAll, it, expect } from 'vitest' + import { configureGraphQLIntrospection } from '../introspection' describe('configureGraphQLIntrospection', () => { diff --git a/packages/graphql-server/src/__tests__/makeDirectives.test.ts b/packages/graphql-server/src/__tests__/makeDirectives.test.ts index 9209954019a4..61834b8a4040 100644 --- a/packages/graphql-server/src/__tests__/makeDirectives.test.ts +++ b/packages/graphql-server/src/__tests__/makeDirectives.test.ts @@ -1,4 +1,5 @@ import gql from 'graphql-tag' +import { describe, it, test, expect } from 'vitest' import type { DirectiveParams } from '..' import { diff --git a/packages/graphql-server/src/__tests__/makeMergedSchema.test.ts b/packages/graphql-server/src/__tests__/makeMergedSchema.test.ts index 5dcdd5c9b16b..9804e8564d76 100644 --- a/packages/graphql-server/src/__tests__/makeMergedSchema.test.ts +++ b/packages/graphql-server/src/__tests__/makeMergedSchema.test.ts @@ -1,6 +1,7 @@ import type { GraphQLResolveInfo } from 'graphql' import { parse, graphql, GraphQLError } from 'graphql' import gql from 'graphql-tag' +import { vi, describe, it, expect } from 'vitest' import { makeDirectivesForPlugin, @@ -14,7 +15,7 @@ import type { SdlGlobImports, } from '../types' -jest.mock('@redwoodjs/project-config', () => { +vi.mock('@redwoodjs/project-config', () => { return { getConfig: () => { return { diff --git a/packages/graphql-server/src/__tests__/makeSubscriptions.test.ts b/packages/graphql-server/src/__tests__/makeSubscriptions.test.ts index d7d7496d3d6a..98554f718cde 100644 --- a/packages/graphql-server/src/__tests__/makeSubscriptions.test.ts +++ b/packages/graphql-server/src/__tests__/makeSubscriptions.test.ts @@ -1,4 +1,5 @@ import gql from 'graphql-tag' +import { describe, it, expect } from 'vitest' import { makeSubscriptions } from '../subscriptions/makeSubscriptions' const countdownSchema = gql` diff --git a/packages/graphql-server/src/__tests__/mapRwCorsToYoga.test.ts b/packages/graphql-server/src/__tests__/mapRwCorsToYoga.test.ts index 5869e401cc87..2ce32c9078c3 100644 --- a/packages/graphql-server/src/__tests__/mapRwCorsToYoga.test.ts +++ b/packages/graphql-server/src/__tests__/mapRwCorsToYoga.test.ts @@ -1,3 +1,5 @@ +import { describe, it, expect } from 'vitest' + import { mapRwCorsOptionsToYoga } from '../cors' /** Yoga CORS Options looks like diff --git a/packages/graphql-server/src/functions/__tests__/authDecoders.test.ts b/packages/graphql-server/src/functions/__tests__/authDecoders.test.ts index dced7179a262..4155bc0b3d07 100644 --- a/packages/graphql-server/src/functions/__tests__/authDecoders.test.ts +++ b/packages/graphql-server/src/functions/__tests__/authDecoders.test.ts @@ -1,11 +1,13 @@ import type { APIGatewayProxyEvent, Context } from 'aws-lambda' +import { vi, describe, it, expect } from 'vitest' import { createLogger } from '@redwoodjs/api/logger' import { createGraphQLHandler } from '../../functions/graphql' -jest.mock('../../makeMergedSchema', () => { - const { makeExecutableSchema } = require('@graphql-tools/schema') +vi.mock('../../makeMergedSchema', async () => { + const { makeExecutableSchema } = await import('@graphql-tools/schema') + const { context } = await import('@redwoodjs/context') // Return executable schema return { @@ -27,7 +29,7 @@ jest.mock('../../makeMergedSchema', () => { resolvers: { Query: { me: () => { - const globalContext = require('@redwoodjs/context').context + const globalContext = context as any const currentUser = globalContext.currentUser return { @@ -44,7 +46,7 @@ jest.mock('../../makeMergedSchema', () => { } }) -jest.mock('../../directives/makeDirectives', () => { +vi.mock('../../directives/makeDirectives', () => { return { makeDirectivesForPlugin: () => [], } diff --git a/packages/graphql-server/src/functions/__tests__/globalContext.test.ts b/packages/graphql-server/src/functions/__tests__/globalContext.test.ts index 7df76ce30531..b93592f1a538 100644 --- a/packages/graphql-server/src/functions/__tests__/globalContext.test.ts +++ b/packages/graphql-server/src/functions/__tests__/globalContext.test.ts @@ -1,3 +1,5 @@ +import { describe, it, expect } from 'vitest' + import { context as globalContext, setContext } from '@redwoodjs/context' import { getAsyncStoreInstance } from '@redwoodjs/context/dist/store' diff --git a/packages/graphql-server/src/functions/__tests__/healthCheck.test.ts b/packages/graphql-server/src/functions/__tests__/healthCheck.test.ts index 6e252baacc0a..995d30d0d35e 100644 --- a/packages/graphql-server/src/functions/__tests__/healthCheck.test.ts +++ b/packages/graphql-server/src/functions/__tests__/healthCheck.test.ts @@ -1,11 +1,12 @@ import type { APIGatewayProxyEvent, Context } from 'aws-lambda' +import { vi, describe, it, expect } from 'vitest' import { createLogger } from '@redwoodjs/api/logger' import { createGraphQLHandler } from '../../functions/graphql' -jest.mock('../../makeMergedSchema', () => { - const { makeExecutableSchema } = require('@graphql-tools/schema') +vi.mock('../../makeMergedSchema', async () => { + const { makeExecutableSchema } = await import('@graphql-tools/schema') // Return executable schema return { @@ -32,7 +33,7 @@ jest.mock('../../makeMergedSchema', () => { } }) -jest.mock('../../directives/makeDirectives', () => { +vi.mock('../../directives/makeDirectives', () => { return { makeDirectivesForPlugin: () => [], } diff --git a/packages/graphql-server/src/functions/__tests__/readinessCheck.test.ts b/packages/graphql-server/src/functions/__tests__/readinessCheck.test.ts index df1916a692f0..2aa37ea1b62c 100644 --- a/packages/graphql-server/src/functions/__tests__/readinessCheck.test.ts +++ b/packages/graphql-server/src/functions/__tests__/readinessCheck.test.ts @@ -1,11 +1,12 @@ import type { APIGatewayProxyEvent, Context } from 'aws-lambda' +import { vi, describe, expect, it } from 'vitest' import { createLogger } from '@redwoodjs/api/logger' import { createGraphQLHandler } from '../../functions/graphql' -jest.mock('../../makeMergedSchema', () => { - const { makeExecutableSchema } = require('@graphql-tools/schema') +vi.mock('../../makeMergedSchema', async () => { + const { makeExecutableSchema } = await import('@graphql-tools/schema') // Return executable schema return { @@ -32,7 +33,7 @@ jest.mock('../../makeMergedSchema', () => { } }) -jest.mock('../../directives/makeDirectives', () => { +vi.mock('../../directives/makeDirectives', () => { return { makeDirectivesForPlugin: () => [], } diff --git a/packages/graphql-server/src/functions/__tests__/useRequireAuth.test.ts b/packages/graphql-server/src/functions/__tests__/useRequireAuth.test.ts index 7f8c362c14b7..3d81024f797d 100644 --- a/packages/graphql-server/src/functions/__tests__/useRequireAuth.test.ts +++ b/packages/graphql-server/src/functions/__tests__/useRequireAuth.test.ts @@ -1,8 +1,8 @@ import type { APIGatewayEvent, Context } from 'aws-lambda' import jwt from 'jsonwebtoken' +import { describe, it, expect } from 'vitest' import { AuthenticationError } from '../../errors' -import type { UseRequireAuth } from '../useRequireAuth' import { getCurrentUser } from './fixtures/auth' @@ -64,7 +64,7 @@ const handler = async ( ): Promise => { // @MARK // Don't use globalContext until beforeAll runs - const globalContext = require('@redwoodjs/context').context + const { context: globalContext } = await import('@redwoodjs/context') const currentUser = globalContext.currentUser return { @@ -83,7 +83,9 @@ const handlerWithAuthChecks = async ( // TODO: Add requireAuth('role') here // or isAuthenticated() - const { hasRole, isAuthenticated, requireAuth } = require('./fixtures/auth') + const { hasRole, isAuthenticated, requireAuth } = await import( + './fixtures/auth.js' + ) const body = { message: '', @@ -114,7 +116,7 @@ const handlerWithError = async ( ): Promise => { // @MARK // Don't use globalContext until beforeAll runs - const globalContext = require('@redwoodjs/context').context + const { context: globalContext } = await import('@redwoodjs/context') const currentUser = globalContext.currentUser try { @@ -150,9 +152,7 @@ describe('useRequireAuth', () => { // @MARK // Because we use context inside useRequireAuth, we only want to import this function // once we disable context isolation for our test - const { - useRequireAuth, - }: { useRequireAuth: UseRequireAuth } = require('../useRequireAuth') + const { useRequireAuth } = await import('../useRequireAuth.js') const handlerEnrichedWithAuthentication = useRequireAuth({ handlerFn: handler, @@ -184,9 +184,7 @@ describe('useRequireAuth', () => { // @MARK // Because we use context inside useRequireAuth, we only want to import this function // once we disable context isolation for our test - const { - useRequireAuth, - }: { useRequireAuth: UseRequireAuth } = require('../useRequireAuth') + const { useRequireAuth } = await import('../useRequireAuth.js') const handlerEnrichedWithAuthentication = useRequireAuth({ handlerFn: handler, @@ -226,9 +224,7 @@ describe('useRequireAuth', () => { }) it('is 200 status if an error occurs when getting current user info', async () => { - const { - useRequireAuth, - }: { useRequireAuth: UseRequireAuth } = require('../useRequireAuth') + const { useRequireAuth } = await import('../useRequireAuth.js') const handlerEnrichedWithAuthentication = useRequireAuth({ handlerFn: handler, @@ -251,9 +247,7 @@ describe('useRequireAuth', () => { }) it('is 200 status if no auth headers present', async () => { - const { - useRequireAuth, - }: { useRequireAuth: UseRequireAuth } = require('../useRequireAuth') + const { useRequireAuth } = await import('../useRequireAuth.js') const handlerEnrichedWithAuthentication = useRequireAuth({ handlerFn: handler, @@ -280,9 +274,7 @@ describe('useRequireAuth', () => { }) it('is 200 status with token if the auth provider is unsupported', async () => { - const { - useRequireAuth, - }: { useRequireAuth: UseRequireAuth } = require('../useRequireAuth') + const { useRequireAuth } = await import('../useRequireAuth.js') const handlerEnrichedWithAuthentication = useRequireAuth({ handlerFn: handler, @@ -313,9 +305,7 @@ describe('useRequireAuth', () => { }) it('returns 200 if decoding JWT succeeds for netlify', async () => { - const { - useRequireAuth, - }: { useRequireAuth: UseRequireAuth } = require('../useRequireAuth') + const { useRequireAuth } = await import('../useRequireAuth.js') const handlerEnrichedWithAuthentication = useRequireAuth({ handlerFn: handler, @@ -355,9 +345,7 @@ describe('useRequireAuth', () => { }) it('is 200 status if decoding JWT fails for netlify', async () => { - const { - useRequireAuth, - }: { useRequireAuth: UseRequireAuth } = require('../useRequireAuth') + const { useRequireAuth } = await import('../useRequireAuth.js') const handlerEnrichedWithAuthentication = useRequireAuth({ handlerFn: handler, @@ -381,9 +369,7 @@ describe('useRequireAuth', () => { }) it('is 200 status if decoding JWT fails for supabase', async () => { - const { - useRequireAuth, - }: { useRequireAuth: UseRequireAuth } = require('../useRequireAuth') + const { useRequireAuth } = await import('../useRequireAuth.js') const handlerEnrichedWithAuthentication = useRequireAuth({ handlerFn: handler, @@ -407,9 +393,7 @@ describe('useRequireAuth', () => { }) it('is 500 Server Error status if handler errors', async () => { - const { - useRequireAuth, - }: { useRequireAuth: UseRequireAuth } = require('../useRequireAuth') + const { useRequireAuth } = await import('../useRequireAuth.js') const customHeaders = { 'auth-provider': 'custom', @@ -433,9 +417,7 @@ describe('useRequireAuth', () => { }) it('enables the use of auth functions inside the handler to check that isAuthenticated blocks unauthenticated users', async () => { - const { - useRequireAuth, - }: { useRequireAuth: UseRequireAuth } = require('../useRequireAuth') + const { useRequireAuth } = await import('../useRequireAuth.js') const netlifyJWTHeaders = { 'auth-provider': 'netlify', @@ -459,9 +441,7 @@ describe('useRequireAuth', () => { }) it("enables the use of auth functions inside the handler to check that requireAuth throws if the user doesn't have the required role", async () => { - const { - useRequireAuth, - }: { useRequireAuth: UseRequireAuth } = require('../useRequireAuth') + const { useRequireAuth } = await import('../useRequireAuth.js') // Note: The Bearer token JWT contains: // { @@ -497,9 +477,7 @@ describe('useRequireAuth', () => { }) it('enables the use of auth functions inside the handler to check editor role', async () => { - const { - useRequireAuth, - }: { useRequireAuth: UseRequireAuth } = require('../useRequireAuth') + const { useRequireAuth } = await import('../useRequireAuth.js') // The authorization JWT is valid and has roles in app metadata // { diff --git a/packages/graphql-server/src/plugins/__tests__/useArmor.test.ts b/packages/graphql-server/src/plugins/__tests__/useArmor.test.ts index 4997e7a83505..01384e49e22f 100644 --- a/packages/graphql-server/src/plugins/__tests__/useArmor.test.ts +++ b/packages/graphql-server/src/plugins/__tests__/useArmor.test.ts @@ -1,11 +1,12 @@ import type { APIGatewayProxyEvent, Context } from 'aws-lambda' +import { vi, expect, it, describe } from 'vitest' import { createLogger } from '@redwoodjs/api/logger' import { createGraphQLHandler } from '../../functions/graphql' -jest.mock('../../makeMergedSchema', () => { - const { makeExecutableSchema } = require('@graphql-tools/schema') +vi.mock('../../makeMergedSchema', async () => { + const { makeExecutableSchema } = await import('@graphql-tools/schema') // Return executable schema return { @@ -64,7 +65,7 @@ jest.mock('../../makeMergedSchema', () => { } }) -jest.mock('../../directives/makeDirectives', () => { +vi.mock('../../directives/makeDirectives', () => { return { makeDirectivesForPlugin: () => [], } diff --git a/packages/graphql-server/src/plugins/__tests__/useRedwoodAuthContext.test.ts b/packages/graphql-server/src/plugins/__tests__/useRedwoodAuthContext.test.ts index ff5453c480d5..f0ae3c2e8e3d 100644 --- a/packages/graphql-server/src/plugins/__tests__/useRedwoodAuthContext.test.ts +++ b/packages/graphql-server/src/plugins/__tests__/useRedwoodAuthContext.test.ts @@ -1,15 +1,19 @@ import { useEngine } from '@envelop/core' import { createSpiedPlugin, createTestkit } from '@envelop/testing' import * as GraphQLJS from 'graphql' +import { vi, describe, beforeEach, it, expect } from 'vitest' + +import type apiPackage from '@redwoodjs/api' import { testSchema, testQuery } from '../__fixtures__/common' import { useRedwoodAuthContext } from '../useRedwoodAuthContext' const authDecoder = async (token: string) => ({ token }) -jest.mock('@redwoodjs/api', () => { +vi.mock('@redwoodjs/api', async (importOriginal) => { + const originalApi = await importOriginal() return { - ...jest.requireActual('@redwoodjs/api'), + ...originalApi, getAuthenticationContext: jest.fn().mockResolvedValue([ { sub: '1', email: 'ba@zin.ga' }, { diff --git a/packages/graphql-server/src/plugins/__tests__/useRedwoodDirective.test.ts b/packages/graphql-server/src/plugins/__tests__/useRedwoodDirective.test.ts index 88b4c3afe526..ad15f601dd96 100644 --- a/packages/graphql-server/src/plugins/__tests__/useRedwoodDirective.test.ts +++ b/packages/graphql-server/src/plugins/__tests__/useRedwoodDirective.test.ts @@ -5,6 +5,7 @@ import * as GraphQLJS from 'graphql' import { getDirectiveValues } from 'graphql' import type { Plugin } from 'graphql-yoga' import { createSchema } from 'graphql-yoga' +import { describe, it, expect } from 'vitest' import type { GraphQLTypeWithFields } from '../../index' import { useRedwoodDirective, DirectiveType } from '../useRedwoodDirective' diff --git a/packages/graphql-server/src/plugins/__tests__/useRedwoodError.test.ts b/packages/graphql-server/src/plugins/__tests__/useRedwoodError.test.ts index 56a0ddcb36b7..1fa4c5925e7b 100644 --- a/packages/graphql-server/src/plugins/__tests__/useRedwoodError.test.ts +++ b/packages/graphql-server/src/plugins/__tests__/useRedwoodError.test.ts @@ -1,5 +1,6 @@ import type { APIGatewayProxyEvent, Context } from 'aws-lambda' import { CurrencyDefinition, CurrencyResolver } from 'graphql-scalars' +import { vi, describe, it, expect } from 'vitest' import type { RedwoodError as RedwoodErrorType, @@ -9,16 +10,17 @@ import { createLogger } from '@redwoodjs/api/logger' import { createGraphQLHandler } from '../../functions/graphql' -jest.mock('../../makeMergedSchema', () => { - const { createGraphQLError } = require('graphql-yoga') - const { makeExecutableSchema } = require('@graphql-tools/schema') - const { - ForbiddenError, - RedwoodGraphQLError, - } = require('@redwoodjs/graphql-server/dist/errors') - - const { CurrencyResolver } = require('graphql-scalars') - const { RedwoodError, EmailValidationError } = require('@redwoodjs/api') as { +vi.mock('../../makeMergedSchema', async () => { + const { createGraphQLError } = await import('graphql-yoga') + const { makeExecutableSchema } = await import('@graphql-tools/schema') + const { ForbiddenError, RedwoodGraphQLError } = await import( + '@redwoodjs/graphql-server/dist/errors' + ) + + const { CurrencyResolver } = await import('graphql-scalars') + const { RedwoodError, EmailValidationError } = (await import( + '@redwoodjs/api' + )) as { RedwoodError: typeof RedwoodErrorType EmailValidationError: typeof EmailValidationErrorType } @@ -128,7 +130,7 @@ jest.mock('../../makeMergedSchema', () => { } }) -jest.mock('../../directives/makeDirectives', () => { +vi.mock('../../directives/makeDirectives', () => { return { makeDirectivesForPlugin: () => [], } diff --git a/packages/graphql-server/src/plugins/__tests__/useRedwoodGlobalContextSetter.test.ts b/packages/graphql-server/src/plugins/__tests__/useRedwoodGlobalContextSetter.test.ts index 639c7c6f88e2..6a24f01f825f 100644 --- a/packages/graphql-server/src/plugins/__tests__/useRedwoodGlobalContextSetter.test.ts +++ b/packages/graphql-server/src/plugins/__tests__/useRedwoodGlobalContextSetter.test.ts @@ -1,6 +1,7 @@ import { useEngine } from '@envelop/core' import { createTestkit } from '@envelop/testing' import * as GraphQLJS from 'graphql' +import { test, expect } from 'vitest' import type { GlobalContext } from '@redwoodjs/context' import { context, setContext } from '@redwoodjs/context' diff --git a/packages/graphql-server/src/plugins/__tests__/useRedwoodLogger.test.ts b/packages/graphql-server/src/plugins/__tests__/useRedwoodLogger.test.ts index 8a931256d911..9063a238538d 100644 --- a/packages/graphql-server/src/plugins/__tests__/useRedwoodLogger.test.ts +++ b/packages/graphql-server/src/plugins/__tests__/useRedwoodLogger.test.ts @@ -5,6 +5,7 @@ import { join } from 'path' import { useEngine } from '@envelop/core' import { createTestkit } from '@envelop/testing' import * as GraphQLJS from 'graphql' +import { describe, it, expect } from 'vitest' import type { Logger, LoggerOptions } from '@redwoodjs/api/logger' import { createLogger } from '@redwoodjs/api/logger' diff --git a/packages/graphql-server/src/plugins/__tests__/useRedwoodPopulateContext.test.ts b/packages/graphql-server/src/plugins/__tests__/useRedwoodPopulateContext.test.ts index 2e70c6837a31..b8d544bc23fe 100644 --- a/packages/graphql-server/src/plugins/__tests__/useRedwoodPopulateContext.test.ts +++ b/packages/graphql-server/src/plugins/__tests__/useRedwoodPopulateContext.test.ts @@ -1,6 +1,7 @@ import { useEngine } from '@envelop/core' import { createSpiedPlugin, createTestkit } from '@envelop/testing' import * as GraphQLJS from 'graphql' +import { describe, expect, it, beforeEach, vi } from 'vitest' import { testSchema, testQuery } from '../__fixtures__/common' import { useRedwoodPopulateContext } from '../useRedwoodPopulateContext' @@ -21,7 +22,7 @@ describe('Populates context', () => { }) it('Should extend context based on output of function', async () => { - const populateContextSpy = jest.fn(() => { + const populateContextSpy = vi.fn(() => { return { bazinga: true, } @@ -44,7 +45,7 @@ describe('Populates context', () => { }) it('Should extend context with an object, if one is provided', async () => { - const populateContextSpy = jest.fn(() => { + const populateContextSpy = vi.fn(() => { return { bazinga: true, } diff --git a/packages/graphql-server/vitest.config.mts b/packages/graphql-server/vitest.config.mts new file mode 100644 index 000000000000..aa13ec335cf4 --- /dev/null +++ b/packages/graphql-server/vitest.config.mts @@ -0,0 +1,16 @@ +import { defineConfig, configDefaults } from 'vitest/config' + +export default defineConfig({ + test: { + exclude: [...configDefaults.exclude, '**/fixtures'], + env: { + WEBHOOK_SECRET: 'MY_VOICE_IS_MY_PASSPORT_VERIFY_ME', + }, + setupFiles: ['vitest.setup.mts'], + server: { + deps: { + fallbackCJS: true, + }, + }, + }, +}) diff --git a/packages/graphql-server/vitest.setup.mts b/packages/graphql-server/vitest.setup.mts new file mode 100644 index 000000000000..d5add7b4f7ca --- /dev/null +++ b/packages/graphql-server/vitest.setup.mts @@ -0,0 +1,4 @@ +import { vi } from 'vitest' + +// @ts-expect-error ... +globalThis.jest = vi diff --git a/yarn.lock b/yarn.lock index 6555a867f99c..4c468508e6e6 100644 --- a/yarn.lock +++ b/yarn.lock @@ -8267,12 +8267,12 @@ __metadata: graphql-scalars: "npm:1.23.0" graphql-tag: "npm:2.12.6" graphql-yoga: "npm:5.6.3" - jest: "npm:29.7.0" jsonwebtoken: "npm:9.0.2" lodash: "npm:4.17.21" tsx: "npm:4.17.0" typescript: "npm:5.5.4" uuid: "npm:10.0.0" + vitest: "npm:2.0.5" languageName: unknown linkType: soft