Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: allow chmod to fail in setup #1197

Merged
merged 1 commit into from
Jan 6, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
46 changes: 46 additions & 0 deletions src/steps/writing/writeStructure.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
import { describe, expect, it, vi } from "vitest";

import { Options } from "../../shared/types.js";
import { writeStructure } from "./writeStructure.js";

const mock$ = vi.fn();

vi.mock("execa", () => ({
get $() {
return mock$;
},
}));

vi.mock("./creation/index.js");
vi.mock("./writeStructureWorker.js");

const options = {
access: "public",
author: "TestAuthor",
base: "everything",
description: "Test description.",
directory: ".",
email: {
github: "[email protected]",
npm: "[email protected]",
},
keywords: ["abc", "def ghi", "jkl mno pqr"],
mode: "create",
owner: "TestOwner",
repository: "test-repository",
title: "Test Title",
} satisfies Options;

describe("writeStructure", () => {
it("resolves when chmod resolves", async () => {
mock$.mockResolvedValue(undefined);

await expect(writeStructure(options)).resolves.toBeUndefined();
});

it("resolves when chmod rejects", async () => {
mock$.mockRejectedValue(new Error("Oh no!"));

await expect(writeStructure(options)).resolves.toBeUndefined();
});
});
8 changes: 6 additions & 2 deletions src/steps/writing/writeStructure.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,10 @@ import { writeStructureWorker } from "./writeStructureWorker.js";
export async function writeStructure(options: Options) {
await writeStructureWorker(await createStructure(options), ".");

// https://github.com/JoshuaKGoldberg/create-typescript-app/issues/718
await $`chmod ug+x .husky/pre-commit`;
try {
// https://github.com/JoshuaKGoldberg/create-typescript-app/issues/718
await $`chmod ug+x .husky/pre-commit`;
} catch {
// https://github.com/JoshuaKGoldberg/create-typescript-app/issues/1195
}
}