Skip to content

Commit

Permalink
feat: setup vitest and test, use pnpm
Browse files Browse the repository at this point in the history
  • Loading branch information
micksabox committed Apr 4, 2024
1 parent 3976f0c commit 1bf3762
Show file tree
Hide file tree
Showing 7 changed files with 11,081 additions and 2 deletions.
59 changes: 59 additions & 0 deletions app/utils/env.server.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
/* eslint-disable @typescript-eslint/no-namespace */
/* eslint-disable @typescript-eslint/no-empty-interface */
import { z } from 'zod'

const schema = z.object({
NODE_ENV: z.enum(['production', 'development', 'test'] as const),
// If using database and sessions uncomment these
// DATABASE_PATH: z.string(),
// DATABASE_URL: z.string(),
// SESSION_SECRET: z.string(),
// INTERNAL_COMMAND_TOKEN: z.string(),
// HONEYPOT_SECRET: z.string(),
// If you plan on using Sentry, uncomment this line
// SENTRY_DSN: z.string(),
// If you plan to use Resend, uncomment this line
// RESEND_API_KEY: z.string(),
// If you plan to use GitHub auth, remove the default:
})

declare global {
namespace NodeJS {
interface ProcessEnv extends z.infer<typeof schema> {}
}
}

export function init() {
const parsed = schema.safeParse(process.env)

if (parsed.success === false) {
console.error('❌ Invalid environment variables:', parsed.error.flatten().fieldErrors)

throw new Error('Invalid environment variables')
}
}

/**
* This is used in both `entry.server.ts` and `root.tsx` to ensure that
* the environment variables are set and globally available before the app is
* started.
*
* NOTE: Do *not* add any environment variables in here that you do not wish to
* be included in the client.
* @returns all public ENV variables
*/
export function getEnv() {
return {
MODE: process.env.NODE_ENV,
// SENTRY_DSN: process.env.SENTRY_DSN,
}
}

type ENV = ReturnType<typeof getEnv>

declare global {
let ENV: ENV
interface Window {
ENV: ENV
}
}
7 changes: 6 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
"dev": "NODE_ENV=development remix dev --manual",
"build": "remix build",
"start": "remix-serve ./build/index.js",
"test": "vitest",
"typecheck": "tsc --noEmit",
"typecheck:watch": "tsc --noEmit --watch",
"lint": "eslint --quiet src --ext .ts,.tsx && stylelint src/**/*.less",
Expand Down Expand Up @@ -67,6 +68,9 @@
"@commitlint/config-conventional": "^17.4.4",
"@remix-run/dev": "^2.5.1",
"@tanstack/react-query-devtools": "^4.29.1",
"@testing-library/jest-dom": "^6.4.2",
"@testing-library/react": "^14.2.1",
"@testing-library/user-event": "^14.5.2",
"@types/js-yaml": "^4.0.9",
"@types/loadable__component": "^5.13.4",
"@types/node": "^18.15.11",
Expand Down Expand Up @@ -106,6 +110,7 @@
"vite": "^5.0.12",
"vite-plugin-external": "^1.2.8",
"vite-plugin-svgr": "^4.2.0",
"vite-tsconfig-paths": "^4.3.1"
"vite-tsconfig-paths": "^4.3.1",
"vitest": "^1.4.0"
}
}
Loading

0 comments on commit 1bf3762

Please sign in to comment.