Skip to content

Commit

Permalink
Merge pull request #835 from haohao-how/dev
Browse files Browse the repository at this point in the history
Remove .env.test file
  • Loading branch information
bradleyayers authored Feb 1, 2025
2 parents 8e7c57c + eb5a3e0 commit 49af4e4
Show file tree
Hide file tree
Showing 13 changed files with 35 additions and 36 deletions.
3 changes: 0 additions & 3 deletions .github/workflows/ci-daily.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
3 changes: 0 additions & 3 deletions .github/workflows/pr.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
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
Expand Up @@ -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
Expand Up @@ -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:
Expand Down
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";
Expand All @@ -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({
Expand All @@ -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`
Expand Down
2 changes: 1 addition & 1 deletion projects/app/src/client/ui/auth.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
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.
Expand Down
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`,
Expand Down Expand Up @@ -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({
Expand Down
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";
Expand Down Expand Up @@ -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);
Expand Down
1 change: 0 additions & 1 deletion projects/app/src/typings/node.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand Down
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__;

0 comments on commit 49af4e4

Please sign in to comment.