mirror of
https://github.com/usebruno/bruno.git
synced 2024-11-25 01:14:23 +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
|
||||
- name: Test Package 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/
|
||||
/playwright-report/
|
||||
/playwright/.cache/
|
||||
|
||||
#dev editor
|
||||
bruno.iml
|
||||
.idea
|
@ -116,7 +116,7 @@ const Sidebar = () => {
|
||||
</GitHubButton>
|
||||
)}
|
||||
</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>
|
||||
|
@ -213,7 +213,7 @@ const runSingleRequest = async function (
|
||||
const testFile = get(bruJson, 'request.tests');
|
||||
if (testFile && testFile.length) {
|
||||
const testRuntime = new TestRuntime();
|
||||
const result = testRuntime.runTests(
|
||||
const result = await testRuntime.runTests(
|
||||
testFile,
|
||||
request,
|
||||
response,
|
||||
|
@ -1,5 +1,5 @@
|
||||
{
|
||||
"version": "v0.16.2",
|
||||
"version": "v0.16.3",
|
||||
"name": "bruno",
|
||||
"description": "Opensource API Client for Exploring and Testing APIs",
|
||||
"homepage": "https://www.usebruno.com",
|
||||
|
@ -11,7 +11,8 @@ const {
|
||||
isDirectory,
|
||||
browseDirectory,
|
||||
createDirectory,
|
||||
searchForBruFiles
|
||||
searchForBruFiles,
|
||||
sanitizeDirectoryName
|
||||
} = require('../utils/filesystem');
|
||||
const { stringifyJson } = require('../utils/common');
|
||||
const { openCollectionDialog, openCollection } = require('../app/collections');
|
||||
@ -315,7 +316,7 @@ const registerRendererEventHandlers = (mainWindow, watcher, lastOpenedCollection
|
||||
|
||||
ipcMain.handle('renderer:import-collection', async (event, collection, collectionLocation) => {
|
||||
try {
|
||||
let collectionName = collection.name;
|
||||
let collectionName = sanitizeDirectoryName(collection.name);
|
||||
let collectionPath = path.join(collectionLocation, collectionName);
|
||||
|
||||
if (fs.existsSync(collectionPath)) {
|
||||
@ -359,7 +360,7 @@ const registerRendererEventHandlers = (mainWindow, watcher, lastOpenedCollection
|
||||
const uid = generateUidBasedOnHash(collectionPath);
|
||||
const brunoConfig = {
|
||||
version: '1',
|
||||
name: collection.name,
|
||||
name: collectionName,
|
||||
type: 'collection'
|
||||
};
|
||||
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');
|
||||
if (testFile && testFile.length) {
|
||||
const testRuntime = new TestRuntime();
|
||||
const testResults = testRuntime.runTests(
|
||||
const testResults = await testRuntime.runTests(
|
||||
testFile,
|
||||
request,
|
||||
response,
|
||||
@ -389,7 +389,7 @@ const registerNetworkIpc = (mainWindow) => {
|
||||
const testFile = item.draft ? get(item.draft, 'request.tests') : get(item, 'request.tests');
|
||||
if (testFile && testFile.length) {
|
||||
const testRuntime = new TestRuntime();
|
||||
const testResults = testRuntime.runTests(
|
||||
const testResults = await testRuntime.runTests(
|
||||
testFile,
|
||||
request,
|
||||
error.response,
|
||||
@ -725,7 +725,7 @@ const registerNetworkIpc = (mainWindow) => {
|
||||
const testFile = item.draft ? get(item.draft, 'request.tests') : get(item, 'request.tests');
|
||||
if (testFile && testFile.length) {
|
||||
const testRuntime = new TestRuntime();
|
||||
const testResults = testRuntime.runTests(
|
||||
const testResults = await testRuntime.runTests(
|
||||
testFile,
|
||||
request,
|
||||
response,
|
||||
@ -804,7 +804,7 @@ const registerNetworkIpc = (mainWindow) => {
|
||||
const testFile = item.draft ? get(item.draft, 'request.tests') : get(item, 'request.tests');
|
||||
if (testFile && testFile.length) {
|
||||
const testRuntime = new TestRuntime();
|
||||
const testResults = testRuntime.runTests(
|
||||
const testResults = await testRuntime.runTests(
|
||||
testFile,
|
||||
request,
|
||||
error.response,
|
||||
|
@ -114,6 +114,10 @@ const searchForBruFiles = (dir) => {
|
||||
return searchForFiles(dir, '.bru');
|
||||
};
|
||||
|
||||
const sanitizeDirectoryName = (name) => {
|
||||
return name.replace(/[<>:"/\\|?*\x00-\x1F]+/g, '-');
|
||||
};
|
||||
|
||||
module.exports = {
|
||||
isValidPathname,
|
||||
exists,
|
||||
@ -127,5 +131,6 @@ module.exports = {
|
||||
createDirectory,
|
||||
browseDirectory,
|
||||
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
|
||||
const atob = require('atob');
|
||||
const axios = require('axios');
|
||||
const btoa = require('btoa');
|
||||
const lodash = require('lodash');
|
||||
const moment = require('moment');
|
||||
@ -20,7 +21,7 @@ const CryptoJS = require('crypto-js');
|
||||
class TestRuntime {
|
||||
constructor() {}
|
||||
|
||||
runTests(
|
||||
async runTests(
|
||||
testsFile,
|
||||
request,
|
||||
response,
|
||||
@ -78,6 +79,7 @@ class TestRuntime {
|
||||
root: [collectionPath],
|
||||
mock: {
|
||||
atob,
|
||||
axios,
|
||||
btoa,
|
||||
lodash,
|
||||
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 {
|
||||
request,
|
||||
|
@ -1,6 +1,6 @@
|
||||
const Test = (__brunoTestResults, chai) => (description, callback) => {
|
||||
const Test = (__brunoTestResults, chai) => async (description, callback) => {
|
||||
try {
|
||||
callback();
|
||||
await callback();
|
||||
__brunoTestResults.addResult({ description, status: 'pass' });
|
||||
} catch (error) {
|
||||
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