check array length and only add newlines if length > 0

Signed-off-by: Max Falk <gmdfalk@gmail.com>
This commit is contained in:
Max Falk
2021-06-07 23:51:34 +02:00
committed by Fredrik Adelöw
parent 21e8ebef5d
commit 30627bd3e7
2 changed files with 14 additions and 3 deletions
+11 -1
View File
@@ -23,6 +23,16 @@ describe('formatErrorMessage with esbuild plugin error', () => {
plugin: 'esbuild',
message: 'test',
});
expect(msg).toBe('test\n\n');
expect(msg).toBe('test');
});
it('given error with errors array then error message should have new lines', () => {
const msg = formatErrorMessage({
code: 'PLUGIN_ERROR',
plugin: 'esbuild',
message: 'test',
id: 'index.js',
errors: [{ text: 'Dummy', location: { line: 1, column: 1 } }],
});
expect(msg).toContain('test\n\n');
});
});
+3 -2
View File
@@ -27,8 +27,9 @@ export function formatErrorMessage(error: any) {
if (error.code === 'PLUGIN_ERROR') {
if (error.plugin === 'esbuild') {
msg += `${error.message}\n\n`;
if (error.errors) {
msg += `${error.message}`;
if (error.errors?.length) {
msg += `\n\n`;
for (const { text, location } of error.errors) {
const { line, column } = location;
const path = relativePath(paths.targetDir, error.id);