Skip to content

Commit d9087e1

Browse files
committed
test: adapt success test
1 parent 420f745 commit d9087e1

File tree

2 files changed

+18
-15
lines changed

2 files changed

+18
-15
lines changed

lib/success.js

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -153,8 +153,9 @@ export default async function success(pluginConfig, context) {
153153
if (!isEmpty(additionalReleases) && !isNil(ghRelaseId)) {
154154
const newBody =
155155
addReleases === 'top'
156-
? [...additionalReleases, '\n---\n'].concat(nextRelease.notes)
157-
: [...nextRelease.notes, '\n---\n'].concat(additionalReleases);
156+
? additionalReleases.concat('\n---\n', nextRelease.notes)
157+
: nextRelease.notes.concat('\n---\n', additionalReleases);
158+
158159
await github.repos.updateRelease({owner, repo, release_id: ghRelaseId, body: newBody});
159160
}
160161
}

test/success.test.js

Lines changed: 15 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,31 +1,32 @@
11
import {escape} from 'node:querystring';
2-
import {beforeEach, afterEach, serial} from 'ava';
2+
3+
import nock from 'nock';
34
import {repeat} from 'lodash-es';
4-
import {cleanAll} from 'nock';
5-
import {stub} from 'sinon';
6-
import proxyquire from 'proxyquire';
5+
import sinon from 'sinon';
6+
import test from 'ava';
7+
import quibble from 'quibble';
78

89
import {ISSUE_ID} from '../lib/definitions/constants.js';
910
import getReleaseLinks from '../lib/get-release-links.js';
1011
import {authenticate} from './helpers/mock-github.js';
11-
import rateLimit from './helpers/rate-limit.js';
12+
import * as RATE_LIMIT_MOCK from './helpers/rate-limit.js';
1213

1314
/* eslint camelcase: ["error", {properties: "never"}] */
1415

15-
const success = proxyquire('../lib/success', {
16-
'./get-client': proxyquire('../lib/get-client', {'./definitions/rate-limit': rateLimit}),
17-
});
16+
// mock rate limit imported via lib/get-client.js
17+
await quibble.esm('../lib/definitions/rate-limit.js', RATE_LIMIT_MOCK)
18+
const success = (await import('../lib/success.js')).default
1819

1920
test.beforeEach((t) => {
2021
// Mock logger
21-
t.context.log = stub();
22-
t.context.error = stub();
22+
t.context.log = sinon.stub();
23+
t.context.error = sinon.stub();
2324
t.context.logger = {log: t.context.log, error: t.context.error};
2425
});
2526

2627
test.afterEach.always(() => {
2728
// Clear nock
28-
cleanAll();
29+
nock.cleanAll();
2930
});
3031

3132
test.serial(
@@ -701,6 +702,7 @@ test.serial('Editing the release to include all release links at the top', async
701702
{name: 'S3', url: 's3://my-bucket/release-asset'},
702703
{name: 'Docker: docker.io/python:slim'},
703704
];
705+
704706
const github = authenticate(env)
705707
.get(`/repos/${owner}/${repo}`)
706708
.reply(200, {full_name: `${owner}/${repo}`})
@@ -721,7 +723,7 @@ test.serial('Editing the release to include all release links at the top', async
721723
)
722724
.reply(200, {items: []})
723725
.patch(`/repos/${owner}/${repo}/releases/${releaseId}`, {
724-
body: [...getReleaseLinks(releases), '\n---\n', nextRelease.notes],
726+
body: getReleaseLinks(releases) + '\n---\n' + nextRelease.notes,
725727
})
726728
.reply(200, {html_url: releaseUrl});
727729

@@ -985,7 +987,7 @@ test.serial('Ignore errors when adding comments and closing issues', async (t) =
985987
.patch(`/repos/${owner}/${repo}/issues/3`, {state: 'closed'})
986988
.reply(200, {html_url: 'https://github.com/issues/3'});
987989

988-
const [error1, error2] = await t.throwsAsync(
990+
const { errors: [error1, error2] } = await t.throwsAsync(
989991
success(pluginConfig, {
990992
env,
991993
options,

0 commit comments

Comments
 (0)