diff --git a/packages/bruno-cli/src/runner/run-single-request.js b/packages/bruno-cli/src/runner/run-single-request.js index 00381c576..b77c7f61e 100644 --- a/packages/bruno-cli/src/runner/run-single-request.js +++ b/packages/bruno-cli/src/runner/run-single-request.js @@ -21,6 +21,10 @@ const { shouldUseProxy, PatchedHttpsProxyAgent } = require('../utils/proxy-util' const path = require('path'); const protocolRegex = /^([-+\w]{1,25})(:?\/\/|:)/; +const onConsoleLog = (type, args) => { + console[type](...args); +}; + const runSingleRequest = async function ( filename, bruJson, @@ -83,7 +87,7 @@ const runSingleRequest = async function ( envVariables, runtimeVariables, collectionPath, - null, + onConsoleLog, processEnvVars, scriptingConfig ); diff --git a/packages/bruno-js/src/sandbox/quickjs/index.js b/packages/bruno-js/src/sandbox/quickjs/index.js index 913795b54..1b2cbc0a1 100644 --- a/packages/bruno-js/src/sandbox/quickjs/index.js +++ b/packages/bruno-js/src/sandbox/quickjs/index.js @@ -9,7 +9,6 @@ const { newQuickJSWASMModule, memoizePromiseFactory } = require('quickjs-emscrip // execute `npm run sandbox:bundle-libraries` if the below file doesn't exist const getBundledCode = require('../bundle-browser-rollup'); -const addSleepShimToContext = require('./shims/sleep'); let QuickJSSyncContext; const loader = memoizePromiseFactory(() => newQuickJSWASMModule()); @@ -103,7 +102,6 @@ const executeQuickJsVmAsync = async ({ script: externalScript, context: external req && addBrunoRequestShimToContext(vm, req); res && addBrunoResponseShimToContext(vm, res); consoleFn && addConsoleShimToContext(vm, consoleFn); - addSleepShimToContext(vm); addLocalModuleLoaderShimToContext(vm, collectionPath); await addLibraryShimsToContext(vm); @@ -113,10 +111,10 @@ const executeQuickJsVmAsync = async ({ script: externalScript, context: external const script = ` (async () => { const setTimeout = async(fn, timer) => { - v = await sleep(timer); + v = await bru.sleep(timer); fn.apply(); } - await sleep(0); + await bru.sleep(0); try { ${externalScript} } diff --git a/packages/bruno-js/src/sandbox/quickjs/shims/bru.js b/packages/bruno-js/src/sandbox/quickjs/shims/bru.js index 5add1032e..5b1063404 100644 --- a/packages/bruno-js/src/sandbox/quickjs/shims/bru.js +++ b/packages/bruno-js/src/sandbox/quickjs/shims/bru.js @@ -63,6 +63,17 @@ const addBruShimToContext = (vm, bru) => { vm.setProp(bruObject, 'getSecretVar', getSecretVar); getSecretVar.dispose(); + const sleep = vm.newFunction('sleep', (timer) => { + const t = vm.getString(timer); + const promise = vm.newPromise(); + setTimeout(() => { + promise.resolve(vm.newString('slept')); + }, t); + promise.settled.then(vm.runtime.executePendingJobs); + return promise.handle; + }); + sleep.consume((handle) => vm.setProp(bruObject, 'sleep', handle)); + vm.setProp(vm.global, 'bru', bruObject); bruObject.dispose(); }; diff --git a/packages/bruno-js/src/sandbox/quickjs/shims/sleep.js b/packages/bruno-js/src/sandbox/quickjs/shims/sleep.js deleted file mode 100644 index 79fd146f9..000000000 --- a/packages/bruno-js/src/sandbox/quickjs/shims/sleep.js +++ /dev/null @@ -1,14 +0,0 @@ -const addSleepShimToContext = (vm) => { - const sleepHandle = vm.newFunction('sleep', (timer) => { - const t = vm.getString(timer); - const promise = vm.newPromise(); - setTimeout(() => { - promise.resolve(vm.newString('slept')); - }, t); - promise.settled.then(vm.runtime.executePendingJobs); - return promise.handle; - }); - sleepHandle.consume((handle) => vm.setProp(vm.global, 'sleep', handle)); -}; - -module.exports = addSleepShimToContext;