Skip to content

Commit 72e0011

Browse files
authored
Get Playwright at least runnable (#197)
* Add utility `env`, fix TS type yelling * Replace all `import.meta.env`s with a wrapper * Update README to show the need for `.env.development.local` * fmt
1 parent 5e0b4db commit 72e0011

File tree

15 files changed

+43
-25
lines changed

15 files changed

+43
-25
lines changed

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ This repository is an open-source example of how to quickly get up and running w
44

55
To get started
66

7-
create a `.env` following .env.example
7+
create a `.env.development.local` following `.env.example`
88

99
then
1010

package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@
2121
"@sveltejs/vite-plugin-svelte": "^3.0.2",
2222
"@testing-library/jest-dom": "^6.2.0",
2323
"@testing-library/svelte": "^4.0.5",
24+
"@types/node": "^24.0.4",
2425
"@types/object.groupby": "^1.0.3",
2526
"@types/testing-library__jest-dom": "^6.0.0",
2627
"@types/three": "^0.160.0",

playwright.config.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,9 @@ import { AUTH_COOKIE_NAME } from './src/lib/cookies'
33
import dotenv from 'dotenv'
44
import path from 'path'
55

6-
dotenv.config({ path: path.resolve(path.dirname('.'), '.env.development') })
6+
dotenv.config({
7+
path: path.resolve(path.dirname('.'), `.env.development${process.env.CI ? '' : '.local'}`)
8+
})
79
const expiration = new Date()
810
expiration.setFullYear(expiration.getFullYear() + 1)
911

src/lib/consts.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ import { msSinceStartOfDay, msSinceStartOfMonth, msSinceAWeekAgo, msSinceStartOf
33
export const PERSIST_KEY_VERSION = '2024-06-21'
44
export const PERSIST_KEY_GENERATIONS = 'TEXT_TO_CAD_GENERATIONS'
55
export const PERSIST_KEY_UNREAD = 'TEXT_TO_CAD_UNREAD'
6-
export const DOMAIN = import.meta.env.DEV ? 'localhost' : '.zoo.dev'
6+
export const DOMAIN = (import.meta.env || process.env).DEV ? 'localhost' : '.zoo.dev'
77

88
export const PLAYWRIGHT_MOCKING_HEADER = 'x-playwright-mocking'
99

src/lib/endpoints.ts

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import type { Models } from '@kittycad/lib/types'
22
import { ITEMS_PER_PAGE } from './consts'
3+
import { env } from '$lib/env'
34

45
export type CADFormat = Models['FileExportFormat_type']
56

@@ -21,18 +22,17 @@ interface ListParams {
2122

2223
export const endpoints = {
2324
convert: (output_format: CADFormat = 'obj') =>
24-
`${import.meta.env.VITE_API_BASE_URL}/file/conversion/gltf/${output_format}`,
25+
`${env.VITE_API_BASE_URL}/file/conversion/gltf/${output_format}`,
2526
feedback: (id: string, feedback: Models['TextToCad_type']['feedback']) =>
26-
`${import.meta.env.VITE_API_BASE_URL}/user/text-to-cad/${id}?feedback=${feedback}`,
27+
`${env.VITE_API_BASE_URL}/user/text-to-cad/${id}?feedback=${feedback}`,
2728
list: ({ limit = ITEMS_PER_PAGE, page_token }: ListParams) =>
28-
`${import.meta.env.VITE_API_BASE_URL}/user/text-to-cad?no_models=true&limit=${limit}${
29+
`${env.VITE_API_BASE_URL}/user/text-to-cad?no_models=true&limit=${limit}${
2930
page_token ? `&page_token=${page_token}` : ''
3031
}`,
3132
prompt: (output_format: CADFormat = 'gltf') =>
32-
`${import.meta.env.VITE_API_BASE_URL}/ai/text-to-cad/${output_format}`,
33-
view: (id: string) => `${import.meta.env.VITE_API_BASE_URL}/user/text-to-cad/${id}`,
34-
viewNoModels: (id: string) =>
35-
`${import.meta.env.VITE_API_BASE_URL}/user/text-to-cad/${id}?no_models=true`,
33+
`${env.VITE_API_BASE_URL}/ai/text-to-cad/${output_format}`,
34+
view: (id: string) => `${env.VITE_API_BASE_URL}/user/text-to-cad/${id}`,
35+
viewNoModels: (id: string) => `${env.VITE_API_BASE_URL}/user/text-to-cad/${id}?no_models=true`,
3636
localConvert: (output_format: CADFormat) => `/api/convert/${output_format}`,
3737
localFeedback: `/api/submit-feedback`
3838
}

src/lib/env.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
export const env = import.meta.env || process.env

src/lib/paths.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
export const SIGN_OUT_PARAM = 'signout'
2+
import { env } from '$lib/env'
23

3-
const SITE = import.meta.env.VITE_SITE_BASE_URL
4+
const SITE = env.VITE_SITE_BASE_URL
45
const GITHUB_REPO = `https://github.com/KittyCAD/text-to-cad-ui`
56

67
export const paths = {

src/routes/(sidebarLayout)/+layout.server.ts

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,20 +3,21 @@ import { AUTH_COOKIE_NAME } from '$lib/cookies.js'
33
import { hooksUserMocks, isUserMock } from '$lib/mocks.js'
44
import { SIGN_OUT_PARAM } from '$lib/paths.js'
55
import { redirect } from '@sveltejs/kit'
6+
import { env } from '$lib/env'
67

78
export const load = async ({ cookies, request, url, fetch }) => {
89
if (url.searchParams.get(SIGN_OUT_PARAM)) {
910
signOut()
1011
}
1112

1213
const mockRequestHeader = request.headers.get(PLAYWRIGHT_MOCKING_HEADER)
13-
const token = import.meta.env.PROD ? cookies.get(AUTH_COOKIE_NAME) : import.meta.env.VITE_TOKEN
14+
const token = env.PROD ? cookies.get(AUTH_COOKIE_NAME) : env.VITE_TOKEN
1415

1516
if (!token) {
1617
signOut()
1718
}
1819

19-
const currentUser = await fetch(import.meta.env.VITE_API_BASE_URL + '/user', {
20+
const currentUser = await fetch(env.VITE_API_BASE_URL + '/user', {
2021
method: 'GET',
2122
headers: {
2223
'Content-Type': 'application/json',

src/routes/+layout.server.ts

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,9 @@
11
import { AUTH_COOKIE_NAME } from '$lib/cookies.js'
2+
import { env } from '$lib/env'
23

34
/** @type {import('./$types').LayoutData} */
45
export const load = async ({ locals, cookies }) => {
5-
const token =
6-
import.meta.env.MODE === 'production'
7-
? cookies.get(AUTH_COOKIE_NAME)
8-
: import.meta.env.VITE_TOKEN
6+
const token = env.MODE === 'production' ? cookies.get(AUTH_COOKIE_NAME) : env.VITE_TOKEN
97

108
return {
119
user: !locals.user || 'error_code' in locals.user ? undefined : locals.user,

src/routes/+page.server.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,9 @@
11
import { AUTH_COOKIE_NAME } from '$lib/cookies.js'
22
import { redirect } from '@sveltejs/kit'
3+
import { env } from '$lib/env'
34

45
export const load = async ({ cookies, url }) => {
5-
const token = import.meta.env.PROD ? cookies.get(AUTH_COOKIE_NAME) : import.meta.env.VITE_TOKEN
6+
const token = env.PROD ? cookies.get(AUTH_COOKIE_NAME) : env.VITE_TOKEN
67

78
if (token) {
89
throw redirect(302, '/dashboard' + (url.search || ''))

0 commit comments

Comments
 (0)