diff --git a/action.yml b/action.yml index e8e00d2..2edbf5c 100644 --- a/action.yml +++ b/action.yml @@ -42,13 +42,13 @@ runs: path: | ~/.android/avd/* ~/.android/adb* - key: avd-${{ matrix.api-level } + key: avd-29 - name: create AVD and generate snapshot for caching - if: steps.avd-cache.outputs.cache-hit != 'true' + if: ${{ steps.avd-cache.outputs.cache-hit != 'true' }} uses: reactivecircus/android-emulator-runner@v2 with: - api-level: ${{ matrix.api-level }} + api-level: 29 force-avd-creation: false emulator-options: -no-window -gpu swiftshader_indirect -noaudio -no-boot-anim -camera-back none disable-animations: false diff --git a/dist/index.js b/dist/index.js index 2464948..0f4181f 100644 --- a/dist/index.js +++ b/dist/index.js @@ -9493,7 +9493,7 @@ const core = __nccwpck_require__(6442) const Base64 = (__nccwpck_require__(835)/* .Base64 */ .D) const { loadFile, searchFilesXml } = __nccwpck_require__(9078) const { parserXmlToObject } = __nccwpck_require__(1253) -const { getGithubUsernameData, getGithubRepositoryNameData } = __nccwpck_require__(1911) +const { getGithubUsernameData, getGithubRepositoryNameData } = __nccwpck_require__(1911) const APPROVED_GRADE = 3 const UNAPPROVED_GRADE = 1 @@ -9513,33 +9513,27 @@ const UNAPPROVED_GRADE = 1 function runStepsEvaluator(pathList) { try { const pathFiles = getTestFiles(pathList) - const testCasesList = pathFiles.map((pathFile) => { + + const testCases = pathFiles.map((pathFile) => { return buildTestCaseList(pathFile.path, pathFile.files) }).reduce((acc, testType) => acc.concat(testType), []) - const output = generateOutputJSON(testCasesList) - const outputBase64 = parserJSONtoBase64(output) + const testCasesJSON = convertTestCasesToJSON(testCases) + const testCasesInBase64 = convertTestCasesToBase64(testCasesJSON) + + core.setOutput('result', testCasesInBase64) - core.setOutput('result', outputBase64) + core.info('\u001b[38;5;6m[info] ✅ Avaliador finalizado.') } catch(error) { core.setFailed(`Action failed with error: ${error}`) } } -/** - * @param {Object} content_json - * @returns {string} - */ -function parserJSONtoBase64(content_json) { +function convertTestCasesToBase64(testCasesJSON) { var enc = new Base64() - return enc.encode(content_json) + return enc.encode(testCasesJSON) } -/** - * @param {string} path - * @param {string[]} files - * @returns {Object[]} - */ function buildTestCaseList(path, files){ return files.map((file) => { const loadedFile = loadFile(`${path}/${file}`) @@ -9561,89 +9555,32 @@ function getTestFiles(pathList) { return pathFiles } -/** - * Gera saida em json apartir de um objeto - * TODO get github_username e github_repository - * @param {*} testcaseList - * @example generateOutputJSON() - * @returns - * { - "github_username":"katiacih", - "github_repository":"project_test_example", - "evaluations":[ - {"grade":1,"description":"addition_isIncorrect"}, - {"grade":3,"description":"addition_isCorrect"} - ] - } - */ -function generateOutputJSON(testcaseList) { + +function convertTestCasesToJSON(testCases) { const username = getGithubUsernameData() const repository = getGithubRepositoryNameData() return JSON.stringify({ github_username: username, github_repository: repository, - evaluations: generateObjectEvaluations(testcaseList) + evaluations: generateEvaluations(testCases) }) } - -/** - * Para cada testcase retorna a estrutura com nota e descrição - * @param {*} failures Lista de failures do requisito. - * @param {*} requirementDescription Descrição do requisito. - * @example getGrade( [ - { - message: 'java.lang.AssertionError: expected:<7> but was:<8>', - type: 'java.lang.AssertionError' - } -], "Description ...") - * @returns { - grade: UNAPPROVED_GRADE | APPROVED_GRADE, - description: "" - } - */ -function getGrade( failures, requirementDescription ) { - if(failures !== null && failures?.length > 0 ){ +function getGrade(failures, requirementDescription) { + if (failures !== null && failures?.length > 0 ) { return { grade: UNAPPROVED_GRADE, description: requirementDescription } } else return { grade: APPROVED_GRADE, description: requirementDescription } } -/** - * Dado uma lista de testcases monta a estrutura com ojeto para gerar output - * @param {*} testcaseList Lista de testcases - * @example generateObjectEvaluations([ - { - name: 'addition_isIcorrect', - classname: 'com.example.myapplication_teste.ExampleUnitTest', - time: '0.004', - failures: [ [Object] ] - }, - { - name: 'addition_isCorrect', - classname: 'com.example.myapplication_teste.ExampleUnitTest', - time: '0.0', - failures: null - } - ]) -* @returns [ - { grade: 1, description: 'addition_isIcorrect' }, - { grade: 3, description: 'addition_isCorrect' }] - */ -function generateObjectEvaluations(testcaseList) { - return testcaseList.map((testcase) => { - return getGrade(testcase.failures, testcase.name) +function generateEvaluations(testCases) { + return testCases.map((testCase) => { + return getGrade(testCase.failures, testCase.name) }) } -/** - * Mapea um objeto testcase para analise - * @param {obj} testcase - * @example mapTestCase(testcase) - * @author Kátia Cibele - */ -function mapTestCase(testcase) { - return testcase.map((item) => { +function mapTestCase(testCase) { + return testCase.map((item) => { return { name: item.$.name, classname: item.$.classname, @@ -9653,14 +9590,7 @@ function mapTestCase(testcase) { }) } -/** - * Mapea um objeto testsuite para analise - * @param {object} obj - * @example mapValues({}) - * @return {object} - */ function mapValuesTestSuite(obj) { - return { name: obj.testsuite.$.name, tests: obj.testsuite.$.tests, @@ -9672,28 +9602,18 @@ function mapValuesTestSuite(obj) { time: obj.testsuite.$.time, testcase: mapTestCase(obj.testsuite.testcase) } - } module.exports = { - generateObjectEvaluations, - generateOutputJSON, - getGrade, - mapTestCase, - mapValuesTestSuite, - parserJSONtoBase64, runStepsEvaluator } - - /***/ }), /***/ 9078: /***/ ((module, __unused_webpack_exports, __nccwpck_require__) => { - const fs = __nccwpck_require__(7147) const path = __nccwpck_require__(1017) const core = __nccwpck_require__(6442) @@ -9801,16 +9721,6 @@ module.exports = { const xml2js = __nccwpck_require__(6193) -/** - * Transforma objeto json in base64 - * @param {string} content_json - * @example parserJSONtoBase64(content_json) - * @output string - */ -function parserJSONtoBase64(content_json) { - return Buffer.from(content_json).toString('base64') -} - /** * Transforma xml em object * @param {string} xml_string @@ -9855,10 +9765,8 @@ function parserXmlToObject(xml_string) { return output } - module.exports = { - parserXmlToObject, - parserJSONtoBase64 + parserXmlToObject } diff --git a/src/controller/evaluator.js b/src/controller/evaluator.js index ad79d0a..63f9bad 100644 --- a/src/controller/evaluator.js +++ b/src/controller/evaluator.js @@ -2,7 +2,7 @@ const core = require('@actions/core') const Base64 = require('base64-string').Base64 const { loadFile, searchFilesXml } = require('./fileManager') const { parserXmlToObject } = require('./xmlParser') -const { getGithubUsernameData, getGithubRepositoryNameData } = require('./util') +const { getGithubUsernameData, getGithubRepositoryNameData } = require('./util') const APPROVED_GRADE = 3 const UNAPPROVED_GRADE = 1 @@ -22,33 +22,27 @@ const UNAPPROVED_GRADE = 1 function runStepsEvaluator(pathList) { try { const pathFiles = getTestFiles(pathList) - const testCasesList = pathFiles.map((pathFile) => { + + const testCases = pathFiles.map((pathFile) => { return buildTestCaseList(pathFile.path, pathFile.files) }).reduce((acc, testType) => acc.concat(testType), []) - const output = generateOutputJSON(testCasesList) - const outputBase64 = parserJSONtoBase64(output) + const testCasesJSON = convertTestCasesToJSON(testCases) + const testCasesInBase64 = convertTestCasesToBase64(testCasesJSON) + + core.setOutput('result', testCasesInBase64) - core.setOutput('result', outputBase64) + core.info('\u001b[38;5;6m[info] ✅ Avaliador finalizado.') } catch(error) { core.setFailed(`Action failed with error: ${error}`) } } -/** - * @param {Object} content_json - * @returns {string} - */ -function parserJSONtoBase64(content_json) { +function convertTestCasesToBase64(testCasesJSON) { var enc = new Base64() - return enc.encode(content_json) + return enc.encode(testCasesJSON) } -/** - * @param {string} path - * @param {string[]} files - * @returns {Object[]} - */ function buildTestCaseList(path, files){ return files.map((file) => { const loadedFile = loadFile(`${path}/${file}`) @@ -70,89 +64,32 @@ function getTestFiles(pathList) { return pathFiles } -/** - * Gera saida em json apartir de um objeto - * TODO get github_username e github_repository - * @param {*} testcaseList - * @example generateOutputJSON() - * @returns - * { - "github_username":"katiacih", - "github_repository":"project_test_example", - "evaluations":[ - {"grade":1,"description":"addition_isIncorrect"}, - {"grade":3,"description":"addition_isCorrect"} - ] - } - */ -function generateOutputJSON(testcaseList) { + +function convertTestCasesToJSON(testCases) { const username = getGithubUsernameData() const repository = getGithubRepositoryNameData() return JSON.stringify({ github_username: username, github_repository: repository, - evaluations: generateObjectEvaluations(testcaseList) + evaluations: generateEvaluations(testCases) }) } - -/** - * Para cada testcase retorna a estrutura com nota e descrição - * @param {*} failures Lista de failures do requisito. - * @param {*} requirementDescription Descrição do requisito. - * @example getGrade( [ - { - message: 'java.lang.AssertionError: expected:<7> but was:<8>', - type: 'java.lang.AssertionError' - } -], "Description ...") - * @returns { - grade: UNAPPROVED_GRADE | APPROVED_GRADE, - description: "" - } - */ -function getGrade( failures, requirementDescription ) { - if(failures !== null && failures?.length > 0 ){ +function getGrade(failures, requirementDescription) { + if (failures !== null && failures?.length > 0 ) { return { grade: UNAPPROVED_GRADE, description: requirementDescription } } else return { grade: APPROVED_GRADE, description: requirementDescription } } -/** - * Dado uma lista de testcases monta a estrutura com ojeto para gerar output - * @param {*} testcaseList Lista de testcases - * @example generateObjectEvaluations([ - { - name: 'addition_isIcorrect', - classname: 'com.example.myapplication_teste.ExampleUnitTest', - time: '0.004', - failures: [ [Object] ] - }, - { - name: 'addition_isCorrect', - classname: 'com.example.myapplication_teste.ExampleUnitTest', - time: '0.0', - failures: null - } - ]) -* @returns [ - { grade: 1, description: 'addition_isIcorrect' }, - { grade: 3, description: 'addition_isCorrect' }] - */ -function generateObjectEvaluations(testcaseList) { - return testcaseList.map((testcase) => { - return getGrade(testcase.failures, testcase.name) +function generateEvaluations(testCases) { + return testCases.map((testCase) => { + return getGrade(testCase.failures, testCase.name) }) } -/** - * Mapea um objeto testcase para analise - * @param {obj} testcase - * @example mapTestCase(testcase) - * @author Kátia Cibele - */ -function mapTestCase(testcase) { - return testcase.map((item) => { +function mapTestCase(testCase) { + return testCase.map((item) => { return { name: item.$.name, classname: item.$.classname, @@ -162,14 +99,7 @@ function mapTestCase(testcase) { }) } -/** - * Mapea um objeto testsuite para analise - * @param {object} obj - * @example mapValues({}) - * @return {object} - */ function mapValuesTestSuite(obj) { - return { name: obj.testsuite.$.name, tests: obj.testsuite.$.tests, @@ -181,17 +111,8 @@ function mapValuesTestSuite(obj) { time: obj.testsuite.$.time, testcase: mapTestCase(obj.testsuite.testcase) } - } module.exports = { - generateObjectEvaluations, - generateOutputJSON, - getGrade, - mapTestCase, - mapValuesTestSuite, - parserJSONtoBase64, runStepsEvaluator } - - diff --git a/src/controller/fileManager.js b/src/controller/fileManager.js index 564e155..1ef59aa 100644 --- a/src/controller/fileManager.js +++ b/src/controller/fileManager.js @@ -1,4 +1,3 @@ - const fs = require('fs') const path = require('path') const core = require('@actions/core') diff --git a/src/controller/parserOutput.js b/src/controller/parserOutput.js deleted file mode 100644 index 2dda616..0000000 --- a/src/controller/parserOutput.js +++ /dev/null @@ -1,88 +0,0 @@ -const core = require('@actions/core') - -/** - * @param {string} unitTestOutput - * @param {string} instrumentedTestOutput - * @returns {string} - */ -function processingOutputTests(unitTestOutput, instrumentedTestOutput) { - try { - - core.info('\u001b[48;5;6m[info] 🖇 Unindo outputs de testes instrumentados e testes unitários.') - return generateObjectFromOutputs(unitTestOutput, instrumentedTestOutput) - - } catch (error) { - core.setFailed(`${error}`) - } -} - - -/** Unifica outputs de testes instrumentados e testes unitários - * @param {string} unitTestOut string em base64 do objeto dos testes unitarios - * @param {string} instrumentedTestOut string em base64 - * @returns {string} { - github_username: '', - github_repository: '', - evaluations: [] - } - */ -function generateObjectFromOutputs(unitTestOut, instrumentedTestOut) { - try { - - let unitTestObject = parserBase64ToObject(unitTestOut) - let instrumentedTestObject = parserBase64ToObject(instrumentedTestOut) - - let evaluationsList = concatOutputs(unitTestObject, instrumentedTestObject) - - return { - github_username: unitTestObject.github_username, - github_repository: unitTestObject.github_repository, - evaluations: evaluationsList - } - } catch (error) { - throw error - } - -} - - -/** - * Decodifica base64 para objeto - * @param {string} data string em base64 do objeto - * @returns {object} { - github_username: '', - github_repository: '', - evaluations: [] - } - */ -function parserBase64ToObject(data) { - - try { - return JSON.parse(Buffer.from(data, 'base64').toString('utf8')) - }catch (_) { - throw new Error('Erro ao converter base 64 para objeto.') - } -} - -/** - * Concatena listas de evaluations - * @param {Object} data string em base64 do objeto - * @example concatOuputs({github_username: 'user1', - github_repository: 'repo', - evaluations: [{grade: 1, description: 'descricao 1'}]}, {github_username: 'user1', - github_repository: 'repo', - evaluations: [{grade: 2, description: 'descricao 2'}]}) - * @returns {Array} [{grade: 1, description: 'descricao 1'}, {grade: 2, description: 'descricao 2'}] - */ -function concatOutputs(objTest1, objTest2) { - try { - return objTest1.evaluations.concat(objTest2.evaluations) - } catch (_) { - throw new Error('Erro ao unificar outputs.') - } -} - -module.exports = { - processingOutputTests, - generateObjectFromOutputs -} diff --git a/src/controller/xmlParser.js b/src/controller/xmlParser.js index 6962293..bd0dd9b 100644 --- a/src/controller/xmlParser.js +++ b/src/controller/xmlParser.js @@ -1,15 +1,5 @@ const xml2js = require('xml2js') -/** - * Transforma objeto json in base64 - * @param {string} content_json - * @example parserJSONtoBase64(content_json) - * @output string - */ -function parserJSONtoBase64(content_json) { - return Buffer.from(content_json).toString('base64') -} - /** * Transforma xml em object * @param {string} xml_string @@ -54,10 +44,8 @@ function parserXmlToObject(xml_string) { return output } - module.exports = { - parserXmlToObject, - parserJSONtoBase64 + parserXmlToObject } diff --git a/src/test/parserOutput.test.js b/src/test/parserOutput.test.js deleted file mode 100644 index 6ef8c91..0000000 --- a/src/test/parserOutput.test.js +++ /dev/null @@ -1,125 +0,0 @@ -const { parserJSONtoBase64 } = require('../controller/evaluator.js') -const { generateObjectFromOutputs } = require('../controller/parserOutput.js') - -describe('ParserOutput', () => { - - describe('Validate merges two strings in 64 bits com sucessively', () => { - test('With two valid objects then it should return a successfully merged structure.', () => { - const obj1 = parserJSONtoBase64(JSON.stringify({ - github_username:"katiacih", - github_repository:"project_test_example", - evaluations:[ - { grade:4, description:"addition_isIncorrect"}, - { grade:7, description:"addition_isCorrect"} - ] - })) - - const obj2 = parserJSONtoBase64(JSON.stringify({ - github_username: "katiacih", - github_repository:"project_test_example", - evaluations:[ - {grade:1, description:"addition_isIncorrect 4343"}, - {grade:3, description:"addition_isCorrect 43432"} - ] - })) - - expect(generateObjectFromOutputs(obj1, obj2)).toEqual( - { - "github_username":"katiacih", - "github_repository":"project_test_example", - "evaluations":[ - {"grade":4,"description":"addition_isIncorrect"}, - {"grade":7,"description":"addition_isCorrect"}, - {"grade":1,"description":"addition_isIncorrect 4343"}, - {"grade":3,"description":"addition_isCorrect 43432"} - ] - } - ); - - }) - - test('With one of the objects without evaluations then it should return a successfully merged structure.', () => { - const obj1 = parserJSONtoBase64(JSON.stringify({ - github_username:"katiacih", - github_repository:"project_test_example", - evaluations:[ - { grade:4, description:"addition_isIncorrect"}, - { grade:7, description:"addition_isCorrect"} - ] - })) - - const obj2 = parserJSONtoBase64(JSON.stringify({ - github_username: "katiacih", - github_repository:"project_test_example", - evaluations:[] - })) - - expect(generateObjectFromOutputs(obj1, obj2)).toEqual( - { - "github_username":"katiacih", - "github_repository":"project_test_example", - "evaluations":[ - {"grade":4,"description":"addition_isIncorrect"}, - {"grade":7,"description":"addition_isCorrect"} - ] - } - ); - - }) - - test('Given two base64 with the first invalid object then it should return an object successfully.', () => { - const obj1 = parserJSONtoBase64(JSON.stringify({ - github_username:"katiacih", - github_repository:"project_test_example", - evaluations: [] - })) - - const obj2 = parserJSONtoBase64(JSON.stringify({ - github_username: "katiacih", - github_repository:"project_test_example", - evaluations:[ - {grade:1, description:"addition_isIncorrect 4343"}, - {grade:3, description:"addition_isCorrect 43432"} - ] - })) - - expect(generateObjectFromOutputs(obj1, obj2)).toEqual( - { - "github_username":"katiacih", - "github_repository":"project_test_example", - "evaluations":[ - {"grade":1,"description":"addition_isIncorrect 4343"}, - {"grade":3,"description":"addition_isCorrect 43432"} - ] - } - ); - - }) - - - test('Given undefined input should return error', () => { - const error = new Error ("Erro ao converter base 64 para objeto.") - expect(() => generateObjectFromOutputs(null, null)).toThrowError(error) - }) - - test('Given an incomplete object should return error when merging evaluations', () => { - const obj1 = parserJSONtoBase64(JSON.stringify({ - github_username:"katiacih", - github_repository:"project_test_example", - })) - - const obj2 = parserJSONtoBase64(JSON.stringify({ - github_username: "katiacih", - github_repository:"project_test_example", - evaluations:[ - {grade:1, description:"addition_isIncorrect 4343"}, - {grade:3, description:"addition_isCorrect 43432"} - ] - })) - - error = new Error ("Erro ao unificar outputs.") - expect(() => generateObjectFromOutputs(obj1, obj2)).toThrowError(error) - }) - }) - -})