mirror of
https://github.com/usebruno/bruno.git
synced 2024-11-25 09:23:17 +01:00
Merge branch 'main' into bug/correct-result-reporting
This commit is contained in:
commit
4ba4d8fc27
2
.github/workflows/unit-tests.yml
vendored
2
.github/workflows/unit-tests.yml
vendored
@ -29,3 +29,5 @@ jobs:
|
|||||||
run: npm run test --workspace=packages/bruno-js
|
run: npm run test --workspace=packages/bruno-js
|
||||||
- name: Test Package bruno-cli
|
- name: Test Package bruno-cli
|
||||||
run: npm run test --workspace=packages/bruno-cli
|
run: npm run test --workspace=packages/bruno-cli
|
||||||
|
- name: Test Package bruno-electron
|
||||||
|
run: npm run test --workspace=packages/bruno-electron
|
||||||
|
4
.gitignore
vendored
4
.gitignore
vendored
@ -41,3 +41,7 @@ yarn-error.log*
|
|||||||
/test-results/
|
/test-results/
|
||||||
/playwright-report/
|
/playwright-report/
|
||||||
/playwright/.cache/
|
/playwright/.cache/
|
||||||
|
|
||||||
|
#dev editor
|
||||||
|
bruno.iml
|
||||||
|
.idea
|
@ -116,7 +116,7 @@ const Sidebar = () => {
|
|||||||
</GitHubButton>
|
</GitHubButton>
|
||||||
)}
|
)}
|
||||||
</div>
|
</div>
|
||||||
<div className="flex flex-grow items-center justify-end text-xs mr-2">v0.16.2</div>
|
<div className="flex flex-grow items-center justify-end text-xs mr-2">v0.16.3</div>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
@ -213,7 +213,7 @@ const runSingleRequest = async function (
|
|||||||
const testFile = get(bruJson, 'request.tests');
|
const testFile = get(bruJson, 'request.tests');
|
||||||
if (testFile && testFile.length) {
|
if (testFile && testFile.length) {
|
||||||
const testRuntime = new TestRuntime();
|
const testRuntime = new TestRuntime();
|
||||||
const result = testRuntime.runTests(
|
const result = await testRuntime.runTests(
|
||||||
testFile,
|
testFile,
|
||||||
request,
|
request,
|
||||||
response,
|
response,
|
||||||
|
@ -1,5 +1,5 @@
|
|||||||
{
|
{
|
||||||
"version": "v0.16.2",
|
"version": "v0.16.3",
|
||||||
"name": "bruno",
|
"name": "bruno",
|
||||||
"description": "Opensource API Client for Exploring and Testing APIs",
|
"description": "Opensource API Client for Exploring and Testing APIs",
|
||||||
"homepage": "https://www.usebruno.com",
|
"homepage": "https://www.usebruno.com",
|
||||||
|
@ -11,7 +11,8 @@ const {
|
|||||||
isDirectory,
|
isDirectory,
|
||||||
browseDirectory,
|
browseDirectory,
|
||||||
createDirectory,
|
createDirectory,
|
||||||
searchForBruFiles
|
searchForBruFiles,
|
||||||
|
sanitizeDirectoryName
|
||||||
} = require('../utils/filesystem');
|
} = require('../utils/filesystem');
|
||||||
const { stringifyJson } = require('../utils/common');
|
const { stringifyJson } = require('../utils/common');
|
||||||
const { openCollectionDialog, openCollection } = require('../app/collections');
|
const { openCollectionDialog, openCollection } = require('../app/collections');
|
||||||
@ -315,7 +316,7 @@ const registerRendererEventHandlers = (mainWindow, watcher, lastOpenedCollection
|
|||||||
|
|
||||||
ipcMain.handle('renderer:import-collection', async (event, collection, collectionLocation) => {
|
ipcMain.handle('renderer:import-collection', async (event, collection, collectionLocation) => {
|
||||||
try {
|
try {
|
||||||
let collectionName = collection.name;
|
let collectionName = sanitizeDirectoryName(collection.name);
|
||||||
let collectionPath = path.join(collectionLocation, collectionName);
|
let collectionPath = path.join(collectionLocation, collectionName);
|
||||||
|
|
||||||
if (fs.existsSync(collectionPath)) {
|
if (fs.existsSync(collectionPath)) {
|
||||||
@ -359,7 +360,7 @@ const registerRendererEventHandlers = (mainWindow, watcher, lastOpenedCollection
|
|||||||
const uid = generateUidBasedOnHash(collectionPath);
|
const uid = generateUidBasedOnHash(collectionPath);
|
||||||
const brunoConfig = {
|
const brunoConfig = {
|
||||||
version: '1',
|
version: '1',
|
||||||
name: collection.name,
|
name: collectionName,
|
||||||
type: 'collection'
|
type: 'collection'
|
||||||
};
|
};
|
||||||
const content = await stringifyJson(brunoConfig);
|
const content = await stringifyJson(brunoConfig);
|
||||||
|
@ -315,7 +315,7 @@ const registerNetworkIpc = (mainWindow) => {
|
|||||||
const testFile = item.draft ? get(item.draft, 'request.tests') : get(item, 'request.tests');
|
const testFile = item.draft ? get(item.draft, 'request.tests') : get(item, 'request.tests');
|
||||||
if (testFile && testFile.length) {
|
if (testFile && testFile.length) {
|
||||||
const testRuntime = new TestRuntime();
|
const testRuntime = new TestRuntime();
|
||||||
const testResults = testRuntime.runTests(
|
const testResults = await testRuntime.runTests(
|
||||||
testFile,
|
testFile,
|
||||||
request,
|
request,
|
||||||
response,
|
response,
|
||||||
@ -389,7 +389,7 @@ const registerNetworkIpc = (mainWindow) => {
|
|||||||
const testFile = item.draft ? get(item.draft, 'request.tests') : get(item, 'request.tests');
|
const testFile = item.draft ? get(item.draft, 'request.tests') : get(item, 'request.tests');
|
||||||
if (testFile && testFile.length) {
|
if (testFile && testFile.length) {
|
||||||
const testRuntime = new TestRuntime();
|
const testRuntime = new TestRuntime();
|
||||||
const testResults = testRuntime.runTests(
|
const testResults = await testRuntime.runTests(
|
||||||
testFile,
|
testFile,
|
||||||
request,
|
request,
|
||||||
error.response,
|
error.response,
|
||||||
@ -725,7 +725,7 @@ const registerNetworkIpc = (mainWindow) => {
|
|||||||
const testFile = item.draft ? get(item.draft, 'request.tests') : get(item, 'request.tests');
|
const testFile = item.draft ? get(item.draft, 'request.tests') : get(item, 'request.tests');
|
||||||
if (testFile && testFile.length) {
|
if (testFile && testFile.length) {
|
||||||
const testRuntime = new TestRuntime();
|
const testRuntime = new TestRuntime();
|
||||||
const testResults = testRuntime.runTests(
|
const testResults = await testRuntime.runTests(
|
||||||
testFile,
|
testFile,
|
||||||
request,
|
request,
|
||||||
response,
|
response,
|
||||||
@ -804,7 +804,7 @@ const registerNetworkIpc = (mainWindow) => {
|
|||||||
const testFile = item.draft ? get(item.draft, 'request.tests') : get(item, 'request.tests');
|
const testFile = item.draft ? get(item.draft, 'request.tests') : get(item, 'request.tests');
|
||||||
if (testFile && testFile.length) {
|
if (testFile && testFile.length) {
|
||||||
const testRuntime = new TestRuntime();
|
const testRuntime = new TestRuntime();
|
||||||
const testResults = testRuntime.runTests(
|
const testResults = await testRuntime.runTests(
|
||||||
testFile,
|
testFile,
|
||||||
request,
|
request,
|
||||||
error.response,
|
error.response,
|
||||||
|
@ -114,6 +114,10 @@ const searchForBruFiles = (dir) => {
|
|||||||
return searchForFiles(dir, '.bru');
|
return searchForFiles(dir, '.bru');
|
||||||
};
|
};
|
||||||
|
|
||||||
|
const sanitizeDirectoryName = (name) => {
|
||||||
|
return name.replace(/[<>:"/\\|?*\x00-\x1F]+/g, '-');
|
||||||
|
};
|
||||||
|
|
||||||
module.exports = {
|
module.exports = {
|
||||||
isValidPathname,
|
isValidPathname,
|
||||||
exists,
|
exists,
|
||||||
@ -127,5 +131,6 @@ module.exports = {
|
|||||||
createDirectory,
|
createDirectory,
|
||||||
browseDirectory,
|
browseDirectory,
|
||||||
searchForFiles,
|
searchForFiles,
|
||||||
searchForBruFiles
|
searchForBruFiles,
|
||||||
|
sanitizeDirectoryName
|
||||||
};
|
};
|
||||||
|
26
packages/bruno-electron/src/utils/filesystem.test.js
Normal file
26
packages/bruno-electron/src/utils/filesystem.test.js
Normal file
@ -0,0 +1,26 @@
|
|||||||
|
const { sanitizeDirectoryName } = require('./filesystem.js');
|
||||||
|
|
||||||
|
describe('sanitizeDirectoryName', () => {
|
||||||
|
it('should replace invalid characters with hyphens', () => {
|
||||||
|
const input = '<>:"/\\|?*\x00-\x1F';
|
||||||
|
const expectedOutput = '---';
|
||||||
|
expect(sanitizeDirectoryName(input)).toEqual(expectedOutput);
|
||||||
|
});
|
||||||
|
|
||||||
|
it('should not modify valid directory names', () => {
|
||||||
|
const input = 'my-directory';
|
||||||
|
expect(sanitizeDirectoryName(input)).toEqual(input);
|
||||||
|
});
|
||||||
|
|
||||||
|
it('should replace multiple invalid characters with a single hyphen', () => {
|
||||||
|
const input = 'my<>invalid?directory';
|
||||||
|
const expectedOutput = 'my-invalid-directory';
|
||||||
|
expect(sanitizeDirectoryName(input)).toEqual(expectedOutput);
|
||||||
|
});
|
||||||
|
|
||||||
|
it('should handle names with slashes', () => {
|
||||||
|
const input = 'my/invalid/directory';
|
||||||
|
const expectedOutput = 'my-invalid-directory';
|
||||||
|
expect(sanitizeDirectoryName(input)).toEqual(expectedOutput);
|
||||||
|
});
|
||||||
|
});
|
@ -10,6 +10,7 @@ const { cleanJson } = require('../utils');
|
|||||||
|
|
||||||
// Inbuilt Library Support
|
// Inbuilt Library Support
|
||||||
const atob = require('atob');
|
const atob = require('atob');
|
||||||
|
const axios = require('axios');
|
||||||
const btoa = require('btoa');
|
const btoa = require('btoa');
|
||||||
const lodash = require('lodash');
|
const lodash = require('lodash');
|
||||||
const moment = require('moment');
|
const moment = require('moment');
|
||||||
@ -20,7 +21,7 @@ const CryptoJS = require('crypto-js');
|
|||||||
class TestRuntime {
|
class TestRuntime {
|
||||||
constructor() {}
|
constructor() {}
|
||||||
|
|
||||||
runTests(
|
async runTests(
|
||||||
testsFile,
|
testsFile,
|
||||||
request,
|
request,
|
||||||
response,
|
response,
|
||||||
@ -78,6 +79,7 @@ class TestRuntime {
|
|||||||
root: [collectionPath],
|
root: [collectionPath],
|
||||||
mock: {
|
mock: {
|
||||||
atob,
|
atob,
|
||||||
|
axios,
|
||||||
btoa,
|
btoa,
|
||||||
lodash,
|
lodash,
|
||||||
moment,
|
moment,
|
||||||
@ -89,7 +91,8 @@ class TestRuntime {
|
|||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
vm.run(testsFile, path.join(collectionPath, 'vm.js'));
|
const asyncVM = vm.run(`module.exports = async () => { ${testsFile}}`, path.join(collectionPath, 'vm.js'));
|
||||||
|
await asyncVM();
|
||||||
|
|
||||||
return {
|
return {
|
||||||
request,
|
request,
|
||||||
|
@ -1,6 +1,6 @@
|
|||||||
const Test = (__brunoTestResults, chai) => (description, callback) => {
|
const Test = (__brunoTestResults, chai) => async (description, callback) => {
|
||||||
try {
|
try {
|
||||||
callback();
|
await callback();
|
||||||
__brunoTestResults.addResult({ description, status: 'pass' });
|
__brunoTestResults.addResult({ description, status: 'pass' });
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
console.log(chai.AssertionError);
|
console.log(chai.AssertionError);
|
||||||
|
53
packages/bruno-js/tests/runtime.spec.js
Normal file
53
packages/bruno-js/tests/runtime.spec.js
Normal file
@ -0,0 +1,53 @@
|
|||||||
|
const { describe, it, expect } = require('@jest/globals');
|
||||||
|
const TestRuntime = require('../src/runtime/test-runtime');
|
||||||
|
|
||||||
|
describe('runtime', () => {
|
||||||
|
describe('test-runtime', () => {
|
||||||
|
const baseRequest = {
|
||||||
|
method: 'GET',
|
||||||
|
url: 'http://localhost:3000/',
|
||||||
|
headers: {},
|
||||||
|
data: undefined
|
||||||
|
};
|
||||||
|
const baseResponse = {
|
||||||
|
status: 200,
|
||||||
|
statusText: 'OK',
|
||||||
|
data: [
|
||||||
|
{
|
||||||
|
id: 1
|
||||||
|
},
|
||||||
|
{
|
||||||
|
id: 2
|
||||||
|
},
|
||||||
|
{
|
||||||
|
id: 3
|
||||||
|
}
|
||||||
|
]
|
||||||
|
};
|
||||||
|
|
||||||
|
it('should wait async tests', async () => {
|
||||||
|
const testFile = `
|
||||||
|
await test('async test', ()=> {
|
||||||
|
return new Promise((resolve)=> {
|
||||||
|
setTimeout(()=> {resolve()},200)
|
||||||
|
})
|
||||||
|
})
|
||||||
|
`;
|
||||||
|
|
||||||
|
const runtime = new TestRuntime();
|
||||||
|
const result = await runtime.runTests(
|
||||||
|
testFile,
|
||||||
|
{ ...baseRequest },
|
||||||
|
{ ...baseResponse },
|
||||||
|
{},
|
||||||
|
{},
|
||||||
|
'.',
|
||||||
|
null,
|
||||||
|
process.env
|
||||||
|
);
|
||||||
|
expect(result.results.map((el) => ({ description: el.description, status: el.status }))).toEqual([
|
||||||
|
{ description: 'async test', status: 'pass' }
|
||||||
|
]);
|
||||||
|
});
|
||||||
|
});
|
||||||
|
});
|
Loading…
Reference in New Issue
Block a user