Skip to content

Commit

Permalink
[FIX] Console: Handle consequitive builds correctly
Browse files Browse the repository at this point in the history
Resolves a bug where after a build has completed, any following builds
would re-use the project metadata of the previous build, leading to
incorrect log messages and clashes if the same project is being built
twice.
  • Loading branch information
RandomByte committed Nov 19, 2024
1 parent f8085bd commit 5ffc3ac
Show file tree
Hide file tree
Showing 2 changed files with 98 additions and 0 deletions.
1 change: 1 addition & 0 deletions lib/writers/Console.js
Original file line number Diff line number Diff line change
Expand Up @@ -141,6 +141,7 @@ class Console {
}

#handleBuildMetadataEvent({projectsToBuild}) {
this.#projectMetadata = new Map();
projectsToBuild.forEach((projectName) => {
this.#projectMetadata.set(projectName, {
buildStarted: false,
Expand Down
97 changes: 97 additions & 0 deletions test/lib/writers/Console.js
Original file line number Diff line number Diff line change
Expand Up @@ -870,3 +870,100 @@ test.serial("Disable: Stops progress bar", (t) => {
t.is(stderrWriteStub.callCount, 1, "Logged one message");
});

test.serial("Build metadata events (multiple projects)", (t) => {
const {stderrWriteStub} = t.context;
process.emit("ui5.build-metadata", {
projectsToBuild: ["project.a"]
});

process.emit("ui5.build-status", {
level: "verbose", // Should not get logged
projectName: "project.a",
projectType: "project-type",
status: "project-build-start",
});

process.emit("ui5.build-status", {
level: "info",
projectName: "project.a",
projectType: "project-type",
status: "project-build-end",
});

// Independent build of another project
process.emit("ui5.build-metadata", {
projectsToBuild: ["project.b"]
});

process.emit("ui5.build-status", {
level: "verbose", // Should not get logged
projectName: "project.b",
projectType: "project-type",
status: "project-build-start",
});

process.emit("ui5.build-status", {
level: "info",
projectName: "project.b",
projectType: "project-type",
status: "project-build-end",
});


t.is(stderrWriteStub.callCount, 2, "Logged one message");
t.is(stripAnsi(stderrWriteStub.getCall(0).args[0]),
`info Project 1 of 1: ${figures.tick} Finished building project-type project project.a\n`,
"Logged expected message");
t.is(stripAnsi(stderrWriteStub.getCall(1).args[0]),
`info Project 1 of 1: ${figures.tick} Finished building project-type project project.b\n`,
"Logged expected message");
});

test.serial("Build metadata events (same project)", (t) => {
const {stderrWriteStub} = t.context;
process.emit("ui5.build-metadata", {
projectsToBuild: ["project.a"]
});

process.emit("ui5.build-status", {
level: "verbose", // Should not get logged
projectName: "project.a",
projectType: "project-type",
status: "project-build-start",
});

process.emit("ui5.build-status", {
level: "info",
projectName: "project.a",
projectType: "project-type",
status: "project-build-end",
});

// Repeated build of the same project
process.emit("ui5.build-metadata", {
projectsToBuild: ["project.a"]
});

process.emit("ui5.build-status", {
level: "verbose", // Should not get logged
projectName: "project.a",
projectType: "project-type",
status: "project-build-start",
});

process.emit("ui5.build-status", {
level: "info",
projectName: "project.a",
projectType: "project-type",
status: "project-build-end",
});


t.is(stderrWriteStub.callCount, 2, "Logged one message");
t.is(stripAnsi(stderrWriteStub.getCall(0).args[0]),
`info Project 1 of 1: ${figures.tick} Finished building project-type project project.a\n`,
"Logged expected message");
t.is(stripAnsi(stderrWriteStub.getCall(1).args[0]),
`info Project 1 of 1: ${figures.tick} Finished building project-type project project.a\n`,
"Logged expected message");
});

0 comments on commit 5ffc3ac

Please sign in to comment.