Add tested parser for terminal perf interaction toggle
Co-authored-by: Julius Marminge <[email protected]>
This commit is contained in:
1 parent
e51724767a
commit
20febcc58e
3 files changed
+60
-6
No files matched your search
@@ -4,17 +4,16 @@ import os from "node:os";
|
||||
import path from "node:path";
|
||||
|
||||
import { BrowserWindow, contentTracing, type WebContents } from "electron";
|
||||
import { shouldRunTerminalPerfInteractions } from "./perfConfig";
|
||||
|
||||
const PERF_AUTOMATION_ENABLED = process.env.T3CODE_DESKTOP_PERF_AUTOMATION === "1";
|
||||
const PERF_TRACE_OUT_PATH = process.env.T3CODE_DESKTOP_PERF_TRACE_OUT?.trim() ?? "";
|
||||
const PERF_DONE_OUT_PATH = process.env.T3CODE_DESKTOP_PERF_DONE_OUT?.trim() ?? "";
|
||||
const PERF_SEED_PATH = process.env.T3CODE_DESKTOP_PERF_SEED_PATH?.trim() ?? "";
|
||||
const RUN_TERMINAL_INTERACTIONS = (() => {
|
||||
const raw = process.env.T3CODE_DESKTOP_PERF_RUN_TERMINAL?.trim().toLowerCase();
|
||||
if (raw === "1" || raw === "true") return true;
|
||||
if (raw === "0" || raw === "false") return false;
|
||||
return process.env.CI !== "true";
|
||||
})();
|
||||
const RUN_TERMINAL_INTERACTIONS = shouldRunTerminalPerfInteractions({
|
||||
T3CODE_DESKTOP_PERF_RUN_TERMINAL: process.env.T3CODE_DESKTOP_PERF_RUN_TERMINAL,
|
||||
CI: process.env.CI,
|
||||
});
|
||||
|
||||
function delay(ms: number): Promise<void> {
|
||||
return new Promise((resolve) => setTimeout(resolve, ms));
|
||||
|
||||
@@ -0,0 +1,44 @@
|
||||
import { describe, expect, it } from "vitest";
|
||||
|
||||
import { shouldRunTerminalPerfInteractions } from "./perfConfig";
|
||||
|
||||
describe("shouldRunTerminalPerfInteractions", () => {
|
||||
it("defaults to enabled outside CI when env is unset", () => {
|
||||
expect(shouldRunTerminalPerfInteractions({ CI: "false" })).toBe(true);
|
||||
expect(shouldRunTerminalPerfInteractions({ CI: undefined })).toBe(true);
|
||||
});
|
||||
|
||||
it("defaults to disabled in CI when env is unset", () => {
|
||||
expect(shouldRunTerminalPerfInteractions({ CI: "true" })).toBe(false);
|
||||
});
|
||||
|
||||
it("supports explicit true values", () => {
|
||||
expect(
|
||||
shouldRunTerminalPerfInteractions({
|
||||
T3CODE_DESKTOP_PERF_RUN_TERMINAL: "1",
|
||||
CI: "true",
|
||||
}),
|
||||
).toBe(true);
|
||||
expect(
|
||||
shouldRunTerminalPerfInteractions({
|
||||
T3CODE_DESKTOP_PERF_RUN_TERMINAL: " true ",
|
||||
CI: "true",
|
||||
}),
|
||||
).toBe(true);
|
||||
});
|
||||
|
||||
it("supports explicit false values", () => {
|
||||
expect(
|
||||
shouldRunTerminalPerfInteractions({
|
||||
T3CODE_DESKTOP_PERF_RUN_TERMINAL: "0",
|
||||
CI: "false",
|
||||
}),
|
||||
).toBe(false);
|
||||
expect(
|
||||
shouldRunTerminalPerfInteractions({
|
||||
T3CODE_DESKTOP_PERF_RUN_TERMINAL: " false ",
|
||||
CI: "false",
|
||||
}),
|
||||
).toBe(false);
|
||||
});
|
||||
});
|
||||
@@ -0,0 +1,11 @@
|
||||
type PerfToggleEnv = {
|
||||
T3CODE_DESKTOP_PERF_RUN_TERMINAL?: string | undefined;
|
||||
CI?: string | undefined;
|
||||
};
|
||||
|
||||
export function shouldRunTerminalPerfInteractions(env: PerfToggleEnv): boolean {
|
||||
const raw = env.T3CODE_DESKTOP_PERF_RUN_TERMINAL?.trim().toLowerCase();
|
||||
if (raw === "1" || raw === "true") return true;
|
||||
if (raw === "0" || raw === "false") return false;
|
||||
return env.CI !== "true";
|
||||
}
|
||||
Reference in new issue
Block a user