Skip to content

Commit 3044a32

Browse files
committed
test: adapt addChannel test
1 parent 6c04ddf commit 3044a32

File tree

6 files changed

+25
-42
lines changed

6 files changed

+25
-42
lines changed

index.js

Lines changed: 5 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ import failGitHub from './lib/fail.js';
1010

1111
let verified;
1212

13-
async function verifyConditions(pluginConfig, context) {
13+
export async function verifyConditions(pluginConfig, context) {
1414
const {options} = context;
1515
// If the GitHub publish plugin is used and has `assets`, `successComment`, `failComment`, `failTitle`, `labels` or `assignees` configured, validate it now in order to prevent any release if the configuration is wrong
1616
if (options.publish) {
@@ -29,7 +29,7 @@ async function verifyConditions(pluginConfig, context) {
2929
verified = true;
3030
}
3131

32-
async function publish(pluginConfig, context) {
32+
export async function publish(pluginConfig, context) {
3333
if (!verified) {
3434
await verifyGitHub(pluginConfig, context);
3535
verified = true;
@@ -38,7 +38,7 @@ async function publish(pluginConfig, context) {
3838
return publishGitHub(pluginConfig, context);
3939
}
4040

41-
async function addChannel(pluginConfig, context) {
41+
export async function addChannel(pluginConfig, context) {
4242
if (!verified) {
4343
await verifyGitHub(pluginConfig, context);
4444
verified = true;
@@ -47,7 +47,7 @@ async function addChannel(pluginConfig, context) {
4747
return addChannelGitHub(pluginConfig, context);
4848
}
4949

50-
async function success(pluginConfig, context) {
50+
export async function success(pluginConfig, context) {
5151
if (!verified) {
5252
await verifyGitHub(pluginConfig, context);
5353
verified = true;
@@ -56,7 +56,7 @@ async function success(pluginConfig, context) {
5656
await successGitHub(pluginConfig, context);
5757
}
5858

59-
async function fail(pluginConfig, context) {
59+
export async function fail(pluginConfig, context) {
6060
if (!verified) {
6161
await verifyGitHub(pluginConfig, context);
6262
verified = true;
@@ -65,6 +65,3 @@ async function fail(pluginConfig, context) {
6565
await failGitHub(pluginConfig, context);
6666
}
6767

68-
const plugin = {verifyConditions, addChannel, publish, success, fail};
69-
70-
export default plugin;

lib/definitions/constants.js

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,3 @@
1-
const ISSUE_ID = '<!-- semantic-release:github -->';
1+
export const ISSUE_ID = '<!-- semantic-release:github -->';
22

3-
const RELEASE_NAME = 'GitHub release';
4-
5-
const CONSTANTS = {ISSUE_ID, RELEASE_NAME};
6-
7-
export default CONSTANTS;
3+
export const RELEASE_NAME = 'GitHub release';

lib/definitions/rate-limit.js

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,15 @@
11
/**
22
* Default exponential backoff configuration for retries.
33
*/
4-
const RETRY_CONF = {retries: 3, factor: 2, minTimeout: 1000};
4+
export const RETRY_CONF = {retries: 3, factor: 2, minTimeout: 1000};
55

66
/**
77
* Rate limit per API endpoints.
88
*
99
* See {@link https://developer.github.com/v3/search/#rate-limit|Search API rate limit}.
1010
* See {@link https://developer.github.com/v3/#rate-limiting|Rate limiting}.
1111
*/
12-
const RATE_LIMITS = {
12+
export const RATE_LIMITS = {
1313
search: ((60 * 1000) / 30) * 1.1, // 30 calls per minutes => 1 call every 2s + 10% safety margin
1414
core: {
1515
read: ((60 * 60 * 1000) / 5000) * 1.1, // 5000 calls per hour => 1 call per 720ms + 10% safety margin
@@ -22,8 +22,4 @@ const RATE_LIMITS = {
2222
*
2323
* See {@link https://developer.github.com/v3/guides/best-practices-for-integrators/#dealing-with-abuse-rate-limits|Dealing with abuse rate limits}
2424
*/
25-
const GLOBAL_RATE_LIMIT = 1000;
26-
27-
const RATE_LIMIT = {RETRY_CONF, RATE_LIMITS, GLOBAL_RATE_LIMIT};
28-
29-
export default RATE_LIMIT;
25+
export const GLOBAL_RATE_LIMIT = 1000;

test/add-channel.test.js

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,27 +1,27 @@
11
import test from 'ava';
2-
import {cleanAll} from 'nock';
3-
import {stub} from 'sinon';
4-
import proxyquire from 'proxyquire';
2+
import nock from 'nock';
3+
import sinon from 'sinon';
4+
import quibble from "quibble"
55

66
import {authenticate} from './helpers/mock-github.js';
7-
import rateLimit from './helpers/rate-limit.js';
7+
import * as RATE_LIMIT from './helpers/rate-limit.js';
88

99
/* eslint camelcase: ["error", {properties: "never"}] */
1010

11-
const addChannel = proxyquire('../lib/add-channel', {
12-
'./get-client': proxyquire('../lib/get-client', {'./definitions/rate-limit': rateLimit}),
13-
});
11+
// mock rate limit imported via lib/get-client.js
12+
await quibble.esm('../lib/definitions/rate-limit.js', RATE_LIMIT)
13+
const addChannel = (await import('../lib/add-channel.js')).default
1414

1515
test.beforeEach((t) => {
1616
// Mock logger
17-
t.context.log = stub();
18-
t.context.error = stub();
17+
t.context.log = sinon.stub();
18+
t.context.error = sinon.stub();
1919
t.context.logger = {log: t.context.log, error: t.context.error};
2020
});
2121

2222
test.afterEach.always(() => {
2323
// Clear nock
24-
cleanAll();
24+
nock.cleanAll();
2525
});
2626

2727
test.serial('Update a release', async (t) => {

test/helpers/mock-github.js

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ import nock from 'nock';
99
* @param {String} [githubApiPathPrefix=env.GH_PREFIX || env.GITHUB_PREFIX || ''] The GitHub Enterprise API prefix.
1010
* @return {Object} A `nock` object ready to respond to a github authentication request.
1111
*/
12-
function authenticate(
12+
export function authenticate(
1313
env = {},
1414
{
1515
githubToken = env.GH_TOKEN || env.GITHUB_TOKEN || 'GH_TOKEN',
@@ -28,7 +28,7 @@ function authenticate(
2828
* @param {String} [uploadUrl] The url on which to intercept http requests.
2929
* @return {Object} A `nock` object ready to respond to a github file upload request.
3030
*/
31-
function upload(
31+
export function upload(
3232
env = {},
3333
{
3434
githubToken = env.GH_TOKEN || env.GITHUB_TOKEN || 'GH_TOKEN',
@@ -41,6 +41,3 @@ function upload(
4141
reqheaders: {Authorization: `token ${githubToken}`, 'content-type': contentType, 'content-length': contentLength},
4242
});
4343
}
44-
45-
const mockGithub = {authenticate, upload};
46-
export default mockGithub;

test/helpers/rate-limit.js

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,5 @@
1-
const RETRY_CONF = {retries: 3, factor: 1, minTimeout: 1, maxTimeout: 1};
1+
export const RETRY_CONF = {retries: 3, factor: 1, minTimeout: 1, maxTimeout: 1};
22

3-
const RATE_LIMITS = {search: 1, core: {read: 1, write: 1}};
3+
export const RATE_LIMITS = {search: 1, core: {read: 1, write: 1}};
44

5-
const GLOBAL_RATE_LIMIT = 1;
6-
7-
const RATE_LIMIT = {RETRY_CONF, RATE_LIMITS, GLOBAL_RATE_LIMIT};
8-
export default RATE_LIMIT;
5+
export const GLOBAL_RATE_LIMIT = 1;

0 commit comments

Comments
 (0)