Skip to content

Commit 28fc449

Browse files
committed
tests: use an explicit project config
I am about to introduce a change to make the project config non-optional. Let's prepare the tests for it, by adding an explicit config (rather than detecting a specific commit that is expected to be present when running the tests). Signed-off-by: Johannes Schindelin <[email protected]>
1 parent 98adf11 commit 28fc449

8 files changed

+29
-27
lines changed

lib/project-options.ts

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { commitExists, revParse } from "./git.js";
1+
import { revParse } from "./git.js";
22
import { IConfig, projectInfo } from "./project-config.js";
33

44
// For now, only the Git, Cygwin and BusyBox projects are supported
@@ -39,10 +39,6 @@ export class ProjectOptions {
3939
// BusyBox
4040
4141
midUrlPrefix = "https://www.mail-archive.com/[email protected]&q=";
42-
} else if (await commitExists("7ccd18012de2e6c47e5", workDir)) {
43-
// We're running in the test suite!
44-
45-
midUrlPrefix = "https://dummy.com/?mid=";
4642
} else {
4743
throw new Error("Unrecognized project");
4844
}

tests/ci-helper.test.ts

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,7 @@ import { GitNotes } from "../lib/git-notes.js";
55
import { GitHubGlue, IGitHubUser, IPRComment, IPRCommit, IPullRequestInfo } from "../lib/github-glue.js";
66
import { IMailMetadata } from "../lib/mail-metadata.js";
77
import { testSmtpServer } from "test-smtp-server";
8-
import { testCreateRepo, TestRepo } from "./test-lib.js";
9-
import defaultConfig from "../lib/gitgitgadget-config.js";
8+
import { testCreateRepo, TestRepo, testConfig } from "./test-lib.js";
109

1110
const sourceFileName = fileURLToPath(import.meta.url);
1211

@@ -32,7 +31,7 @@ function testQ(label: string, fn: AsyncFn) {
3231
});
3332
}
3433

35-
const config = defaultConfig;
34+
const config = testConfig;
3635

3736
const eMailOptions = {
3837
smtpserver: new testSmtpServer(),

tests/gitgitgadget.test.ts

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,7 @@ import { GitNotes } from "../lib/git-notes.js";
55
import { GitGitGadget, IGitGitGadgetOptions } from "../lib/gitgitgadget.js";
66
import { PatchSeries } from "../lib/patch-series.js";
77
import { IPatchSeriesMetadata } from "../lib/patch-series-metadata.js";
8-
import { testCreateRepo } from "./test-lib.js";
9-
import defaultConfig from "../lib/gitgitgadget-config.js";
8+
import { testCreateRepo, testConfig } from "./test-lib.js";
109

1110
// This test script might take quite a while to run
1211
jest.setTimeout(60000);
@@ -207,7 +206,7 @@ test("generate tag/notes from a Pull Request", async () => {
207206
await git(["config", "user.email", "[email protected]"], repo.options);
208207

209208
const patches = await PatchSeries.getFromNotes(
210-
defaultConfig,
209+
testConfig,
211210
notes,
212211
pullRequestURL,
213212
pullRequestTitle,
@@ -250,7 +249,7 @@ to have included in git.git [https://github.com/git/git].`);
250249

251250
const headCommit2 = await repo.revParse("HEAD");
252251
const patches2 = await PatchSeries.getFromNotes(
253-
defaultConfig,
252+
testConfig,
254253
notes,
255254
pullRequestURL,
256255
pullRequestTitle,
@@ -342,7 +341,7 @@ test("allow/disallow", async () => {
342341
const notes = new GitNotes(remote.workDir);
343342
await notes.set("", {} as IGitGitGadgetOptions);
344343

345-
const gitGitGadget = await GitGitGadget.get(defaultConfig, workDir);
344+
const gitGitGadget = await GitGitGadget.get(testConfig, workDir);
346345

347346
// pretend that the notes ref had been changed in the meantime
348347
await notes.set("", { allowedUsers: ["first-one"] } as IGitGitGadgetOptions, true);
@@ -370,7 +369,7 @@ test("allow/disallow with env vars", async () => {
370369
const notes = new GitNotes(remote.workDir);
371370
await notes.set("", {} as IGitGitGadgetOptions);
372371

373-
const gitGitGadget = await GitGitGadget.get(defaultConfig, workDir);
372+
const gitGitGadget = await GitGitGadget.get(testConfig, workDir);
374373

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

tests/mail-archive-helper.test.ts

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,7 @@ import { GitNotes } from "../lib/git-notes.js";
66
import { GitHubGlue } from "../lib/github-glue.js";
77
import { MailArchiveGitHelper, IGitMailingListMirrorState } from "../lib/mail-archive-helper.js";
88
import { IMailMetadata } from "../lib/mail-metadata.js";
9-
import { testCreateRepo } from "./test-lib.js";
10-
import defaultConfig from "../lib/gitgitgadget-config.js";
9+
import { testCreateRepo, testConfig } from "./test-lib.js";
1110
import { IConfig } from "../lib/project-config.js";
1211

1312
/* eslint max-classes-per-file: ["error", 2] */
@@ -97,7 +96,7 @@ interface ICommit {
9796
parents: [{ sha: string; url: string; html_url?: string }];
9897
}
9998

100-
const config = { ...defaultConfig }; // make a copy
99+
const config = { ...testConfig }; // make a copy
101100
config.repo.owner = "test";
102101
config.repo.name = "test";
103102

tests/misc-helper.test.ts

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,16 @@
11
import { expect, jest, test } from "@jest/globals";
22
import { fileURLToPath } from "url";
33
import { git } from "../lib/git.js";
4-
import { testCreateRepo, TestRepo } from "./test-lib.js";
4+
import { testCreateRepo, TestRepo, testConfig } from "./test-lib.js";
55
import { execFile } from "child_process";
66
import * as util from "util";
7-
import defaultConfig from "../lib/gitgitgadget-config.js";
87

98
const execChild = util.promisify(execFile);
109

1110
jest.setTimeout(180000);
1211
const sourceFileName = fileURLToPath(import.meta.url);
1312

14-
const config = defaultConfig;
13+
const config = testConfig;
1514

1615
// Create three repos.
1716
// worktree is a local copy for doing updates and has the config

tests/patch-series.test.ts

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,7 @@ import { git } from "../lib/git.js";
44
import { GitNotes } from "../lib/git-notes.js";
55
import { PatchSeries } from "../lib/patch-series.js";
66
import { ProjectOptions } from "../lib/project-options.js";
7-
import { testCreateRepo } from "./test-lib.js";
8-
import defaultConfig from "../lib/gitgitgadget-config.js";
7+
import { testCreateRepo, testConfig } from "./test-lib.js";
98

109
jest.setTimeout(60000);
1110
const sourceFileName = fileURLToPath(import.meta.url);
@@ -101,7 +100,7 @@ class PatchSeriesTest extends PatchSeries {
101100
}
102101

103102
const x = new PatchSeriesTest(
104-
defaultConfig,
103+
testConfig,
105104
new GitNotes(),
106105
{},
107106
new ProjectOptionsTest(),

tests/project-options.test.ts

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,7 @@ import { isDirectory } from "../lib/fs-util.js";
44
import { GitNotes } from "../lib/git-notes.js";
55
import { PatchSeries } from "../lib/patch-series.js";
66
import { ProjectOptions } from "../lib/project-options.js";
7-
import { testCreateRepo } from "./test-lib.js";
8-
import defaultConfig from "../lib/gitgitgadget-config.js";
7+
import { testCreateRepo, testConfig } from "./test-lib.js";
98

109
// This test script might take quite a while to run
1110
jest.setTimeout(20000);
@@ -24,7 +23,7 @@ test("project options", async () => {
2423
expect(await repo.commit("C")).not.toEqual("");
2524

2625
const options2 = await ProjectOptions.get(
27-
defaultConfig,
26+
testConfig,
2827
repo.workDir,
2928
"test-project-options",
3029
["Nguyễn Thái Ngọc Duy <[email protected]>"],
@@ -44,7 +43,7 @@ test("project options", async () => {
4443
headLabel: options2.branchName,
4544
iteration: 1,
4645
};
47-
const x = new X(defaultConfig, new GitNotes(repo.workDir), {}, options2, prMeta, undefined, 1);
46+
const x = new X(testConfig, new GitNotes(repo.workDir), {}, options2, prMeta, undefined, 1);
4847
const mbox = await x.generateMBox();
4948
const needle = "=?UTF-8?Q?Nguy=E1=BB=85n_Th=C3=A1i_Ng=E1=BB=8Dc?= Duy";
5049
expect(mbox).toEqual(expect.stringContaining(needle));

tests/test-lib.ts

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,20 @@ import * as path from "path";
44
import { fileURLToPath } from "url";
55
import { isDirectory, isFile } from "../lib/fs-util.js";
66
import { git, IGitOptions, revParse } from "../lib/git.js";
7+
import defaultConfig from "../lib/gitgitgadget-config.js";
78
const dirName = path.dirname(fileURLToPath(import.meta.url));
89

10+
export const testConfig = {
11+
...defaultConfig,
12+
// We're running in the test suite!
13+
project: {
14+
cc: [],
15+
...defaultConfig.project,
16+
17+
urlPrefix: "https://dummy.com/?mid=",
18+
},
19+
};
20+
921
export async function removeRecursively(directory: string): Promise<void> {
1022
if (!(await isDirectory(directory))) {
1123
await unlink(directory);

0 commit comments

Comments
 (0)