Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Implement wasp/client/test API #1704

Merged
merged 1 commit into from
Jan 31, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -10,15 +10,19 @@ import { Query } from 'wasp/rpc'
import config from 'wasp/core/config'
import { HttpMethod, Route } from 'wasp/types'

// PRIVATE API
export type { Route } from 'wasp/types'

// PRIVATE API
export type MockQuery = <Input, Output, MockOutput extends Output>(
query: Query<Input, Output>,
resJson: MockOutput
) => void

// PRIVATE API
export type MockApi = (route: Route, resJson: unknown) => void

// PUBLIC API
// Inspired by the Tanstack React Query helper:
// https://github.com/TanStack/query/blob/4ae99561ca3383d6de3f4aad656a49ba4a17b57a/packages/react-query/src/__tests__/utils.tsx#L7-L26
export function renderInContext(ui: ReactElement): RenderResult {
Expand All @@ -39,6 +43,7 @@ export function renderInContext(ui: ReactElement): RenderResult {
}
}

// PUBLIC API
export function mockServer(): {
server: SetupServer
mockQuery: MockQuery
Expand Down
7 changes: 3 additions & 4 deletions waspc/data/Generator/templates/sdk/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -74,10 +74,8 @@
"./server/queries": "./dist/server/queries/index.js",
{=! Used by our code, uncodumented (but accessible) for users. =}
"./server/auth/email": "./dist/server/auth/email/index.js",
{=! Used by users, documented. =}
"./test": "./dist/test/index.js",
{=! Used by our code, uncodumented (but accessible) for users. =}
"./test/*": "./dist/test/*.js",
"./client/test/*": "./dist/client/test/*.js",
{=! Used by our code, uncodumented (but accessible) for users. =}
"./server/crud/*": "./dist/server/crud/*",
{=! Used by our code, uncodumented (but accessible) for users. =}
Expand Down Expand Up @@ -118,7 +116,8 @@
"./client/crud": "./dist/client/crud/index.js",
"./server/email": "./dist/server/email/index.js",
"./server/jobs": "./dist/server/jobs/index.js",
"./client/router": "./dist/client/router/index.js"
"./client/router": "./dist/client/router/index.js",
"./client/test": "./dist/client/test/index.js"
},
{=!
TypeScript doesn't care about the redirects we define above in "exports" field; those
Expand Down
2 changes: 1 addition & 1 deletion waspc/examples/todo-typescript/src/Todo.test.tsx
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { test, expect } from 'vitest'
import { screen } from '@testing-library/react'

import { mockServer, renderInContext } from 'wasp/test'
import { mockServer, renderInContext } from 'wasp/client/test'
import { getTasks } from 'wasp/rpc/queries'
import { Todo, areThereAnyTasks } from './Todo'
import { MainPage } from './MainPage'
Expand Down
4 changes: 2 additions & 2 deletions waspc/src/Wasp/Generator/SdkGenerator.hs
Original file line number Diff line number Diff line change
Expand Up @@ -93,9 +93,9 @@ genSdkReal spec =
genFileCopy [relfile|server/HttpError.ts|],
genFileCopy [relfile|server/AuthError.ts|],
genFileCopy [relfile|types/index.ts|],
genFileCopy [relfile|test/vitest/helpers.tsx|],
genFileCopy [relfile|test/index.ts|],
genFileCopy [relfile|server/jobs/pgBoss/types.ts|],
genFileCopy [relfile|client/test/vitest/helpers.tsx|],
genFileCopy [relfile|client/test/index.ts|],
genServerConfigFile spec,
genTsConfigJson,
genServerUtils spec,
Expand Down
Loading