Ps/fix dev flags not defined (#6683)

* Handle devFlags not defined

* Default dev flags to false
This commit is contained in:
Matt Gibson 2023-10-24 11:48:01 -04:00 committed by GitHub
parent 950e327477
commit c798c92c84
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 10 additions and 4 deletions

View File

@ -13,5 +13,6 @@
"secretsManager": true, "secretsManager": true,
"showPasswordless": true, "showPasswordless": true,
"enableCipherKeyEncryption": false "enableCipherKeyEncryption": false
} },
"devFlags": {}
} }

View File

@ -36,8 +36,13 @@ describe("devFlagEnabled", () => {
process.env.ENV = "development"; process.env.ENV = "development";
}); });
it("returns true by default", () => { it("returns false by default", () => {
expect(devFlagEnabled<any>("nonExistentFlag")).toBe(true); expect(devFlagEnabled<any>("nonExistentFlag")).toBe(false);
});
it("returns false if devFlags is not defined", () => {
delete process.env.DEV_FLAGS;
expect(devFlagEnabled<any>("nonExistentFlag")).toBe(false);
}); });
it("returns true if enabled", () => { it("returns true if enabled", () => {

View File

@ -45,7 +45,7 @@ export function devFlagEnabled<DevFlags extends SharedDevFlags>(flag: keyof DevF
} }
const devFlags = getFlags<DevFlags>(process.env.DEV_FLAGS); const devFlags = getFlags<DevFlags>(process.env.DEV_FLAGS);
return devFlags[flag] == null || !!devFlags[flag]; return devFlags?.[flag] == null ? false : !!devFlags[flag];
} }
/** /**