[OpenAI] Set up logging for browser (#31239)
### Describe the problem that is addressed by this PR Fix the failing browser issue in injecting Azure Log Level
This commit is contained in:
Родитель
9f9511a842
Коммит
5c1d60c4cf
|
@ -0,0 +1,36 @@
|
|||
// Copyright (c) Microsoft Corporation.
|
||||
// Licensed under the MIT License.
|
||||
import type { GlobalSetupContext } from "vitest/node";
|
||||
|
||||
enum EnvVarKeys {
|
||||
AZURE_LOG_LEVEL = "AZURE_LOG_LEVEL",
|
||||
}
|
||||
declare module "vitest" {
|
||||
type MyEnvVarKeys = {
|
||||
[K in keyof typeof EnvVarKeys]: string;
|
||||
};
|
||||
export interface ProvidedContext extends MyEnvVarKeys {}
|
||||
}
|
||||
|
||||
const defaultLogLevel = "info";
|
||||
|
||||
function assertEnvironmentVariable(key: string): string {
|
||||
const value = process.env[key];
|
||||
// handle defaults
|
||||
if (!value) {
|
||||
switch (key) {
|
||||
case EnvVarKeys.AZURE_LOG_LEVEL:
|
||||
return defaultLogLevel;
|
||||
default:
|
||||
throw new Error(`Environment variable ${key} is not defined.`);
|
||||
}
|
||||
}
|
||||
return value;
|
||||
}
|
||||
|
||||
export default async function ({ provide }: GlobalSetupContext) {
|
||||
for (const key of Object.values(EnvVarKeys)) {
|
||||
provide(key, assertEnvironmentVariable(key));
|
||||
}
|
||||
return function () {};
|
||||
}
|
Загрузка…
Ссылка в новой задаче