diff --git a/.gitignore b/.gitignore index 6ee4a8a..b02b793 100644 --- a/.gitignore +++ b/.gitignore @@ -1,4 +1,5 @@ bin/ node_modules/ coverage/ -build/ \ No newline at end of file +build/ +.idea/ diff --git a/src/output-parser/output-parser.ts b/src/output-parser/output-parser.ts index a808e55..98571c8 100644 --- a/src/output-parser/output-parser.ts +++ b/src/output-parser/output-parser.ts @@ -13,14 +13,14 @@ export class OutputParser { // keep track of groups for the current step of a job private groupMatrix: Record; - private isPartOfGroup: boolean; + private isPartOfGroup: Record; constructor(output: string) { this.output = output; this.stepMatrix = {}; this.outputMatrix = {}; this.groupMatrix = {}; - this.isPartOfGroup = false; + this.isPartOfGroup = {}; } /** @@ -140,7 +140,7 @@ export class OutputParser { // if the line is an output line if (stepOutputMatcherResult !== null) { // if output is part of some group then update it - if (this.isPartOfGroup) { + if (this.isPartOfGroup[stepOutputMatcherResult[1]]) { const length = this.groupMatrix[stepOutputMatcherResult[1]].length; this.groupMatrix[stepOutputMatcherResult[1]][length - 1].output += stepOutputMatcherResult[2] + "\n"; @@ -167,7 +167,7 @@ export class OutputParser { name: startGroupMatcherResult[2], output: "", }); - this.isPartOfGroup = true; + this.isPartOfGroup[startGroupMatcherResult[1]] = true; } } @@ -187,7 +187,7 @@ export class OutputParser { const length = this.groupMatrix[endGroupMatcherResult[1]].length; this.groupMatrix[endGroupMatcherResult[1]][length - 1].output = this.groupMatrix[endGroupMatcherResult[1]][length - 1].output.trim(); - this.isPartOfGroup = false; + this.isPartOfGroup[endGroupMatcherResult[1]] = false; } } diff --git a/test/unit/output-parser/output-parser.test.ts b/test/unit/output-parser/output-parser.test.ts new file mode 100644 index 0000000..0b060db --- /dev/null +++ b/test/unit/output-parser/output-parser.test.ts @@ -0,0 +1,111 @@ +import { OutputParser } from "@aj/output-parser/output-parser"; +import path from "path"; +import fs from "fs"; + +describe("parseOutput", () => { + const resources = path.resolve(process.cwd(), "test", "unit", "resources", "output-parser"); + + describe("groups", () => { + test("some groups", async () => { + const output = fs.readFileSync(path.join(resources, "act-groups-sorted.log")).toString(); + const parser = new OutputParser(output); + + const result = parser.parseOutput(); + + expect(result).toStrictEqual([ + { + "groups": [ + { + "name": "Unit Tests", + "output": "1231 tests executed." + }, + { + "name": "Integration Tests", + "output": "32 tests executed." + } + ], + "name": "Main Testing", + "output": "1231 tests executed.\n32 tests executed.", + "status": 0 + }, + { + "groups": [ + { + "name": "Lint", + "output": "No linting errors found." + } + ], + "name": "Main Lint", + "output": "No linting errors found.", + "status": 0 + } + ]); + }); + + test("interleaved groups", async () => { + const output = fs.readFileSync(path.join(resources, "act-groups-interleaved.log")).toString(); + const parser = new OutputParser(output); + + const result = parser.parseOutput(); + + expect(result).toStrictEqual([ + { + "groups": [ + { + "name": "Unit Tests", + "output": "1231 tests executed." + }, + { + "name": "Integration Tests", + "output": "32 tests executed." + } + ], + "name": "Main Testing", + "output": "1231 tests executed.\n32 tests executed.", + "status": 0 + }, + { + "groups": [ + { + "name": "Lint", + "output": "No linting errors found." + } + ], + "name": "Main Lint", + "output": "No linting errors found.", + "status": 0 + } + ]); + }); + + test("mixed groups", async () => { + const output = fs.readFileSync(path.join(resources, "act-groups-mixed.log")).toString(); + const parser = new OutputParser(output); + + const result = parser.parseOutput(); + + expect(result).toStrictEqual([ + { + "groups": [ + { + "name": "Unit Tests", + "output": "1231 tests executed." + }, + { + "name": "Integration Tests", + "output": "32 tests executed." + } + ], + "name": "Main Testing", + "output": "1231 tests executed.\n32 tests executed.", + "status": 0 + }, + { + "name": "Main Lint", + "output": "No problems found.", + "status": 0 + } + ]); + }); + }); +}); diff --git a/test/unit/resources/output-parser/act-groups-interleaved.log b/test/unit/resources/output-parser/act-groups-interleaved.log new file mode 100644 index 0000000..69169ff --- /dev/null +++ b/test/unit/resources/output-parser/act-groups-interleaved.log @@ -0,0 +1,13 @@ +[Build/Tests ] ⭐ Run Main Testing +[Build/Tests ] ❓ ::group::Unit Tests +[Build/Tests ] | 1231 tests executed. +[Build/Static Analysis ] ⭐ Run Main Lint +[Build/Static Analysis ] ❓ ::group::Lint +[Build/Tests ] ❓ ::endgroup:: +[Build/Static Analysis ] | No linting errors found. +[Build/Tests ] ❓ ::group::Integration Tests +[Build/Tests ] | 32 tests executed. +[Build/Tests ] ❓ ::endgroup:: +[Build/Tests ] ✅ Success - Main Testing +[Build/Static Analysis ] ❓ ::endgroup:: +[Build/Static Analysis ] ✅ Success - Main Lint diff --git a/test/unit/resources/output-parser/act-groups-mixed.log b/test/unit/resources/output-parser/act-groups-mixed.log new file mode 100644 index 0000000..c7294ee --- /dev/null +++ b/test/unit/resources/output-parser/act-groups-mixed.log @@ -0,0 +1,11 @@ +[Build/Tests ] ⭐ Run Main Testing +[Build/Tests ] ❓ ::group::Unit Tests +[Build/Static Analysis ] ⭐ Run Main Lint +[Build/Static Analysis ] | No problems found. +[Build/Tests ] | 1231 tests executed. +[Build/Tests ] ❓ ::endgroup:: +[Build/Tests ] ❓ ::group::Integration Tests +[Build/Tests ] | 32 tests executed. +[Build/Tests ] ❓ ::endgroup:: +[Build/Static Analysis ] ✅ Success - Main Lint +[Build/Tests ] ✅ Success - Main Testing diff --git a/test/unit/resources/output-parser/act-groups-sorted.log b/test/unit/resources/output-parser/act-groups-sorted.log new file mode 100644 index 0000000..74f7361 --- /dev/null +++ b/test/unit/resources/output-parser/act-groups-sorted.log @@ -0,0 +1,13 @@ +[Build/Tests ] ⭐ Run Main Testing +[Build/Tests ] ❓ ::group::Unit Tests +[Build/Tests ] | 1231 tests executed. +[Build/Tests ] ❓ ::endgroup:: +[Build/Tests ] ❓ ::group::Integration Tests +[Build/Tests ] | 32 tests executed. +[Build/Tests ] ❓ ::endgroup:: +[Build/Tests ] ✅ Success - Main Testing +[Build/Static Analysis ] ⭐ Run Main Lint +[Build/Static Analysis ] ❓ ::group::Lint +[Build/Static Analysis ] | No linting errors found. +[Build/Static Analysis ] ❓ ::endgroup:: +[Build/Static Analysis ] ✅ Success - Main Lint