Skip to content

Commit 0dd98d8

Browse files
Add 2 more tests and, use more gifs (#13)
1 parent b5a7fa7 commit 0dd98d8

File tree

4 files changed

+42
-1
lines changed

4 files changed

+42
-1
lines changed

jest.config.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,9 @@ module.exports = {
77
},
88
transformIgnorePatterns: ["node_modules/(?!variables/.*)"],
99
modulePathIgnorePatterns: ["out/"],
10+
collectCoverage: true,
11+
coverageDirectory: "coverage",
12+
coverageReporters: ["lcov", "text-summary"],
1013
reporters: [
1114
"default",
1215
[

src/tests/uploadScreenshots.test.ts

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,38 @@ describe("uploadScreenshots", () => {
5050
});
5151
});
5252

53+
it("handles invalid xcresultPath gracefully", async () => {
54+
mockedGetApps.mockReturnValue([mockApp]);
55+
mockedGetApp.mockReturnValue(mockApp);
56+
process.env.FIREBASE_SERVICE_ACCOUNT = JSON.stringify({
57+
type: "service_account",
58+
});
59+
process.env.FIREBASE_STORAGE_BUCKET = "bucket-name";
60+
61+
const invalidXcresultPath = "./nonexistent/path";
62+
await expect(
63+
uploadScreenshots(123, invalidXcresultPath, "./src/tests/exampleFiles")
64+
).rejects.toThrow("The specified xcresultPath does not exist.");
65+
66+
// Additional assertions can be added here
67+
});
68+
69+
it("throws an error if the Firebase service account is corrupted", async () => {
70+
// Set environment variables to undefined to simulate the missing service account
71+
process.env.FIREBASE_SERVICE_ACCOUNT = undefined;
72+
mockedGetApps.mockReturnValue([]);
73+
await expect(
74+
uploadScreenshots(123, "/path/to/xcresult", "/path/to/screenshots")
75+
).rejects.toThrow(
76+
"In order to upload, you have to set FIREBASE_STORAGE_BUCKET and FIREBASE_SERVICE_ACCOUNT in the environment variables."
77+
);
78+
79+
// Reset the environment variables after the test
80+
process.env.FIREBASE_SERVICE_ACCOUNT = JSON.stringify({
81+
type: "service_account",
82+
});
83+
});
84+
5385
it("successfully uploads screenshots and returns download URLs", async () => {
5486
mockedGetApps.mockReturnValue([mockApp]);
5587
mockedGetApp.mockReturnValue(mockApp);

src/utils/addCommentToPR.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,7 @@ export default async (result: WriteSummaryResult) => {
7272

7373
async function getRandomGif(search: string) {
7474
const httpClient = new http.HttpClient();
75-
const randomNumber = Math.floor(Math.random() * 101);
75+
const randomNumber = Math.floor(Math.random() * 201);
7676
const res = await httpClient.get(
7777
`https://api.giphy.com/v1/gifs/search?api_key=PFZ64SqzXhfNwVVWo6iwe1UjZzUomr1j&q=${search}&limit=1&offset=${randomNumber}&rating=g&lang=en&bundle=messaging_non_clips`
7878
);

src/utils/uploadScreenshots.ts

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import { glob } from "glob";
44
import dotenv from "dotenv";
55
import * as path from "path";
66
import * as util from "util";
7+
import * as fs from "fs";
78

89
const exec = util.promisify(require("child_process").exec);
910

@@ -77,6 +78,11 @@ async function getScreenshotsFromXcresult(
7778
const scriptPath = path.resolve(
7879
`${__dirname}/../../scripts/scale_screenshots.sh`
7980
);
81+
82+
if (!fs.existsSync(xcresultPath)) {
83+
throw new Error("The specified xcresultPath does not exist.");
84+
}
85+
8086
await exec("brew install imagemagick --quiet");
8187
await exec("brew install chargepoint/xcparse/xcparse --quiet");
8288
await exec(`rm -rf ${destinationPath}`);

0 commit comments

Comments
 (0)