Skip to content

Commit c8baacc

Browse files
committed
Use arrow for short functions, 2nd round.
Signed-off-by: Eric Wang <[email protected]>
1 parent 20f3979 commit c8baacc

File tree

7 files changed

+23
-67
lines changed

7 files changed

+23
-67
lines changed

test/plugins/test_cache.js

+8-28
Original file line numberDiff line numberDiff line change
@@ -30,9 +30,7 @@ describe('plugin:cache', function() {
3030
config.init();
3131
plugin.init();
3232

33-
h.getCacheDir = function() {
34-
return HOME;
35-
};
33+
h.getCacheDir = () => HOME;
3634
cache.__set__('h', h);
3735
cache.init();
3836

@@ -60,10 +58,7 @@ describe('plugin:cache', function() {
6058

6159
it('should getProblems w/o cache ok', function(done) {
6260
cache.del('problems');
63-
64-
NEXT.getProblems = function(cb) {
65-
return cb(null, PROBLEMS);
66-
};
61+
NEXT.getProblems = cb => cb(null, PROBLEMS);
6762

6863
plugin.getProblems(function(e, problems) {
6964
assert.equal(e, null);
@@ -74,10 +69,7 @@ describe('plugin:cache', function() {
7469

7570
it('should getProblems w/o cache fail if client error', function(done) {
7671
cache.del('problems');
77-
78-
NEXT.getProblems = function(cb) {
79-
return cb('client getProblems error');
80-
};
72+
NEXT.getProblems = cb => cb('client getProblems error');
8173

8274
plugin.getProblems(function(e, problems) {
8375
assert.equal(e, 'client getProblems error');
@@ -101,10 +93,7 @@ describe('plugin:cache', function() {
10193
it('should getProblem w/o cache ok', function(done) {
10294
cache.set('problems', PROBLEMS);
10395
cache.del('0.slug0.algorithms');
104-
105-
NEXT.getProblem = function(problem, cb) {
106-
return cb(null, PROBLEMS[0]);
107-
};
96+
NEXT.getProblem = (problem, cb) => cb(null, PROBLEMS[0]);
10897

10998
plugin.getProblem(_.clone(PROBLEM), function(e, problem) {
11099
assert.equal(e, null);
@@ -116,10 +105,7 @@ describe('plugin:cache', function() {
116105
it('should getProblem fail if client error', function(done) {
117106
cache.set('problems', PROBLEMS);
118107
cache.del('0.slug0.algorithms');
119-
120-
NEXT.getProblem = function(problem, cb) {
121-
return cb('client getProblem error');
122-
};
108+
NEXT.getProblem = (problem, cb) => cb('client getProblem error');
123109

124110
plugin.getProblem(_.clone(PROBLEM), function(e, problem) {
125111
assert.equal(e, 'client getProblem error');
@@ -185,9 +171,7 @@ describe('plugin:cache', function() {
185171
assert.equal(session.getUser(), null);
186172
assert.equal(session.isLogin(), false);
187173

188-
NEXT.login = function(user, cb) {
189-
return cb(null, user);
190-
};
174+
NEXT.login = (user, cb) => cb(null, user);
191175

192176
plugin.login(USER, function(e, user) {
193177
assert.equal(e, null);
@@ -204,9 +188,7 @@ describe('plugin:cache', function() {
204188
config.autologin.enable = false;
205189
cache.del(h.KEYS.user);
206190

207-
NEXT.login = function(user, cb) {
208-
return cb(null, user);
209-
};
191+
NEXT.login = (user, cb) => cb(null, user);
210192

211193
plugin.login(USER, function(e, user) {
212194
assert.equal(e, null);
@@ -218,9 +200,7 @@ describe('plugin:cache', function() {
218200
});
219201

220202
it('should login fail if client login error', function(done) {
221-
NEXT.login = function(user, cb) {
222-
return cb('client login error');
223-
};
203+
NEXT.login = (user, cb) => cb('client login error');
224204

225205
plugin.login(USER, function(e, user) {
226206
assert.equal(e, 'client login error');

test/plugins/test_leetcode.js

+2-4
Original file line numberDiff line numberDiff line change
@@ -33,10 +33,8 @@ describe('plugin:leetcode', function() {
3333
config.init();
3434
plugin.init();
3535

36-
session.getUser = function() {
37-
return USER;
38-
};
39-
session.saveUser = function() {};
36+
session.getUser = () => USER;
37+
session.saveUser = () => {};
4038
plugin.__set__('session', session);
4139
});
4240

test/plugins/test_retry.js

+5-15
Original file line numberDiff line numberDiff line change
@@ -18,9 +18,7 @@ describe('plugin:retry', function() {
1818
config.init();
1919
plugin.init();
2020

21-
session.getUser = function() {
22-
return USER;
23-
};
21+
session.getUser = () => USER;
2422

2523
plugin.__set__('config', config);
2624
plugin.__set__('session', session);
@@ -29,9 +27,7 @@ describe('plugin:retry', function() {
2927

3028
it('should fail if auto login disabled', function(done) {
3129
config.autologin.enable = false;
32-
NEXT.getProblems = function(cb) {
33-
return cb(session.errors.EXPIRED);
34-
};
30+
NEXT.getProblems = cb => cb(session.errors.EXPIRED);
3531

3632
plugin.getProblems(function(e, problems) {
3733
assert.equal(e, session.errors.EXPIRED);
@@ -49,9 +45,7 @@ describe('plugin:retry', function() {
4945
return cb(null, PROBLEMS);
5046
};
5147

52-
NEXT.login = function(user, cb) {
53-
return cb(null, user);
54-
};
48+
NEXT.login = (user, cb) => cb(null, user);
5549

5650
plugin.getProblems(function(e, problems) {
5751
assert.equal(e, null);
@@ -70,9 +64,7 @@ describe('plugin:retry', function() {
7064
return cb(null, PROBLEMS);
7165
};
7266

73-
session.getUser = function() {
74-
return null;
75-
};
67+
session.getUser = () => null;
7668

7769
plugin.getProblems(function(e, problems) {
7870
assert.equal(e, null);
@@ -83,9 +75,7 @@ describe('plugin:retry', function() {
8375

8476
it('should fail if other errors', function(done) {
8577
config.autologin.enable = true;
86-
NEXT.getProblems = function(cb) {
87-
return cb('unknown error');
88-
};
78+
NEXT.getProblems = cb => cb('unknown error');
8979

9080
plugin.getProblems(function(e, problems) {
9181
assert.equal(e, 'unknown error');

test/test_cache.js

+1-3
Original file line numberDiff line numberDiff line change
@@ -15,9 +15,7 @@ describe('cache', function() {
1515
const cachedir = './tmp';
1616
execSync('rm -rf ' + cachedir);
1717

18-
h.getCacheDir = function() {
19-
return cachedir;
20-
};
18+
h.getCacheDir = () => cachedir;
2119
cache.__set__('h', h);
2220
cache.init();
2321
});

test/test_config.js

+1-3
Original file line numberDiff line numberDiff line change
@@ -12,9 +12,7 @@ describe('config', function() {
1212
beforeEach(function() {
1313
config = rewire('../lib/config');
1414
const h = rewire('../lib/helper');
15-
h.getConfigFile = function() {
16-
return f;
17-
};
15+
h.getConfigFile = () => f;
1816
config.__set__('h', h);
1917
});
2018

test/test_core.js

+4-12
Original file line numberDiff line numberDiff line change
@@ -39,12 +39,8 @@ describe('core', function() {
3939
});
4040

4141
beforeEach(function() {
42-
NEXT.getProblems = function(cb) {
43-
return cb(null, PROBLEMS);
44-
};
45-
NEXT.getProblem = function(problem, cb) {
46-
return cb(null, problem);
47-
};
42+
NEXT.getProblems = cb => cb(null, PROBLEMS);
43+
NEXT.getProblem = (problem, cb) => cb(null, problem);
4844
});
4945

5046
describe('#filterProblems', function() {
@@ -280,9 +276,7 @@ describe('core', function() {
280276
});
281277

282278
it('should getProblem fail if client error', function(done) {
283-
NEXT.getProblem = function(problem, cb) {
284-
return cb('client getProblem error');
285-
};
279+
NEXT.getProblem = (problem, cb) => cb('client getProblem error');
286280

287281
plugin.getProblem(0, function(e, problem) {
288282
assert.equal(e, 'client getProblem error');
@@ -299,9 +293,7 @@ describe('core', function() {
299293
});
300294

301295
it('should getProblem fail if getProblems error', function(done) {
302-
NEXT.getProblems = function(cb) {
303-
return cb('getProblems error');
304-
};
296+
NEXT.getProblems = cb => cb('getProblems error');
305297

306298
plugin.getProblem(0, function(e, problem) {
307299
assert.equal(e, 'getProblems error');

test/test_plugin.js

+2-2
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ describe('plugin', function() {
2121
const core = new Plugin(3, 'Core', '4.0', '');
2222

2323
before(function() {
24-
const noop = function() {};
24+
const noop = () => {};
2525
cache.init = noop;
2626
leetcode.init = noop;
2727
retry.init = noop;
@@ -91,7 +91,7 @@ describe('plugin', function() {
9191
function clean() {
9292
if (fs.existsSync(src)) fs.unlinkSync(src);
9393
if (fs.existsSync(dst)) fs.unlinkSync(dst);
94-
h.getPluginFile = function() { return dst; };
94+
h.getPluginFile = () => dst;
9595
}
9696

9797
beforeEach(clean);

0 commit comments

Comments
 (0)