Skip to content

Commit 14452d0

Browse files
committed
test: client: dom: io: get rid of mock-require
1 parent 5c1ad5f commit 14452d0

File tree

2 files changed

+23
-25
lines changed

2 files changed

+23
-25
lines changed

client/dom/io/index.js

Lines changed: 19 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,14 @@
11
'use strict';
22

33
const {FS} = require('../../../common/cloudfunc');
4-
const sendRequest = require('./send-request');
4+
const _sendRequest = require('./send-request');
55

66
const imgPosition = {
77
top: true,
88
};
99

1010
module.exports.delete = async (url, data) => {
11-
return await sendRequest({
11+
return await _sendRequest({
1212
method: 'DELETE',
1313
url: FS + url,
1414
data,
@@ -19,7 +19,7 @@ module.exports.delete = async (url, data) => {
1919
};
2020

2121
module.exports.patch = async (url, data) => {
22-
return await sendRequest({
22+
return await _sendRequest({
2323
method: 'PATCH',
2424
url: FS + url,
2525
data,
@@ -28,15 +28,19 @@ module.exports.patch = async (url, data) => {
2828
};
2929

3030
module.exports.write = async (url, data) => {
31-
return await sendRequest({
31+
return await _sendRequest({
3232
method: 'PUT',
3333
url: FS + url,
3434
data,
3535
imgPosition,
3636
});
3737
};
3838

39-
module.exports.createDirectory = async (url) => {
39+
module.exports.createDirectory = async (url, overrides = {}) => {
40+
const {
41+
sendRequest = _sendRequest,
42+
} = overrides;
43+
4044
return await sendRequest({
4145
method: 'PUT',
4246
url: `${FS}${url}?dir`,
@@ -47,7 +51,7 @@ module.exports.createDirectory = async (url) => {
4751
module.exports.read = async (url, dataType = 'text') => {
4852
const notLog = !url.includes('?');
4953

50-
return await sendRequest({
54+
return await _sendRequest({
5155
method: 'GET',
5256
url: FS + url,
5357
notLog,
@@ -56,7 +60,7 @@ module.exports.read = async (url, dataType = 'text') => {
5660
};
5761

5862
module.exports.copy = async (from, to, names) => {
59-
return await sendRequest({
63+
return await _sendRequest({
6064
method: 'PUT',
6165
url: '/copy',
6266
data: {
@@ -69,23 +73,23 @@ module.exports.copy = async (from, to, names) => {
6973
};
7074

7175
module.exports.pack = async (data) => {
72-
return await sendRequest({
76+
return await _sendRequest({
7377
method: 'PUT',
7478
url: '/pack',
7579
data,
7680
});
7781
};
7882

7983
module.exports.extract = async (data) => {
80-
return await sendRequest({
84+
return await _sendRequest({
8185
method: 'PUT',
8286
url: '/extract',
8387
data,
8488
});
8589
};
8690

8791
module.exports.move = async (from, to, names) => {
88-
return await sendRequest({
92+
return await _sendRequest({
8993
method: 'PUT',
9094
url: '/move',
9195
data: {
@@ -98,7 +102,7 @@ module.exports.move = async (from, to, names) => {
98102
};
99103

100104
module.exports.rename = async (from, to) => {
101-
return await sendRequest({
105+
return await _sendRequest({
102106
method: 'PUT',
103107
url: '/rename',
104108
data: {
@@ -111,7 +115,7 @@ module.exports.rename = async (from, to) => {
111115

112116
module.exports.Config = {
113117
read: async () => {
114-
return await sendRequest({
118+
return await _sendRequest({
115119
method: 'GET',
116120
url: '/config',
117121
imgPosition,
@@ -120,7 +124,7 @@ module.exports.Config = {
120124
},
121125

122126
write: async (data) => {
123-
return await sendRequest({
127+
return await _sendRequest({
124128
method: 'PATCH',
125129
url: '/config',
126130
data,
@@ -131,7 +135,7 @@ module.exports.Config = {
131135

132136
module.exports.Markdown = {
133137
read: async (url) => {
134-
return await sendRequest({
138+
return await _sendRequest({
135139
method: 'GET',
136140
url: `/markdown${url}`,
137141
imgPosition,
@@ -140,7 +144,7 @@ module.exports.Markdown = {
140144
},
141145

142146
render: async (data) => {
143-
return await sendRequest({
147+
return await _sendRequest({
144148
method: 'PUT',
145149
url: '/markdown',
146150
data,

client/dom/io/index.spec.js

Lines changed: 4 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,14 @@
11
'use strict';
22

33
const {test, stub} = require('supertape');
4-
5-
const mockRequire = require('mock-require');
6-
7-
const {reRequire, stopAll} = mockRequire;
4+
const io = require('.');
85

96
test('client: dom: io', (t) => {
107
const sendRequest = stub();
11-
mockRequire('./send-request', sendRequest);
128

13-
const io = reRequire('.');
14-
15-
io.createDirectory('/hello');
9+
io.createDirectory('/hello', {
10+
sendRequest,
11+
});
1612

1713
const expected = {
1814
imgPosition: {
@@ -22,8 +18,6 @@ test('client: dom: io', (t) => {
2218
url: '/fs/hello?dir',
2319
};
2420

25-
stopAll();
26-
2721
t.calledWith(sendRequest, [expected]);
2822
t.end();
2923
});

0 commit comments

Comments
 (0)