Skip to content

Commit

Permalink
fix: support groups in interleaved parallel job outputs (#62)
Browse files Browse the repository at this point in the history
* Import project in IntelliJ IDEA (ignore project folder)

* Add basic test for groups

* Add tests for #60 and interleaved groups

* Fix #60
  • Loading branch information
TWiStErRob authored Dec 27, 2023
1 parent 4245c86 commit 84ecaff
Show file tree
Hide file tree
Showing 6 changed files with 155 additions and 6 deletions.
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
bin/
node_modules/
coverage/
build/
build/
.idea/
10 changes: 5 additions & 5 deletions src/output-parser/output-parser.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,14 +13,14 @@ export class OutputParser {
// keep track of groups for the current step of a job
private groupMatrix: Record<string, Group[]>;

private isPartOfGroup: boolean;
private isPartOfGroup: Record<string, boolean>;

constructor(output: string) {
this.output = output;
this.stepMatrix = {};
this.outputMatrix = {};
this.groupMatrix = {};
this.isPartOfGroup = false;
this.isPartOfGroup = {};
}

/**
Expand Down Expand Up @@ -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";
Expand All @@ -167,7 +167,7 @@ export class OutputParser {
name: startGroupMatcherResult[2],
output: "",
});
this.isPartOfGroup = true;
this.isPartOfGroup[startGroupMatcherResult[1]] = true;
}
}

Expand All @@ -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;
}
}

Expand Down
111 changes: 111 additions & 0 deletions test/unit/output-parser/output-parser.test.ts
Original file line number Diff line number Diff line change
@@ -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
}
]);
});
});
});
13 changes: 13 additions & 0 deletions test/unit/resources/output-parser/act-groups-interleaved.log
Original file line number Diff line number Diff line change
@@ -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
11 changes: 11 additions & 0 deletions test/unit/resources/output-parser/act-groups-mixed.log
Original file line number Diff line number Diff line change
@@ -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
13 changes: 13 additions & 0 deletions test/unit/resources/output-parser/act-groups-sorted.log
Original file line number Diff line number Diff line change
@@ -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

0 comments on commit 84ecaff

Please sign in to comment.