Skip to content

Commit c17d618

Browse files
authored
Remove checks for the undefined TEST environment variable (#7779)
* Remove unused TEST environment variable * Use the long form of mode flag for clarity
1 parent 250346c commit c17d618

File tree

8 files changed

+47
-74
lines changed

8 files changed

+47
-74
lines changed

interface.d.ts

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -72,13 +72,12 @@ export interface IElectronAPI {
7272
}
7373
process: {
7474
env: {
75+
NODE_ENV: string
7576
VITE_KITTYCAD_API_BASE_URL: string
7677
VITE_KITTYCAD_API_WEBSOCKET_URL: string
7778
VITE_KITTYCAD_API_TOKEN: string
7879
VITE_KITTYCAD_SITE_BASE_URL: string
7980
VITE_KITTYCAD_SITE_APP_URL: string
80-
NODE_ENV: string
81-
TEST: string
8281
}
8382
}
8483
kittycad: (access: string, args: any) => any

package.json

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -126,15 +126,15 @@
126126
"postinstall": "electron-rebuild",
127127
"generate:machine-api": "npx openapi-typescript ./openapi/machine-api.json -o src/lib/machine-api.d.ts",
128128
"tron:start": "electron-forge start",
129-
"tronb:vite:dev": "vite build -c vite.main.config.ts -m development && vite build -c vite.preload.config.ts -m development && vite build -c vite.renderer.config.ts -m development",
129+
"tronb:vite:dev": "vite build -c vite.main.config.ts --mode=development && vite build -c vite.preload.config.ts --mode=development && vite build -c vite.renderer.config.ts --mode=development",
130130
"tronb:vite:prod": "vite build -c vite.main.config.ts && vite build -c vite.preload.config.ts && vite build -c vite.renderer.config.ts",
131131
"tronb:package:dev": "npm run tronb:vite:dev && electron-builder --config electron-builder.yml",
132132
"tronb:package:prod": "npm run tronb:vite:prod && electron-builder --config electron-builder.yml --publish always",
133133
"test-setup": "npm install && npm run build:wasm",
134-
"test": "vitest --mode development",
134+
"test": "vitest --mode=development",
135135
"test:rust": "(cd rust && just test && just lint)",
136136
"test:snapshots": "cross-env TARGET=web NODE_ENV=development playwright test --config=playwright.config.ts --grep=@snapshot --trace=on",
137-
"test:unit": "vitest run --mode development --exclude **/jest-component-unit-tests/*",
137+
"test:unit": "vitest run --mode=development --exclude **/jest-component-unit-tests/*",
138138
"test:unit:components": "jest -c jest-component-unit-tests/jest.config.ts --rootDir jest-component-unit-tests/",
139139
"test:e2e:web": "cross-env TARGET=web NODE_ENV=development playwright test --config=playwright.config.ts --project=\"Google Chrome\" --grep=@web",
140140
"test:e2e:desktop": "cross-env TARGET=desktop playwright test --config=playwright.electron.config.ts --grep-invert=\"@snapshot|@web\"",

src/components/LspProvider.tsx

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@ import {
77
LanguageServerClient,
88
LspWorkerEventType,
99
} from '@kittycad/codemirror-lsp-client'
10-
import env from '@src/env'
1110
import React, { createContext, useContext, useMemo, useState } from 'react'
1211
import { useNavigate } from 'react-router-dom'
1312
import type * as LSP from 'vscode-languageserver-protocol'
@@ -78,7 +77,7 @@ export const LspProvider = ({ children }: { children: React.ReactNode }) => {
7877
// But the server happens async so we break this into two parts.
7978
// Below is the client and server promise.
8079
const { lspClient: kclLspClient } = useMemo(() => {
81-
if (!token || token === '' || env().TEST) {
80+
if (!token || token === '') {
8281
return { lspClient: null }
8382
}
8483

@@ -137,7 +136,7 @@ export const LspProvider = ({ children }: { children: React.ReactNode }) => {
137136
// We do not want to restart the server, its just wasteful.
138137
const kclLSP = useMemo(() => {
139138
let plugin = null
140-
if (isKclLspReady && !env().TEST && kclLspClient) {
139+
if (isKclLspReady && kclLspClient) {
141140
// Set up the lsp plugin.
142141
const lsp = kcl({
143142
documentUri: `file:///${PROJECT_ENTRYPOINT}`,
@@ -171,7 +170,7 @@ export const LspProvider = ({ children }: { children: React.ReactNode }) => {
171170
}, [kclLspClient, isKclLspReady])
172171

173172
const { lspClient: copilotLspClient } = useMemo(() => {
174-
if (!token || token === '' || env().TEST) {
173+
if (!token || token === '') {
175174
return { lspClient: null }
176175
}
177176

@@ -213,7 +212,7 @@ export const LspProvider = ({ children }: { children: React.ReactNode }) => {
213212
// We do not want to restart the server, its just wasteful.
214213
const copilotLSP = useMemo(() => {
215214
let plugin = null
216-
if (isCopilotLspReady && !env().TEST && copilotLspClient) {
215+
if (isCopilotLspReady && copilotLspClient) {
217216
// Set up the lsp plugin.
218217
const lsp = copilotPlugin({
219218
documentUri: `file:///${PROJECT_ENTRYPOINT}`,

src/components/ModelingSidebar/ModelingPanes/KclEditorPane.tsx

Lines changed: 33 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,6 @@ import {
3535
rectangularSelection,
3636
} from '@codemirror/view'
3737
import interact from '@replit/codemirror-interact'
38-
import env from '@src/env'
3938
import { useSelector } from '@xstate/react'
4039
import { useEffect, useMemo, useRef } from 'react'
4140

@@ -148,43 +147,40 @@ export const KclEditorPane = () => {
148147
if (kclLSP) extensions.push(Prec.highest(kclLSP))
149148
if (copilotLSP) extensions.push(copilotLSP)
150149

151-
// These extensions have proven to mess with vitest
152-
if (!env().TEST) {
153-
extensions.push(
154-
lintGutter(),
155-
lineNumbers(),
156-
highlightActiveLineGutter(),
157-
highlightSpecialChars(),
158-
foldGutter(),
159-
EditorState.allowMultipleSelections.of(true),
160-
indentOnInput(),
161-
bracketMatching(),
162-
closeBrackets(),
163-
highlightActiveLine(),
164-
highlightSelectionMatches(),
165-
syntaxHighlighting(defaultHighlightStyle, {
166-
fallback: true,
167-
}),
168-
rectangularSelection(),
169-
dropCursor(),
170-
interact({
171-
rules: [
172-
// a rule for a number dragger
173-
{
174-
// the regexp matching the value
175-
regexp: onMouseDragRegex,
176-
// set cursor to "ew-resize" on hover
177-
cursor: 'ew-resize',
178-
// change number value based on mouse X movement on drag
179-
onDrag: (text, setText, e) => {
180-
onMouseDragMakeANewNumber(text, setText, e)
181-
},
150+
extensions.push(
151+
lintGutter(),
152+
lineNumbers(),
153+
highlightActiveLineGutter(),
154+
highlightSpecialChars(),
155+
foldGutter(),
156+
EditorState.allowMultipleSelections.of(true),
157+
indentOnInput(),
158+
bracketMatching(),
159+
closeBrackets(),
160+
highlightActiveLine(),
161+
highlightSelectionMatches(),
162+
syntaxHighlighting(defaultHighlightStyle, {
163+
fallback: true,
164+
}),
165+
rectangularSelection(),
166+
dropCursor(),
167+
interact({
168+
rules: [
169+
// a rule for a number dragger
170+
{
171+
// the regexp matching the value
172+
regexp: onMouseDragRegex,
173+
// set cursor to "ew-resize" on hover
174+
cursor: 'ew-resize',
175+
// change number value based on mouse X movement on drag
176+
onDrag: (text, setText, e) => {
177+
onMouseDragMakeANewNumber(text, setText, e)
182178
},
183-
],
184-
})
185-
)
186-
if (textWrapping.current) extensions.push(EditorView.lineWrapping)
187-
}
179+
},
180+
],
181+
})
182+
)
183+
if (textWrapping.current) extensions.push(EditorView.lineWrapping)
188184

189185
return extensions
190186
}, [kclLSP, copilotLSP, textWrapping.current, cursorBlinking.current])

src/env.test.ts

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,6 @@ describe('@src/env', () => {
1414
VITE_KITTYCAD_API_TOKEN: 'redacted',
1515
VITE_KITTYCAD_SITE_BASE_URL: 'https://dev.zoo.dev',
1616
VITE_KITTYCAD_SITE_APP_URL: 'https://app.dev.zoo.dev',
17-
TEST: 'true',
1817
}
1918
const actual = env()
2019
expect(typeof actual.VITE_KITTYCAD_API_TOKEN).toBe('string')
@@ -34,7 +33,6 @@ describe('@src/env', () => {
3433
expect(typeof actual.VITE_KITTYCAD_API_TOKEN).toBe('string')
3534
expect(typeof actual.VITE_KITTYCAD_SITE_BASE_URL).toBe('string')
3635
expect(typeof actual.VITE_KITTYCAD_SITE_APP_URL).toBe('string')
37-
expect(typeof actual.TEST).toBe('string')
3836
})
3937
})
4038
describe('windowElectronProcessEnv', () => {
@@ -55,7 +53,6 @@ describe('@src/env', () => {
5553
VITE_KITTYCAD_API_TOKEN: 'redacted',
5654
VITE_KITTYCAD_SITE_BASE_URL: 'https://dev.zoo.dev',
5755
VITE_KITTYCAD_SITE_APP_URL: 'https://app.dev.zoo.dev',
58-
TEST: 'true',
5956
},
6057
},
6158
})
@@ -67,7 +64,6 @@ describe('@src/env', () => {
6764
VITE_KITTYCAD_API_TOKEN: 'redacted',
6865
VITE_KITTYCAD_SITE_BASE_URL: 'https://dev.zoo.dev',
6966
VITE_KITTYCAD_SITE_APP_URL: 'https://app.dev.zoo.dev',
70-
TEST: 'true',
7167
}
7268
const actual = windowElectronProcessEnv()
7369
expect(actual).toStrictEqual(expected)
@@ -94,7 +90,6 @@ describe('@src/env', () => {
9490
expect(typeof actual?.VITE_KITTYCAD_API_TOKEN).toBe('string')
9591
expect(typeof actual?.VITE_KITTYCAD_SITE_BASE_URL).toBe('string')
9692
expect(typeof actual?.VITE_KITTYCAD_SITE_APP_URL).toBe('string')
97-
expect(typeof actual?.TEST).toBe('string')
9893
})
9994
})
10095
})

src/env.ts

Lines changed: 0 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@ type EnvironmentVariables = {
55
readonly VITE_KITTYCAD_API_TOKEN: string | undefined
66
readonly VITE_KITTYCAD_SITE_BASE_URL: string | undefined
77
readonly VITE_KITTYCAD_SITE_APP_URL: string | undefined
8-
readonly TEST: string | undefined
98
}
109

1110
export const viteEnv = () => {
@@ -26,16 +25,7 @@ export const processEnv = () => {
2625
if (typeof process === 'undefined') {
2726
// Web, no window.process or process
2827
return undefined
29-
} else if (
30-
typeof process !== 'undefined' &&
31-
typeof window !== 'undefined' &&
32-
process.env.TEST !== 'true'
33-
) {
34-
// Web, you made window.process, why :(, need process.env.TEST to make sure the frontend gets evaluated.
35-
// The frontend can spoof this too :(
36-
return undefined
3728
}
38-
3929
return process.env
4030
}
4131

@@ -49,7 +39,6 @@ export const processEnv = () => {
4939
export default (): EnvironmentVariables => {
5040
// Compute the possible environment variables, order operation is important
5141
// runtime (TODO) > process.env > window.electron.process.env > import.meta.env
52-
5342
const viteOnly = viteEnv()
5443
const windowElectronProcessEnvOnly = windowElectronProcessEnv()
5544
const processEnvOnly = processEnv()
@@ -66,7 +55,6 @@ export default (): EnvironmentVariables => {
6655
(env.VITE_KITTYCAD_SITE_BASE_URL as string) || undefined,
6756
VITE_KITTYCAD_SITE_APP_URL:
6857
(env.VITE_KITTYCAD_SITE_APP_URL as string) || undefined,
69-
TEST: (env.TEST as string) || undefined,
7058
}
7159
return environmentVariables
7260
}

src/lib/settings/settingsUtils.ts

Lines changed: 6 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@ import type { Configuration } from '@rust/kcl-lib/bindings/Configuration'
22
import type { NamedView } from '@rust/kcl-lib/bindings/NamedView'
33
import type { ProjectConfiguration } from '@rust/kcl-lib/bindings/ProjectConfiguration'
44
import { default_app_settings } from '@rust/kcl-wasm-lib/pkg/kcl_wasm_lib'
5-
import env from '@src/env'
65

76
import {
87
defaultAppSettings,
@@ -548,14 +547,12 @@ export function getSettingInputType(setting: Setting) {
548547

549548
export const jsAppSettings = async (): Promise<DeepPartial<Configuration>> => {
550549
let jsAppSettings = default_app_settings()
551-
if (!env().TEST) {
552-
// TODO: https://github.com/KittyCAD/modeling-app/issues/6445
553-
const settings = await import('@src/lib/singletons').then((module) =>
554-
module.getSettings()
555-
)
556-
if (settings) {
557-
jsAppSettings = getAllCurrentSettings(settings)
558-
}
550+
// TODO: https://github.com/KittyCAD/modeling-app/issues/6445
551+
const settings = await import('@src/lib/singletons').then((module) =>
552+
module.getSettings()
553+
)
554+
if (settings) {
555+
jsAppSettings = getAllCurrentSettings(settings)
559556
}
560557
return settingsPayloadToConfiguration(jsAppSettings)
561558
}

src/preload.ts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -293,7 +293,6 @@ contextBridge.exposeInMainWorld('electron', {
293293
'VITE_KITTYCAD_API_TOKEN',
294294
'VITE_KITTYCAD_SITE_BASE_URL',
295295
'VITE_KITTYCAD_SITE_APP_URL',
296-
'TEST',
297296
])
298297
),
299298
},

0 commit comments

Comments
 (0)