mirror of
https://github.com/usebruno/bruno.git
synced 2026-07-09 06:55:03 +00:00
* feat: add description column to various tables and enhance UI interactions - Introduced a description column in Headers, VarsTable, and other components to allow multi-line descriptions. - Added toggle buttons to show/hide the description column in relevant tables. - Updated EditableTable component to support dynamic row addition with customizable labels. - Enhanced UI for better user experience with consistent button styles and spacing adjustments. * chore: resize fix handles * fix: restrict column check for last index * refactor: remove unwanted style and fix bottom padding of the last child in the table row * tests: improve testability and fix impacted locators * tests: fix locators for value fields * fix: improve newline handling in description prefix * fix: ts changes * chore: remove redundant code and fix description roundtrip * chore: remove redundant check * tests(bru-lang): tests for description and annotation * test: improve locators and tests * tests: descriptions * chore: re-add description setup * fix: re-add description cols * chore: fix the double click reset * fix: account for hidden sidebar in request pane width calculation * refactor: ui/ux fixes for data type toggle * chore: inline common deps into bruno-lang and bruno-schema * chore: tests * chore: fix ux for descriptions * fix: layout for environment vars table * fix: ensure correct row selection for multipart file upload in tests * feat: enhance UID assignment for request headers and variables in collections * chore: simplify * chore: update pkg * chore: abstract the e2e utils * chore: fix exports * tests: fix locators for datatype vars * fix: ux issue with secrets in environment table * tests: update locators for collection headers and vars descriptions * tests: update locators to use data attributes for datatype selectors * chore: update default css width for actions column * chore: remove tooltip for string type warnings * fix: reduce name widths * refactor: update annotation serialization to use single-quote delimiters for descriptions * refactor(tests): simplify description formatting in jsonToEnv tests * feat: add multiline description escaping and unescaping functions with tests * refactor: clean up imports and improve multiline text block handling * refactor: update locators to use new test IDs for environment variable editors * refactor: streamline header input handling and improve environment variable row access * refactor: update e2e-test job to support self-hosted runners * refactor: update E2E test runner configuration to include e2e and macOS environments --------- Co-authored-by: Pragadesh-45 <temporaryg7904@gmail.com>
481 lines
11 KiB
JavaScript
481 lines
11 KiB
JavaScript
const parser = require('../src/jsonToEnv');
|
|
|
|
describe('jsonToEnv', () => {
|
|
it('should stringify empty vars', () => {
|
|
const input = {
|
|
variables: []
|
|
};
|
|
|
|
const output = parser(input);
|
|
const expected = `vars {
|
|
}
|
|
`;
|
|
|
|
expect(output).toEqual(expected);
|
|
});
|
|
|
|
it('should stringify single var line', () => {
|
|
const input = {
|
|
variables: [
|
|
{
|
|
name: 'url',
|
|
value: 'http://localhost:3000',
|
|
enabled: true
|
|
}
|
|
]
|
|
};
|
|
|
|
const output = parser(input);
|
|
const expected = `vars {
|
|
url: http://localhost:3000
|
|
}
|
|
`;
|
|
expect(output).toEqual(expected);
|
|
});
|
|
|
|
it('should stringify multiple var lines', () => {
|
|
const input = {
|
|
variables: [
|
|
{
|
|
name: 'url',
|
|
value: 'http://localhost:3000',
|
|
enabled: true
|
|
},
|
|
{
|
|
name: 'port',
|
|
value: '3000',
|
|
enabled: false
|
|
}
|
|
]
|
|
};
|
|
|
|
const expected = `vars {
|
|
url: http://localhost:3000
|
|
~port: 3000
|
|
}
|
|
`;
|
|
const output = parser(input);
|
|
expect(output).toEqual(expected);
|
|
});
|
|
|
|
it('should stringify description in vars', () => {
|
|
const input = {
|
|
variables: [
|
|
{
|
|
name: 'url',
|
|
value: 'http://localhost:3000',
|
|
enabled: true,
|
|
description: 'Base API URL.'
|
|
}
|
|
]
|
|
};
|
|
|
|
const output = parser(input);
|
|
expect(output).toEqual(`vars {
|
|
@description('Base API URL.')
|
|
url: http://localhost:3000
|
|
}
|
|
`);
|
|
});
|
|
|
|
it('should stringify multiline description with triple-quoted literal newlines', () => {
|
|
const input = {
|
|
variables: [
|
|
{
|
|
name: 'url',
|
|
value: 'http://localhost:3000',
|
|
enabled: true,
|
|
description: 'Line one\nLine two'
|
|
}
|
|
]
|
|
};
|
|
|
|
const output = parser(input);
|
|
expect(output).toContain('@description(\'\'\'\n Line one\n Line two\n \'\'\')');
|
|
});
|
|
|
|
it('should stringify description with emoji', () => {
|
|
const input = {
|
|
variables: [
|
|
{
|
|
name: 'token',
|
|
value: 'secret',
|
|
enabled: true,
|
|
description: 'API key 🔐 required'
|
|
}
|
|
]
|
|
};
|
|
|
|
const output = parser(input);
|
|
expect(output).toContain('@description(\'API key 🔐 required\')');
|
|
expect(output).toContain('token: secret');
|
|
});
|
|
|
|
it('should stringify multiline description with emoji using triple-quoted literal newlines', () => {
|
|
const input = {
|
|
variables: [
|
|
{
|
|
name: 'note',
|
|
value: 'val',
|
|
enabled: true,
|
|
description: 'Launch 🚀\nSecond line'
|
|
}
|
|
]
|
|
};
|
|
|
|
const output = parser(input);
|
|
expect(output).toContain('@description(\'\'\'\n Launch 🚀\n Second line\n \'\'\')');
|
|
});
|
|
|
|
it('should stringify description with LF (\\n) as multiline triple-quoted', () => {
|
|
const input = {
|
|
variables: [
|
|
{
|
|
name: 'note',
|
|
value: 'val',
|
|
enabled: true,
|
|
description: 'First\nSecond\nThird'
|
|
}
|
|
]
|
|
};
|
|
|
|
const output = parser(input);
|
|
expect(output).toContain('@description(\'\'\'\n First\n Second\n Third\n \'\'\')');
|
|
});
|
|
|
|
it('should stringify description with CRLF (\\r\\n) as multiline triple-quoted with LF normalization', () => {
|
|
const input = {
|
|
variables: [
|
|
{
|
|
name: 'note',
|
|
value: 'val',
|
|
enabled: true,
|
|
description: 'Line one\r\nLine two'
|
|
}
|
|
]
|
|
};
|
|
|
|
const output = parser(input);
|
|
// indentString normalizes \r\n to \n when serializing
|
|
expect(output).toContain('@description(\'\'\'\n Line one\n Line two\n \'\'\')');
|
|
});
|
|
|
|
it('should stringify secret vars', () => {
|
|
const input = {
|
|
variables: [
|
|
{
|
|
name: 'url',
|
|
value: 'http://localhost:3000',
|
|
enabled: true
|
|
},
|
|
{
|
|
name: 'token',
|
|
value: 'abracadabra',
|
|
enabled: true,
|
|
secret: true
|
|
}
|
|
]
|
|
};
|
|
|
|
const output = parser(input);
|
|
const expected = `vars {
|
|
url: http://localhost:3000
|
|
}
|
|
vars:secret [
|
|
token
|
|
]
|
|
`;
|
|
expect(output).toEqual(expected);
|
|
});
|
|
|
|
it('should stringify multiple secret vars', () => {
|
|
const input = {
|
|
variables: [
|
|
{
|
|
name: 'url',
|
|
value: 'http://localhost:3000',
|
|
enabled: true
|
|
},
|
|
{
|
|
name: 'access_token',
|
|
value: 'abracadabra',
|
|
enabled: true,
|
|
secret: true
|
|
},
|
|
{
|
|
name: 'access_secret',
|
|
value: 'abracadabra',
|
|
enabled: false,
|
|
secret: true
|
|
}
|
|
]
|
|
};
|
|
|
|
const output = parser(input);
|
|
const expected = `vars {
|
|
url: http://localhost:3000
|
|
}
|
|
vars:secret [
|
|
access_token,
|
|
~access_secret
|
|
]
|
|
`;
|
|
expect(output).toEqual(expected);
|
|
});
|
|
|
|
it('should stringify even if the only secret vars are present', () => {
|
|
const input = {
|
|
variables: [
|
|
{
|
|
name: 'token',
|
|
value: 'abracadabra',
|
|
enabled: true,
|
|
secret: true
|
|
}
|
|
]
|
|
};
|
|
|
|
const output = parser(input);
|
|
const expected = `vars:secret [
|
|
token
|
|
]
|
|
`;
|
|
expect(output).toEqual(expected);
|
|
});
|
|
|
|
it('should emit @description prefix even for multiline variables', () => {
|
|
const input = {
|
|
variables: [
|
|
{
|
|
name: 'json_data',
|
|
value: '{\n "name": "test"\n}',
|
|
enabled: true,
|
|
description: 'A multiline JSON blob'
|
|
}
|
|
]
|
|
};
|
|
|
|
const output = parser(input);
|
|
expect(output).toEqual(`vars {
|
|
@description('A multiline JSON blob')
|
|
json_data: '''
|
|
{
|
|
"name": "test"
|
|
}
|
|
'''
|
|
}
|
|
`);
|
|
});
|
|
|
|
it('should stringify multiline variables', () => {
|
|
const input = {
|
|
variables: [
|
|
{
|
|
name: 'json_data',
|
|
value: '{\n "name": "test",\n "value": 123\n}',
|
|
enabled: true
|
|
}
|
|
]
|
|
};
|
|
|
|
const output = parser(input);
|
|
const expected = `vars {
|
|
json_data: '''
|
|
{
|
|
"name": "test",
|
|
"value": 123
|
|
}
|
|
'''
|
|
}
|
|
`;
|
|
expect(output).toEqual(expected);
|
|
});
|
|
|
|
it('should stringify multiline variables containing indentation', () => {
|
|
const input = {
|
|
variables: [
|
|
{
|
|
name: 'script',
|
|
value: 'function test() {\n console.log("hello");\n return true;\n}',
|
|
enabled: true
|
|
}
|
|
]
|
|
};
|
|
|
|
const output = parser(input);
|
|
const expected = `vars {
|
|
script: '''
|
|
function test() {
|
|
console.log("hello");
|
|
return true;
|
|
}
|
|
'''
|
|
}
|
|
`;
|
|
expect(output).toEqual(expected);
|
|
});
|
|
|
|
it('should stringify disabled multiline variable', () => {
|
|
const input = {
|
|
variables: [
|
|
{
|
|
name: 'disabled_multiline',
|
|
value: 'line 1\nline 2\nline 3',
|
|
enabled: false
|
|
}
|
|
]
|
|
};
|
|
|
|
const output = parser(input);
|
|
const expected = `vars {
|
|
~disabled_multiline: '''
|
|
line 1
|
|
line 2
|
|
line 3
|
|
'''
|
|
}
|
|
`;
|
|
expect(output).toEqual(expected);
|
|
});
|
|
|
|
it('should stringify multiple multiline variables', () => {
|
|
const input = {
|
|
variables: [
|
|
{
|
|
name: 'config',
|
|
value: 'debug=true\nport=3000',
|
|
enabled: true
|
|
},
|
|
{
|
|
name: 'template',
|
|
value: '<html>\n <body>Hello World</body>\n</html>',
|
|
enabled: true
|
|
}
|
|
]
|
|
};
|
|
|
|
const output = parser(input);
|
|
const expected = `vars {
|
|
config: '''
|
|
debug=true
|
|
port=3000
|
|
'''
|
|
template: '''
|
|
<html>
|
|
<body>Hello World</body>
|
|
</html>
|
|
'''
|
|
}
|
|
`;
|
|
expect(output).toEqual(expected);
|
|
});
|
|
|
|
describe('typed environment variables', () => {
|
|
it('should serialize @number dataType as a decorator', () => {
|
|
const input = {
|
|
variables: [
|
|
{ name: 'port', value: 3000, enabled: true, dataType: 'number' }
|
|
]
|
|
};
|
|
|
|
const output = parser(input);
|
|
expect(output).toEqual(`vars {
|
|
@number
|
|
port: 3000
|
|
}
|
|
`);
|
|
});
|
|
|
|
it('should serialize @boolean dataType as a decorator', () => {
|
|
const input = {
|
|
variables: [
|
|
{ name: 'isEnabled', value: true, enabled: true, dataType: 'boolean' }
|
|
]
|
|
};
|
|
|
|
const output = parser(input);
|
|
expect(output).toEqual(`vars {
|
|
@boolean
|
|
isEnabled: true
|
|
}
|
|
`);
|
|
});
|
|
|
|
it('should serialize @object dataType with JSON-stringified multiline value', () => {
|
|
const input = {
|
|
variables: [
|
|
{ name: 'config', value: { a: 1, b: 'x' }, enabled: true, dataType: 'object' }
|
|
]
|
|
};
|
|
|
|
const output = parser(input);
|
|
expect(output).toContain('@object');
|
|
expect(output).toContain('"a": 1');
|
|
expect(output).toContain('"b": "x"');
|
|
});
|
|
|
|
it('should not emit a decorator for string dataType', () => {
|
|
const input = {
|
|
variables: [
|
|
{ name: 'apiKey', value: 'abc123', enabled: true, dataType: 'string' }
|
|
]
|
|
};
|
|
|
|
const output = parser(input);
|
|
expect(output).toEqual(`vars {
|
|
apiKey: abc123
|
|
}
|
|
`);
|
|
});
|
|
|
|
it('should drop dataType annotations from existing list and rebuild from dataType field', () => {
|
|
const input = {
|
|
variables: [
|
|
{
|
|
name: 'port',
|
|
value: 3000,
|
|
enabled: true,
|
|
annotations: [{ name: 'string' }, { name: 'description', value: 'service port' }],
|
|
dataType: 'number'
|
|
}
|
|
]
|
|
};
|
|
|
|
const output = parser(input);
|
|
// @string from old annotations should be dropped, @number should be set from dataType
|
|
expect(output).toContain('@number');
|
|
expect(output).not.toContain('@string');
|
|
expect(output).toContain('@description(\'service port\')');
|
|
});
|
|
|
|
it('should emit dataType but not the value for secret vars', () => {
|
|
const input = {
|
|
variables: [
|
|
{ name: 'api_key', value: 'redacted', enabled: true, secret: true, dataType: 'number' }
|
|
]
|
|
};
|
|
|
|
const output = parser(input);
|
|
// secret vars use the vars:secret block: the dataType is emitted as a
|
|
// decorator, but the value is never written to disk.
|
|
expect(output).toContain('vars:secret');
|
|
expect(output).toContain('api_key');
|
|
expect(output).toContain('@number');
|
|
expect(output).not.toContain('redacted');
|
|
});
|
|
|
|
it('should round-trip non-string values through getValueString', () => {
|
|
const input = {
|
|
variables: [
|
|
{ name: 'port', value: 8080, enabled: true, dataType: 'number' },
|
|
{ name: 'flag', value: false, enabled: true, dataType: 'boolean' }
|
|
]
|
|
};
|
|
|
|
const output = parser(input);
|
|
expect(output).toContain('port: 8080');
|
|
expect(output).toContain('flag: false');
|
|
});
|
|
});
|
|
});
|