fix(js-sandbox): resolve errors with pw.env namespace in legacy sandbox (#5433)

This commit is contained in:
James George 2025-10-06 16:45:35 +05:30 committed by GitHub
parent 6bbfb9b8b7
commit 11b07db12c
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
2 changed files with 22 additions and 15 deletions

View file

@ -256,9 +256,11 @@ declare namespace pw {
headers: HoppRESTResponseHeader[]
}>
namespace env {
function set(key: string, value: string): void
function unset(key: string): void
function get(key: string): string
function getResolve(key: string): string
function resolve(key: string): string
function resolve(value: string): string
}
}

View file

@ -158,21 +158,24 @@ export function getSharedEnvMethods(
}
/**
* Legacy sandbox version - Returns flat methods for `pw` namespace only
* Legacy sandbox version - Methods pre-wrapped in `env` for direct `pw` namespace assignment
* (Experimental sandbox powered by `faraday-cage` handles this wrapping via bootstrap code)
*/
export function getSharedEnvMethods(
envs: TestResult["envs"],
isHoppNamespace?: false
): {
methods: {
get: (key: string, options?: EnvAPIOptions) => string | null | undefined
getResolve: (
key: string,
options?: EnvAPIOptions
) => string | null | undefined
set: (key: string, value: string, options?: EnvAPIOptions) => void
unset: (key: string, options?: EnvAPIOptions) => void
resolve: (key: string) => string
env: {
get: (key: string, options?: EnvAPIOptions) => string | null | undefined
getResolve: (
key: string,
options?: EnvAPIOptions
) => string | null | undefined
set: (key: string, value: string, options?: EnvAPIOptions) => void
unset: (key: string, options?: EnvAPIOptions) => void
resolve: (key: string) => string
}
}
updatedEnvs: TestResult["envs"]
}
@ -380,11 +383,13 @@ export function getSharedEnvMethods(
// Legacy scripting sandbox (Only `pw` namespace)
return {
methods: {
get: envGetFn,
getResolve: envGetResolveFn,
set: envSetFn,
unset: envUnsetFn,
resolve: envResolveFn,
env: {
get: envGetFn,
getResolve: envGetResolveFn,
set: envSetFn,
unset: envUnsetFn,
resolve: envResolveFn,
},
},
updatedEnvs,
}