Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Implement detection for runner #3105

Closed
wants to merge 3 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions packages/bruno-app/src/components/CodeEditor/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,7 @@ if (!SERVER_RENDERED) {
'bru.setNextRequest(requestName)',
'req.disableParsingResponseJson()',
'bru.getRequestVar(key)',
'bru.getExecutionMode()',
'bru.sleep(ms)'
];
CodeMirror.registerHelper('hint', 'brunoJS', (editor, options) => {
Expand Down
3 changes: 3 additions & 0 deletions packages/bruno-cli/src/runner/run-single-request.js
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,9 @@ const runSingleRequest = async function (
collectionRoot,
runtime
) {

runtimeVariables["__internal__executionMode"] = 'cli';

try {
let request;
let nextRequestName;
Expand Down
7 changes: 7 additions & 0 deletions packages/bruno-electron/src/ipc/network/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -490,6 +490,8 @@ const registerNetworkIpc = (mainWindow) => {
const cancelTokenUid = uuid();
const requestUid = uuid();

runtimeVariables["__internal__executionMode"] = 'single';

mainWindow.webContents.send('main:run-request-event', {
type: 'request-queued',
requestUid,
Expand Down Expand Up @@ -659,6 +661,8 @@ const registerNetworkIpc = (mainWindow) => {
collectionUid
});

runtimeVariables["__internal__executionMode"] = undefined;

mainWindow.webContents.send('main:script-environment-update', {
envVariables: testResults.envVariables,
runtimeVariables: testResults.runtimeVariables,
Expand Down Expand Up @@ -871,6 +875,7 @@ const registerNetworkIpc = (mainWindow) => {
const scriptingConfig = get(brunoConfig, 'scripts', {});
scriptingConfig.runtime = getJsSandboxRuntime(collection);
const collectionRoot = get(collection, 'root', {});
runtimeVariables["__internal__executionMode"] = 'runner';

const abortController = new AbortController();
saveCancelToken(cancelTokenUid, abortController);
Expand Down Expand Up @@ -1126,6 +1131,8 @@ const registerNetworkIpc = (mainWindow) => {
...eventData
});

runtimeVariables["__internal__executionMode"] = undefined;

mainWindow.webContents.send('main:script-environment-update', {
envVariables: testResults.envVariables,
runtimeVariables: testResults.runtimeVariables,
Expand Down
4 changes: 4 additions & 0 deletions packages/bruno-js/src/bru.js
Original file line number Diff line number Diff line change
Expand Up @@ -116,6 +116,10 @@ class Bru {
sleep(ms) {
return new Promise((resolve) => setTimeout(resolve, ms));
}

getExecutionMode() {
return this.runtimeVariables["__internal__executionMode"];
}
}

module.exports = Bru;
6 changes: 6 additions & 0 deletions packages/bruno-js/src/sandbox/quickjs/shims/bru.js
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,12 @@ const addBruShimToContext = (vm, bru) => {
vm.setProp(bruObject, 'getCollectionVar', getCollectionVar);
getCollectionVar.dispose();

let getExecutionMode = vm.newFunction('getExecutionMode', function () {
return marshallToVm(bru.getExecutionMode(), vm);
});
vm.setProp(bruObject, 'getExecutionMode', getExecutionMode);
getExecutionMode.dispose();

const sleep = vm.newFunction('sleep', (timer) => {
const t = vm.getString(timer);
const promise = vm.newPromise();
Expand Down