Skip to content

Commit 420f745

Browse files
committed
test: adapt publish test
1 parent f2ad2f5 commit 420f745

File tree

2 files changed

+15
-14
lines changed

2 files changed

+15
-14
lines changed

lib/publish.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ import {resolve, basename, extname} from 'node:path';
22
import {stat, readFile} from 'node:fs/promises';
33

44
import {isPlainObject, template} from 'lodash-es';
5-
import {getType} from 'mime';
5+
import mime from 'mime';
66
import debugFactory from 'debug';
77

88
import {RELEASE_NAME} from './definitions/constants.js';
@@ -82,7 +82,7 @@ export default async function publish(pluginConfig, context) {
8282
data: await readFile(resolve(cwd, filePath)),
8383
name: fileName,
8484
headers: {
85-
'content-type': getType(extname(fileName)) || 'text/plain',
85+
'content-type': mime.getType(extname(fileName)) || 'text/plain',
8686
'content-length': file.size,
8787
},
8888
};

test/publish.test.js

Lines changed: 13 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -2,32 +2,33 @@ import {stat} from 'node:fs/promises';
22
import {resolve} from 'node:path';
33
import {escape} from 'node:querystring';
44

5+
import nock from 'nock';
6+
import quibble from "quibble"
7+
import sinon from 'sinon';
8+
import tempy from 'tempy';
59
import test from 'ava';
6-
import {cleanAll} from 'nock';
7-
import {stub} from 'sinon';
8-
import proxyquire from 'proxyquire';
9-
import {directory} from 'tempy';
1010

1111
import {authenticate, upload} from './helpers/mock-github.js';
12-
import rateLimit from './helpers/rate-limit.js';
12+
import * as RATE_LIMIT_MOCK from './helpers/rate-limit.js';
1313

1414
/* eslint camelcase: ["error", {properties: "never"}] */
1515

16+
// mock rate limit imported via lib/get-client.js
17+
await quibble.esm('../lib/definitions/rate-limit.js', RATE_LIMIT_MOCK) // eslint-disable-line
18+
const publish = (await import('../lib/publish.js')).default
19+
1620
const cwd = 'test/fixtures/files';
17-
const publish = proxyquire('../lib/publish', {
18-
'./get-client': proxyquire('../lib/get-client', {'./definitions/rate-limit': rateLimit}),
19-
});
2021

2122
test.beforeEach((t) => {
2223
// Mock logger
23-
t.context.log = stub();
24-
t.context.error = stub();
24+
t.context.log = sinon.stub();
25+
t.context.error = sinon.stub();
2526
t.context.logger = {log: t.context.log, error: t.context.error};
2627
});
2728

2829
test.afterEach.always(() => {
2930
// Clear nock
30-
cleanAll();
31+
nock.cleanAll();
3132
});
3233

3334
test.serial('Publish a release', async (t) => {
@@ -334,7 +335,7 @@ test.serial('Publish a release with an array of missing assets', async (t) => {
334335
const owner = 'test_user';
335336
const repo = 'test_repo';
336337
const env = {GITHUB_TOKEN: 'github_token'};
337-
const emptyDirectory = directory();
338+
const emptyDirectory = tempy.directory();
338339
const pluginConfig = {assets: [emptyDirectory, {path: 'missing.txt', name: 'missing.txt'}]};
339340
const nextRelease = {gitTag: 'v1.0.0', name: 'v1.0.0', notes: 'Test release note body'};
340341
const options = {repositoryUrl: `https://github.com/${owner}/${repo}.git`};

0 commit comments

Comments
 (0)