slidebug
TTCTheo's Typesafe Cult
•Created by slidebug on 5/10/2023 in #questions
Vitest Test can't load serverRuntimeConfig
Hey im currently running into this error:
``
This is my userid.test.ts:
`
vitest.config.ts
``
So how to correctly mock the serverRuntimeConfig?
FAIL src/server/tests/userid.test.ts [ src/server/tests/userid.test.ts ]
TypeError: Cannot destructure property 'serverRuntimeConfig' of 'default(...)' as it is undefined.
❯ src/server/trpc/router/distribution-report.ts:20:9
18| import { loadMessages } from "utils/i18n";
19|
20| const { serverRuntimeConfig } = getConfig();
| ^
21|
22| /**
❯ src/server/trpc/router/index.ts:9:31
❯ src/server/tests/userid.test.ts:2:31
FAIL src/server/tests/userid.test.ts [ src/server/tests/userid.test.ts ]
TypeError: Cannot destructure property 'serverRuntimeConfig' of 'default(...)' as it is undefined.
❯ src/server/trpc/router/distribution-report.ts:20:9
18| import { loadMessages } from "utils/i18n";
19|
20| const { serverRuntimeConfig } = getConfig();
| ^
21|
22| /**
❯ src/server/trpc/router/index.ts:9:31
❯ src/server/tests/userid.test.ts:2:31
import { type inferProcedureInput } from "@trpc/server";
import { createInnerTRPCContext } from "server/trpc/context";
import { AppRouter, appRouter } from "server/trpc/router";
import { expect, test } from "vitest";
test("example router", async () => {
const ctx = createInnerTRPCContext({
session: {
user: { token: "123", role: "ADMIN" },
expires: "1",
},
});
const caller = appRouter.createCaller(ctx);
type Input = inferProcedureInput<AppRouter["user"]["getById"]>;
const input: Input = "1";
// i know that the code below won't work, but thats not the problem of this error.
const example = await caller.user.getById(input);
expect(example).toMatchObject({ greeting: "Hello test" });
});
import { type inferProcedureInput } from "@trpc/server";
import { createInnerTRPCContext } from "server/trpc/context";
import { AppRouter, appRouter } from "server/trpc/router";
import { expect, test } from "vitest";
test("example router", async () => {
const ctx = createInnerTRPCContext({
session: {
user: { token: "123", role: "ADMIN" },
expires: "1",
},
});
const caller = appRouter.createCaller(ctx);
type Input = inferProcedureInput<AppRouter["user"]["getById"]>;
const input: Input = "1";
// i know that the code below won't work, but thats not the problem of this error.
const example = await caller.user.getById(input);
expect(example).toMatchObject({ greeting: "Hello test" });
});
import { defineConfig, configDefaults } from "vitest/config";
import { resolve } from "path";
import tsconfigPaths from "vite-tsconfig-paths";
import react from "@vitejs/plugin-react";
import { loadEnvConfig } from "@next/env";
loadEnvConfig(process.cwd());
export default defineConfig({
plugins: [tsconfigPaths(), react()],
test: {
environment: "node",
exclude: [...configDefaults.exclude],
},
resolve: {
alias: [{ find: "@", replacement: resolve(__dirname, "./src") }],
},
});
import { defineConfig, configDefaults } from "vitest/config";
import { resolve } from "path";
import tsconfigPaths from "vite-tsconfig-paths";
import react from "@vitejs/plugin-react";
import { loadEnvConfig } from "@next/env";
loadEnvConfig(process.cwd());
export default defineConfig({
plugins: [tsconfigPaths(), react()],
test: {
environment: "node",
exclude: [...configDefaults.exclude],
},
resolve: {
alias: [{ find: "@", replacement: resolve(__dirname, "./src") }],
},
});
3 replies
TTCTheo's Typesafe Cult
•Created by slidebug on 1/12/2023 in #questions
Cannot read properties of undefined (reading 'id)
Hey guys i just started with create-t3-app and setup the discord auth.
but when im trying to login i get this error
https://next-auth.js.org/errors#jwt_session_error Cannot read properties of undefined (reading 'id')
https://next-auth.js.org/errors#jwt_session_error Cannot read properties of undefined (reading 'id')
11 replies