From 51c4118a9d8037816d6c22d509481c9f337511cb Mon Sep 17 00:00:00 2001 From: Frank Noirot Date: Thu, 21 Mar 2024 16:01:58 -0400 Subject: [PATCH] Clarify and simplify dev setup --- .env.development | 2 ++ .env.example | 5 +---- README.md | 22 +++++++------------ package.json | 1 + playwright.config.ts | 2 +- src/routes/+layout.server.ts | 2 +- .../api/convert/[output_format]/+server.ts | 4 +++- src/routes/api/get-generation/+server.ts | 2 +- src/routes/api/submit-feedback/+server.ts | 4 +++- src/routes/api/submit-prompt/+server.ts | 4 +++- 10 files changed, 24 insertions(+), 24 deletions(-) create mode 100644 .env.development diff --git a/.env.development b/.env.development new file mode 100644 index 0000000..ae628d2 --- /dev/null +++ b/.env.development @@ -0,0 +1,2 @@ +VITE_API_BASE_URL=https://api.dev.zoo.dev +VITE_SITE_BASE_URL=https://dev.zoo.dev \ No newline at end of file diff --git a/.env.example b/.env.example index 6e08406..2f7a9c2 100644 --- a/.env.example +++ b/.env.example @@ -1,4 +1 @@ -VITE_API_BASE_URL=https://api.dev.zoo.dev -VITE_SITE_BASE_URL=https://dev.zoo.dev -PLAYWRIGHT_SESSION_COOKIE="your-token-from-dev.zoo.dev" -VITE_TOKEN="your-token-from-dev.zoo.dev" \ No newline at end of file +VITE_ZOO_DEV_TOKEN="your-token-from-dev.zoo.dev" # A dev API token from dev.zoo.dev \ No newline at end of file diff --git a/README.md b/README.md index 2f72df6..de4d5c2 100644 --- a/README.md +++ b/README.md @@ -4,9 +4,10 @@ This repository is an open-source example of how to quickly get up and running w ## Developing -1. Get a dev api token from: https://dev.zoo.dev -2. Set a `VITE_TOKEN` environment variable in `./.env.development` -3. Run the dev server with `yarn dev -- --open` +1. Remove the `.example` from `/.env.example`, leaving it `.env` (Git will ignore this and prevent you from accidentally publishing your dev API token) +2. Set the `VITE_ZOO_DEV_TOKEN` environment variable in with a **dev** API token from: https://dev.zoo.dev in `/.env` +3. Set the `PLAYWRIGHT_TESTING_TOKEN` environment variable with a **prod** API token from: https://zoo.dev in `/.env` +4. Run the dev server with `yarn dev -- --open` ## Building @@ -20,18 +21,11 @@ You can preview the production build with `yarn preview`. ## Before submitting a PR -Please run the following commands to ensure that your code is as ready for review as it can be: - -```bash -yarn fmt --fix && yarn test -``` +Please run the `yarn prep` to lint, format, type-check and test your code to ensure it's as ready for code review as possible. ### Running Playwright E2E tests locally -In order to run our Playwright testing suite locally, please set the `PLAYWRIGHT_SESSION_COOKIE` variable within `.env.development` to a token from a logged in local development session. You can retrieve it by: - -1. logging in to the project locally using the method outlined above -2. opening the Application tab in your browser developer tools -3. copying out the value of the cookie titled `__Secure-next-auth.session-token` with the domain of `localhost` +If you've set a `VITE_ZOO_DEV_TOKEN` in `/.env` as described above, you should be able to run the `yarn test` command successfully, which runs `yarn test:integration` and `yarn test:unit` in series. -Now you should be able to run the `yarn test:integration` and `yarn test` commands successfully. +- We use [Playwright](https://playwright.dev) for end-to-end testing. Try running `yarn test:integration --ui` for a handy visualizer of your tests as they run! +- We use [Vitest](https://vitest.dev) for unit and component testing. diff --git a/package.json b/package.json index c26a648..022f129 100644 --- a/package.json +++ b/package.json @@ -6,6 +6,7 @@ "dev": "vite dev", "build": "vite build", "preview": "vite preview", + "prep": "yarn fmt --fix && yarn check && yarn lint && yarn test", "test": "npm run test:integration && npm run test:unit run", "check": "svelte-kit sync && svelte-check --tsconfig ./tsconfig.json", "check:watch": "svelte-kit sync && svelte-check --tsconfig ./tsconfig.json --watch", diff --git a/playwright.config.ts b/playwright.config.ts index 34d9b41..46f683d 100644 --- a/playwright.config.ts +++ b/playwright.config.ts @@ -14,7 +14,7 @@ const config: PlaywrightTestConfig = { cookies: [ { name: AUTH_COOKIE_NAME, - value: process.env.PLAYWRIGHT_SESSION_COOKIE ?? '', + value: process.env.VITE_ZOO_DEV_TOKEN ?? '', domain: 'localhost', path: '/', expires: expiration.getTime() / 1000, diff --git a/src/routes/+layout.server.ts b/src/routes/+layout.server.ts index 44fcef9..31bf1a5 100644 --- a/src/routes/+layout.server.ts +++ b/src/routes/+layout.server.ts @@ -5,7 +5,7 @@ export const load = async ({ locals, cookies }) => { const token = import.meta.env.MODE === 'production' ? cookies.get(AUTH_COOKIE_NAME) - : import.meta.env.VITE_TOKEN + : import.meta.env.VITE_ZOO_DEV_TOKEN return { user: !locals.user || 'error_code' in locals.user ? undefined : locals.user, diff --git a/src/routes/api/convert/[output_format]/+server.ts b/src/routes/api/convert/[output_format]/+server.ts index ba3192e..ebbd64c 100644 --- a/src/routes/api/convert/[output_format]/+server.ts +++ b/src/routes/api/convert/[output_format]/+server.ts @@ -9,7 +9,9 @@ export type ConvertResponse = Models['FileConversion_type'] & { } export const POST: RequestHandler = async ({ cookies, fetch, request, params }) => { - const token = import.meta.env.PROD ? cookies.get(AUTH_COOKIE_NAME) : import.meta.env.VITE_TOKEN + const token = import.meta.env.PROD + ? cookies.get(AUTH_COOKIE_NAME) + : import.meta.env.VITE_ZOO_DEV_TOKEN if (!token) throw error(401, 'You must be logged in to use this API.') const body = await request.text() diff --git a/src/routes/api/get-generation/+server.ts b/src/routes/api/get-generation/+server.ts index f167ade..adeaf51 100644 --- a/src/routes/api/get-generation/+server.ts +++ b/src/routes/api/get-generation/+server.ts @@ -11,7 +11,7 @@ export const POST: RequestHandler = async ({ cookies, fetch, request }) => { const token = import.meta.env.MODE === 'production' ? cookies.get(AUTH_COOKIE_NAME) - : import.meta.env.VITE_TOKEN + : import.meta.env.VITE_ZOO_DEV_TOKEN const body = await request.json() diff --git a/src/routes/api/submit-feedback/+server.ts b/src/routes/api/submit-feedback/+server.ts index 9b51ccb..013464d 100644 --- a/src/routes/api/submit-feedback/+server.ts +++ b/src/routes/api/submit-feedback/+server.ts @@ -8,7 +8,9 @@ export type LoadResponse = { } export const POST: RequestHandler = async ({ cookies, fetch, request }) => { - const token = import.meta.env.PROD ? cookies.get(AUTH_COOKIE_NAME) : import.meta.env.VITE_TOKEN + const token = import.meta.env.PROD + ? cookies.get(AUTH_COOKIE_NAME) + : import.meta.env.VITE_ZOO_DEV_TOKEN const body = await request.json() if (!(body?.id && body?.feedback)) diff --git a/src/routes/api/submit-prompt/+server.ts b/src/routes/api/submit-prompt/+server.ts index 1d3e401..5723470 100644 --- a/src/routes/api/submit-prompt/+server.ts +++ b/src/routes/api/submit-prompt/+server.ts @@ -9,7 +9,9 @@ export type PromptLoadResponse = { } export const POST: RequestHandler = async ({ cookies, fetch, request }) => { - const token = import.meta.env.PROD ? cookies.get(AUTH_COOKIE_NAME) : import.meta.env.VITE_TOKEN + const token = import.meta.env.PROD + ? cookies.get(AUTH_COOKIE_NAME) + : import.meta.env.VITE_ZOO_DEV_TOKEN if (!token) throw error(401, 'You must be logged in to use this API.') const body = await request.json()