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

Feat: Skip request #2397

Closed
wants to merge 13 commits into from
Closed
3 changes: 2 additions & 1 deletion packages/bruno-app/src/components/CodeEditor/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,8 @@ if (!SERVER_RENDERED) {
'bru.setEnvVar(key,value)',
'bru.getVar(key)',
'bru.setVar(key,value)',
'bru.setNextRequest(requestName)'
'bru.setNextRequest(requestName)',
'bru.skipRequest()'
];
CodeMirror.registerHelper('hint', 'brunoJS', (editor, options) => {
const cursor = editor.getCursor();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,10 @@ const StyledWrapper = styled.div`
.error-message {
color: ${(props) => props.theme.colors.text.muted};
}

.skipped-request {
color: ${(props) => props.theme.colors.text.muted};
}
`;

export default StyledWrapper;
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,10 @@ const Wrapper = styled.div`
color: ${(props) => props.theme.colors.text.muted};
}
}

.skipped-request {
color: ${(props) => props.theme.colors.text.muted};
}
`;

export default Wrapper;
15 changes: 11 additions & 4 deletions packages/bruno-app/src/components/RunnerResults/index.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import { get, cloneDeep } from 'lodash';
import { runCollectionFolder, cancelRunnerExecution } from 'providers/ReduxStore/slices/collections/actions';
import { resetCollectionRunner } from 'providers/ReduxStore/slices/collections';
import { findItemInCollection, getTotalRequestCountInCollection } from 'utils/collections';
import { IconRefresh, IconCircleCheck, IconCircleX, IconCheck, IconX, IconRun } from '@tabler/icons';
import { IconRefresh, IconCircleCheck, IconCircleOff, IconCircleX, IconCheck, IconX, IconRun } from '@tabler/icons';
import slash from 'utils/common/slash';
import ResponsePane from './ResponsePane';
import StyledWrapper from './StyledWrapper';
Expand Down Expand Up @@ -58,7 +58,8 @@ export default function RunnerResults({ collection }) {
pathname: info.pathname,
relativePath: getRelativePath(collection.pathname, info.pathname)
};
if (newItem.status !== 'error') {

if (newItem.status !== 'error' && newItem.status !== 'skipped') {
if (newItem.testResults) {
const failed = newItem.testResults.filter((result) => result.status === 'fail');
newItem.testStatus = failed.length ? 'fail' : 'pass';
Expand Down Expand Up @@ -104,6 +105,9 @@ export default function RunnerResults({ collection }) {
const failedRequests = items.filter((item) => {
return (item.status !== 'error' && item.testStatus === 'fail') || item.assertionStatus === 'fail';
});
const skipedRequests = items.filter((item) => {
JorgeTrovisco marked this conversation as resolved.
Show resolved Hide resolved
return item.status == 'skipped';
});

if (!items || !items.length) {
return (
Expand Down Expand Up @@ -146,7 +150,8 @@ export default function RunnerResults({ collection }) {
ref={runnerBodyRef}
>
<div className="pb-2 font-medium test-summary">
Total Requests: {items.length}, Passed: {passedRequests.length}, Failed: {failedRequests.length}
Total Requests: {items.length}, Passed: {passedRequests.length}, Failed: {failedRequests.length}, Skipped:{' '}
{skipedRequests.length}
</div>
{items.map((item) => {
return (
Expand All @@ -156,6 +161,8 @@ export default function RunnerResults({ collection }) {
<span>
{item.status !== 'error' && item.testStatus === 'pass' ? (
<IconCircleCheck className="test-success" size={20} strokeWidth={1.5} />
) : item.status === 'skipped' ? (
<IconCircleOff className="skipped-request" size={20} strokeWidth={1.5} />
) : (
<IconCircleX className="test-failure" size={20} strokeWidth={1.5} />
)}
Expand All @@ -165,7 +172,7 @@ export default function RunnerResults({ collection }) {
>
{item.relativePath}
</span>
{item.status !== 'error' && item.status !== 'completed' ? (
{item.status !== 'error' && item.status !== 'completed' && item.status != 'skipped' ? (
<IconRefresh className="animate-spin ml-1" size={18} strokeWidth={1.5} />
) : (
<span className="text-xs link cursor-pointer" onClick={() => setSelectedItem(item)}>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1417,6 +1417,12 @@ export const collectionsSlice = createSlice({
item.requestSent = action.payload.requestSent;
}

if (type === 'request-skipped') {
const item = collection.runnerResult.items.find((i) => i.uid === request.uid);
item.status = 'skipped';
item.responseReceived = action.payload.responseReceived;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What's the reason item.responseReceived is set here?
Seems like a copy paste mistake but I could be wrong.
I would expect action.payload.responseReceived to be undefined when the request is skipped so item.responseReceived would be as well?

Also why are we using .find() here, whereas all the other types use .findLast()?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hi,

You're right, responseReceived is no longer necessary.

Regarding the find vs findLast change, it was made after I checked out the branch, so I didn't catch it during the merge.

Captura de ecrã 2024-08-27, às 20 06 51

Copy link
Contributor

@nikischin nikischin Aug 27, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you so much for your fast reply! Looks very good (on code level)

So have you been able to reproduce my error or do I need to set up some collection to reproduce the error?

Or did I use the function not as intended?

}

if (type === 'response-received') {
const item = collection.runnerResult.items.find((i) => i.uid === request.uid);
item.status = 'completed';
Expand Down
14 changes: 14 additions & 0 deletions packages/bruno-electron/src/ipc/network/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -905,6 +905,20 @@ const registerNetworkIpc = (mainWindow) => {
scriptingConfig
);

if (preRequestScriptResult?.isSkippedRequest) {
mainWindow.webContents.send('main:run-folder-event', {
type: 'request-skipped',
responseReceived: {
JorgeTrovisco marked this conversation as resolved.
Show resolved Hide resolved
status: 'Skipped',
statusText: 'OK'
},
...eventData
});

currentRequestIndex++;
continue;
}

if (preRequestScriptResult?.nextRequestName !== undefined) {
nextRequestName = preRequestScriptResult.nextRequestName;
}
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 @@ -80,6 +80,10 @@ class Bru {
setNextRequest(nextRequest) {
this.nextRequest = nextRequest;
}

skipRequest() {
this.isSkippedRequest = true;
}
}

module.exports = Bru;
3 changes: 2 additions & 1 deletion packages/bruno-js/src/runtime/script-runtime.js
Original file line number Diff line number Diff line change
Expand Up @@ -126,7 +126,8 @@ class ScriptRuntime {
request,
envVariables: cleanJson(envVariables),
collectionVariables: cleanJson(collectionVariables),
nextRequestName: bru.nextRequest
nextRequestName: bru.nextRequest,
isSkippedRequest: bru.isSkippedRequest
};
}

Expand Down