implement req.getPathName()

This commit is contained in:
tlaloc911 2024-10-14 04:19:51 +00:00
parent 2fc79e0e7f
commit b7e8c9d87f
5 changed files with 15 additions and 0 deletions

View File

@ -56,6 +56,7 @@ if (!SERVER_RENDERED) {
'req.getTimeout()',
'req.setTimeout(timeout)',
'req.getExecutionMode()',
'req.getPathName()',
'bru',
'bru.cwd()',
'bru.getEnvName(key)',

View File

@ -44,6 +44,7 @@ const runSingleRequest = async function (
request = prepareRequest(bruJson.request, collectionRoot);
request.__bruno__executionMode = 'cli';
request.__pathname = path.join(collectionPath,filename);
const scriptingConfig = get(brunoConfig, 'scripts', {});
scriptingConfig.runtime = runtime;

View File

@ -538,6 +538,7 @@ const registerNetworkIpc = (mainWindow) => {
const collectionRoot = get(collection, 'root', {});
const request = prepareRequest(item, collection);
request.__bruno__executionMode = 'standalone';
request.__pathname = item.pathname;
const envVars = getEnvVars(environment);
const processEnvVars = getProcessEnvVars(collectionUid);
const brunoConfig = getBrunoConfig(collectionUid);
@ -979,6 +980,7 @@ const registerNetworkIpc = (mainWindow) => {
const request = prepareRequest(item, collection);
request.__bruno__executionMode = 'runner';
request.__pathname = item.pathname;
const requestUid = uuid();
const processEnvVars = getProcessEnvVars(collectionUid);

View File

@ -177,6 +177,11 @@ class BrunoRequest {
getExecutionMode() {
return this.req.__bruno__executionMode;
}
getPathName() {
return this.req.__pathname;
}
}
module.exports = BrunoRequest;

View File

@ -117,6 +117,12 @@ const addBrunoRequestShimToContext = (vm, req) => {
vm.setProp(reqObject, 'getExecutionMode', getExecutionMode);
getExecutionMode.dispose();
let getPathName = vm.newFunction('getPathName', function () {
return marshallToVm(req.getPathName(), vm);
});
vm.setProp(reqObject, 'getPathName', getPathName);
getPathName.dispose();
vm.setProp(vm.global, 'req', reqObject);
reqObject.dispose();
};