Skip to content

Commit c8cc147

Browse files
chore: add .env.test file and update package.json to use loadEnv for environment variables (#399)
1 parent 60cefb3 commit c8cc147

File tree

6 files changed

+17
-44
lines changed

6 files changed

+17
-44
lines changed

.env.test

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
CONVERTKIT_KEY="..."

app/lib/blog.server.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import invariant from "tiny-invariant";
1+
import assert from "node:assert";
22
import { LRUCache } from "lru-cache";
33
import yaml from "yaml";
44
import { processMarkdown } from "~/lib/md.server";
@@ -12,7 +12,7 @@ const postContentsBySlug = Object.fromEntries(
1212
eager: true,
1313
}),
1414
).map(([filePath, contents]) => {
15-
invariant(
15+
assert(
1616
typeof contents === "string",
1717
`Expected ${filePath} to be a string, but got ${typeof contents}`,
1818
);
@@ -43,7 +43,7 @@ export async function getBlogPost(slug: string): Promise<BlogPost> {
4343

4444
let result = await processMarkdown(contents);
4545
let { attributes, html } = result;
46-
invariant(
46+
assert(
4747
isMarkdownPostFrontmatter(attributes),
4848
`Invalid post frontmatter in ${slug}`,
4949
);
@@ -57,7 +57,7 @@ export async function getBlogPost(slug: string): Promise<BlogPost> {
5757
}
5858
attributes.authors = validatedAuthors;
5959

60-
invariant(
60+
assert(
6161
isMarkdownPostFrontmatter(attributes),
6262
`Invalid post frontmatter in ${slug}`,
6363
);

app/routes/jam/schedule.server.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import invariant from "tiny-invariant";
1+
import assert from "node:assert";
22
import yaml from "yaml";
33
import { processMarkdown } from "~/lib/md.server";
44
import { z } from "zod";
@@ -13,7 +13,7 @@ const speakerImageModules = import.meta.glob(
1313

1414
const imageUrlByKey = new Map(
1515
Object.entries(speakerImageModules).map(([path, url]) => {
16-
invariant(
16+
assert(
1717
typeof url === "string",
1818
`Speaker image "${path}" is not a string. Please check the schedule file.`,
1919
);
@@ -69,7 +69,7 @@ export async function getSchedule(): Promise<ScheduleItem[]> {
6969
let imgSrc: string | undefined;
7070
if (item.imgFilename) {
7171
imgSrc = imageUrlByKey.get(item.imgFilename);
72-
invariant(
72+
assert(
7373
imgSrc,
7474
`Speaker "${item.speaker}" has image filename "${item.imgFilename}" but no matching image file.`,
7575
);

package.json

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414
"deploy": "flyctl deploy --build-arg REMIX_TOKEN=${REMIX_TOKEN}",
1515
"push:stage": "git tag -f stage && git push origin stage -f",
1616
"start": "cross-env NODE_ENV=production node server.ts",
17-
"preview": "cross-env NODE_ENV=production dotenv node server.ts",
17+
"preview": "cross-env NODE_ENV=production node --env-file=.env server.ts",
1818
"lint": "eslint --cache --cache-location ./node_modules/.cache/eslint .",
1919
"lint:fix": "pnpm run lint -- --fix",
2020
"test": "vitest",
@@ -30,13 +30,12 @@
3030
"clsx": "^2.1.1",
3131
"cross-env": "^10.1.0",
3232
"cssnano": "^6.0.3",
33-
"dotenv": "^16.6.1",
3433
"emoji-regex": "^10.6.0",
3534
"escape-goat": "^4.0.0",
3635
"fathom-client": "^3.6.0",
3736
"feed": "^4.2.2",
3837
"front-matter": "^4.0.2",
39-
"isbot": "^4",
38+
"isbot": "^5",
4039
"lru-cache": "^10.1.0",
4140
"parse-numeric-range": "^1.3.0",
4241
"react": "^18.3.1",
@@ -55,7 +54,6 @@
5554
"shiki": "^0.14.7",
5655
"source-map-support": "^0.5.21",
5756
"svg2img": "^1.0.0-beta.2",
58-
"tiny-invariant": "^1.3.3",
5957
"unified": "^11.0.5",
6058
"unist-util-visit": "^5.0.0",
6159
"yaml": "^2.8.2",
@@ -78,7 +76,6 @@
7876
"@vitejs/plugin-react": "^5.1.4",
7977
"@vitest/coverage-v8": "^3.2.4",
8078
"autoprefixer": "^10.4.24",
81-
"dotenv-cli": "^7.4.4",
8279
"eslint": "^8.57.1",
8380
"eslint-config-prettier": "^10.1.8",
8481
"eslint-plugin-import": "^2.32.0",

pnpm-lock.yaml

Lines changed: 2 additions & 26 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

vitest.config.mts

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,14 @@
11
/// <reference types="vite/client" />
22

3-
import fs from "node:fs";
4-
import path from "node:path";
53
import { defineConfig } from "vitest/config";
4+
import { loadEnv } from "vite";
65
import react from "@vitejs/plugin-react";
76
import tsconfigPaths from "vite-tsconfig-paths";
8-
import dotenv from "dotenv";
97

10-
let env = dotenv.parse(
11-
fs.readFileSync(path.resolve(process.cwd(), ".env.example")),
12-
);
8+
// Load all env vars (no prefix filter) from .env, .env.test, etc.
9+
let env = loadEnv("test", process.cwd(), "");
10+
11+
console.log({ env });
1312

1413
export default defineConfig({
1514
plugins: [react(), tsconfigPaths()],

0 commit comments

Comments
 (0)