Skip to content

Commit f640314

Browse files
committed
test(logger): Add tests for task-skip event
1 parent 5a1b071 commit f640314

File tree

2 files changed

+111
-7
lines changed

2 files changed

+111
-7
lines changed

packages/logger/lib/writers/Console.js

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -401,20 +401,16 @@ class Console {
401401
this._getProgressBar()?.increment(1);
402402
break;
403403
case "task-skip":
404-
if (taskMetadata.executionSkipped) {
404+
if (taskMetadata.executionEnded) {
405405
throw new Error(`writers/Console: ` +
406-
`Unexpected duplicate task-skip event for project ${projectName}, task ${taskName}`);
406+
`Unexpected task-skip event for project ${projectName}, task ${taskName}. ` +
407+
`Task execution already ended`);
407408
}
408409
if (taskMetadata.executionStarted) {
409410
throw new Error(`writers/Console: ` +
410411
`Unexpected task-skip event for project ${projectName}, task ${taskName}. ` +
411412
`Task execution already started`);
412413
}
413-
if (taskMetadata.executionEnded) {
414-
throw new Error(`writers/Console: ` +
415-
`Unexpected task-skip event for project ${projectName}, task ${taskName}. ` +
416-
`Task execution already ended`);
417-
}
418414
taskMetadata.executionEnded = true;
419415
message = `${chalk.green(figures.tick)} Skipping task ${chalk.bold(taskName)}`;
420416

packages/logger/test/lib/writers/Console.js

Lines changed: 108 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -721,6 +721,114 @@ test.serial("ProjectBuild status (end): Task execution not started", (t) => {
721721
t.is(stderrWriteStub.callCount, 0, "Logged zero messages");
722722
});
723723

724+
test.serial("ProjectBuild status (skip)", (t) => {
725+
const {stderrWriteStub} = t.context;
726+
process.emit("ui5.build-metadata", {
727+
projectsToBuild: ["project.a"]
728+
});
729+
730+
process.emit("ui5.project-build-metadata", {
731+
projectName: "project.a",
732+
projectType: "project-type",
733+
tasksToRun: ["task.a"]
734+
});
735+
736+
process.emit("ui5.project-build-status", {
737+
level: "info",
738+
projectName: "project.a",
739+
projectType: "project-type",
740+
taskName: "task.a",
741+
status: "task-skip",
742+
});
743+
744+
t.is(stderrWriteStub.callCount, 1, "Logged one message");
745+
t.is(stripAnsi(stderrWriteStub.getCall(0).args[0]),
746+
`info project.a ${figures.tick} Skipping task task.a\n`,
747+
"Logged expected message");
748+
});
749+
750+
test.serial("ProjectBuild status (skip): Task execution already started", (t) => {
751+
const {stderrWriteStub} = t.context;
752+
process.emit("ui5.build-metadata", {
753+
projectsToBuild: ["project.a"]
754+
});
755+
756+
process.emit("ui5.project-build-metadata", {
757+
projectName: "project.a",
758+
projectType: "project-type",
759+
tasksToRun: ["task.a"]
760+
});
761+
762+
process.emit("ui5.project-build-status", {
763+
level: "silly",
764+
projectName: "project.a",
765+
projectType: "project-type",
766+
taskName: "task.a",
767+
status: "task-start",
768+
});
769+
770+
t.throws(() => {
771+
process.emit("ui5.project-build-status", {
772+
level: "info",
773+
projectName: "project.a",
774+
projectType: "project-type",
775+
taskName: "task.a",
776+
status: "task-skip",
777+
});
778+
}, {
779+
message:
780+
"writers/Console: Unexpected task-skip event for project project.a, task task.a. " +
781+
"Task execution already started"
782+
});
783+
784+
t.is(stderrWriteStub.callCount, 0, "Logged zero messages");
785+
});
786+
787+
test.serial("ProjectBuild status (skip): Task execution already ended", (t) => {
788+
const {stderrWriteStub} = t.context;
789+
process.emit("ui5.build-metadata", {
790+
projectsToBuild: ["project.a"]
791+
});
792+
793+
process.emit("ui5.project-build-metadata", {
794+
projectName: "project.a",
795+
projectType: "project-type",
796+
tasksToRun: ["task.a"]
797+
});
798+
799+
process.emit("ui5.project-build-status", {
800+
level: "silly",
801+
projectName: "project.a",
802+
projectType: "project-type",
803+
taskName: "task.a",
804+
status: "task-start",
805+
});
806+
807+
process.emit("ui5.project-build-status", {
808+
level: "silly",
809+
projectName: "project.a",
810+
projectType: "project-type",
811+
taskName: "task.a",
812+
status: "task-end",
813+
});
814+
815+
t.throws(() => {
816+
process.emit("ui5.project-build-status", {
817+
level: "info",
818+
projectName: "project.a",
819+
projectType: "project-type",
820+
taskName: "task.a",
821+
status: "task-skip",
822+
});
823+
}, {
824+
message:
825+
"writers/Console: Unexpected task-skip event for project project.a, task task.a. " +
826+
"Task execution already ended"
827+
});
828+
829+
t.is(stderrWriteStub.callCount, 0, "Logged zero messages");
830+
});
831+
724832
test.serial("ProjectBuild status: Unknown status", (t) => {
725833
const {stderrWriteStub} = t.context;
726834
process.emit("ui5.build-metadata", {

0 commit comments

Comments
 (0)