Skip to content

Commit

Permalink
Add 2 more tests and, use more gifs (#13)
Browse files Browse the repository at this point in the history
  • Loading branch information
PerThomasHaga authored Dec 14, 2023
1 parent b5a7fa7 commit 0dd98d8
Show file tree
Hide file tree
Showing 4 changed files with 42 additions and 1 deletion.
3 changes: 3 additions & 0 deletions jest.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,9 @@ module.exports = {
},
transformIgnorePatterns: ["node_modules/(?!variables/.*)"],
modulePathIgnorePatterns: ["out/"],
collectCoverage: true,
coverageDirectory: "coverage",
coverageReporters: ["lcov", "text-summary"],
reporters: [
"default",
[
Expand Down
32 changes: 32 additions & 0 deletions src/tests/uploadScreenshots.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,38 @@ describe("uploadScreenshots", () => {
});
});

it("handles invalid xcresultPath gracefully", async () => {
mockedGetApps.mockReturnValue([mockApp]);
mockedGetApp.mockReturnValue(mockApp);
process.env.FIREBASE_SERVICE_ACCOUNT = JSON.stringify({
type: "service_account",
});
process.env.FIREBASE_STORAGE_BUCKET = "bucket-name";

const invalidXcresultPath = "./nonexistent/path";
await expect(
uploadScreenshots(123, invalidXcresultPath, "./src/tests/exampleFiles")
).rejects.toThrow("The specified xcresultPath does not exist.");

// Additional assertions can be added here
});

it("throws an error if the Firebase service account is corrupted", async () => {
// Set environment variables to undefined to simulate the missing service account
process.env.FIREBASE_SERVICE_ACCOUNT = undefined;
mockedGetApps.mockReturnValue([]);
await expect(
uploadScreenshots(123, "/path/to/xcresult", "/path/to/screenshots")
).rejects.toThrow(
"In order to upload, you have to set FIREBASE_STORAGE_BUCKET and FIREBASE_SERVICE_ACCOUNT in the environment variables."
);

// Reset the environment variables after the test
process.env.FIREBASE_SERVICE_ACCOUNT = JSON.stringify({
type: "service_account",
});
});

it("successfully uploads screenshots and returns download URLs", async () => {
mockedGetApps.mockReturnValue([mockApp]);
mockedGetApp.mockReturnValue(mockApp);
Expand Down
2 changes: 1 addition & 1 deletion src/utils/addCommentToPR.ts
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ export default async (result: WriteSummaryResult) => {

async function getRandomGif(search: string) {
const httpClient = new http.HttpClient();
const randomNumber = Math.floor(Math.random() * 101);
const randomNumber = Math.floor(Math.random() * 201);
const res = await httpClient.get(
`https://api.giphy.com/v1/gifs/search?api_key=PFZ64SqzXhfNwVVWo6iwe1UjZzUomr1j&q=${search}&limit=1&offset=${randomNumber}&rating=g&lang=en&bundle=messaging_non_clips`
);
Expand Down
6 changes: 6 additions & 0 deletions src/utils/uploadScreenshots.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import { glob } from "glob";
import dotenv from "dotenv";
import * as path from "path";
import * as util from "util";
import * as fs from "fs";

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

Expand Down Expand Up @@ -77,6 +78,11 @@ async function getScreenshotsFromXcresult(
const scriptPath = path.resolve(
`${__dirname}/../../scripts/scale_screenshots.sh`
);

if (!fs.existsSync(xcresultPath)) {
throw new Error("The specified xcresultPath does not exist.");
}

await exec("brew install imagemagick --quiet");
await exec("brew install chargepoint/xcparse/xcparse --quiet");
await exec(`rm -rf ${destinationPath}`);
Expand Down

0 comments on commit 0dd98d8

Please sign in to comment.