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

Remove .env.test file #835

Merged
merged 2 commits into from
Feb 1, 2025
Merged
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
3 changes: 0 additions & 3 deletions .github/workflows/ci-daily.yml
Original file line number Diff line number Diff line change
@@ -30,9 +30,6 @@ jobs:
- run: moon ci --color --base $HHH_EMPTY_GIT_TREE
env:
CHROMATIC_PROJECT_TOKEN: ${{ secrets.CHROMATIC_PROJECT_TOKEN }}
# <.env.test>
EXPO_PUBLIC_REPLICACHE_LICENSE_KEY: HHH_TEST_LICENSE_KEY
# </.env.test>
# Magic "empty" tree https://jiby.tech/post/git-diff-empty-repo/, so
# that all files are seen as "affected" by moon ci, and thus all CI
# tests are run.
3 changes: 0 additions & 3 deletions .github/workflows/pr.yml
Original file line number Diff line number Diff line change
@@ -97,9 +97,6 @@ jobs:
moon-ci:
runs-on: ubuntu-latest
env:
# <.env.test>
EXPO_PUBLIC_REPLICACHE_LICENSE_KEY: HHH_TEST_LICENSE_KEY
# </.env.test>
VERCEL_ORG_ID: ${{ secrets.VERCEL_ORG_ID }}
VERCEL_PROJECT_ID: ${{ secrets.VERCEL_PROJECT_ID_STATIC }}
strategy:
2 changes: 0 additions & 2 deletions projects/app/.env.test

This file was deleted.

4 changes: 0 additions & 4 deletions projects/app/drizzle.config.ts
Original file line number Diff line number Diff line change
@@ -4,8 +4,4 @@ export default defineConfig({
schema: `./src/server/schema.ts`,
out: `./drizzle`,
dialect: `postgresql`,
dbCredentials: {
// eslint-disable-next-line @typescript-eslint/no-non-null-assertion
url: process.env.NEON_DATABASE_URL!,
},
});
2 changes: 0 additions & 2 deletions projects/app/moon.yml
Original file line number Diff line number Diff line change
@@ -228,15 +228,13 @@ tasks:
options:
envFile:
- .env.local
- .env.test

testWatch:
command: node --test --watch --import tsx "src/**/*.test.ts"
local: true
options:
envFile:
- .env.local
- .env.test

typecheck:
deps:
16 changes: 13 additions & 3 deletions projects/app/src/client/ui/ReplicacheContext.tsx
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import { trpc } from "@/client/trpc";
import { SrsType } from "@/data/model";
import { v4 } from "@/data/rizzleSchema";
import { replicacheLicenseKey } from "@/env";
import { AppRouter } from "@/server/routers/_app";
import { failFastIfMissingEnvVars } from "@/util/env";
import { nextReview, UpcomingReview } from "@/util/fsrs";
import { cookieSchema, r, RizzleReplicache } from "@/util/rizzle";
import { invariant } from "@haohaohow/lib/invariant";
@@ -17,13 +17,22 @@ import {
useRef,
useState,
} from "react";
import { HTTPRequestInfo, PullResponseV1, ReadTransaction } from "replicache";
import {
HTTPRequestInfo,
PullResponseV1,
ReadTransaction,
TEST_LICENSE_KEY,
} from "replicache";
import { useAuth, UseAuth2Data } from "./auth";
import { kvStore } from "./replicacheOptions";
import { useRenderGuard } from "./util";

export type Rizzle = RizzleReplicache<typeof v4>;

if (failFastIfMissingEnvVars) {
invariant(process.env.EXPO_PUBLIC_REPLICACHE_LICENSE_KEY != null);
}

const ReplicacheContext = createContext<Rizzle | null>(null);

function ReplicacheProviderWithDeps({
@@ -41,7 +50,8 @@ function ReplicacheProviderWithDeps({
return r.replicache(
{
name: replicacheDbName,
licenseKey: replicacheLicenseKey,
licenseKey:
process.env.EXPO_PUBLIC_REPLICACHE_LICENSE_KEY ?? TEST_LICENSE_KEY,
kvStore,
// No need for a custom logSink here, just using normal console.*
// functions are fine because `Sentry.captureConsoleIntegration`
2 changes: 1 addition & 1 deletion projects/app/src/client/ui/auth.ts
Original file line number Diff line number Diff line change
@@ -57,7 +57,7 @@ type AuthApi = {
signOut: () => void;
};

// TODO: how to handle beind anonymous then logging in but there's an existing
// TODO: how to handle being anonymous then logging in but there's an existing
// user. It's more like "switch user" than it is anything else. Maybe even in
// the anonymous case you should have to give your name? Only after you actually
// save some useful state.
2 changes: 1 addition & 1 deletion projects/app/src/client/ui/replicacheOptions.web.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { ReplicacheOptions } from "replicache";

// Intentionally DO NOT allow Expo top inline the environment variable,
// Intentionally DO NOT allow Expo to inline the environment variable,
// otherwise it will leak into the browser bundle otherwise the browser code
// will also think it's in static render mode and use the
// ExperimentalMemKVStore.
9 changes: 0 additions & 9 deletions projects/app/src/env.ts

This file was deleted.

15 changes: 9 additions & 6 deletions projects/app/src/server/lib/inngest.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,16 @@
import { failFastIfMissingEnvVars } from "@/util/env";
import { invariant } from "@haohaohow/lib/invariant";
import { sentryMiddleware } from "@inngest/middleware-sentry";
import { Inngest } from "inngest";
import * as postmark from "postmark";
import { z } from "zod";

const { POSTMARK_SERVER_TOKEN } = process.env;

if (failFastIfMissingEnvVars) {
invariant(POSTMARK_SERVER_TOKEN != null, `POSTMARK_SERVER_TOKEN is required`);
}

// Create a client to send and receive events
export const inngest = new Inngest({
id: `my-app`,
@@ -69,12 +76,8 @@ const helloWorldEmail = inngest.createFunction(
{ id: `hello-world-email` },
{ event: `test/hello.world.email` },
async ({ step }) => {
invariant(
process.env.POSTMARK_SERVER_TOKEN != null,
`POSTMARK_SERVER_TOKEN is required`,
);

const client = new postmark.ServerClient(process.env.POSTMARK_SERVER_TOKEN);
invariant(POSTMARK_SERVER_TOKEN != null);
const client = new postmark.ServerClient(POSTMARK_SERVER_TOKEN);

const response = await step.run(`sendEmail`, () =>
client.sendEmail({
3 changes: 2 additions & 1 deletion projects/app/src/server/schemaUtil.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import * as r from "@/data/rizzleSchema";
import { isRunningTests } from "@/util/env";
import { RizzleType, RizzleTypeDef } from "@/util/rizzle";
import { invariant } from "@haohaohow/lib/invariant";
import { ColumnBaseConfig, Table } from "drizzle-orm";
@@ -37,7 +38,7 @@ function unstable__columnName(column: PgCustomColumn): string {
* Adds the table and column name to Zod parsing errors to help debugging.
*/
function drizzleColumnTypeEnhancedErrors(column: PgCustomColumn) {
if (`NODE_TEST_CONTEXT` in process.env || __DEV__) {
if (isRunningTests || __DEV__) {
// *always* run this code path so that it fails loudly in tests/dev, rather
// than only in the case of a zod parsing.
unstable__columnName(column);
1 change: 0 additions & 1 deletion projects/app/src/typings/node.d.ts
Original file line number Diff line number Diff line change
@@ -14,7 +14,6 @@ declare global {
EXPO_PUBLIC_REPLICACHE_LICENSE_KEY?: string;
EXPO_PUBLIC_SENTRY_DSN?: string;
EXPO_PUBLIC_USE_STATIC?: string | boolean; // boolean during static render, string on web
NEON_DATABASE_URL?: string;
NODE_ENV?: string;
POSTMARK_SERVER_TOKEN?: string;
}
9 changes: 9 additions & 0 deletions projects/app/src/util/env.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
// true when running under the Node.js test runner.
export const isRunningTests = `NODE_TEST_CONTEXT` in process.env;

// true when running CI (e.g. `moon ci`). This can be different from running
// tests (e.g. when `eas build` runs).
export const isRunningCi = `CI` in process.env;

export const failFastIfMissingEnvVars =
!isRunningTests && !isRunningCi && !__DEV__;