Skip to content

Commit

Permalink
Merge pull request #4 from betrybe/ajusta-mensagem-feedback
Browse files Browse the repository at this point in the history
Adiciona listagem de avisos
  • Loading branch information
inaC authored Sep 15, 2020
2 parents 2c60855 + 4b43768 commit 235bd0c
Show file tree
Hide file tree
Showing 8 changed files with 508 additions and 47 deletions.
118 changes: 107 additions & 11 deletions __tests__/feedbackMessage.test.js
Original file line number Diff line number Diff line change
@@ -1,17 +1,28 @@
const buildFeedbackMessage = require('../feedbackMessage');
const noError = require('./fixtures/eslint-results/frontEndNoError.json');
const oneError = require('./fixtures/eslint-results/oneError.json');
const multipleErrorsOneFile = require('./fixtures/eslint-results/multipleErrorsOneFile.json');
const multipleWarningsOneFile = require('./fixtures/eslint-results/multipleWarningsOneFile.json');
const multipleWarningsAndErrorsOneFile = require('./fixtures/eslint-results/multipleWarningsAndErrorsOneFile.json');
const multipleErrorsMultipleFiles = require('./fixtures/eslint-results/multipleErrorsMultipleFiles.json');
const multipleWarningsMultipleFiles = require('./fixtures/eslint-results/multipleWarningsMultipleFiles.json');
const noError = require('./fixtures/eslint-results/frontEndNoError.json');
const oneError = require('./fixtures/eslint-results/oneError.json');
const oneErrorOneFileMultipleWarningsAnotherFile = require('./fixtures/eslint-results/oneErrorOneFileMultipleWarningsAnotherFile.json');
const oneWarning = require('./fixtures/eslint-results/oneWarning.json');

describe('Feedback message', () => {
describe('No error is found', () => {
test('When there is no file to be evaluated, a no error encountered message is returned', () => {
expect(buildFeedbackMessage([], './')).toBe('### Nenhum erro encontrado.')
describe('No issue is found', () => {
test('When there is no file to be evaluated, a no issue encountered message is returned', () => {
expect(buildFeedbackMessage([], './')).toBe(
'### Nenhum erro encontrado.\n' +
'### Nenhum aviso encontrado.'
)
});

test('When there are files to be evaluated, a no error encountered message is returned', () => {
expect(buildFeedbackMessage(noError, './')).toBe('### Nenhum erro encontrado.')
test('When there are files to be evaluated, a no issue encountered message is returned', () => {
expect(buildFeedbackMessage(noError, './')).toBe(
'### Nenhum erro encontrado.\n' +
'### Nenhum aviso encontrado.'
)
});
});

Expand All @@ -21,7 +32,9 @@ describe('Feedback message', () => {
'\n' +
'#### Arquivo `/my-project/index.js`\n' +
'\n' +
'- Linha **1**: Function \'isPentagon\' has too many parameters (5). Maximum allowed is 4.\n'
'- Linha **1**: Function \'isPentagon\' has too many parameters (5). Maximum allowed is 4.\n' +
'\n' +
'### Nenhum aviso encontrado.'
);
});

Expand All @@ -35,7 +48,9 @@ describe('Feedback message', () => {
'- Linha **3**: \'name\' is missing in props validation\n' +
'- Linha **3**: `Hello, ` must be placed on a new line\n' +
'- Linha **3**: `{name}` must be placed on a new line\n' +
'- Linha **5**: Missing semicolon.\n'
'- Linha **5**: Missing semicolon.\n' +
'\n' +
'### Nenhum aviso encontrado.'
);
});

Expand All @@ -51,7 +66,86 @@ describe('Feedback message', () => {
'' +
'#### Arquivo `/my-react-project/src/components/Greeting.js`\n' +
'\n' +
'- Linha **3**: \'name\' is missing in props validation\n'
'- Linha **3**: \'name\' is missing in props validation\n' +
'\n' +
'### Nenhum aviso encontrado.'
);
});
});

test('When one warning is found, a message showing the warning is returned', () => {
expect(buildFeedbackMessage(oneWarning, './')).toBe(
'### Nenhum erro encontrado.\n' +
'### Foi encontrado 1 aviso.\n' +
'\n' +
'#### Arquivo `/back-end/index.js`\n' +
'\n' +
'- Linha **8**: Unexpected console statement.\n'
);
});

describe('Multiple warnings are found', () => {
test('When all warnings are contained in one file, a message listing all those warnings is returned', () => {
expect(buildFeedbackMessage(multipleWarningsOneFile, './')).toBe(
'### Nenhum erro encontrado.\n' +
'### Foram encontrados 2 avisos.\n' +
'\n' +
'#### Arquivo `/front-end/src/App.js`\n' +
'\n' +
'- Linha **7**: Unexpected console statement.\n' +
'- Linha **28**: Unexpected alert.\n'
);
});

test('When the warnings span multiple files, a message listing all those warnings is returned', () => {
expect(buildFeedbackMessage(multipleWarningsMultipleFiles, './')).toBe(
'### Nenhum erro encontrado.\n' +
'### Foram encontrados 3 avisos.\n' +
'\n' +
'#### Arquivo `/front-end/src/App.js`\n' +
'\n' +
'- Linha **7**: Unexpected console statement.\n' +
'- Linha **28**: Unexpected alert.\n' +
'' +
'#### Arquivo `/front-end/src/components/Greeting.js`\n' +
'\n' +
'- Linha **7**: Missing trailing comma.\n'
);
});
});

describe('Errors and warnings are found', () => {
test('When all errors and warnings are contained in one file, a message listing both errors and warnings is returned', () => {
expect(buildFeedbackMessage(multipleWarningsAndErrorsOneFile, './')).toBe(
'### Foi encontrado 1 erro.\n' +
'\n' +
'#### Arquivo `/front-end/src/App.js`\n'+
'\n' +
'- Linha **33**: Newline required at end of file but not found.\n' +
'\n' +
'### Foram encontrados 2 avisos.\n' +
'\n' +
'#### Arquivo `/front-end/src/App.js`\n'+
'\n' +
'- Linha **7**: Unexpected console statement.\n' +
'- Linha **28**: Unexpected alert.\n'
);
});

test('When errors are in one file and warnings are in another one, a message listing both errors and warnings for those files is returned', () => {
expect(buildFeedbackMessage(oneErrorOneFileMultipleWarningsAnotherFile, './')).toBe(
'### Foi encontrado 1 erro.\n' +
'\n' +
'#### Arquivo `/front-end/src/components/Greeting.js`\n'+
'\n' +
'- Linha **2**: Missing semicolon.\n' +
'\n' +
'### Foram encontrados 2 avisos.\n' +
'\n' +
'#### Arquivo `/front-end/src/App.js`\n'+
'\n' +
'- Linha **7**: Unexpected console statement.\n' +
'- Linha **28**: Unexpected alert.\n'
);
});
});
Expand All @@ -68,7 +162,9 @@ describe('Feedback message', () => {
'' +
'#### Arquivo `/src/components/Greeting.js`\n' +
'\n' +
'- Linha **3**: \'name\' is missing in props validation\n'
'- Linha **3**: \'name\' is missing in props validation\n' +
'\n' +
'### Nenhum aviso encontrado.'
);
});
});
Original file line number Diff line number Diff line change
@@ -0,0 +1,74 @@
[
{
"filePath": "/front-end/src/App.js",
"messages": [
{
"ruleId": "no-console",
"severity": 1,
"message": "Unexpected console statement.",
"line": 7,
"column": 3,
"nodeType": "MemberExpression",
"messageId": "unexpected",
"endLine": 7,
"endColumn": 14
},
{
"ruleId": "no-alert",
"severity": 1,
"message": "Unexpected alert.",
"line": 28,
"column": 44,
"nodeType": "CallExpression",
"messageId": "unexpected",
"endLine": 28,
"endColumn": 68
},
{
"ruleId": "eol-last",
"severity": 2,
"message": "Newline required at end of file but not found.",
"line": 33,
"column": 20,
"nodeType": "Program",
"messageId": "missing",
"fix": {
"range": [
774,
774
],
"text": "\n"
}
}
],
"errorCount": 1,
"warningCount": 2,
"fixableErrorCount": 1,
"fixableWarningCount": 0,
"source": "import React from 'react';\nimport logo from './logo.svg';\nimport './App.css';\nimport Greeting from './components/Greeting';\n\nfunction App() {\n console.log('Rendering App..');\n\n return (\n <div className=\"App\">\n <header className=\"App-header\">\n <img src={logo} className=\"App-logo\" alt=\"logo\" />\n <p>\n Edit\n <code>src/App.js</code>\n and save to reload.\n </p>\n <a\n className=\"App-link\"\n href=\"https://reactjs.org\"\n target=\"_blank\"\n rel=\"noopener noreferrer\"\n >\n Learn React\n </a>\n </header>\n <Greeting name=\"Alex\" />\n <button type=\"button\" onClick={() => alert('You clicked me!')}>Click me!</button>\n </div>\n );\n}\n\nexport default App;"
},
{
"filePath": "/front-end/src/components/Greeting.js",
"messages": [],
"errorCount": 0,
"warningCount": 0,
"fixableErrorCount": 0,
"fixableWarningCount": 0
},
{
"filePath": "/front-end/src/index.js",
"messages": [],
"errorCount": 0,
"warningCount": 0,
"fixableErrorCount": 0,
"fixableWarningCount": 0
},
{
"filePath": "/front-end/src/setupTests.js",
"messages": [],
"errorCount": 0,
"warningCount": 0,
"fixableErrorCount": 0,
"fixableWarningCount": 0
}
]
Original file line number Diff line number Diff line change
@@ -0,0 +1,78 @@
[
{
"filePath": "/front-end/src/App.js",
"messages": [
{
"ruleId": "no-console",
"severity": 1,
"message": "Unexpected console statement.",
"line": 7,
"column": 3,
"nodeType": "MemberExpression",
"messageId": "unexpected",
"endLine": 7,
"endColumn": 14
},
{
"ruleId": "no-alert",
"severity": 1,
"message": "Unexpected alert.",
"line": 28,
"column": 44,
"nodeType": "CallExpression",
"messageId": "unexpected",
"endLine": 28,
"endColumn": 68
}
],
"errorCount": 0,
"warningCount": 2,
"fixableErrorCount": 0,
"fixableWarningCount": 0,
"source": "import React from 'react';\nimport logo from './logo.svg';\nimport './App.css';\nimport Greeting from './components/Greeting';\n\nfunction App() {\n console.log('Rendering App..');\n\n return (\n <div className=\"App\">\n <header className=\"App-header\">\n <img src={logo} className=\"App-logo\" alt=\"logo\" />\n <p>\n Edit\n <code>src/App.js</code>\n and save to reload.\n </p>\n <a\n className=\"App-link\"\n href=\"https://reactjs.org\"\n target=\"_blank\"\n rel=\"noopener noreferrer\"\n >\n Learn React\n </a>\n </header>\n <Greeting name=\"Alex\" />\n <button type=\"button\" onClick={() => alert('You clicked me!')}>Click me!</button>\n </div>\n );\n}\n\nexport default App;\n"
},
{
"filePath": "/front-end/src/components/Greeting.js",
"messages": [
{
"ruleId": "comma-dangle",
"severity": 1,
"message": "Missing trailing comma.",
"line": 7,
"column": 36,
"nodeType": "Property",
"messageId": "missing",
"endLine": 8,
"endColumn": 1,
"fix": {
"range": [
183,
183
],
"text": ","
}
}
],
"errorCount": 0,
"warningCount": 1,
"fixableErrorCount": 0,
"fixableWarningCount": 1,
"source": "import React from 'react';\nimport PropTypes from 'prop-types';\n\nconst Greeting = ({ name }) => <h1>{`Hello, ${name}`}</h1>;\n\nGreeting.propTypes = {\n name: PropTypes.string.isRequired\n};\n\nexport default Greeting;\n"
},
{
"filePath": "/front-end/src/index.js",
"messages": [],
"errorCount": 0,
"warningCount": 0,
"fixableErrorCount": 0,
"fixableWarningCount": 0
},
{
"filePath": "/front-end/src/setupTests.js",
"messages": [],
"errorCount": 0,
"warningCount": 0,
"fixableErrorCount": 0,
"fixableWarningCount": 0
}
]
58 changes: 58 additions & 0 deletions __tests__/fixtures/eslint-results/multipleWarningsOneFile.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
[
{
"filePath": "/front-end/src/App.js",
"messages": [
{
"ruleId": "no-console",
"severity": 1,
"message": "Unexpected console statement.",
"line": 7,
"column": 3,
"nodeType": "MemberExpression",
"messageId": "unexpected",
"endLine": 7,
"endColumn": 14
},
{
"ruleId": "no-alert",
"severity": 1,
"message": "Unexpected alert.",
"line": 28,
"column": 44,
"nodeType": "CallExpression",
"messageId": "unexpected",
"endLine": 28,
"endColumn": 68
}
],
"errorCount": 0,
"warningCount": 2,
"fixableErrorCount": 0,
"fixableWarningCount": 0,
"source": "import React from 'react';\nimport logo from './logo.svg';\nimport './App.css';\nimport Greeting from './components/Greeting';\n\nfunction App() {\n console.log('Rendering App..');\n\n return (\n <div className=\"App\">\n <header className=\"App-header\">\n <img src={logo} className=\"App-logo\" alt=\"logo\" />\n <p>\n Edit\n <code>src/App.js</code>\n and save to reload.\n </p>\n <a\n className=\"App-link\"\n href=\"https://reactjs.org\"\n target=\"_blank\"\n rel=\"noopener noreferrer\"\n >\n Learn React\n </a>\n </header>\n <Greeting name=\"Alex\" />\n <button type=\"button\" onClick={() => alert('You clicked me!')}>Click me!</button>\n </div>\n );\n}\n\nexport default App;\n"
},
{
"filePath": "/front-end/src/components/Greeting.js",
"messages": [],
"errorCount": 0,
"warningCount": 0,
"fixableErrorCount": 0,
"fixableWarningCount": 0
},
{
"filePath": "/front-end/src/index.js",
"messages": [],
"errorCount": 0,
"warningCount": 0,
"fixableErrorCount": 0,
"fixableWarningCount": 0
},
{
"filePath": "/front-end/src/setupTests.js",
"messages": [],
"errorCount": 0,
"warningCount": 0,
"fixableErrorCount": 0,
"fixableWarningCount": 0
}
]
Loading

0 comments on commit 235bd0c

Please sign in to comment.