aboutsummaryrefslogtreecommitdiff
path: root/src/formats.test.ts
diff options
context:
space:
mode:
authorKevin J Hoerr <kjhoerr@protonmail.com>2021-09-16 15:45:34 -0400
committerKevin J Hoerr <kjhoerr@protonmail.com>2021-09-16 15:45:34 -0400
commit6bbd3f03104e6dcd9da89a8ec5dcb5d992ee3ed5 (patch)
tree6f44b79750ad00267c8840b3aa472ee64aefc66b /src/formats.test.ts
parent77575aab559f058d886a691eefe262cf0f306710 (diff)
downloadao-coverage-6bbd3f03104e6dcd9da89a8ec5dcb5d992ee3ed5.tar.gz
ao-coverage-6bbd3f03104e6dcd9da89a8ec5dcb5d992ee3ed5.tar.bz2
ao-coverage-6bbd3f03104e6dcd9da89a8ec5dcb5d992ee3ed5.zip
#7 Add Cobertura format
Diffstat (limited to 'src/formats.test.ts')
-rw-r--r--src/formats.test.ts79
1 files changed, 72 insertions, 7 deletions
diff --git a/src/formats.test.ts b/src/formats.test.ts
index 1536b5d..02f9a3e 100644
--- a/src/formats.test.ts
+++ b/src/formats.test.ts
@@ -74,7 +74,7 @@ describe("Formats object", () => {
const result = Formats.listFormats();
// Assert
- expect(result).toEqual(["tarpaulin"]);
+ expect(result).toEqual(["tarpaulin", "cobertura"]);
});
it("should return the requested format", () => {
@@ -105,14 +105,14 @@ describe("Tarpaulin format", () => {
expect(matcher).toEqual(defaultColorMatches);
});
- it("should parse coverage from a normal tarpaulin file", () => {
+ it("should parse coverage from a normal tarpaulin file", async () => {
// Arrange
const file = fs.readFileSync(reportPath("tarpaulin-report.html"), "utf-8");
const format = Formats.getFormat("tarpaulin");
// Act
- const result = format.parseCoverage(file);
+ const result = await format.parseCoverage(file);
// Assert
expect(typeof result).toEqual("number");
@@ -122,14 +122,14 @@ describe("Tarpaulin format", () => {
}
});
- it("should parse coverage from an empty tarpaulin file", () => {
+ it("should parse coverage from an empty tarpaulin file", async () => {
// Arrange
const file = fs.readFileSync(reportPath("tarpaulin-empty.html"), "utf-8");
const format = Formats.getFormat("tarpaulin");
// Act
- const result = format.parseCoverage(file);
+ const result = await format.parseCoverage(file);
// Assert
expect(typeof result).toEqual("number");
@@ -138,14 +138,79 @@ describe("Tarpaulin format", () => {
}
});
- it("should return error when parsing coverage from invalid file", () => {
+ it("should return error when parsing coverage from invalid file", async () => {
// Arrange
const file = fs.readFileSync(reportPath("tarpaulin-invalid.html"), "utf-8");
const format = Formats.getFormat("tarpaulin");
// Act
- const result = format.parseCoverage(file);
+ const result = await format.parseCoverage(file);
+
+ // Assert
+ expect(typeof result).not.toEqual("number");
+ if (typeof result !== "number") {
+ expect(result.message).toEqual("Invalid report document");
+ }
+ });
+});
+
+describe("Cobertura format", () => {
+ const reportPath = (file: string): string =>
+ path.join(__dirname, "..", "example_reports", file);
+
+ it("should use the default color matcher", () => {
+ // Arrange
+ const format = Formats.getFormat("cobertura");
+
+ // Act
+ const matcher = format.matchColor;
+
+ // Assert
+ expect(matcher).toEqual(defaultColorMatches);
+ });
+
+ it("should parse coverage from a normal cobertura file", async () => {
+ // Arrange
+ const file = fs.readFileSync(reportPath("cobertura-report.xml"), "utf-8");
+
+ const format = Formats.getFormat("cobertura");
+
+ // Act
+ const result = await format.parseCoverage(file);
+
+ // Assert
+ expect(typeof result).toEqual("number");
+ if (typeof result === "number") {
+ // 96.17% is the result given in the document itself
+ expect(result.toFixed(2)).toEqual("96.04");
+ }
+ });
+
+ it("should parse coverage from an empty cobertura file", async () => {
+ // Arrange
+ const file = fs.readFileSync(reportPath("cobertura-empty.xml"), "utf-8");
+
+ const format = Formats.getFormat("cobertura");
+
+ // Act
+ const result = await format.parseCoverage(file);
+
+ // Assert
+ expect(typeof result).toEqual("number");
+ if (typeof result === "number") {
+ expect(result.toFixed(2)).toEqual("0.00");
+ }
+ });
+
+ it("should return error when parsing coverage from invalid file", async () => {
+ // Arrange
+ const file = fs.readFileSync(reportPath("cobertura-invalid.xml"), "utf-8");
+
+ const format = Formats.getFormat("cobertura");
+
+ // Act
+ const result = await format.parseCoverage(file);
// Assert
expect(typeof result).not.toEqual("number");