Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
644 changes: 42 additions & 602 deletions package-lock.json

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@
"c8": "10.1.3",
"cpy": "12.1.0",
"cz-conventional-changelog": "3.3.0",
"fetch-mock": "npm:@gr2m/[email protected]",
"fetch-mock": "12.6.0",
"lockfile-lint": "4.14.1",
"ls-engines": "0.9.3",
"npm-run-all2": "8.0.4",
Expand Down
109 changes: 62 additions & 47 deletions test/add-channel.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -34,15 +34,16 @@ test("Update a release", async (t) => {
const releaseUrl = `https://github.com/${owner}/${repo}/releases/${nextRelease.version}`;
const releaseId = 1;

const fetch = fetchMock
.sandbox()
.getOnce(
const fm = fetchMock
.createInstance()
.get(
`https://api.github.local/repos/${owner}/${repo}/releases/tags/${nextRelease.gitTag}`,
{
id: releaseId,
},
{ repeat: 1 },
)
.patchOnce(
.patch(
`https://api.github.local/repos/${owner}/${repo}/releases/${releaseId}`,
{
html_url: releaseUrl,
Expand All @@ -53,6 +54,7 @@ test("Update a release", async (t) => {
name: nextRelease.name,
prerelease: false,
},
repeat: 1,
},
);

Expand All @@ -68,7 +70,7 @@ test("Update a release", async (t) => {
{
Octokit: TestOctokit.defaults((options) => ({
...options,
request: { ...options.request, fetch },
request: { ...options.request, fetch: fm.fetchHandler },
})),
},
);
Expand All @@ -78,7 +80,7 @@ test("Update a release", async (t) => {
"Updated GitHub release: %s",
releaseUrl,
]);
t.true(fetch.done());
t.true(fm.callHistory.done());
});

test("Update a maintenance release", async (t) => {
Expand All @@ -96,15 +98,16 @@ test("Update a maintenance release", async (t) => {
const releaseUrl = `https://github.com/${owner}/${repo}/releases/${nextRelease.version}`;
const releaseId = 1;

const fetch = fetchMock
.sandbox()
.getOnce(
const fm = fetchMock
.createInstance()
.get(
`https://api.github.local/repos/${owner}/${repo}/releases/tags/${nextRelease.gitTag}`,
{
id: releaseId,
},
{ repeat: 1 },
)
.patchOnce(
.patch(
`https://api.github.local/repos/${owner}/${repo}/releases/${releaseId}`,
{
html_url: releaseUrl,
Expand All @@ -115,6 +118,7 @@ test("Update a maintenance release", async (t) => {
name: nextRelease.name,
prerelease: false,
},
repeat: 1,
},
);

Expand All @@ -130,7 +134,7 @@ test("Update a maintenance release", async (t) => {
{
Octokit: TestOctokit.defaults((options) => ({
...options,
request: { ...options.request, fetch },
request: { ...options.request, fetch: fm.fetchHandler },
})),
},
);
Expand All @@ -140,7 +144,7 @@ test("Update a maintenance release", async (t) => {
"Updated GitHub release: %s",
releaseUrl,
]);
t.true(fetch.done());
t.true(fm.callHistory.done());
});

test("Update a prerelease", async (t) => {
Expand All @@ -157,15 +161,16 @@ test("Update a prerelease", async (t) => {
const releaseUrl = `https://github.com/${owner}/${repo}/releases/${nextRelease.version}`;
const releaseId = 1;

const fetch = fetchMock
.sandbox()
.getOnce(
const fm = fetchMock
.createInstance()
.get(
`https://api.github.local/repos/${owner}/${repo}/releases/tags/${nextRelease.gitTag}`,
{
id: releaseId,
},
{ repeat: 1 },
)
.patchOnce(
.patch(
`https://api.github.local/repos/${owner}/${repo}/releases/${releaseId}`,
{
html_url: releaseUrl,
Expand All @@ -176,6 +181,7 @@ test("Update a prerelease", async (t) => {
name: nextRelease.name,
prerelease: false,
},
repeat: 1,
},
);

Expand All @@ -191,7 +197,7 @@ test("Update a prerelease", async (t) => {
{
Octokit: TestOctokit.defaults((options) => ({
...options,
request: { ...options.request, fetch },
request: { ...options.request, fetch: fm.fetchHandler },
})),
},
);
Expand All @@ -201,7 +207,7 @@ test("Update a prerelease", async (t) => {
"Updated GitHub release: %s",
releaseUrl,
]);
t.true(fetch.done());
t.true(fm.callHistory.done());
});

test("Update a release with a custom github url", async (t) => {
Expand All @@ -222,15 +228,16 @@ test("Update a release with a custom github url", async (t) => {
const releaseUrl = `${env.GH_URL}/${owner}/${repo}/releases/${nextRelease.version}`;
const releaseId = 1;

const fetch = fetchMock
.sandbox()
.getOnce(
const fm = fetchMock
.createInstance()
.get(
`https://othertesturl.com:443/prefix/repos/${owner}/${repo}/releases/tags/${nextRelease.gitTag}`,
{
id: releaseId,
},
{ repeat: 1 },
)
.patchOnce(
.patch(
`https://othertesturl.com:443/prefix/repos/${owner}/${repo}/releases/${releaseId}`,
{
html_url: releaseUrl,
Expand All @@ -241,6 +248,7 @@ test("Update a release with a custom github url", async (t) => {
name: nextRelease.name,
prerelease: false,
},
repeat: 1,
},
);

Expand All @@ -256,7 +264,7 @@ test("Update a release with a custom github url", async (t) => {
{
Octokit: TestOctokit.defaults((options) => ({
...options,
request: { ...options.request, fetch },
request: { ...options.request, fetch: fm.fetchHandler },
})),
},
);
Expand All @@ -266,7 +274,7 @@ test("Update a release with a custom github url", async (t) => {
"Updated GitHub release: %s",
releaseUrl,
]);
t.true(fetch.done());
t.true(fm.callHistory.done());
});

test("Create the new release if current one is missing", async (t) => {
Expand All @@ -282,13 +290,14 @@ test("Create the new release if current one is missing", async (t) => {
const options = { repositoryUrl: `https://github.com/${owner}/${repo}.git` };
const releaseUrl = `https://github.com/${owner}/${repo}/releases/${nextRelease.version}`;

const fetch = fetchMock
.sandbox()
.getOnce(
const fm = fetchMock
.createInstance()
.get(
`https://api.github.local/repos/${owner}/${repo}/releases/tags/${nextRelease.gitTag}`,
404,
{ repeat: 1 },
)
.postOnce(
.post(
`https://api.github.local/repos/${owner}/${repo}/releases`,
{
html_url: releaseUrl,
Expand All @@ -300,6 +309,7 @@ test("Create the new release if current one is missing", async (t) => {
body: nextRelease.notes,
prerelease: false,
},
repeat: 1,
},
);

Expand All @@ -315,7 +325,7 @@ test("Create the new release if current one is missing", async (t) => {
{
Octokit: TestOctokit.defaults((options) => ({
...options,
request: { ...options.request, fetch },
request: { ...options.request, fetch: fm.fetchHandler },
})),
},
);
Expand All @@ -329,7 +339,7 @@ test("Create the new release if current one is missing", async (t) => {
"Published GitHub release: %s",
releaseUrl,
]);
t.true(fetch.done());
t.true(fm.callHistory.done());
});

test("Throw error if cannot read current release", async (t) => {
Expand All @@ -344,11 +354,12 @@ test("Throw error if cannot read current release", async (t) => {
};
const options = { repositoryUrl: `https://github.com/${owner}/${repo}.git` };

const fetch = fetchMock
.sandbox()
.getOnce(
const fm = fetchMock
.createInstance()
.get(
`https://api.github.local/repos/${owner}/${repo}/releases/tags/${nextRelease.gitTag}`,
500,
{ repeat: 1 },
);

const error = await t.throwsAsync(
Expand All @@ -364,14 +375,14 @@ test("Throw error if cannot read current release", async (t) => {
{
Octokit: TestOctokit.defaults((options) => ({
...options,
request: { ...options.request, fetch },
request: { ...options.request, fetch: fm.fetchHandler },
})),
},
),
);

t.is(error.status, 500);
t.true(fetch.done());
t.true(fm.callHistory.done());
});

test("Throw error if cannot create missing current release", async (t) => {
Expand All @@ -388,19 +399,21 @@ test("Throw error if cannot create missing current release", async (t) => {
repositoryUrl: `https://github.com/${owner}/${repo}.git`,
};

const fetch = fetchMock
.sandbox()
.getOnce(
const fm = fetchMock
.createInstance()
.get(
`https://api.github.local/repos/${owner}/${repo}/releases/tags/${nextRelease.gitTag}`,
404,
{ repeat: 1 },
)
.postOnce(`https://api.github.local/repos/${owner}/${repo}/releases`, 500, {
.post(`https://api.github.local/repos/${owner}/${repo}/releases`, 500, {
body: {
tag_name: nextRelease.gitTag,
name: nextRelease.name,
body: nextRelease.notes,
prerelease: false,
},
repeat: 1,
});

const error = await t.throwsAsync(
Expand All @@ -416,14 +429,14 @@ test("Throw error if cannot create missing current release", async (t) => {
{
Octokit: TestOctokit.defaults((options) => ({
...options,
request: { ...options.request, fetch },
request: { ...options.request, fetch: fm.fetchHandler },
})),
},
),
);

t.is(error.status, 500);
t.true(fetch.done());
t.true(fm.callHistory.done());
});

test("Throw error if cannot update release", async (t) => {
Expand All @@ -439,13 +452,14 @@ test("Throw error if cannot update release", async (t) => {
const options = { repositoryUrl: `https://github.com/${owner}/${repo}.git` };
const releaseId = 1;

const fetch = fetchMock
.sandbox()
.getOnce(
const fm = fetchMock
.createInstance()
.get(
`https://api.github.local/repos/${owner}/${repo}/releases/tags/${nextRelease.gitTag}`,
{ id: releaseId },
{ repeat: 1 },
)
.patchOnce(
.patch(
`https://api.github.local/repos/${owner}/${repo}/releases/${releaseId}`,
404,
{
Expand All @@ -454,6 +468,7 @@ test("Throw error if cannot update release", async (t) => {
name: nextRelease.name,
prerelease: false,
},
repeat: 1,
},
);

Expand All @@ -470,12 +485,12 @@ test("Throw error if cannot update release", async (t) => {
{
Octokit: TestOctokit.defaults((options) => ({
...options,
request: { ...options.request, fetch },
request: { ...options.request, fetch: fm.fetchHandler },
})),
},
),
);

t.is(error.status, 404);
t.true(fetch.done());
t.true(fm.callHistory.done());
});
Loading