diff --git a/tests/ci-helper.test.ts b/tests/ci-helper.test.ts index c588c9ee74..feb4264c01 100644 --- a/tests/ci-helper.test.ts +++ b/tests/ci-helper.test.ts @@ -1,9 +1,9 @@ import { afterAll, beforeAll, expect, jest, test } from "@jest/globals"; -import { fileURLToPath } from 'url'; +import { fileURLToPath } from "url"; import { CIHelper } from "../lib/ci-helper.js"; import { GitNotes } from "../lib/git-notes.js"; import { getConfig } from "../lib/gitgitgadget-config.js"; -import { GitHubGlue, IGitHubUser, IPRComment, IPRCommit, IPullRequestInfo, } from "../lib/github-glue.js"; +import { GitHubGlue, IGitHubUser, IPRComment, IPRCommit, IPullRequestInfo } from "../lib/github-glue.js"; import { IMailMetadata } from "../lib/mail-metadata.js"; import { testSmtpServer } from "test-smtp-server"; import { testCreateRepo, TestRepo } from "./test-lib.js"; @@ -22,7 +22,7 @@ function testQ(label: string, fn: AsyncFn) { console.log = mockLog; await fn(); } catch (e) { - mockLog.mock.calls.forEach(call => { + mockLog.mock.calls.forEach((call) => { originalConsoleLog(call[0]); }); throw e; @@ -36,14 +36,13 @@ getConfig(); const eMailOptions = { smtpserver: new testSmtpServer(), - smtpOpts: "" + smtpOpts: "", }; beforeAll((): void => { eMailOptions.smtpserver.startServer(); // start listening eMailOptions.smtpOpts = - `{port: ${eMailOptions.smtpserver.getPort() - }, secure: true, tls: {rejectUnauthorized: false}}`; + `{port: ${eMailOptions.smtpserver.getPort()}, secure: true, tls: {rejectUnauthorized: false}}`; }); afterAll((): void => { @@ -64,21 +63,18 @@ class TestCIHelper extends CIHelper { this.ghGlue = this.github; const commentInfo = { id: 1, url: "ok" }; - const addPRComment = jest.fn( async (): - // eslint-disable-next-line @typescript-eslint/require-await - Promise<{id: number; url: string}> => commentInfo ); + // eslint-disable-next-line @typescript-eslint/require-await + const addPRComment = jest.fn(async (): Promise<{ id: number; url: string }> => commentInfo); this.ghGlue.addPRComment = addPRComment; this.addPRCommentCalls = addPRComment.mock.calls; - const updatePR = jest.fn( async (): - // eslint-disable-next-line @typescript-eslint/require-await - Promise => 1 ); + // eslint-disable-next-line @typescript-eslint/require-await + const updatePR = jest.fn(async (): Promise => 1); this.ghGlue.updatePR = updatePR; this.updatePRCalls = updatePR.mock.calls; - const addPRLabels = jest.fn( async (_: string, labels: string[]): - // eslint-disable-next-line @typescript-eslint/require-await - Promise => labels ); + // eslint-disable-next-line @typescript-eslint/require-await + const addPRLabels = jest.fn(async (_: string, labels: string[]): Promise => labels); this.ghGlue.addPRLabels = addPRLabels; this.addPRLabelsCalls = addPRLabels.mock.calls; @@ -87,27 +83,23 @@ class TestCIHelper extends CIHelper { } public setGHGetPRInfo(o: IPullRequestInfo): void { - this.ghGlue.getPRInfo = jest.fn( async (): - // eslint-disable-next-line @typescript-eslint/require-await - Promise => o ); + // eslint-disable-next-line @typescript-eslint/require-await + this.ghGlue.getPRInfo = jest.fn(async (): Promise => o); } public setGHGetPRComment(o: IPRComment): void { - this.ghGlue.getPRComment = jest.fn( async (): - // eslint-disable-next-line @typescript-eslint/require-await - Promise => o ); + // eslint-disable-next-line @typescript-eslint/require-await + this.ghGlue.getPRComment = jest.fn(async (): Promise => o); } public setGHGetPRCommits(o: IPRCommit[]): void { - this.ghGlue.getPRCommits = jest.fn( async (): - // eslint-disable-next-line @typescript-eslint/require-await - Promise => o ); + // eslint-disable-next-line @typescript-eslint/require-await + this.ghGlue.getPRCommits = jest.fn(async (): Promise => o); } public setGHGetGitHubUserInfo(o: IGitHubUser): void { - this.ghGlue.getGitHubUserInfo = jest.fn( async (): - // eslint-disable-next-line @typescript-eslint/require-await - Promise => o ); + // eslint-disable-next-line @typescript-eslint/require-await + this.ghGlue.getGitHubUserInfo = jest.fn(async (): Promise => o); } public addMaxCommitsException(pullRequestURL: string): void { @@ -140,20 +132,20 @@ async function setupRepos(instance: string): // re-route the URLs const url = `https://github.com/gitgitgadget/git`; - await worktree.git([ "config", `url.${gggRemote.workDir}.insteadOf`, url ]); - await gggLocal.git([ "config", `url.${gggRemote.workDir}.insteadOf`, url ]); + await worktree.git(["config", `url.${gggRemote.workDir}.insteadOf`, url]); + await gggLocal.git(["config", `url.${gggRemote.workDir}.insteadOf`, url]); // set needed config - await worktree.git([ "config", "--add", "gitgitgadget.workDir", gggLocal.workDir, ]); + await worktree.git(["config", "--add", "gitgitgadget.workDir", gggLocal.workDir]); // misc-helper and gitgitgadget use this and ci-helper relies on insteadOf above await worktree.git(["config", "--add", "gitgitgadget.publishRemote", gggRemote.workDir]); - await worktree.git([ "config", "--add", "gitgitgadget.smtpUser", "joe_user@example.com", ]); - await worktree.git([ "config", "--add", "gitgitgadget.smtpHost", "localhost", ]); - await worktree.git([ "config", "--add", "gitgitgadget.smtpPass", "secret", ]); - await worktree.git([ "config", "--add", "gitgitgadget.smtpOpts", eMailOptions.smtpOpts, ]); + await worktree.git(["config", "--add", "gitgitgadget.smtpUser", "joe_user@example.com"]); + await worktree.git(["config", "--add", "gitgitgadget.smtpHost", "localhost"]); + await worktree.git(["config", "--add", "gitgitgadget.smtpPass", "secret"]); + await worktree.git(["config", "--add", "gitgitgadget.smtpOpts", eMailOptions.smtpOpts]); const notes = new GitNotes(gggRemote.workDir); - await notes.set("", {allowedUsers: ["ggg", "user1"]}, true); + await notes.set("", { allowedUsers: ["ggg", "user1"] }, true); // Initial empty commit const commitA = await gggRemote.commit("A"); @@ -222,8 +214,7 @@ testQ("identify upstream commit", async () => { const gggRemote = await testCreateRepo(sourceFileName, "-gitgitgadget"); // re-route the URLs - await worktree.git(["config", `url.${gggRemote.workDir}.insteadOf`, - "https://github.com/gitgitgadget/git"]); + await worktree.git(["config", `url.${gggRemote.workDir}.insteadOf`, "https://github.com/gitgitgadget/git"]); // Set up fake upstream branches const commitA = await gggRemote.commit("A"); @@ -255,8 +246,7 @@ testQ("identify upstream commit", async () => { await gggRemote.git(["merge", "--no-ff", "gg/via-pull-request"]); // Update the `mail-to-commit` notes ref, at least the part we care about - const mail2CommitNotes = new GitNotes(gggRemote.workDir, - "refs/notes/mail-to-commit"); + const mail2CommitNotes = new GitNotes(gggRemote.workDir, "refs/notes/mail-to-commit"); await mail2CommitNotes.setString(messageID, commitBNew); // "publish" the gitgitgadget notes @@ -296,8 +286,7 @@ testQ("handle comment allow basic test", async () => { ci.setGHGetGitHubUserInfo(user); await ci.handleComment("gitgitgadget", 433865360); - expect(ci.addPRCommentCalls[0][1]) - .toMatch(/is now allowed to use GitGitGadget/); + expect(ci.addPRCommentCalls[0][1]).toMatch(/is now allowed to use GitGitGadget/); }); testQ("handle comment allow fail invalid user", async () => { @@ -314,10 +303,8 @@ testQ("handle comment allow fail invalid user", async () => { ci.setGHGetPRComment(comment); - await expect(ci.handleComment("gitgitgadget", 433865360)). - rejects.toThrow(/is not a valid GitHub username/); - expect(ci.addPRCommentCalls[0][1]) - .toMatch(/is not a valid GitHub username/); + await expect(ci.handleComment("gitgitgadget", 433865360)).rejects.toThrow(/is not a valid GitHub username/); + expect(ci.addPRCommentCalls[0][1]).toMatch(/is not a valid GitHub username/); }); testQ("handle comment allow no public email", async () => { @@ -342,10 +329,8 @@ testQ("handle comment allow no public email", async () => { ci.setGHGetGitHubUserInfo(user); await ci.handleComment("gitgitgadget", 433865360); - expect(ci.addPRCommentCalls[0][1]) - .toMatch(/is now allowed to use GitGitGadget/); - expect(ci.addPRCommentCalls[0][1]) - .toMatch(/no public email address set/); + expect(ci.addPRCommentCalls[0][1]).toMatch(/is now allowed to use GitGitGadget/); + expect(ci.addPRCommentCalls[0][1]).toMatch(/no public email address set/); }); testQ("handle comment allow already allowed", async () => { @@ -371,12 +356,10 @@ testQ("handle comment allow already allowed", async () => { ci.setGHGetGitHubUserInfo(user); await ci.handleComment("gitgitgadget", 433865360); - expect(ci.addPRCommentCalls[0][1]) - .toMatch(/already allowed to use GitGitGadget/); + expect(ci.addPRCommentCalls[0][1]).toMatch(/already allowed to use GitGitGadget/); }); -testQ("handle comment allow no name specified (with trailing white space)", - async () => { +testQ("handle comment allow no name specified (with trailing white space)", async () => { const { worktree, gggLocal } = await setupRepos("a5"); const ci = new TestCIHelper(gggLocal.workDir, false, worktree.workDir); @@ -415,8 +398,7 @@ testQ("handle comment allow no name specified (with trailing white space)", ci.setGHGetGitHubUserInfo(user); await ci.handleComment("gitgitgadget", 433865360); - expect(ci.addPRCommentCalls[0][1]) - .toMatch(/already allowed to use GitGitGadget/); + expect(ci.addPRCommentCalls[0][1]).toMatch(/already allowed to use GitGitGadget/); }); testQ("handle comment disallow basic test", async () => { @@ -442,8 +424,7 @@ testQ("handle comment disallow basic test", async () => { ci.setGHGetGitHubUserInfo(user); await ci.handleComment("gitgitgadget", 433865360); - expect(ci.addPRCommentCalls[0][1]) - .toMatch(/is no longer allowed to use GitGitGadget/); + expect(ci.addPRCommentCalls[0][1]).toMatch(/is no longer allowed to use GitGitGadget/); }); testQ("handle comment disallow was not allowed", async () => { @@ -462,8 +443,7 @@ testQ("handle comment disallow was not allowed", async () => { ci.setGHGetPRComment(comment); await ci.handleComment("gitgitgadget", 433865360); - expect(ci.addPRCommentCalls[0][1]) - .toMatch(/already not allowed to use GitGitGadget/); + expect(ci.addPRCommentCalls[0][1]).toMatch(/already not allowed to use GitGitGadget/); }); testQ("handle comment submit not author", async () => { @@ -504,10 +484,8 @@ testQ("handle comment submit not author", async () => { ci.setGHGetPRComment(comment); ci.setGHGetGitHubUserInfo(user); - await expect(ci.handleComment("gitgitgadget", 433865360)). - rejects.toThrow(/Only the owner of a PR can submit/); - expect(ci.addPRCommentCalls[0][1]) - .toMatch(/Only the owner of a PR can submit/); + await expect(ci.handleComment("gitgitgadget", 433865360)).rejects.toThrow(/Only the owner of a PR can submit/); + expect(ci.addPRCommentCalls[0][1]).toMatch(/Only the owner of a PR can submit/); }); testQ("handle comment submit not mergeable", async () => { @@ -548,10 +526,8 @@ testQ("handle comment submit not mergeable", async () => { ci.setGHGetPRComment(comment); ci.setGHGetGitHubUserInfo(user); - await expect(ci.handleComment("gitgitgadget", 433865360)). - rejects.toThrow(/does not merge cleanly/); - expect(ci.addPRCommentCalls[0][1]) - .toMatch(/does not merge cleanly/); + await expect(ci.handleComment("gitgitgadget", 433865360)).rejects.toThrow(/does not merge cleanly/); + expect(ci.addPRCommentCalls[0][1]).toMatch(/does not merge cleanly/); }); testQ("handle comment submit email success", async () => { @@ -562,8 +538,7 @@ testQ("handle comment submit email success", async () => { const template = "fine template\r\nnew line"; // add template to master repo - await gggRemote.commit("temple", ".github//PULL_REQUEST_TEMPLATE.md", - template); + await gggRemote.commit("temple", ".github//PULL_REQUEST_TEMPLATE.md", template); const commitA = await gggRemote.revParse("HEAD"); expect(commitA).not.toBeUndefined(); @@ -574,7 +549,8 @@ testQ("handle comment submit email success", async () => { // get the pr refs in place const pullRequestRef = `refs/pull/${prNumber}`; await gggRemote.git([ - "fetch", worktree.workDir, + "fetch", + worktree.workDir, `refs/heads/master:${pullRequestRef}/head`, `refs/heads/master:${pullRequestRef}/merge`, ]); // fake merge @@ -591,29 +567,30 @@ testQ("handle comment submit email success", async () => { name: "e. e. cummings", type: "basic", }; - const commits = [{ - author: { - email: "ggg@example.com", - login: "ggg", - name: "e. e. cummings", - }, - commit: "BA55FEEDBEEF", - committer: { - email: "ggg@example.com", - login: "ggg", - name: "e. e. cummings", + const commits = [ + { + author: { + email: "ggg@example.com", + login: "ggg", + name: "e. e. cummings", + }, + commit: "BA55FEEDBEEF", + committer: { + email: "ggg@example.com", + login: "ggg", + name: "e. e. cummings", + }, + message: "Submit ok\n\nSuccinct message\n\nSigned-off-by: x", + parentCount: 1, }, - message: "Submit ok\n\nSuccinct message\n\nSigned-off-by: x", - parentCount: 1, - }]; + ]; const prInfo = { author: "ggg", baseCommit: commitA, baseLabel: "gitgitgadget:next", baseOwner: "gitgitgadget", baseRepo: "git", - body: `Super body\r\n${template}\r\nCc: Copy One \r\n` - + "Cc: Copy Two ", + body: `Super body\r\n${template}\r\nCc: Copy One \r\nCc: Copy Two `, hasComments: true, headCommit: commitB, headLabel: "somebody:master", @@ -646,8 +623,7 @@ testQ("handle comment preview email success", async () => { const prNumber = 59; const template = "fine template\nnew line"; - await gggRemote.commit("temple", ".github//PULL_REQUEST_TEMPLATE.md", - template); + await gggRemote.commit("temple", ".github//PULL_REQUEST_TEMPLATE.md", template); const commitA = await gggRemote.revParse("HEAD"); expect(commitA).not.toBeUndefined(); @@ -658,7 +634,8 @@ testQ("handle comment preview email success", async () => { // get the pr refs in place const pullRequestRef = `refs/pull/${prNumber}`; await gggRemote.git([ - "fetch", worktree.workDir, + "fetch", + worktree.workDir, `refs/heads/master:${pullRequestRef}/head`, `refs/heads/master:${pullRequestRef}/merge`, ]); // fake merge @@ -675,21 +652,23 @@ testQ("handle comment preview email success", async () => { name: "e. e. cummings", type: "basic", }; - const commits = [{ - author: { - email: "ggg@example.com", - login: "ggg", - name: "e. e. cummings", - }, - commit: "BA55FEEDBEEF", - committer: { - email: "ggg@example.com", - login: "ggg", - name: "e. e. cummings", + const commits = [ + { + author: { + email: "ggg@example.com", + login: "ggg", + name: "e. e. cummings", + }, + commit: "BA55FEEDBEEF", + committer: { + email: "ggg@example.com", + login: "ggg", + name: "e. e. cummings", + }, + message: "Submit ok\n\nSigned-off-by: x", + parentCount: 1, }, - message: "Submit ok\n\nSigned-off-by: x", - parentCount: 1, - }]; + ]; const prInfo = { author: "ggg", baseCommit: commitA, @@ -724,8 +703,7 @@ testQ("handle comment preview email success", async () => { comment.body = " /preview"; ci.setGHGetPRComment(comment); await ci.handleComment("gitgitgadget", 433865360); // do it again - expect(ci.addPRCommentCalls[1][1]) - .toMatch(/Preview email sent as/); + expect(ci.addPRCommentCalls[1][1]).toMatch(/Preview email sent as/); const msgId2 = ci.addPRCommentCalls[0][1].match(/\[(.*)\]/); expect(msgId2).not.toBeUndefined(); @@ -761,7 +739,8 @@ testQ("handle push/comment too many commits fails", async () => { // get the pr refs in place const pullRequestRef = `refs/pull/${prNumber}`; await gggRemote.git([ - "fetch", worktree.workDir, + "fetch", + worktree.workDir, `refs/heads/master:${pullRequestRef}/head`, `refs/heads/master:${pullRequestRef}/merge`, ]); // fake merge @@ -820,8 +799,7 @@ testQ("handle push/comment too many commits fails", async () => { const failMsg = `The pull request has ${commits.length} commits.`; // fail for too many commits on push - await expect(ci.handlePush("gitgitgadget", 433865360)). - rejects.toThrow(/Failing check due/); + await expect(ci.handlePush("gitgitgadget", 433865360)).rejects.toThrow(/Failing check due/); expect(ci.addPRCommentCalls[0][1]).toMatch(failMsg); ci.addPRCommentCalls.length = 0; @@ -856,8 +834,7 @@ testQ("handle push/comment too many commits fails", async () => { ci.setGHGetGitHubUserInfo(user); ci.setGHGetPRCommits(commits); - await expect(ci.handlePush("gitgitgadget", 433865360)). - rejects.toThrow(/Failing check due/); + await expect(ci.handlePush("gitgitgadget", 433865360)).rejects.toThrow(/Failing check due/); expect(ci.addPRCommentCalls[0][1]).toMatch(/Welcome/); expect(ci.addPRCommentCalls[1][1]).toMatch(failMsg); @@ -865,7 +842,7 @@ testQ("handle push/comment too many commits fails", async () => { }); testQ("handle push/comment merge commits fails", async () => { - const { worktree, gggLocal, gggRemote} = await setupRepos("pu2"); + const { worktree, gggLocal, gggRemote } = await setupRepos("pu2"); const ci = new TestCIHelper(gggLocal.workDir, false, worktree.workDir); const prNumber = 59; @@ -880,10 +857,12 @@ testQ("handle push/comment merge commits fails", async () => { // get the pr refs in place const pullRequestRef = `refs/pull/${prNumber}`; - await gggRemote.git( - [ "fetch", worktree.workDir, - `refs/heads/master:${pullRequestRef}/head`, - `refs/heads/master:${pullRequestRef}/merge`]); // fake merge + await gggRemote.git([ + "fetch", + worktree.workDir, + `refs/heads/master:${pullRequestRef}/head`, + `refs/heads/master:${pullRequestRef}/merge`, + ]); // fake merge // GitHubGlue Responses const comment = { @@ -897,21 +876,23 @@ testQ("handle push/comment merge commits fails", async () => { name: "e. e. cummings", type: "basic", }; - const commits = [{ - author: { - email: "ggg@example.com", - login: "ggg", - name: "e. e. cummings", - }, - commit: "BAD1FEEDBEEF", - committer: { - email: "ggg@example.com", - login: "ggg", - name: "e. e. cummings", + const commits = [ + { + author: { + email: "ggg@example.com", + login: "ggg", + name: "e. e. cummings", + }, + commit: "BAD1FEEDBEEF", + committer: { + email: "ggg@example.com", + login: "ggg", + name: "e. e. cummings", + }, + message: "Merge a commit", + parentCount: 2, }, - message: "Merge a commit", - parentCount: 2, - }]; + ]; const prInfo = { author: "ggg", @@ -936,8 +917,7 @@ testQ("handle push/comment merge commits fails", async () => { ci.setGHGetGitHubUserInfo(user); // fail for merge commits on push - await expect(ci.handlePush("gitgitgadget", 433865360)). - rejects.toThrow(/Failing check due/); + await expect(ci.handlePush("gitgitgadget", 433865360)).rejects.toThrow(/Failing check due/); expect(ci.addPRCommentCalls[0][1]).toMatch(commits[0].commit); ci.addPRCommentCalls.length = 0; @@ -960,8 +940,7 @@ testQ("handle push/comment merge commits fails", async () => { comment.author = "starfish"; user.login = "starfish"; - await expect(ci.handlePush("gitgitgadget", 433865360)). - rejects.toThrow(/Failing check due/); + await expect(ci.handlePush("gitgitgadget", 433865360)).rejects.toThrow(/Failing check due/); expect(ci.addPRCommentCalls[0][1]).toMatch(/Welcome/); expect(ci.addPRCommentCalls[1][1]).toMatch(commits[0].commit); @@ -1000,19 +979,17 @@ testQ("handle push/comment merge commits fails", async () => { parentCount: 2, }); - await expect(ci.handlePush("gitgitgadget", 433865360)). - rejects.toThrow(/Failing check due/); + await expect(ci.handlePush("gitgitgadget", 433865360)).rejects.toThrow(/Failing check due/); expect(ci.addPRCommentCalls[0][1]).toMatch(/Welcome/); expect(ci.addPRCommentCalls[1][1]).toMatch(commits[0].commit); expect(ci.addPRCommentCalls[1][1]).not.toMatch(commits[1].commit); expect(ci.addPRCommentCalls[1][1]).toMatch(commits[2].commit); ci.addPRCommentCalls.length = 0; - }); testQ("disallow no-reply emails", async () => { - const { worktree, gggLocal, gggRemote} = await setupRepos("pu2"); + const { worktree, gggLocal, gggRemote } = await setupRepos("pu2"); const ci = new TestCIHelper(gggLocal.workDir, false, worktree.workDir); const prNumber = 59; @@ -1027,10 +1004,12 @@ testQ("disallow no-reply emails", async () => { // get the pr refs in place const pullRequestRef = `refs/pull/${prNumber}`; - await gggRemote.git( - [ "fetch", worktree.workDir, - `refs/heads/master:${pullRequestRef}/head`, - `refs/heads/master:${pullRequestRef}/merge`]); // fake merge + await gggRemote.git([ + "fetch", + worktree.workDir, + `refs/heads/master:${pullRequestRef}/head`, + `refs/heads/master:${pullRequestRef}/merge`, + ]); // fake merge // GitHubGlue Responses const comment = { @@ -1044,21 +1023,23 @@ testQ("disallow no-reply emails", async () => { name: "e. e. cummings", type: "basic", }; - const commits = [{ - author: { - email: "random@users.noreply.github.com", - login: "random", - name: "random", - }, - commit: "BAD1FEEDBEEF", - committer: { - email: "ggg@example.com", - login: "ggg", - name: "e. e. cummings", + const commits = [ + { + author: { + email: "random@users.noreply.github.com", + login: "random", + name: "random", + }, + commit: "BAD1FEEDBEEF", + committer: { + email: "ggg@example.com", + login: "ggg", + name: "e. e. cummings", + }, + message: "Using ineligible email address", + parentCount: 1, }, - message: "Using ineligible email address", - parentCount: 1, - }]; + ]; const prInfo = { author: "ggg", @@ -1083,15 +1064,13 @@ testQ("disallow no-reply emails", async () => { ci.setGHGetGitHubUserInfo(user); // fail for commits with fake email on push - await expect(ci.handlePush("gitgitgadget", 433865360)). - rejects.toThrow(/Failing check due/); - + await expect(ci.handlePush("gitgitgadget", 433865360)).rejects.toThrow(/Failing check due/); }); // Basic tests for ci-helper - lint tests are in commit-lint.tests.ts testQ("basic lint tests", async () => { - const { worktree, gggLocal, gggRemote} = await setupRepos("pu4"); + const { worktree, gggLocal, gggRemote } = await setupRepos("pu4"); const ci = new TestCIHelper(gggLocal.workDir, false, worktree.workDir); const prNumber = 59; @@ -1106,10 +1085,12 @@ testQ("basic lint tests", async () => { // get the pr refs in place const pullRequestRef = `refs/pull/${prNumber}`; - await gggRemote.git( - [ "fetch", worktree.workDir, - `refs/heads/master:${pullRequestRef}/head`, - `refs/heads/master:${pullRequestRef}/merge`]); // fake merge + await gggRemote.git([ + "fetch", + worktree.workDir, + `refs/heads/master:${pullRequestRef}/head`, + `refs/heads/master:${pullRequestRef}/merge`, + ]); // fake merge // GitHubGlue Responses const comment = { @@ -1209,19 +1190,17 @@ testQ("basic lint tests", async () => { ci.setGHGetGitHubUserInfo(user); // fail for commits with lint errors - await expect(ci.handlePush("gitgitgadget", 433865360)). - rejects.toThrow(/Failing check due/); + await expect(ci.handlePush("gitgitgadget", 433865360)).rejects.toThrow(/Failing check due/); expect(ci.addPRCommentCalls[0][1]).toMatch(commits[0].commit); expect(ci.addPRCommentCalls[0][1]).toMatch(/too short/); expect(ci.addPRCommentCalls[1][1]).toMatch(commits[1].commit); expect(ci.addPRCommentCalls[1][1]).toMatch(/empty line/); expect(ci.addPRCommentCalls[2][1]).toMatch(commits[3].commit); expect(ci.addPRCommentCalls[2][1]).toMatch(/lower case/); - }); testQ("Handle comment cc", async () => { - const {worktree, gggLocal} = await setupRepos("cc"); + const { worktree, gggLocal } = await setupRepos("cc"); const ci = new TestCIHelper(gggLocal.workDir, false, worktree.workDir); const prNumber = 59; @@ -1229,7 +1208,7 @@ testQ("Handle comment cc", async () => { // GitHubGlue Responses const comment = { author: "ggg", - body: "/cc \"Some Body\" ", + body: '/cc "Some Body" ', prNumber, }; const user = { @@ -1262,16 +1241,15 @@ testQ("Handle comment cc", async () => { await ci.handleComment("gitgitgadget", prNumber); - expect(ci.updatePRCalls[0][ci.updatePRCalls[0].length-1]).toMatch(/Some Body/); + expect(ci.updatePRCalls[0][ci.updatePRCalls[0].length - 1]).toMatch(/Some Body/); ci.updatePRCalls.length = 0; - comment.body = "/cc \"A Body\" , " - + "\"S Body\" "; + comment.body = '/cc "A Body" , "S Body" '; await ci.handleComment("gitgitgadget", prNumber); - expect(ci.updatePRCalls[0][ci.updatePRCalls[0].length-1]).toMatch(/A Body/); - expect(ci.updatePRCalls[1][ci.updatePRCalls[0].length-1]).toMatch(/S Body/); + expect(ci.updatePRCalls[0][ci.updatePRCalls[0].length - 1]).toMatch(/A Body/); + expect(ci.updatePRCalls[1][ci.updatePRCalls[0].length - 1]).toMatch(/S Body/); ci.updatePRCalls.length = 0; // email will not be re-added to list @@ -1279,6 +1257,6 @@ testQ("Handle comment cc", async () => { await ci.handleComment("gitgitgadget", prNumber); - expect(ci.updatePRCalls[0][ci.updatePRCalls[0].length-1]).toMatch(/S Body/); + expect(ci.updatePRCalls[0][ci.updatePRCalls[0].length - 1]).toMatch(/S Body/); expect(ci.updatePRCalls).toHaveLength(1); }); diff --git a/tests/commit-lint.test.ts b/tests/commit-lint.test.ts index 86e564af3b..764df0fde8 100644 --- a/tests/commit-lint.test.ts +++ b/tests/commit-lint.test.ts @@ -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=${ - ""}QZDOvaMDdZbpNXrVWQdN-jmfN8wC6YVhmw@mail.gmail.com/\n\n${ - ""}Signed-off-by: x}`; + ""}QZDOvaMDdZbpNXrVWQdN-jmfN8wC6YVhmw@mail.gmail.com/\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); }); @@ -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/); @@ -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 }); }); diff --git a/tests/git-notes.test.ts b/tests/git-notes.test.ts index dc333b9577..dd007c268c 100644 --- a/tests/git-notes.test.ts +++ b/tests/git-notes.test.ts @@ -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"; @@ -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`; @@ -36,8 +34,7 @@ test("set/get notes", async () => { pullRequestURL, }; expect(await notes.set(pullRequestURL, metadata)).toBeUndefined(); - expect(await notes.get(pullRequestURL)) - .toEqual(metadata); + expect(await notes.get(pullRequestURL)).toEqual(metadata); const commit = await revParse(notes.notesRef, notes.workDir); expect(commit).not.toBeUndefined(); @@ -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/); - }); diff --git a/tests/git.test.ts b/tests/git.test.ts index 0e63f0b31b..89de8f51a7 100644 --- a/tests/git.test.ts +++ b/tests/git.test.ts @@ -14,7 +14,7 @@ for (let i = 0; i < configCount; i++) { const sleep = async (ms: number) => { await new Promise((resolve) => { - setTimeout(() => { resolve(); }, ms); + setTimeout(() => resolve(), ms); }); }; @@ -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); }); @@ -53,11 +53,11 @@ test("sequencing", async () => { const lineHandler = async (line: string): Promise => { 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); }); @@ -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); -}); \ No newline at end of file +}); diff --git a/tests/gitgitgadget.test.ts b/tests/gitgitgadget.test.ts index b66acdd2a5..8478e36ca6 100644 --- a/tests/gitgitgadget.test.ts +++ b/tests/gitgitgadget.test.ts @@ -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"; @@ -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 @@ -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 `; await git(["config", "user.name", "GitGitGadget"], repo.options); - await git(["config", "user.email", "gitgitgadget@example.com"], - repo.options); + await git(["config", "user.email", "gitgitgadget@example.com"], repo.options); const patches = await PatchSeries.getFromNotes(notes, pullRequestURL, pullRequestTitle, @@ -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(""); @@ -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: /); @@ -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", @@ -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 @@ -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 }); @@ -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(); }); @@ -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(); }); diff --git a/tests/github-glue.test.ts b/tests/github-glue.test.ts index b146ae39a8..49ae6fa9b5 100644 --- a/tests/github-glue.test.ts +++ b/tests/github-glue.test.ts @@ -32,7 +32,7 @@ located at the same directory level as this project (ie ../). class GitHubProxy extends GitHubGlue { public octo: Octokit; - public constructor(workDir = "./" , owner = "gitgitfadget", repo = "git") { + public constructor(workDir = "./", owner = "gitgitfadget", repo = "git") { super(workDir, owner, repo); this.octo = this.client; } @@ -53,13 +53,13 @@ let owner: string; let repo: string; beforeAll(async () => { - owner = await gitConfig(`gitgitgadget.CIGitHubTestUser`) || ""; - repo = await gitConfig(`gitgitgadget.${owner}.gitHubRepo`) || ""; + owner = (await gitConfig(`gitgitgadget.CIGitHubTestUser`)) || ""; + repo = (await gitConfig(`gitgitgadget.${owner}.gitHubRepo`)) || ""; }); test("identify user", async () => { if (owner && repo) { - const userName = await gitConfig(`user.name`, `../${repo}`) || ""; + const userName = (await gitConfig(`user.name`, `../${repo}`)) || ""; const github = new GitHubProxy(`../${repo}`, owner, repo); await github.authenticate(owner); @@ -92,7 +92,7 @@ test("pull requests", async () => { !Object.prototype.hasOwnProperty.call(process.env, "system.definitionId")) { let pullRequestURL = ""; - oldPrs.map(pr => { + oldPrs.map((pr) => { if (pr.title === titleBase) { // need to clean up? pullRequestURL = pr.pullRequestURL; } @@ -103,11 +103,7 @@ test("pull requests", async () => { } try { // delete remote branch - await github.octo.rest.git.deleteRef({ - owner, - ref: `heads/${branchBase}`, - repo, - }); + await github.octo.rest.git.deleteRef({ owner, ref: `heads/${branchBase}`, repo }); } catch (e) { const error = e as Error; expect(error.toString()).toMatch(/Reference does not exist/); @@ -119,9 +115,7 @@ test("pull requests", async () => { const error = e as Error; expect(error.toString()).toMatch(/not found/); } - } - else - { + } else { const now = new Date(); suffix = `_${now.toISOString().replace(/[:.]/g, "_")}`; } @@ -167,7 +161,7 @@ test("pull requests", async () => { const prKey: pullRequestKey = { owner, repo, - pull_number: prData.number + pull_number: prData.number, }; const prs = await github.getOpenPRs(owner); @@ -193,25 +187,20 @@ test("pull requests", async () => { expect(prNewTitle.title).toMatch(prTitle); const newComment = "Adding a comment to the PR"; - const {id, url} = await github.addPRComment(prData.html_url, - newComment); + const { id, url } = await github.addPRComment(prData.html_url, newComment); expect(url).toMatch(id.toString()); const comment = await github.getPRComment(owner, id); expect(comment.body).toMatch(newComment); // update the local repo to test commit comment - await git(["fetch", "origin", "--", `+${branchRef}:${branchRef}`], - { workDir: repoDir }); + await git(["fetch", "origin", "--", `+${branchRef}:${branchRef}`], { workDir: repoDir }); const commitComment = "comment about commit"; const reviewResult = await github - .addPRCommitComment(prData.html_url, cFile.data.commit.sha || '', - repoDir, commitComment); + .addPRCommitComment(prData.html_url, cFile.data.commit.sha || '', repoDir, commitComment); - const commentReply = - await github.addPRCommentReply(prData.html_url, - reviewResult.id, newComment); + const commentReply = await github.addPRCommentReply(prData.html_url, reviewResult.id, newComment); expect(commentReply.url).toMatch(commentReply.id.toString()); @@ -255,21 +244,19 @@ test("add PR cc requests", async () => { }; const commentInfo = { id: 1, url: "ok" }; - github.addPRComment = jest.fn( async (): - // eslint-disable-next-line @typescript-eslint/require-await - Promise<{id: number; url: string}> => commentInfo ); + // eslint-disable-next-line @typescript-eslint/require-await + github.addPRComment = jest.fn(async (): Promise<{ id: number; url: string }> => commentInfo); - // eslint-disable-next-line @typescript-eslint/require-await - const updatePR = jest.fn( async (_prKey, body: string): Promise => { + // eslint-disable-next-line @typescript-eslint/require-await + const updatePR = jest.fn(async (_prKey, body: string): Promise => { prInfo.body = body; // set new body for next test return 1; }); github.updatePR = updatePR; - github.getPRInfo = jest.fn( async (): - // eslint-disable-next-line @typescript-eslint/require-await - Promise => prInfo); + // eslint-disable-next-line @typescript-eslint/require-await + github.getPRInfo = jest.fn(async (): Promise => prInfo); const ghUser = { email: "joe_kerr@example.org", @@ -278,9 +265,8 @@ test("add PR cc requests", async () => { type: "unknown", }; - github.getGitHubUserInfo= jest.fn( async (): - // eslint-disable-next-line @typescript-eslint/require-await - Promise => ghUser); + // eslint-disable-next-line @typescript-eslint/require-await + github.getGitHubUserInfo = jest.fn(async (): Promise => ghUser); // Test cc update to PR const prCc = "Not Real "; @@ -480,17 +466,16 @@ test("test missing values in response using small schema", async () => { // Response for any octokit calls - will be returned by the hook.wrap() // being set below. - let response: OctokitResponse | - OctokitResponse | - OctokitResponse | - OctokitResponse<[ICommit]> | - OctokitResponse; + let response: OctokitResponse + | OctokitResponse + | OctokitResponse + | OctokitResponse<[ICommit]> + | OctokitResponse; response = prListResponse; // eslint-disable-next-line @typescript-eslint/require-await github.octo.hook.wrap("request", async () => { - // eslint-disable-next-line @typescript-eslint/no-unsafe-return return response; }); @@ -513,7 +498,7 @@ test("test missing values in response using small schema", async () => { pullRequestSimple.user = null; pullRequestSimple.base.repo.owner = sampleUser; // if (!pullRequest.user) { - await expect(github.getPRInfo({owner, repo: testRepo.name, pull_number: 2})).rejects.toThrow(/is missing info/); + await expect(github.getPRInfo({ owner, repo: testRepo.name, pull_number: 2 })).rejects.toThrow(/is missing info/); interface IIssueComment { body?: string; @@ -534,9 +519,7 @@ test("test missing values in response using small schema", async () => { response = issueCommentResponse; // reset response value // if (!response.data.user) { - await expect(github.getPRComment(owner, 77)).rejects.toThrow( - /is missing info/ - ); + await expect(github.getPRComment(owner, 77)).rejects.toThrow(/is missing info/); interface ICommit { commit: { @@ -570,19 +553,13 @@ test("test missing values in response using small schema", async () => { response = getCommitsResponse; // reset response value // if (!cm.commit.committer || !cm.commit.author || !cm.sha) { - await expect(github.getPRCommits(owner, 22)).rejects.toThrow( - /information missing/ - ); + await expect(github.getPRCommits(owner, 22)).rejects.toThrow(/information missing/); commitObj.commit.author = null; - await expect(github.getPRCommits(owner, 22)).rejects.toThrow( - /information missing/ - ); + await expect(github.getPRCommits(owner, 22)).rejects.toThrow(/information missing/); commitObj.commit.committer = null; - await expect(github.getPRCommits(owner, 22)).rejects.toThrow( - /information missing/ - ); + await expect(github.getPRCommits(owner, 22)).rejects.toThrow(/information missing/); interface IPrivateUser extends IBasicUser { name: string | null; diff --git a/tests/logger.ts b/tests/logger.ts index 4e306c6ca9..4d8c008bde 100644 --- a/tests/logger.ts +++ b/tests/logger.ts @@ -7,7 +7,6 @@ // logger("some test related data"); const logger = (() => { - // eslint-disable-next-line @typescript-eslint/no-explicit-any const debugLog = (...body: any[]) => { // eslint-disable-next-line @typescript-eslint/no-unsafe-argument return console.log(...body); @@ -17,4 +16,4 @@ const logger = (() => { return process.env.npm_config_GGGVERBOSE ? debugLog : nodebugLog; })(); -export default logger; \ No newline at end of file +export default logger; diff --git a/tests/mail-archive-helper.test.ts b/tests/mail-archive-helper.test.ts index 578f71fbed..378fc6a788 100644 --- a/tests/mail-archive-helper.test.ts +++ b/tests/mail-archive-helper.test.ts @@ -1,7 +1,7 @@ import { Octokit } from "@octokit/rest"; import { OctokitResponse } from "@octokit/types"; import { expect, jest, test } from "@jest/globals"; -import { fileURLToPath } from 'url'; +import { fileURLToPath } from "url"; import { GitNotes } from "../lib/git-notes.js"; import { getConfig } from "../lib/gitgitgadget-config.js"; import { GitHubGlue } from "../lib/github-glue.js"; @@ -14,13 +14,13 @@ import { testCreateRepo } from "./test-lib.js"; class MailArchiveGitHelperProxy extends MailArchiveGitHelper { public constructor(gggNotes: GitNotes, mailArchiveGitDir: string, githubGlue: GitHubGlue, - state: IGitMailingListMirrorState, branch: string){ + state: IGitMailingListMirrorState, branch: string) { super(gggNotes, mailArchiveGitDir, githubGlue, state, branch); } } class GitHubProxy extends GitHubGlue { public octo: Octokit; - public constructor(workDir = "./" , owner = "gitgitfadget", repo = "git") { + public constructor(workDir = "./", owner = "gitgitfadget", repo = "git") { super(workDir, owner, repo); this.octo = this.client; } @@ -172,13 +172,13 @@ const issueCommentResponse: OctokitResponse = { test("test not a pr related email", async () => { const repo = await testCreateRepo(sourceFileName, "-unrelated"); - await repo.commit("1", "1", ""); // need at least one commit to back up to + await repo.commit("1", "1", ""); // need at least one commit to back up to const mailMeta: IMailMetadata = { messageID: "pull.12345.v1.git.gitgitgadget@example.com", originalCommit: "feeddeadbeef", pullRequestURL: `https://github.com/${config.repo.owner}/${config.repo.name}/pull/1`, - firstPatchLine: 5 + firstPatchLine: 5, }; const replyMessageId = `i${mailMeta.messageID}`; @@ -200,9 +200,9 @@ This Pull Request contains some ipsum lorem. const notes = new GitNotes(repo.workDir); await notes.set(mailMeta.messageID, mailMeta, true); - const mail = new MailArchiveGitHelperProxy(notes, repo.workDir, github, { latestRevision: "HEAD~"}, "master"); + const mail = new MailArchiveGitHelperProxy(notes, repo.workDir, github, { latestRevision: "HEAD~" }, "master"); - const logSpy = jest.spyOn(console, "log").mockImplementation(() => {return;}); + const logSpy = jest.spyOn(console, "log").mockImplementation(() => {}); await mail.processMails(); expect(logSpy).toHaveBeenCalledTimes(1); // verify no more errors logSpy.mockRestore(); @@ -210,13 +210,13 @@ This Pull Request contains some ipsum lorem. test("test already seen", async () => { const repo = await testCreateRepo(sourceFileName, "-seen"); - await repo.commit("1", "1", ""); // need at least one commit to back up to + await repo.commit("1", "1", ""); // need at least one commit to back up to const mailMeta: IMailMetadata = { messageID: "pull.12345.v1.git.gitgitgadget@example.com", originalCommit: "feeddeadbeef", pullRequestURL: `https://github.com/${config.repo.owner}/${config.repo.name}/pull/1`, - firstPatchLine: 5 + firstPatchLine: 5, }; const mbox0 = `From 566155e00ab72541ff0ac21eab84d087b0e882a5 Mon Sep 17 00:00:00 2001 @@ -235,9 +235,9 @@ This Pull Request contains some ipsum lorem. const notes = new GitNotes(repo.workDir); await notes.set(mailMeta.messageID, mailMeta, true); - const mail = new MailArchiveGitHelperProxy(notes, repo.workDir, github, { latestRevision: "HEAD~"}, "master"); + const mail = new MailArchiveGitHelperProxy(notes, repo.workDir, github, { latestRevision: "HEAD~" }, "master"); - const logSpy = jest.spyOn(console, "log").mockImplementation(() => {return;}); + const logSpy = jest.spyOn(console, "log").mockImplementation(() => {}); await mail.processMails(); expect(logSpy).toHaveBeenCalledTimes(2); // verify no more errors expect(logSpy.mock.calls[1][0]).toMatch(/Already handled:/); @@ -246,13 +246,13 @@ This Pull Request contains some ipsum lorem. test("test reply to cover letter", async () => { const repo = await testCreateRepo(sourceFileName, "-cover"); - await repo.commit("1", "1", ""); // need at least one commit to back up to + await repo.commit("1", "1", ""); // need at least one commit to back up to const mailMeta: IMailMetadata = { messageID: "pull.12345.v1.git.gitgitgadget@example.com", originalCommit: "feeddeadbeef", pullRequestURL: `https://github.com/${config.repo.owner}/${config.repo.name}/pull/1`, - firstPatchLine: 5 + firstPatchLine: 5, }; const replyMessageId = `i${mailMeta.messageID}`; @@ -274,7 +274,7 @@ This Pull Request contains some ipsum lorem. const notes = new GitNotes(repo.workDir); await notes.set(mailMeta.messageID, mailMeta, true); - const mail = new MailArchiveGitHelperProxy(notes, repo.workDir, github, { latestRevision: "HEAD~"}, "master"); + const mail = new MailArchiveGitHelperProxy(notes, repo.workDir, github, { latestRevision: "HEAD~" }, "master"); const commitsResponse = getCommitsResponse; const fail = false; @@ -303,7 +303,7 @@ This Pull Request contains some ipsum lorem. return issueCommentResponse; // dummy }); - const logSpy = jest.spyOn(console, "log").mockImplementation(() => {return;}); + const logSpy = jest.spyOn(console, "log").mockImplementation(() => {}); await mail.processMails(); expect(logSpy).toHaveBeenCalledTimes(2); // verify no more errors logSpy.mockRestore(); @@ -315,13 +315,13 @@ This Pull Request contains some ipsum lorem. test("test reply to patch letter", async () => { const repo = await testCreateRepo(sourceFileName, "-patchr"); - await repo.commit("1", "1", ""); // need at least one commit to back up to + await repo.commit("1", "1", ""); // need at least one commit to back up to const mailMeta: IMailMetadata = { messageID: "ppull.12345.v1.git.gitgitgadget@example.com", originalCommit: "feeddeadbeef", pullRequestURL: `https://github.com/${config.repo.owner}/${config.repo.name}/pull/1`, - firstPatchLine: 5 + firstPatchLine: 5, }; const replyMessageId = `i${mailMeta.messageID}`; @@ -360,7 +360,7 @@ This Pull Request contains some ipsum lorem. const notes = new GitNotes(repo.workDir); await notes.set(mailMeta.messageID, mailMeta, true); - const mail = new MailArchiveGitHelperProxy(notes, repo.workDir, github, { latestRevision: "HEAD~~"}, "master"); + const mail = new MailArchiveGitHelperProxy(notes, repo.workDir, github, { latestRevision: "HEAD~~" }, "master"); const commitsResponse = getCommitsResponse; const fail = false; @@ -394,16 +394,16 @@ This Pull Request contains some ipsum lorem. return issueCommentResponse; // dummy }); - const logSpy = jest.spyOn(console, "log").mockImplementation(() => {return;}); + const logSpy = jest.spyOn(console, "log").mockImplementation(() => {}); await mail.processMails(); expect(logSpy).toHaveBeenCalledTimes(3); // verify no more errors logSpy.mockRestore(); expect(commentBody).not.toMatch(/outdated/); - { // allow name reuse - const data = await notes.get(replyMessageId); - expect(data).toBeDefined(); - expect(data?.pullRequestURL).toEqual(mailMeta.pullRequestURL); + { // allow name reuse + const data = await notes.get(replyMessageId); + expect(data).toBeDefined(); + expect(data?.pullRequestURL).toEqual(mailMeta.pullRequestURL); } // check reply to reply tracking @@ -417,13 +417,13 @@ This Pull Request contains some ipsum lorem. test("test reply to outdated patch letter (throws error)", async () => { const repo = await testCreateRepo(sourceFileName, "-patcho"); - await repo.commit("1", "1", ""); // need at least one commit to back up to + await repo.commit("1", "1", ""); // need at least one commit to back up to const mailMeta: IMailMetadata = { messageID: "ppull.12345.v1.git.gitgitgadget@example.com", originalCommit: "feeddeadbeef", pullRequestURL: `https://github.com/${config.repo.owner}/${config.repo.name}/pull/1`, - firstPatchLine: 5 + firstPatchLine: 5, }; const replyMessageId = `i${mailMeta.messageID}`; @@ -447,7 +447,7 @@ This Pull Request contains some ipsum lorem. const notes = new GitNotes(repo.workDir); await notes.set(mailMeta.messageID, mailMeta, true); - const mail = new MailArchiveGitHelperProxy(notes, repo.workDir, github, { latestRevision: "HEAD~"}, "master"); + const mail = new MailArchiveGitHelperProxy(notes, repo.workDir, github, { latestRevision: "HEAD~" }, "master"); const commitsResponse = getCommitsResponse; const fail = true; @@ -481,7 +481,7 @@ This Pull Request contains some ipsum lorem. return issueCommentResponse; // dummy }); - const logSpy = jest.spyOn(console, "log").mockImplementation(() => {return;}); + const logSpy = jest.spyOn(console, "log").mockImplementation(() => {}); await mail.processMails(); expect(logSpy).toHaveBeenCalledTimes(2); // verify no more errors logSpy.mockRestore(); @@ -494,13 +494,13 @@ This Pull Request contains some ipsum lorem. test("test reply to not outdated patch letter (throws error)", async () => { const repo = await testCreateRepo(sourceFileName, "-patchn"); - await repo.commit("1", "1", ""); // need at least one commit to back up to + await repo.commit("1", "1", ""); // need at least one commit to back up to const mailMeta: IMailMetadata = { messageID: "ppull.12345.v1.git.gitgitgadget@example.com", originalCommit: "feeddeadbeef", pullRequestURL: `https://github.com/${config.repo.owner}/${config.repo.name}/pull/1`, - firstPatchLine: 5 + firstPatchLine: 5, }; const replyMessageId = `i${mailMeta.messageID}`; @@ -524,7 +524,7 @@ This Pull Request contains some ipsum lorem. const notes = new GitNotes(repo.workDir); await notes.set(mailMeta.messageID, mailMeta, true); - const mail = new MailArchiveGitHelperProxy(notes, repo.workDir, github, { latestRevision: "HEAD~"}, "master"); + const mail = new MailArchiveGitHelperProxy(notes, repo.workDir, github, { latestRevision: "HEAD~" }, "master"); const commitsResponse = getCommitsResponse; commitsResponse.data[0].sha = mailMeta.originalCommit; @@ -559,7 +559,7 @@ This Pull Request contains some ipsum lorem. return issueCommentResponse; // dummy }); - const logSpy = jest.spyOn(console, "log").mockImplementation(() => {return;}); + const logSpy = jest.spyOn(console, "log").mockImplementation(() => {}); await mail.processMails(); expect(logSpy).toHaveBeenCalledTimes(2); // verify no more errors logSpy.mockRestore(); diff --git a/tests/markdown-renderer.test.ts b/tests/markdown-renderer.test.ts index 98cb893b89..dde663d9b7 100644 --- a/tests/markdown-renderer.test.ts +++ b/tests/markdown-renderer.test.ts @@ -1,4 +1,4 @@ -/* eslint-disable max-len */ +/* eslint-disable @stylistic/max-len */ import { expect, test } from "@jest/globals"; import { md2text } from "../lib/markdown-renderer.js"; @@ -8,8 +8,7 @@ A paragraph with [links](https://gitgitgadget.github.io/), with * a * list * of -* items that might span more than seventy-six characters in a single item ${ - ""}and therefore needs to be wrapped. +* items that might span more than seventy-six characters in a single item and therefore needs to be wrapped. > Starting a block quote. > @@ -37,21 +36,21 @@ A paragraph with links [https://gitgitgadget.github.io/], with }); test("Markdown rendering blockquote test", () => { -const bq1 = `No wrap on 75 chars + const bq1 = `No wrap on 75 chars > 3 5 7 9 1 3 5 7 9 1 3 5 7 9 1 3 5 7 9 1 3 5 7 9 1 3 5 7 9 1 3 5 7 9 1 3 5`; expect(md2text(bq1)).toEqual(`No wrap on 75 chars > 3 5 7 9 1 3 5 7 9 1 3 5 7 9 1 3 5 7 9 1 3 5 7 9 1 3 5 7 9 1 3 5 7 9 1 3 5`); -const bq2 = `Exactly 76 chars should be allowed: + const bq2 = `Exactly 76 chars should be allowed: > 3 5 7 9 1 3 5 7 9 1 3 5 7 9 1 3 5 7 9 1 3 5 7 9 1 3 5 7 9 1 3 5 7 90 2 4 6`; expect(md2text(bq2)).toEqual(`Exactly 76 chars should be allowed: > 3 5 7 9 1 3 5 7 9 1 3 5 7 9 1 3 5 7 9 1 3 5 7 9 1 3 5 7 9 1 3 5 7 90 2 4 6`); -const bq3 = `Wrap on 77 chars: + const bq3 = `Wrap on 77 chars: > 3 5 7 9 1 3 5 7 9 1 3 5 7 9 1 3 5 7 9 1 3 5 7 9 1 3 5 7 9 1 3 5 7 9 1 3 5 7`; expect(md2text(bq3)).toEqual(`Wrap on 77 chars: @@ -59,7 +58,7 @@ const bq3 = `Wrap on 77 chars: > 3 5 7 9 1 3 5 7 9 1 3 5 7 9 1 3 5 7 9 1 3 5 7 9 1 3 5 7 9 1 3 5 7 9 1 3 5 > 7`); -const bq4 = `Third level quote wrap on 77 chars: + const bq4 = `Third level quote wrap on 77 chars: > 3 5 7 9 1 3 5 7 9 1 3 5 7 9 1 3 5 7 9 1 3 5 7 9 1 3 5 7 9 1 3 5 7 9 1 3 5 >>> 5 7 9 1 3 5 7 9 1 3 5 7 9 1 3 5 7 9 1 3 5 7 9 1 3 5 7 9 1 3 5 7 9 1 3 5 7`; @@ -70,7 +69,7 @@ const bq4 = `Third level quote wrap on 77 chars: >>> 5 7 9 1 3 5 7 9 1 3 5 7 9 1 3 5 7 9 1 3 5 7 9 1 3 5 7 9 1 3 5 7 9 1 3 5 >>> 7`); -const bq5 = `76 - 20 = 56 levels: + const bq5 = `76 - 20 = 56 levels: > 3 5 7 9 1 3 5 7 9 1 3 5 7 9 1 3 5 7 9 1 3 5 7 9 1 3 5 7 9 1 3 5 7 9 1 3 5 >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>> 89 1 3 5 7 9 1 3 5 7 9 1 3 5 7 9 1 3 5 7 9 1 3 5 7 9 1 3 5 7 9 1 3 5 7`; @@ -83,7 +82,7 @@ const bq5 = `76 - 20 = 56 levels: >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>> 9 1 3 5 7 9 1 3 5 7 >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>> 9 1 3 5 7`); -const bq6 = `Over 56 levels still has 20 char: + const bq6 = `Over 56 levels still has 20 char: > 3 5 7 9 1 3 5 7 9 1 3 5 7 9 1 3 5 7 9 1 3 5 7 9 1 3 5 7 9 1 3 5 7 9 1 3 5 >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>> 3 5 7 9 1 3 5 7 9 1 3 5 7 9 1 3 5 7 9 1 3 5 7 9 1 3 5 7 9 1 3 5 7`; @@ -96,7 +95,7 @@ const bq6 = `Over 56 levels still has 20 char: >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>> 3 5 7 9 1 3 5 7 9 1 >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>> 3 5 7`); -const bq7 = `Over 56 levels still has 20 char (exact): + const bq7 = `Over 56 levels still has 20 char (exact): > 3 5 7 9 1 3 5 7 9 1 3 5 7 9 1 3 5 7 9 1 3 5 7 9 1 3 5 7 9 1 3 5 7 9 1 3 5 >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>> 3 5 7 9 1 3 56 8 0 23 5 7 9 1 3 5 7 9 1 3 5 7 9 1 3 5 7 9 1 3 5 7`; @@ -118,4 +117,4 @@ test("task lists are rendered correctly", () => { * [x] done item * [ ] item still to do`); -}); \ No newline at end of file +}); diff --git a/tests/misc-helper.test.ts b/tests/misc-helper.test.ts index d2613c0cf7..b19b123db8 100644 --- a/tests/misc-helper.test.ts +++ b/tests/misc-helper.test.ts @@ -1,5 +1,5 @@ import { expect, jest, test } from "@jest/globals"; -import { fileURLToPath } from 'url'; +import { fileURLToPath } from "url"; import { git } from "../lib/git.js"; import { getConfig } from "../lib/gitgitgadget-config.js"; import { testCreateRepo, TestRepo } from "./test-lib.js"; @@ -33,20 +33,20 @@ async function setupRepos(instance: string): Promise<{ worktree: TestRepo; gggLo // re-route the URLs const url = `https://github.com/${config.repo.owner}/${config.repo.name}`; - await worktree.git([ "config", `url.${gggRemote.workDir}.insteadOf`, url ]); - await gggLocal.git([ "config", `url.${gggRemote.workDir}.insteadOf`, url ]); + await worktree.git(["config", `url.${gggRemote.workDir}.insteadOf`, url]); + await gggLocal.git(["config", `url.${gggRemote.workDir}.insteadOf`, url]); // set needed config await worktree.git(["config", "--add", "gitgitgadget.workDir", gggLocal.workDir]); // misc-helper and gitgitgadget use this and ci-helper relies on insteadOf above await worktree.git(["config", "--add", "gitgitgadget.publishRemote", gggRemote.workDir]); - await worktree.git([ "config", "user.name", "Test User" ]); - await gggLocal.git([ "config", "user.name", "Test User" ]); - await gggRemote.git([ "config", "user.name", "Test User" ]); - await worktree.git([ "config", "user.email", "user@example.com" ]); - await gggLocal.git([ "config", "user.email", "user@example.com" ]); - await gggRemote.git([ "config", "user.email", "user@example.com" ]); + await worktree.git(["config", "user.name", "Test User"]); + await gggLocal.git(["config", "user.name", "Test User"]); + await gggRemote.git(["config", "user.name", "Test User"]); + await worktree.git(["config", "user.email", "user@example.com"]); + await gggLocal.git(["config", "user.email", "user@example.com"]); + await gggRemote.git(["config", "user.email", "user@example.com"]); // Initial empty commit const commitA = await gggRemote.commit("A"); @@ -82,14 +82,14 @@ test("init options and init/update tip", async () => { const { worktree, gggLocal, gggRemote } = await setupRepos("mha1"); const miscHelper = async (...args: string[]): Promise => { - const { stdout } = await execChild("node", [ "build/script/misc-helper.js", "-s", - "-g", gggLocal.workDir, "-G", worktree.workDir, ...args ], {env: helperEnv}); + const cmd = ["build/script/misc-helper.js", "-s", "-g", gggLocal.workDir, "-G", worktree.workDir, ...args]; + const { stdout } = await execChild("node", cmd, { env: helperEnv }); return stdout; }; { const user = "beno"; - const options = await miscHelper( "init-gitgitgadget-options", user); + const options = await miscHelper("init-gitgitgadget-options", user); expect(options).toMatch(user); const remoteOptions = await getNote(/ (.*)$/, gggRemote.workDir); @@ -98,7 +98,7 @@ test("init options and init/update tip", async () => { { const tipCommit = "feeddeadbeef"; - const tip = await miscHelper( "init-email-commit-tip", tipCommit); + const tip = await miscHelper("init-email-commit-tip", tipCommit); expect(tip).toMatch(tipCommit); const remotetip = await getNote(/ (.*)\n/, gggRemote.workDir); @@ -107,7 +107,7 @@ test("init options and init/update tip", async () => { { const tipCommit = "feeddeadfade"; - const tip = await miscHelper( "init-email-commit-tip", tipCommit); + const tip = await miscHelper("init-email-commit-tip", tipCommit); expect(tip).toMatch(tipCommit); const remotetip = await getNote(/ (.*)\n/, gggRemote.workDir); @@ -119,14 +119,14 @@ test("init email commit tip and init options", async () => { const { worktree, gggLocal, gggRemote } = await setupRepos("mha2"); const miscHelper = async (...args: string[]): Promise => { - const { stdout } = await execChild("node", [ "build/script/misc-helper.js", "-s", - "-g", gggLocal.workDir, "-G", worktree.workDir, ...args ]); + const cmd = ["build/script/misc-helper.js", "-s", "-g", gggLocal.workDir, "-G", worktree.workDir, ...args]; + const { stdout } = await execChild("node", cmd, { env: helperEnv }); return stdout; }; { const tipCommit = "feeddeadbeef"; - const tip = await miscHelper( "init-email-commit-tip", tipCommit); + const tip = await miscHelper("init-email-commit-tip", tipCommit); expect(tip).toMatch(tipCommit); const remotetip = await getNote(/ (.*)$/, gggRemote.workDir); @@ -135,7 +135,7 @@ test("init email commit tip and init options", async () => { { const user = "beno"; - const options = await miscHelper( "init-gitgitgadget-options", user); + const options = await miscHelper("init-gitgitgadget-options", user); expect(options).toMatch(user); const remoteOptions = await getNote(/ (.*)$/, gggRemote.workDir); diff --git a/tests/patch-series.test.ts b/tests/patch-series.test.ts index d7df4fa0e2..9723e46f48 100644 --- a/tests/patch-series.test.ts +++ b/tests/patch-series.test.ts @@ -1,6 +1,5 @@ -/* eslint-disable max-classes-per-file */ import { expect, jest, test } from "@jest/globals"; -import { fileURLToPath } from 'url'; +import { fileURLToPath } from "url"; import { getConfig } from "../lib/gitgitgadget-config.js"; import { git } from "../lib/git.js"; import { GitNotes } from "../lib/git-notes.js"; @@ -13,8 +12,7 @@ const sourceFileName = fileURLToPath(import.meta.url); getConfig(); -const mbox1 = - `From 38d1082511bb02a709f203481c2787adc6e67c02 Mon Sep 17 00:00:00 2001 +const mbox1 = `From 38d1082511bb02a709f203481c2787adc6e67c02 Mon Sep 17 00:00:00 2001 Message-Id: From: A U Thor @@ -35,7 +33,7 @@ A U Thor (1): README.md | 5 +++++ 1 file changed, 5 insertions(+) ---${ /* we really want that space: */ " "} +--${/* we really want that space: */ " "} 2.17.0.windows.1 From 34042ac7b177e6e5ae2d12f7a39ca3ab5993d817 Mon Sep 17 00:00:00 2001 @@ -64,8 +62,7 @@ index fa400f1..daf4bc3 100755 --- 2.17.0.windows.1 `; -const tagMessage1 = - `This is the subject of the cover letter that wraps around +const tagMessage1 = `This is the subject of the cover letter that wraps around This is the actual body of the cover letter. @@ -86,10 +83,8 @@ class PatchSeriesTest extends PatchSeries { test("mails are split correctly", () => { expect(mails).toHaveLength(2); - expect(mails[0]).toMatch( - /^From [^]*\n-- \n2\.17\.0\.windows\.1\n$/); - expect(mails[1]).toMatch( - /^From [^]*\n---\n2\.17\.0\.windows\.1\n$/); + expect(mails[0]).toMatch(/^From [^]*\n-- \n2\.17\.0\.windows\.1\n$/); + expect(mails[1]).toMatch(/^From [^]*\n---\n2\.17\.0\.windows\.1\n$/); }); const thisAuthor = "GitGitGadget "; @@ -103,18 +98,16 @@ class PatchSeriesTest extends PatchSeries { }; class ProjectOptionsTest extends ProjectOptions { public constructor() { - super("", "","","","",[],"",""); + super("", "", "", "", "", [], "", ""); } } - const x = new PatchSeriesTest(new GitNotes(), {}, - new ProjectOptionsTest(), prMeta, undefined, 1); + const x = new PatchSeriesTest(new GitNotes(), {}, new ProjectOptionsTest(), prMeta, undefined, 1); x.insertCcAndFromLines(mails, thisAuthor, senderName); test("non-ASCII characters are encoded correctly", () => { - const needle = "\"=?UTF-8?Q?Nguy=E1=BB=85n_Th=C3=A1i_Ng=E1=BB=8Dc?=" - +" Duy via GitGitGadget\" "; + const needle = "\"=?UTF-8?Q?Nguy=E1=BB=85n_Th=C3=A1i_Ng=E1=BB=8Dc?= Duy via GitGitGadget\" "; expect(mails[0]).toEqual(expect.stringContaining(needle)); }); @@ -128,12 +121,10 @@ class PatchSeriesTest extends PatchSeries { [ "\"harry \\\"s\\\" truman\" ", "harry =?UTF-8?Q?=22s=22?= truman " ], "mr. name ": "\"mr. name\" ", - "ms. \\backslash ": - "\"ms. \\\\backslash\" ", + "ms. \\backslash ": "\"ms. \\\\backslash\" ", "my name ": false, "name ": false, - "wile e. coyote ": - "\"wile e. coyote\" ", + "wile e. coyote ": "\"wile e. coyote\" ", }; for (const sender of Object.keys(pairs)) { const expected = pairs[sender] || sender; @@ -148,8 +139,7 @@ class PatchSeriesTest extends PatchSeries { test("Cc: is inserted correctly", () => { expect(mails[1]).toMatch(new RegExp("From: \"Some One Else via " - + "GitGitGadget\"[^]*\\nCc: Some One Else[^]*\\n\\n" - + "From: Some One Else.*\\n\\n")); + + "GitGitGadget\"[^]*\\nCc: Some One Else[^]*\\n\\nFrom: Some One Else.*\\n\\n")); }); const coverLetter = PatchSeries.adjustCoverLetter(mails[0]); @@ -161,16 +151,13 @@ class PatchSeriesTest extends PatchSeries { "cover.2.git.author@example.com", "cover.1.git.author@example.com", ]; - const tagMessage = - PatchSeries.generateTagMessage(coverLetter, true, - "https://mid.lookup/", mids); + const tagMessage = PatchSeries.generateTagMessage(coverLetter, true, "https://mid.lookup/", mids); test("Tag message is generated correctly", () => { expect(tagMessage).toBe(tagMessage1); }); const repoUrl = "https://github.com/author/git"; - const withLinks = PatchSeries.insertLinks(tagMessage, repoUrl, - "my-series-v1", "next"); + const withLinks = PatchSeries.insertLinks(tagMessage, repoUrl, "my-series-v1", "next"); test("Links are inserted correctly", () => { const footer = ` Based-On: next at ${repoUrl} @@ -183,19 +170,15 @@ Fetch-It-Via: git fetch ${repoUrl} my-series-v1 const footers = [ "HEADER", - ].concat([ - "This", "is", "a", "fake", "cover letter", - ].map((element: string): string => ` ${element}`)); - - const coverLetterWithRangeDiff = - PatchSeries.insertFooters(coverLetter, true, footers); - const mailWithRangeDiff = - PatchSeries.insertFooters(mails[1], false, footers); + ].concat(["This", "is", "a", "fake", "cover letter",].map((element: string): string => ` ${element}`)); + + const coverLetterWithRangeDiff = PatchSeries.insertFooters(coverLetter, true, footers); + const mailWithRangeDiff = PatchSeries.insertFooters(mails[1], false, footers); test("range-diff is inserted correctly", () => { - expect(coverLetterWithRangeDiff).toMatch( - /\n\nHEADER\n This\n is\n a\n fake\n cover letter\n-- \n2\.17/); - expect(mailWithRangeDiff).toMatch(new RegExp("\\n---\\n\\nHEADER\\n" - + " This\\n is\\n a\\n fake\\n cover letter\\n\\n README")); + expect(coverLetterWithRangeDiff).toMatch(/\n\nHEADER\n This\n is\n a\n fake\n cover letter\n-- \n2\.17/); + expect(mailWithRangeDiff).toMatch( + new RegExp("\\n---\\n\\nHEADER\\n This\\n is\\n a\\n fake\\n cover letter\\n\\n README") + ); }); test("adjust mbox to forced date", () => { @@ -242,8 +225,7 @@ Fetch-It-Via: git fetch ${repoUrl} my-series-v1 ].join("\n"); test("different MIME-Version headers write to log", () => { const mails1 = [mimeBox2]; - const logSpy = jest.spyOn(console, "log") - .mockImplementation(() => {return;}); + const logSpy = jest.spyOn(console, "log").mockImplementation(() => {}); PatchSeries.cleanUpHeaders(mails1); @@ -283,8 +265,7 @@ Fetch-It-Via: git fetch ${repoUrl} my-series-v1 ].join("\n"); test("different Content-Type headers write to log", () => { const mails1 = [contentTypeBox2]; - const logSpy = jest.spyOn(console, "log") - .mockImplementation(() => {return;}); + const logSpy = jest.spyOn(console, "log").mockImplementation(() => {}); PatchSeries.cleanUpHeaders(mails1); @@ -321,12 +302,10 @@ Fetch-It-Via: git fetch ${repoUrl} my-series-v1 "", "Hi!", ].join("\n"); - test("duplicate Content-Transfer-Encoding headers are eliminated", - () => { + test("duplicate Content-Transfer-Encoding headers are eliminated", () => { const mails1 = [contentTransferEncodingBox1]; PatchSeries.cleanUpHeaders(mails1); - expect(mails1[0]).not.toMatch(new RegExp("Content-Transfer-Encoding" - + "[^]*Content-Transfer-Encoding")); + expect(mails1[0]).not.toMatch(new RegExp("Content-Transfer-Encoding[^]*Content-Transfer-Encoding")); }); const contentTransferEncodingBox2 = [ @@ -341,8 +320,7 @@ Fetch-It-Via: git fetch ${repoUrl} my-series-v1 ].join("\n"); test("different Content-Transfer-Encoding headers write to log", () => { const mails1 = [contentTransferEncodingBox2]; - const logSpy = jest.spyOn(console, "log") - .mockImplementation(() => {return;}); + const logSpy = jest.spyOn(console, "log").mockImplementation(() => {}); PatchSeries.cleanUpHeaders(mails1); @@ -365,8 +343,7 @@ Fetch-It-Via: git fetch ${repoUrl} my-series-v1 test("duplicate Content-Description headers throw error", () => { const mails1 = [contentDescriptionBox1]; PatchSeries.cleanUpHeaders(mails1); - expect(mails1[0]).not.toMatch(new RegExp("Content-Description" - + "[^]*Content-Description")); + expect(mails1[0]).not.toMatch(new RegExp("Content-Description[^]*Content-Description")); }); const contentDescriptionBox2 = [ @@ -382,8 +359,7 @@ Fetch-It-Via: git fetch ${repoUrl} my-series-v1 ].join("\n"); test("different Content-Description headers write to log", () => { const mails1 = [contentDescriptionBox2]; - const logSpy = jest.spyOn(console, "log") - .mockImplementation(() => {return;}); + const logSpy = jest.spyOn(console, "log").mockImplementation(() => {}); PatchSeries.cleanUpHeaders(mails1); @@ -422,8 +398,7 @@ Fetch-It-Via: git fetch ${repoUrl} my-series-v1 ].join("\n"); test("different Content-ID headers write to log", () => { const mails1 = [contentIDBox2]; - const logSpy = jest.spyOn(console, "log") - .mockImplementation(() => {return;}); + const logSpy = jest.spyOn(console, "log").mockImplementation(() => {}); PatchSeries.cleanUpHeaders(mails1); @@ -451,8 +426,7 @@ Fetch-It-Via: git fetch ${repoUrl} my-series-v1 "", `based-on: ${basedOn}`, "Cc: Some Contributor ", - "CC: Capital Letters , Hello " - + ", without@any.explicit.name" + "CC: Capital Letters , Hello , without@any.explicit.name" + "; Semi Cologne ", "Cc:No Space ", "Cc: Several Space ", @@ -462,9 +436,7 @@ Fetch-It-Via: git fetch ${repoUrl} my-series-v1 "Please read our guide to continue", ].join("\r\n"); - let parsed = await PatchSeries.parsePullRequest(repo.workDir, - prTitle, - prBody, 76, ""); + let parsed = await PatchSeries.parsePullRequest(repo.workDir, prTitle, prBody, 76, ""); expect(parsed.cc).toEqual([ "Some Contributor ", @@ -478,11 +450,7 @@ Fetch-It-Via: git fetch ${repoUrl} my-series-v1 "Git Maintainer ", ]); - const expectedCover = [ - prTitle, - "", - "some description goes here", - ].join("\n"); + const expectedCover = [prTitle, "", "some description goes here"].join("\n"); expect(parsed.coverLetter).toEqual(expectedCover); expect(parsed.basedOn).toEqual(basedOn); @@ -494,9 +462,7 @@ Fetch-It-Via: git fetch ${repoUrl} my-series-v1 `based-on: ${basedOn}`, ].join("\r\n"); - parsed = await PatchSeries.parsePullRequest(repo.workDir, - prTitle, - prBody, 76, ""); + parsed = await PatchSeries.parsePullRequest(repo.workDir, prTitle, prBody, 76, ""); expect(parsed.cc).toEqual([ "Some Contributor ", @@ -504,9 +470,7 @@ Fetch-It-Via: git fetch ${repoUrl} my-series-v1 "Hello ", ]); - const expectedCover1 = [ - prTitle, - ].join("\n"); + const expectedCover1 = [prTitle].join("\n"); expect(parsed.coverLetter).toEqual(expectedCover1); expect(parsed.basedOn).toEqual(basedOn); @@ -514,9 +478,7 @@ Fetch-It-Via: git fetch ${repoUrl} my-series-v1 // Empty body test prBody = ""; - parsed = await PatchSeries.parsePullRequest(repo.workDir, - prTitle, - prBody, 76, ""); + parsed = await PatchSeries.parsePullRequest(repo.workDir, prTitle, prBody, 76, ""); expect(parsed.cc).toEqual([]); diff --git a/tests/project-options.test.ts b/tests/project-options.test.ts index d8ac53742d..550a19b328 100644 --- a/tests/project-options.test.ts +++ b/tests/project-options.test.ts @@ -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 { GitNotes } from "../lib/git-notes.js"; import { getConfig } from "../lib/gitgitgadget-config.js"; @@ -19,16 +19,14 @@ test("project options", async () => { const initialCommit = "e073a465d0c7bf27664959bc93a9f018ac6f6f00"; expect(await repo.commit("initial")).toEqual(initialCommit); - expect(await repo.git(["rev-parse", "--symbolic-full-name", "HEAD"])) - .toEqual("refs/heads/master"); + expect(await repo.git(["rev-parse", "--symbolic-full-name", "HEAD"])).toEqual("refs/heads/master"); expect(await repo.newBranch("test-project-options")).toEqual(""); expect(await repo.commit("A")).not.toEqual(""); expect(await repo.commit("B")).not.toEqual(""); expect(await repo.commit("C")).not.toEqual(""); const options2 = - await ProjectOptions.get(repo.workDir, "test-project-options", - ["Nguyễn Thái Ngọc Duy "], + await ProjectOptions.get(repo.workDir, "test-project-options", ["Nguyễn Thái Ngọc Duy "], undefined, undefined, "test-project-options^"); expect(options2.workDir).not.toBeUndefined(); expect(options2.midUrlPrefix).toEqual("https://dummy.com/?mid="); @@ -42,11 +40,9 @@ test("project options", async () => { headLabel: options2.branchName, iteration: 1, }; - const x = new X(new GitNotes(repo.workDir), {}, - options2, prMeta, undefined, 1); + const x = new X(new GitNotes(repo.workDir), {}, options2, prMeta, undefined, 1); const mbox = await x.generateMBox(); - const needle = - "=?UTF-8?Q?Nguy=E1=BB=85n_Th=C3=A1i_Ng=E1=BB=8Dc?= Duy"; + const needle = "=?UTF-8?Q?Nguy=E1=BB=85n_Th=C3=A1i_Ng=E1=BB=8Dc?= Duy"; expect(mbox).toEqual(expect.stringContaining(needle)); } }).test(); diff --git a/tests/send-mail.test.ts b/tests/send-mail.test.ts index 122d35a24a..d39b25116e 100644 --- a/tests/send-mail.test.ts +++ b/tests/send-mail.test.ts @@ -2,8 +2,7 @@ import { expect, test } from "@jest/globals"; import { MailArchiveGitHelper } from "../lib/mail-archive-helper.js"; import { parseMBox, parseMBoxMessageIDAndReferences } from "../lib/send-mail.js"; -const mbox0 = - `From 566155e00ab72541ff0ac21eab84d087b0e882a5 Mon Sep 17 00:00:00 2001 +const mbox0 = `From 566155e00ab72541ff0ac21eab84d087b0e882a5 Mon Sep 17 00:00:00 2001 Message-Id: From: =?utf-8?B?w4Z2YXIgQXJuZmrDtnLDsA==?= Bjarmason Date: Fri Sep 21 12:34:56 2001 @@ -54,7 +53,8 @@ test("parse mbox", async () => { expect(parsed.from).toEqual("Ævar Arnfjörð Bjarmason "); expect(parsed.cc).toEqual([ "Some Body ", - "And Somebody Else ", "And Nobody Else ", + "And Somebody Else ", + "And Nobody Else ", ]); expect(parsed.subject).toEqual("[PATCH 0/3] My first Pull Request!"); expect(parsed.headers).toEqual([ @@ -68,8 +68,7 @@ test("parse mbox", async () => { }); test("test quoted printable", async () => { - const mbox = - `From 566155e00ab72541ff0ac21eab84d087b0e882a5 Mon Sep 17 00:00:00 2001 + const mbox = `From 566155e00ab72541ff0ac21eab84d087b0e882a5 Mon Sep 17 00:00:00 2001 Message-Id: From: =?utf-8?B?w4Z2YXIgQXJuZmrDtnLDsA==?= Bjarmason Date: Fri Sep 21 12:34:56 2001 @@ -98,8 +97,7 @@ four byte /=[Ff][0-7]/=f0=90=8d=88 }); test("test quoted printable ascii", async () => { - const mbox = - `From 566155e00ab72541ff0ac21eab84d087b0e882a5 Mon Sep 17 00:00:00 2001 + const mbox = `From 566155e00ab72541ff0ac21eab84d087b0e882a5 Mon Sep 17 00:00:00 2001 Message-Id: From: =?utf-8?B?w4Z2YXIgQXJuZmrDtnLDsA==?= Bjarmason Date: Fri Sep 21 12:34:56 2001 @@ -125,8 +123,7 @@ have included in git.git. test("test base64", async () => { const mailBody = "Base 64 Data"; - const mbox = - `From 566155e00ab72541ff0ac21eab84d087b0e882a5 Mon Sep 17 00:00:00 2001 + const mbox = `From 566155e00ab72541ff0ac21eab84d087b0e882a5 Mon Sep 17 00:00:00 2001 Message-Id: From: =?utf-8?B?w4Z2YXIgQXJuZmrDtnLDsA==?= Bjarmason Date: Fri Sep 21 12:34:56 2001 @@ -147,8 +144,7 @@ ${Buffer.from(mailBody).toString("base64")}`; }); test("test empty body", async () => { - const mbox = - `From 566155e00ab72541ff0ac21eab84d087b0e882a5 Mon Sep 17 00:00:00 2001 + const mbox = `From 566155e00ab72541ff0ac21eab84d087b0e882a5 Mon Sep 17 00:00:00 2001 Message-Id: From: =?utf-8?B?w4Z2YXIgQXJuZmrDtnLDsA==?= Bjarmason Date: Fri Sep 21 12:34:56 2001 @@ -169,8 +165,7 @@ Cc: Some Body , }); test("In-Reply-To/References is parsed correctly", async () => { - const mbox = -`From junio Mon Sep 17 00:00:00 2001 + const mbox = `From junio Mon Sep 17 00:00:00 2001 From: Junio C Hamano To: Tao Klerks Cc: Tao Klerks via GitGitGadget , diff --git a/tests/sous-chef.test.ts b/tests/sous-chef.test.ts index f8f66db7b4..5e9ca1080f 100644 --- a/tests/sous-chef.test.ts +++ b/tests/sous-chef.test.ts @@ -1,7 +1,7 @@ import { expect, test } from "@jest/globals"; import * as fs from "fs"; import path from "path"; -import { fileURLToPath } from 'url'; +import { fileURLToPath } from "url"; import { SousChef } from "../lib/sous-chef.js"; const dirName = path.dirname(fileURLToPath(import.meta.url)); @@ -10,16 +10,13 @@ const mboxFixturePath = `${dirName}/fixtures/whats-cooking-2021-02-10.mbox`; test("Parse What's Cooking mail", async () => { const mbox = await fs.promises.readFile(mboxFixturePath); const sousChef = new SousChef(mbox.toString()); - expect(sousChef.messageID) - .toEqual("xmqqim6zz8x6.fsf@gitster.c.googlers.com"); + expect(sousChef.messageID).toEqual("xmqqim6zz8x6.fsf@gitster.c.googlers.com"); const branchInfo = sousChef.branches.get("js/rebase-i-commit-cleanup-fix"); expect(branchInfo).not.toBeUndefined(); - expect(branchInfo?.merged) - .toEqual("(merged to 'next' on 2021-01-31 at 358f562e1f)"); + expect(branchInfo?.merged).toEqual("(merged to 'next' on 2021-01-31 at 358f562e1f)"); expect(branchInfo?.sectionName).toEqual("Graduated to 'master'"); - const text = - `When "git rebase -i" processes "fixup" insn, there is no reason to + const text = `When "git rebase -i" processes "fixup" insn, there is no reason to clean up the commit log message, but we did the usual stripspace processing. This has been corrected.`; expect(branchInfo?.text).toEqual(text); -}); \ No newline at end of file +}); diff --git a/tests/test-lib.ts b/tests/test-lib.ts index fd0c5e7353..499e447037 100644 --- a/tests/test-lib.ts +++ b/tests/test-lib.ts @@ -1,6 +1,6 @@ import * as fs from "fs"; import * as path from "path"; -import { fileURLToPath } from 'url'; +import { fileURLToPath } from "url"; import * as util from "util"; import { isDirectory, isFile } from "../lib/fs-util.js"; import { git, IGitOptions, revParse } from "../lib/git.js"; @@ -14,7 +14,7 @@ const writeFile = util.promisify(fs.writeFile); const unlink = util.promisify(fs.unlink); export async function removeRecursively(directory: string): Promise { - if (!await isDirectory(directory)) { + if (!(await isDirectory(directory))) { await unlink(directory); } else { const items = await readdir(directory); @@ -41,9 +41,7 @@ export class TestRepo { this.options = options; } - public async commit(message: string, - fileName?: string, contents?: string): - Promise { + public async commit(message: string, fileName?: string, contents?: string): Promise { const [, gitOpts] = this.parseOptionsForCommit(this.options); if (!fileName) { @@ -92,11 +90,10 @@ export class TestRepo { } protected testTick(): number { - return this.testTickEpoch += 60; + return (this.testTickEpoch += 60); } - protected parseOptionsForCommit(options: ITestCommitOptions): - [number, IGitOptions] { + protected parseOptionsForCommit(options: ITestCommitOptions): [number, IGitOptions] { const tick = this.testTick(); const gitOpts = { env: { @@ -139,10 +136,9 @@ export class TestRepo { } } -export async function testCreateRepo(name: string, suffix?: string): - Promise { +export async function testCreateRepo(name: string, suffix?: string): Promise { let tmp = `${dirName}/../.test-dir/`; - if (!await isDirectory(tmp)) { + if (!(await isDirectory(tmp))) { await mkdir(tmp); } tmp = await realpath(tmp); @@ -166,7 +162,7 @@ export async function testCreateRepo(name: string, suffix?: string): await git(["init", dir]); process.env.HOME = tmp; - if (!await isFile(`${tmp}/.gitconfig`)) { + if (!(await isFile(`${tmp}/.gitconfig`))) { await git(["config", "--global", "user.name", "Test User"]); await git(["config", "--global", "user.email", "user@example.com"]); } @@ -181,9 +177,7 @@ export async function testCreateRepo(name: string, suffix?: string): }, workDir: dir, }; - await git(["commit-tree", "-m", "Test commit", - "4b825dc642cb6eb9a060e54bf8d69288fbee4904"], - opts); + await git(["commit-tree", "-m", "Test commit", "4b825dc642cb6eb9a060e54bf8d69288fbee4904"], opts); const gitOpts: ITestCommitOptions = { workDir: dir }; return new TestRepo(gitOpts);