Skip to content

Commit

Permalink
lint: update tests for linting issues
Browse files Browse the repository at this point in the history
Fix space formatting issues.  Change a numnber of `expect()` to single liners.

Signed-off-by: Chris. Webster <[email protected]>
  • Loading branch information
webstech committed Aug 22, 2024
1 parent 02f8b7b commit 348a2ab
Show file tree
Hide file tree
Showing 15 changed files with 349 additions and 481 deletions.
326 changes: 152 additions & 174 deletions tests/ci-helper.test.ts

Large diffs are not rendered by default.

29 changes: 13 additions & 16 deletions tests/commit-lint.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -167,14 +167,12 @@ blah http://www.github.com\n\nSigned-off-by: x`;

commit.message = `contains a long URL that cannot be wrapped\n\n ${
""}[2] https://lore.kernel.org/git/CABPp-BH9tju7WVm=${
""}[email protected]/\n\n${
""}Signed-off-by: x}`;
""}[email protected]/\n\nSigned-off-by: x}`;
lintCheck(commit);

commit.message = `contains a long, whitespace-prefixed error message\n\n${
""} ld-elf.so.1: /usr/local/lib/perl5/5.32/mach/CORE/libperl.so.5.32:${
""} Undefined symbol "strerror_l@FBSD_1.6"\n\n${
""}Signed-off-by: x}`;
""} Undefined symbol "strerror_l@FBSD_1.6"\n\nSigned-off-by: x}`;
lintCheck(commit);
});

Expand All @@ -201,8 +199,7 @@ test("combo lint tests", () => {
expect(lintError.message).toMatch(/not signed/);
});

commit.message = `x: A 34578901234567890123456789012345678901234567890${
""}123456789012345678901234567890`;
commit.message = `x: A 34578901234567890123456789012345678901234567890123456789012345678901234567890`;
lintCheck(commit, (lintError) => {
expect(lintError.checkFailed).toBe(true);
expect(lintError.message).toMatch(/too short/);
Expand Down Expand Up @@ -250,16 +247,16 @@ test("lint options tests", () => {
};

lintCheck(commit, (lintError) => {
expect(lintError.checkFailed).toBe(true);
expect(lintError.message).toMatch(/is too long/);
expect(lintError.message).toMatch(/should be wrapped/);
expect(lintError.message).toMatch(/76/);
}, {});
expect(lintError.checkFailed).toBe(true);
expect(lintError.message).toMatch(/is too long/);
expect(lintError.message).toMatch(/should be wrapped/);
expect(lintError.message).toMatch(/76/);
}, {});

lintCheck(commit, (lintError) => {
expect(lintError.checkFailed).toBe(true);
expect(lintError.message).toMatch(/is too long/);
expect(lintError.message).toMatch(/should be wrapped/);
expect(lintError.message).toMatch(/66/);
}, {maxColumns: 66});
expect(lintError.checkFailed).toBe(true);
expect(lintError.message).toMatch(/is too long/);
expect(lintError.message).toMatch(/should be wrapped/);
expect(lintError.message).toMatch(/66/);
}, { maxColumns: 66 });
});
10 changes: 3 additions & 7 deletions tests/git-notes.test.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { expect, jest, test } from "@jest/globals";
import { fileURLToPath } from 'url';
import { fileURLToPath } from "url";
import { isDirectory } from "../lib/fs-util.js";
import { git, revParse } from "../lib/git.js";
import { GitNotes } from "../lib/git-notes.js";
Expand All @@ -20,9 +20,7 @@ test("set/get notes", async () => {
expect(await notes.setString("hello", "world")).toBeUndefined();
expect(await notes.getString("hello")).toEqual("world");

expect(await git(["log", "-p", "refs/notes/gitgitgadget"], {
workDir: repo.workDir,
})).toMatch(/\n\+hello$/);
expect(await git(["log", "-p", "refs/notes/gitgitgadget"], { workDir: repo.workDir })).toMatch(/\n\+hello$/);

const gitURL = "https://github.com/gitgitgadget/git";
const pullRequestURL = `${gitURL}/git/pull/1`;
Expand All @@ -36,8 +34,7 @@ test("set/get notes", async () => {
pullRequestURL,
};
expect(await notes.set(pullRequestURL, metadata)).toBeUndefined();
expect(await notes.get<IPatchSeriesMetadata>(pullRequestURL))
.toEqual(metadata);
expect(await notes.get<IPatchSeriesMetadata>(pullRequestURL)).toEqual(metadata);

const commit = await revParse(notes.notesRef, notes.workDir);
expect(commit).not.toBeUndefined();
Expand All @@ -59,5 +56,4 @@ test("set/get notes", async () => {
await expect(notesNotM2Chead.update(gitURL)).rejects.toThrow(/know how to update/);
const notesNotM2Ctail = new GitNotes(repo.workDir, "refs/notes/mail-to-commitx");
await expect(notesNotM2Ctail.update(gitURL)).rejects.toThrow(/know how to update/);

});
16 changes: 8 additions & 8 deletions tests/git.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ for (let i = 0; i < configCount; i++) {

const sleep = async (ms: number) => {
await new Promise<void>((resolve) => {
setTimeout(() => { resolve(); }, ms);
setTimeout(() => resolve(), ms);
});
};

Expand All @@ -31,14 +31,14 @@ test("serialization", async () => {
if (waitTime) {
const myWait = --waitTime;
logger(`waiting ${myWait}`);
await sleep(waitTime*50+waitTime%2*60); // odd/even have different waits
await sleep(waitTime * 50 + waitTime % 2 * 60); // odd/even have different waits
logger(`waiting ${myWait} done`);
// track waitTime before and after wait
times.push( {myWait, waitTime});
times.push({ myWait, waitTime });
}
};

expect(await git(["config", "--get-regexp", "TEST"], {lineHandler})).toMatch("");
expect(await git(["config", "--get-regexp", "TEST"], { lineHandler })).toMatch("");
times.map((el) => {
logger(el.waitTime, el.myWait);
});
Expand All @@ -53,11 +53,11 @@ test("sequencing", async () => {

const lineHandler = async (line: string): Promise<void> => {
waitTime--;
await sleep(waitTime*50+waitTime%2*60); // odd/even have different waits
await sleep(waitTime * 50 + waitTime % 2 * 60); // odd/even have different waits
buffer += `${line}\n`;
};

expect(await git(["config", "--get-regexp", "TEST"], {lineHandler})).toMatch("");
expect(await git(["config", "--get-regexp", "TEST"], { lineHandler })).toMatch("");
expect(await git(["config", "--get-regexp", "TEST"], { trimTrailingNewline: false })).toEqual(buffer);
});

Expand Down Expand Up @@ -90,6 +90,6 @@ test("slow stdout", async () => {
process.env.GIT_CONFIG_KEY_0 = `alias.node`;
process.env.GIT_CONFIG_VALUE_0 = `!node`;

expect(await git([`node`, `-e`, `${code}`], {lineHandler})).toEqual("");
expect(await git([`node`, `-e`, `${code}`], { lineHandler })).toEqual("");
expect(await git([`node`, `-e`, `${code}`])).toEqual(buffer);
});
});
62 changes: 20 additions & 42 deletions tests/gitgitgadget.test.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { expect, jest, test } from "@jest/globals";
import { fileURLToPath } from 'url';
import { fileURLToPath } from "url";
import { git, gitCommandExists } from "../lib/git.js";
import { GitNotes } from "../lib/git-notes.js";
import { GitGitGadget, IGitGitGadgetOptions } from "../lib/gitgitgadget.js";
Expand Down Expand Up @@ -49,10 +49,8 @@ Test H. Dev (1):
base-commit: b4bc10cab67df9962ae52c82af9e1a43fd83d806
Published-As: https://github.com/gitgitgadget/git/releases/tag/${
"pr-1/somebody/master-v1".replace(/\//g, "%2F")}
Fetch-It-Via: git fetch https://github.com/gitgitgadget/git ${
""}pr-1/somebody/master-v1
Published-As: https://github.com/gitgitgadget/git/releases/tag/${"pr-1/somebody/master-v1".replace(/\//g, "%2F")}
Fetch-It-Via: git fetch https://github.com/gitgitgadget/git pr-1/somebody/master-v1
Pull-Request: https://github.com/gitgitgadget/git/pull/1
--${" "}
gitgitgadget
Expand Down Expand Up @@ -200,15 +198,13 @@ test("generate tag/notes from a Pull Request", async () => {
const pullRequestURL = "https://github.com/gitgitgadget/git/pull/1";
const pullRequestTitle = "My first Pull Request!";
const pullRequestBody = `This Pull Request contains some really important ${
""}changes that I would love to have included in ${
""}[git.git](https://github.com/git/git).
""}changes that I would love to have included in [git.git](https://github.com/git/git).
Cc: Some Body <[email protected]>
`;

await git(["config", "user.name", "GitGitGadget"], repo.options);
await git(["config", "user.email", "[email protected]"],
repo.options);
await git(["config", "user.email", "[email protected]"], repo.options);

const patches =
await PatchSeries.getFromNotes(notes, pullRequestURL, pullRequestTitle,
Expand All @@ -235,11 +231,9 @@ to have included in git.git [https://github.com/git/git].`);
return "Message-ID";
}

const metadata = await patches.generateAndSend(logger, send, undefined,
pullRequestURL);
const metadata = await patches.generateAndSend(logger, send, undefined, pullRequestURL);

expect(metadata?.coverLetterMessageId)
.toMatch(/pull\.1\.git\.\d+\.gitgitgadget@example\.com/);
expect(metadata?.coverLetterMessageId).toMatch(/pull\.1\.git\.\d+\.gitgitgadget@example\.com/);
expect(mails).toEqual(expectedMails);

expect(await repo.commit("D")).not.toEqual("");
Expand All @@ -252,11 +246,9 @@ to have included in git.git [https://github.com/git/git].`);
"somebody:master", headCommit2,
{}, "GitHub User", undefined);
mails.splice(0);
const metadata2 = await patches2.generateAndSend(logger, send, undefined,
pullRequestURL);
const metadata2 = await patches2.generateAndSend(logger, send, undefined, pullRequestURL);

expect(metadata2?.coverLetterMessageId)
.toMatch(/pull\.1\.v2\.git\.\d+\.gitgitgadget@example\.com/);
expect(metadata2?.coverLetterMessageId).toMatch(/pull\.1\.v2\.git\.\d+\.gitgitgadget@example\.com/);
expect(mails).toHaveLength(5);
if (await gitCommandExists("range-diff", repo.workDir)) {
expect(mails[0]).toMatch(/Range-diff vs v1:\n[^]*\n -: .* 4: /);
Expand All @@ -267,12 +259,10 @@ to have included in git.git [https://github.com/git/git].`);
expect(seriesMeta).not.toBeNull();
expect(seriesMeta?.coverLetterMessageId).not.toBeUndefined();
const coverMid: string | undefined = seriesMeta?.coverLetterMessageId;
expect(coverMid)
.toMatch(/pull\.1\.v2\.git\.\d+\.gitgitgadget@example\.com/);
expect(coverMid).toMatch(/pull\.1\.v2\.git\.\d+\.gitgitgadget@example\.com/);
expect(seriesMeta?.referencesMessageIds).not.toBeUndefined();
const refMid: string | undefined = seriesMeta?.referencesMessageIds?.[0];
expect(refMid)
.toMatch(/pull\.1\.git\.\d+\.gitgitgadget@example\.com/);
expect(refMid).toMatch(/pull\.1\.git\.\d+\.gitgitgadget@example\.com/);
expect(seriesMeta).toEqual({
baseCommit,
baseLabel: "gitgitgadget:next",
Expand All @@ -282,14 +272,11 @@ to have included in git.git [https://github.com/git/git].`);
iteration: 2,
latestTag: "pr-1/somebody/master-v2",
pullRequestURL,
referencesMessageIds: [
refMid,
],
referencesMessageIds: [refMid],
} as IPatchSeriesMetadata);

// verify that the tag was generated correctly
expect((await git(["cat-file", "tag", "pr-1/somebody/master-v2"],
repo.options))
expect((await git(["cat-file", "tag", "pr-1/somebody/master-v2"], repo.options))
.replace(/^[^]*?\n\n/, "")).toEqual(`My first Pull Request!
This Pull Request contains some really important changes that I would love
Expand Down Expand Up @@ -329,9 +316,7 @@ test("allow/disallow", async () => {
const remote = await testCreateRepo(sourceFileName, "-remote");

await git(["config", "gitgitgadget.workDir", workDir], { workDir });
await git(["config",
"gitgitgadget.publishRemote", remote.workDir],
{ workDir });
await git(["config", "gitgitgadget.publishRemote", remote.workDir], { workDir });
await git(["config", "gitgitgadget.smtpUser", "test"], { workDir });
await git(["config", "gitgitgadget.smtpHost", "test"], { workDir });
await git(["config", "gitgitgadget.smtpPass", "test"], { workDir });
Expand All @@ -342,20 +327,14 @@ test("allow/disallow", async () => {
const gitGitGadget = await GitGitGadget.get(workDir);

// pretend that the notes ref had been changed in the meantime
await notes.set("",
{ allowedUsers: ["first-one"] } as IGitGitGadgetOptions,
true);
await notes.set("", { allowedUsers: ["first-one"] } as IGitGitGadgetOptions, true);

expect(gitGitGadget.isUserAllowed("second-one")).toBeFalsy();
expect(await gitGitGadget.allowUser("first-one", "second-one"))
.toBeTruthy();
expect(await gitGitGadget.allowUser("first-one", "second-one"))
.toBeFalsy();
expect(await gitGitGadget.allowUser("first-one", "second-one")).toBeTruthy();
expect(await gitGitGadget.allowUser("first-one", "second-one")).toBeFalsy();
expect(gitGitGadget.isUserAllowed("second-one")).toBeTruthy();
expect(await gitGitGadget.denyUser("first-one", "second-one"))
.toBeTruthy();
expect(await gitGitGadget.denyUser("first-one", "second-one"))
.toBeFalsy();
expect(await gitGitGadget.denyUser("first-one", "second-one")).toBeTruthy();
expect(await gitGitGadget.denyUser("first-one", "second-one")).toBeFalsy();
expect(gitGitGadget.isUserAllowed("second-one")).toBeFalsy();
});

Expand All @@ -379,6 +358,5 @@ test("allow/disallow with env vars", async () => {
await notes.set("", { allowedUsers: ["first-one"] } as IGitGitGadgetOptions, true);

expect(gitGitGadget.isUserAllowed("second-one")).toBeFalsy();
expect(await gitGitGadget.allowUser("first-one", "second-one"))
.toBeTruthy();
expect(await gitGitGadget.allowUser("first-one", "second-one")).toBeTruthy();
});
Loading

0 comments on commit 348a2ab

Please sign in to comment.