Skip to content

Commit 40fcbb8

Browse files
authored
Merge pull request #92 from segayuu/Refacter-test
Refacter test
2 parents f87373d + 0ec75fa commit 40fcbb8

File tree

7 files changed

+110
-184
lines changed

7 files changed

+110
-184
lines changed

test/index.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ const chai = require('chai');
44

55
chai.use(require('chai-as-promised'));
66

7-
describe('hexo-cli', function() {
7+
describe('hexo-cli', () => {
88
require('./scripts/find_pkg');
99
require('./scripts/context');
1010
require('./scripts/hexo');

test/scripts/context.js

Lines changed: 16 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,42 +1,40 @@
11
'use strict';
22

3-
const should = require('chai').should(); // eslint-disable-line
3+
require('chai').should();
44
const sinon = require('sinon');
55

6-
describe('context', function() {
6+
describe('context', () => {
77
const Context = require('../../lib/context');
88

9-
describe('call', function() {
9+
describe('call', () => {
1010
const hexo = new Context();
11-
const spy = sinon.spy(function(args) {
12-
return args;
13-
});
11+
const spy = sinon.spy(args => args);
1412

1513
hexo.extend.console.register('test', spy);
1614

17-
it('success', function() {
15+
it('success', () => {
1816
const args = {foo: 'bar'};
1917

20-
return hexo.call('test', args).then(function(result) {
18+
return hexo.call('test', args).then(result => {
2119
result.should.eql(args);
2220
spy.calledOnce.should.be.true;
2321
spy.lastCall.args[0].should.eql(args);
2422
spy.resetHistory();
2523
});
2624
});
2725

28-
it('console not registered', function() {
26+
it('console not registered', () => {
2927
const hexo = new Context();
3028

31-
return hexo.call('wtf').catch(function(err) {
29+
return hexo.call('wtf').catch(err => {
3230
err.should.have.property('message', 'Console `wtf` has not been registered yet!');
3331
});
3432
});
3533

36-
it('with callback', function(done) {
34+
it('with callback', done => {
3735
const args = {foo: 'bar'};
3836

39-
hexo.call('test', args, function(err, result) {
37+
hexo.call('test', args, (err, result) => {
4038
if (err) return done(err);
4139

4240
result.should.eql(args);
@@ -47,8 +45,8 @@ describe('context', function() {
4745
});
4846
});
4947

50-
it('with callback but no args', function(done) {
51-
hexo.call('test', function(err) {
48+
it('with callback but no args', done => {
49+
hexo.call('test', err => {
5250
if (err) return done(err);
5351

5452
spy.calledOnce.should.be.true;
@@ -58,20 +56,20 @@ describe('context', function() {
5856
});
5957
});
6058

61-
describe('exit', function() {
59+
describe('exit', () => {
6260
let hexo, fatal;
6361

64-
beforeEach(function() {
62+
beforeEach(() => {
6563
hexo = new Context();
6664
fatal = hexo.log.fatal = sinon.spy();
6765
});
6866

69-
it('no error', function() {
67+
it('no error', () => {
7068
hexo.exit();
7169
fatal.called.should.be.false;
7270
});
7371

74-
it('with error', function() {
72+
it('with error', () => {
7573
hexo.exit(new Error('error test'));
7674
fatal.calledOnce.should.be.true;
7775
});

test/scripts/find_pkg.js

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

3-
const should = require('chai').should(); // eslint-disable-line
3+
const should = require('chai').should();
44
const fs = require('hexo-fs');
55
const pathFn = require('path');
66

7-
describe('Find package', function() {
7+
describe('Find package', () => {
88
const findPkg = require('../../lib/find_pkg');
99
const baseDir = pathFn.join(__dirname, 'find_pkg_test');
1010

11-
after(function() {
12-
return fs.rmdir(baseDir);
13-
});
11+
after(() => fs.rmdir(baseDir));
1412

15-
it('not found', function() {
16-
return findPkg(baseDir, {}).then(function(path) {
17-
should.not.exist(path);
18-
});
19-
});
13+
it('not found', () => findPkg(baseDir, {}).then(path => {
14+
should.not.exist(path);
15+
}));
2016

21-
it('found', function() {
17+
it('found', () => {
2218
const pkgPath = pathFn.join(baseDir, 'package.json');
2319

24-
return fs.writeFile(pkgPath, '{"hexo": {}}').then(function() {
25-
return findPkg(baseDir, {});
26-
}).then(function(path) {
20+
return fs.writeFile(pkgPath, '{"hexo": {}}').then(() => findPkg(baseDir, {})).then(path => {
2721
path.should.eql(baseDir);
2822
return fs.unlink(pkgPath);
2923
});
3024
});
3125

32-
it('found in parent directory', function() {
26+
it('found in parent directory', () => {
3327
const pkgPath = pathFn.join(baseDir, '../package.json');
3428

35-
return fs.writeFile(pkgPath, '{"hexo": {}}').then(function() {
36-
return findPkg(baseDir, {});
37-
}).then(function(path) {
29+
return fs.writeFile(pkgPath, '{"hexo": {}}').then(() => findPkg(baseDir, {})).then(path => {
3830
path.should.eql(pathFn.dirname(pkgPath));
3931
return fs.unlink(pkgPath);
4032
});
4133
});
4234

43-
it('found but don\'t have hexo data', function() {
35+
it('found but don\'t have hexo data', () => {
4436
const pkgPath = pathFn.join(baseDir, 'package.json');
4537

46-
return fs.writeFile(pkgPath, '{"name": "hexo"}').then(function() {
47-
return findPkg(baseDir, {});
48-
}).then(function(path) {
38+
return fs.writeFile(pkgPath, '{"name": "hexo"}').then(() => findPkg(baseDir, {})).then(path => {
4939
should.not.exist(path);
5040
return fs.unlink(pkgPath);
5141
});
5242
});
5343

54-
it('relative cwd', function() {
44+
it('relative cwd', () => {
5545
const pkgPath = pathFn.join(baseDir, 'test', 'package.json');
5646

57-
return fs.writeFile(pkgPath, '{"hexo": {}}').then(function() {
58-
return findPkg(baseDir, {cwd: 'test'});
59-
}).then(function(path) {
47+
return fs.writeFile(pkgPath, '{"hexo": {}}').then(() => findPkg(baseDir, {cwd: 'test'})).then(path => {
6048
path.should.eql(pathFn.dirname(pkgPath));
6149
return fs.unlink(pkgPath);
6250
});
6351
});
6452

65-
it('specify cwd but don\'t have hexo data', function() {
66-
return findPkg(baseDir, {cwd: 'test'}).then(function(path) {
67-
should.not.exist(path);
68-
});
69-
});
53+
it('specify cwd but don\'t have hexo data', () => findPkg(baseDir, {cwd: 'test'}).then(path => {
54+
should.not.exist(path);
55+
}));
7056

71-
it('absolute cwd', function() {
57+
it('absolute cwd', () => {
7258
const pkgPath = pathFn.join(baseDir, 'test', 'package.json');
7359
const cwd = pathFn.dirname(pkgPath);
7460

75-
return fs.writeFile(pkgPath, '{"hexo": {}}').then(function() {
76-
return findPkg(baseDir, {cwd: cwd});
77-
}).then(function(path) {
61+
return fs.writeFile(pkgPath, '{"hexo": {}}').then(() => findPkg(baseDir, {cwd})).then(path => {
7862
path.should.eql(cwd);
7963
return fs.unlink(pkgPath);
8064
});

0 commit comments

Comments
 (0)