From 07b23aa9932884ee6304ba35b11dad77d51b1f0d Mon Sep 17 00:00:00 2001 From: YoshinoriN Date: Mon, 1 Oct 2018 23:30:21 +0900 Subject: [PATCH 01/12] Drop node.js v9 and support v10 on AppVeyor --- appveyor.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/appveyor.yml b/appveyor.yml index fbf8ad984b..3493eb55ec 100644 --- a/appveyor.yml +++ b/appveyor.yml @@ -7,7 +7,7 @@ environment: matrix: - nodejs_version: "6" - nodejs_version: "8" - - nodejs_version: "9" + - nodejs_version: "10" matrix: fast_finish: true From acb16e6b6aa216141a911eda31315b74b7398057 Mon Sep 17 00:00:00 2001 From: YoshinoriN Date: Fri, 12 Oct 2018 01:44:36 +0900 Subject: [PATCH 02/12] refactor: var to let/const in test code --- test/fixtures/post_render.js | 6 +- test/index.js | 2 +- test/scripts/box/box.js | 219 ++++++++++--------- test/scripts/box/file.js | 30 +-- test/scripts/console/clean.js | 14 +- test/scripts/console/config.js | 34 +-- test/scripts/console/deploy.js | 24 +-- test/scripts/console/generate.js | 49 +++-- test/scripts/console/list_categories.js | 18 +- test/scripts/console/list_page.js | 14 +- test/scripts/console/list_post.js | 18 +- test/scripts/console/list_tags.js | 18 +- test/scripts/console/migrate.js | 12 +- test/scripts/console/new.js | 56 ++--- test/scripts/console/publish.js | 42 ++-- test/scripts/console/render.js | 36 ++-- test/scripts/extend/console.js | 14 +- test/scripts/extend/deployer.js | 14 +- test/scripts/extend/filter.js | 78 +++---- test/scripts/extend/generator.js | 12 +- test/scripts/extend/helper.js | 10 +- test/scripts/extend/migrator.js | 14 +- test/scripts/extend/processor.js | 8 +- test/scripts/extend/renderer.js | 20 +- test/scripts/extend/tag.js | 42 ++-- test/scripts/filters/backtick_code_block.js | 92 ++++---- test/scripts/filters/excerpt.js | 42 ++-- test/scripts/filters/external_link.js | 16 +- test/scripts/filters/i18n_locals.js | 40 ++-- test/scripts/filters/new_post_path.js | 40 ++-- test/scripts/filters/post_permalink.js | 18 +- test/scripts/filters/render_post.js | 26 +-- test/scripts/filters/save_database.js | 14 +- test/scripts/filters/titlecase.js | 16 +- test/scripts/generators/asset.js | 42 ++-- test/scripts/generators/page.js | 12 +- test/scripts/generators/post.js | 12 +- test/scripts/helpers/css.js | 14 +- test/scripts/helpers/date.js | 38 ++-- test/scripts/helpers/debug.js | 20 +- test/scripts/helpers/favicon_tag.js | 10 +- test/scripts/helpers/feed_tag.js | 10 +- test/scripts/helpers/fragment_cache.js | 4 +- test/scripts/helpers/gravatar.js | 10 +- test/scripts/helpers/image_tag.js | 10 +- test/scripts/helpers/is.js | 8 +- test/scripts/helpers/js.js | 14 +- test/scripts/helpers/link_to.js | 10 +- test/scripts/helpers/list_archives.js | 34 +-- test/scripts/helpers/list_categories.js | 42 ++-- test/scripts/helpers/list_posts.js | 30 +-- test/scripts/helpers/list_tags.js | 36 ++-- test/scripts/helpers/mail_to.js | 28 +-- test/scripts/helpers/markdown.js | 10 +- test/scripts/helpers/number_format.js | 4 +- test/scripts/helpers/open_graph.js | 170 +++++++-------- test/scripts/helpers/paginator.js | 60 +++--- test/scripts/helpers/partial.js | 24 +-- test/scripts/helpers/relative_url.js | 4 +- test/scripts/helpers/render.js | 12 +- test/scripts/helpers/search_form.js | 4 +- test/scripts/helpers/tagcloud.js | 46 ++-- test/scripts/helpers/toc.js | 34 +-- test/scripts/helpers/url_for.js | 6 +- test/scripts/hexo/hexo.js | 74 +++---- test/scripts/hexo/load_config.js | 30 +-- test/scripts/hexo/load_database.js | 16 +- test/scripts/hexo/load_plugins.js | 56 ++--- test/scripts/hexo/locals.js | 18 +- test/scripts/hexo/multi_config_path.js | 66 +++--- test/scripts/hexo/post.js | 146 ++++++------- test/scripts/hexo/render.js | 64 +++--- test/scripts/hexo/router.js | 54 ++--- test/scripts/hexo/scaffold.js | 22 +- test/scripts/hexo/update_package.js | 20 +- test/scripts/models/asset.js | 16 +- test/scripts/models/cache.js | 12 +- test/scripts/models/category.js | 30 +-- test/scripts/models/moment.js | 28 +-- test/scripts/models/page.js | 18 +- test/scripts/models/post.js | 78 ++++--- test/scripts/models/post_asset.js | 20 +- test/scripts/models/tag.js | 30 +-- test/scripts/processors/asset.js | 126 +++++------ test/scripts/processors/common.js | 12 +- test/scripts/processors/data.js | 52 ++--- test/scripts/processors/post.js | 228 ++++++++++---------- test/scripts/renderers/json.js | 6 +- test/scripts/renderers/plain.js | 4 +- test/scripts/renderers/swig.js | 14 +- test/scripts/renderers/yaml.js | 6 +- test/scripts/tags/asset_img.js | 16 +- test/scripts/tags/asset_link.js | 16 +- test/scripts/tags/asset_path.js | 16 +- test/scripts/tags/blockquote.js | 22 +- test/scripts/tags/code.js | 50 ++--- test/scripts/tags/gist.js | 10 +- test/scripts/tags/iframe.js | 12 +- test/scripts/tags/img.js | 38 ++-- test/scripts/tags/include_code.js | 26 +-- test/scripts/tags/jsfiddle.js | 16 +- test/scripts/tags/link.js | 14 +- test/scripts/tags/post_link.js | 10 +- test/scripts/tags/post_path.js | 10 +- test/scripts/tags/pullquote.js | 12 +- test/scripts/tags/vimeo.js | 8 +- test/scripts/tags/youtube.js | 8 +- test/scripts/theme/theme.js | 16 +- test/scripts/theme/view.js | 98 ++++----- test/scripts/theme_processors/config.js | 32 +-- test/scripts/theme_processors/i18n.js | 30 +-- test/scripts/theme_processors/source.js | 46 ++-- test/scripts/theme_processors/view.js | 30 +-- test/util/stream.js | 4 +- 114 files changed, 1822 insertions(+), 1830 deletions(-) diff --git a/test/fixtures/post_render.js b/test/fixtures/post_render.js index 24e4c0cf51..4ef8aeb7f4 100644 --- a/test/fixtures/post_render.js +++ b/test/fixtures/post_render.js @@ -1,13 +1,13 @@ 'use strict'; -var util = require('hexo-util'); +const util = require('hexo-util'); -var code = [ +const code = [ 'if tired && night:', ' sleep()' ].join('\n'); -var content = [ +const content = [ '# Title', '``` python', code, diff --git a/test/index.js b/test/index.js index 1f717e8a04..69b8a0713f 100644 --- a/test/index.js +++ b/test/index.js @@ -1,6 +1,6 @@ 'use strict'; -var chai = require('chai'); +const chai = require('chai'); chai.use(require('chai-as-promised')); diff --git a/test/scripts/box/box.js b/test/scripts/box/box.js index 56c2633fc6..6a00ce8a3a 100644 --- a/test/scripts/box/box.js +++ b/test/scripts/box/box.js @@ -1,20 +1,20 @@ -var should = require('chai').should(); // eslint-disable-line -var pathFn = require('path'); -var fs = require('hexo-fs'); -var Promise = require('bluebird'); -var util = require('hexo-util'); -var sinon = require('sinon'); -var Pattern = util.Pattern; +const should = require('chai').should(); // eslint-disable-line +const pathFn = require('path'); +const fs = require('hexo-fs'); +const Promise = require('bluebird'); +const util = require('hexo-util'); +const sinon = require('sinon'); +const Pattern = util.Pattern; describe('Box', () => { - var Hexo = require('../../../lib/hexo'); - var baseDir = pathFn.join(__dirname, 'box_tmp'); - var Box = require('../../../lib/box'); + const Hexo = require('../../../lib/hexo'); + const baseDir = pathFn.join(__dirname, 'box_tmp'); + const Box = require('../../../lib/box'); function newBox(path, config) { - var hexo = new Hexo(baseDir, {silent: true}); + const hexo = new Hexo(baseDir, {silent: true}); hexo.config = Object.assign(hexo.config, config); - var base = path ? pathFn.join(baseDir, path) : baseDir; + const base = path ? pathFn.join(baseDir, path) : baseDir; return new Box(hexo, base); } @@ -23,32 +23,32 @@ describe('Box', () => { after(() => fs.rmdir(baseDir)); it('constructor - add trailing "/" to the base path', () => { - var box = newBox('foo'); + const box = newBox('foo'); box.base.should.eql(pathFn.join(baseDir, 'foo') + pathFn.sep); }); it('constructor - make ignore an array if its not one', () => { - var box = newBox('foo', {ignore: 'fooDir'}); + const box = newBox('foo', {ignore: 'fooDir'}); box.ignore.should.eql(['fooDir']); }); it('addProcessor() - no pattern', () => { - var box = newBox(); + const box = newBox(); box.addProcessor(() => 'test'); - var p = box.processors[0]; + const p = box.processors[0]; p.pattern.match('').should.eql({}); p.process().should.eql('test'); }); it('addProcessor() - with regex', () => { - var box = newBox(); + const box = newBox(); box.addProcessor(/^foo/, () => 'test'); - var p = box.processors[0]; + const p = box.processors[0]; p.pattern.match('foobar').should.be.ok; p.pattern.should.be.an.instanceof(Pattern); @@ -56,11 +56,11 @@ describe('Box', () => { }); it('addProcessor() - with pattern', () => { - var box = newBox(); + const box = newBox(); box.addProcessor(new Pattern(/^foo/), () => 'test'); - var p = box.processors[0]; + const p = box.processors[0]; p.pattern.match('foobar').should.be.ok; p.pattern.should.be.an.instanceof(Pattern); @@ -68,8 +68,8 @@ describe('Box', () => { }); it('addProcessor() - no fn', () => { - var box = newBox(); - var errorCallback = sinon.spy(err => { + const box = newBox(); + const errorCallback = sinon.spy(err => { err.should.have.property('message', 'fn must be a function'); }); @@ -83,8 +83,8 @@ describe('Box', () => { }); it('process()', () => { - var box = newBox('test'); - var data = {}; + const box = newBox('test'); + const data = {}; box.addProcessor(file => { data[file.path] = file; @@ -94,11 +94,10 @@ describe('Box', () => { fs.writeFile(pathFn.join(box.base, 'a.txt'), 'a'), fs.writeFile(pathFn.join(box.base, 'b', 'c.js'), 'c') ]).then(() => box.process()).then(() => { - var keys = Object.keys(data); - var key, - item; + const keys = Object.keys(data); + let key, item; - for (var i = 0, len = keys.length; i < len; i++) { + for (let i = 0, len = keys.length; i < len; i++) { key = keys[i]; item = data[key]; @@ -111,33 +110,33 @@ describe('Box', () => { }); it('process() - do nothing if target does not exist', () => { - var box = newBox('test'); + const box = newBox('test'); return box.process(); }); it('process() - create', () => { - var box = newBox('test'); - var name = 'a.txt'; - var path = pathFn.join(box.base, name); + const box = newBox('test'); + const name = 'a.txt'; + const path = pathFn.join(box.base, name); - var processor = sinon.spy(); + const processor = sinon.spy(); box.addProcessor(processor); return fs.writeFile(path, 'a').then(() => box.process()).then(() => { - var file = processor.args[0][0]; + const file = processor.args[0][0]; file.type.should.eql('create'); file.path.should.eql(name); }).finally(() => fs.rmdir(box.base)); }); it('process() - mtime changed', () => { - var box = newBox('test'); - var name = 'a.txt'; - var path = pathFn.join(box.base, name); - var cacheId = 'test/' + name; + const box = newBox('test'); + const name = 'a.txt'; + const path = pathFn.join(box.base, name); + const cacheId = 'test/' + name; - var processor = sinon.spy(); + const processor = sinon.spy(); box.addProcessor(processor); return Promise.all([ @@ -147,38 +146,38 @@ describe('Box', () => { modified: 0 }) ]).then(() => box.process()).then(() => { - var file = processor.args[0][0]; + const file = processor.args[0][0]; file.type.should.eql('update'); file.path.should.eql(name); }).finally(() => fs.rmdir(box.base)); }); it('process() - hash changed', () => { - var box = newBox('test'); - var name = 'a.txt'; - var path = pathFn.join(box.base, name); - var cacheId = 'test/' + name; + const box = newBox('test'); + const name = 'a.txt'; + const path = pathFn.join(box.base, name); + const cacheId = 'test/' + name; - var processor = sinon.spy(); + const processor = sinon.spy(); box.addProcessor(processor); return fs.writeFile(path, 'a').then(() => fs.stat(path)).then(stats => box.Cache.insert({ _id: cacheId, modified: stats.mtime })).then(() => box.process()).then(() => { - var file = processor.args[0][0]; + const file = processor.args[0][0]; file.type.should.eql('update'); file.path.should.eql(name); }).finally(() => fs.rmdir(box.base)); }); it('process() - skip', () => { - var box = newBox('test'); - var name = 'a.txt'; - var path = pathFn.join(box.base, name); - var cacheId = 'test/' + name; + const box = newBox('test'); + const name = 'a.txt'; + const path = pathFn.join(box.base, name); + const cacheId = 'test/' + name; - var processor = sinon.spy(); + const processor = sinon.spy(); box.addProcessor(processor); return fs.writeFile(path, 'a').then(() => fs.stat(path)).then(stats => box.Cache.insert({ @@ -186,17 +185,17 @@ describe('Box', () => { modified: stats.mtime, hash: util.hash('a').toString('hex') })).then(() => box.process()).then(() => { - var file = processor.args[0][0]; + const file = processor.args[0][0]; file.type.should.eql('skip'); file.path.should.eql(name); }).finally(() => fs.rmdir(box.base)); }); it('process() - delete', () => { - var box = newBox('test'); - var cacheId = 'test/a.txt'; + const box = newBox('test'); + const cacheId = 'test/a.txt'; - var processor = sinon.spy(file => { + const processor = sinon.spy(file => { file.type.should.eql('delete'); }); @@ -213,10 +212,10 @@ describe('Box', () => { }); it('process() - params', () => { - var box = newBox('test'); - var path = pathFn.join(box.base, 'posts', '123456'); + const box = newBox('test'); + const path = pathFn.join(box.base, 'posts', '123456'); - var processor = sinon.spy(file => { + const processor = sinon.spy(file => { file.params.id.should.eql('123456'); }); @@ -228,8 +227,8 @@ describe('Box', () => { }); it('process() - skip files if they match glob epression in ignore', () => { - var box = newBox('test', {ignore: '**/ignore_me'}); - var data = {}; + const box = newBox('test', {ignore: '**/ignore_me'}); + const data = {}; box.addProcessor(file => { data[file.path] = file; @@ -239,7 +238,7 @@ describe('Box', () => { fs.writeFile(pathFn.join(box.base, 'foo.txt'), 'foo'), fs.writeFile(pathFn.join(box.base, 'ignore_me', 'bar.txt'), 'ignore_me') ]).then(() => box.process()).then(() => { - var keys = Object.keys(data); + const keys = Object.keys(data); keys.length.should.eql(1); keys[0].should.eql('foo.txt'); @@ -247,10 +246,10 @@ describe('Box', () => { }); it('watch() - create', () => { - var box = newBox('test'); - var path = 'a.txt'; - var src = pathFn.join(box.base, path); - var processor = sinon.spy(); + const box = newBox('test'); + const path = 'a.txt'; + const src = pathFn.join(box.base, path); + const processor = sinon.spy(); box.addProcessor(processor); @@ -258,7 +257,7 @@ describe('Box', () => { box.isWatching().should.be.true; return fs.writeFile(src, 'a'); }).delay(500).then(() => { - var file = processor.args[0][0]; + const file = processor.args[0][0]; file.source.should.eql(src); file.path.should.eql(path); @@ -271,12 +270,12 @@ describe('Box', () => { }); it('watch() - update', () => { - var box = newBox('test'); - var path = 'a.txt'; - var src = pathFn.join(box.base, path); - var cacheId = 'test/' + path; - var Cache = box.Cache; - var processor = sinon.spy(); + const box = newBox('test'); + const path = 'a.txt'; + const src = pathFn.join(box.base, path); + const cacheId = 'test/' + path; + const Cache = box.Cache; + const processor = sinon.spy(); box.addProcessor(processor); @@ -284,7 +283,7 @@ describe('Box', () => { fs.writeFile(src, 'a'), Cache.insert({_id: cacheId}) ]).then(() => box.watch()).then(() => fs.appendFile(src, 'b')).delay(500).then(() => { - var file = processor.lastCall.args[0]; + const file = processor.lastCall.args[0]; file.source.should.eql(src); file.path.should.eql(path); @@ -297,12 +296,12 @@ describe('Box', () => { }); it('watch() - delete', () => { - var box = newBox('test'); - var path = 'a.txt'; - var src = pathFn.join(box.base, path); - var cacheId = 'test/' + path; - var Cache = box.Cache; - var processor = sinon.spy(); + const box = newBox('test'); + const path = 'a.txt'; + const src = pathFn.join(box.base, path); + const cacheId = 'test/' + path; + const Cache = box.Cache; + const processor = sinon.spy(); box.addProcessor(processor); @@ -310,7 +309,7 @@ describe('Box', () => { fs.writeFile(src, 'a'), Cache.insert({_id: cacheId}) ]).then(() => box.watch()).then(() => fs.unlink(src)).delay(500).then(() => { - var file = processor.lastCall.args[0]; + const file = processor.lastCall.args[0]; file.source.should.eql(src); file.path.should.eql(path); @@ -323,14 +322,14 @@ describe('Box', () => { }); it('watch() - rename file', () => { - var box = newBox('test'); - var path = 'a.txt'; - var src = pathFn.join(box.base, path); - var newPath = 'b.txt'; - var newSrc = pathFn.join(box.base, newPath); - var cacheId = 'test/' + path; - var Cache = box.Cache; - var processor = sinon.spy(); + const box = newBox('test'); + const path = 'a.txt'; + const src = pathFn.join(box.base, path); + const newPath = 'b.txt'; + const newSrc = pathFn.join(box.base, newPath); + const cacheId = 'test/' + path; + const Cache = box.Cache; + const processor = sinon.spy(); box.addProcessor(processor); @@ -338,10 +337,10 @@ describe('Box', () => { fs.writeFile(src, 'a'), Cache.insert({_id: cacheId}) ]).then(() => box.watch()).then(() => fs.rename(src, newSrc)).delay(500).then(() => { - var lastTwoCalls = processor.args.slice(processor.args.length - 2, processor.args.length); + const lastTwoCalls = processor.args.slice(processor.args.length - 2, processor.args.length); lastTwoCalls.forEach(args => { - var file = args[0]; + const file = args[0]; switch (file.type) { case 'create': @@ -362,14 +361,14 @@ describe('Box', () => { }); it('watch() - rename folder', () => { - var box = newBox('test'); - var path = 'a/b.txt'; - var src = pathFn.join(box.base, path); - var newPath = 'b/b.txt'; - var newSrc = pathFn.join(box.base, newPath); - var cacheId = 'test/' + path; - var Cache = box.Cache; - var processor = sinon.spy(); + const box = newBox('test'); + const path = 'a/b.txt'; + const src = pathFn.join(box.base, path); + const newPath = 'b/b.txt'; + const newSrc = pathFn.join(box.base, newPath); + const cacheId = 'test/' + path; + const Cache = box.Cache; + const processor = sinon.spy(); box.addProcessor(processor); @@ -377,10 +376,10 @@ describe('Box', () => { fs.writeFile(src, 'a'), Cache.insert({_id: cacheId}) ]).then(() => box.watch()).then(() => fs.rename(pathFn.join(box.base, 'a'), pathFn.join(box.base, 'b'))).delay(500).then(() => { - var lastTwoCalls = processor.args.slice(processor.args.length - 2, processor.args.length); + const lastTwoCalls = processor.args.slice(processor.args.length - 2, processor.args.length); lastTwoCalls.forEach(args => { - var file = args[0]; + const file = args[0]; switch (file.type) { case 'create': @@ -401,10 +400,10 @@ describe('Box', () => { }); it('watch() - watcher has started', () => { - var box = newBox(); + const box = newBox(); return box.watch().then(() => { - var errorCallback = sinon.spy(err => { + const errorCallback = sinon.spy(err => { err.should.have.property('message', 'Watcher has already started.'); }); @@ -417,8 +416,8 @@ describe('Box', () => { }); it('watch() - run process() before start watching', () => { - var box = newBox('test'); - var data = []; + const box = newBox('test'); + const data = []; box.addProcessor(file => { data.push(file.path); @@ -436,8 +435,8 @@ describe('Box', () => { }); it('unwatch()', () => { - var box = newBox('test'); - var processor = sinon.spy(); + const box = newBox('test'); + const processor = sinon.spy(); return box.watch().then(() => { box.addProcessor(processor); @@ -453,7 +452,7 @@ describe('Box', () => { }); it('isWatching()', () => { - var box = newBox(); + const box = newBox(); box.isWatching().should.be.false; @@ -468,14 +467,14 @@ describe('Box', () => { }); it('processBefore & processAfter events', () => { - var box = newBox('test'); + const box = newBox('test'); - var beforeSpy = sinon.spy(file => { + const beforeSpy = sinon.spy(file => { file.type.should.eql('create'); file.path.should.eql('a.txt'); }); - var afterSpy = sinon.spy(file => { + const afterSpy = sinon.spy(file => { file.type.should.eql('create'); file.path.should.eql('a.txt'); }); diff --git a/test/scripts/box/file.js b/test/scripts/box/file.js index f7f2a283df..fc0c6731b2 100644 --- a/test/scripts/box/file.js +++ b/test/scripts/box/file.js @@ -1,18 +1,18 @@ -var should = require('chai').should(); // eslint-disable-line -var pathFn = require('path'); -var Promise = require('bluebird'); -var fs = require('hexo-fs'); -var yaml = require('js-yaml'); -var _ = require('lodash'); +const should = require('chai').should(); // eslint-disable-line +const pathFn = require('path'); +const Promise = require('bluebird'); +const fs = require('hexo-fs'); +const yaml = require('js-yaml'); +const _ = require('lodash'); describe('File', () => { - var Hexo = require('../../../lib/hexo'); - var hexo = new Hexo(__dirname); - var Box = require('../../../lib/box'); - var box = new Box(hexo, pathFn.join(hexo.base_dir, 'file_test')); - var File = box.File; + const Hexo = require('../../../lib/hexo'); + const hexo = new Hexo(__dirname); + const Box = require('../../../lib/box'); + const box = new Box(hexo, pathFn.join(hexo.base_dir, 'file_test')); + const File = box.File; - var body = [ + const body = [ 'name:', ' first: John', ' last: Doe', @@ -24,8 +24,8 @@ describe('File', () => { '- Banana' ].join('\n'); - var obj = yaml.load(body); - var path = 'test.yml'; + const obj = yaml.load(body); + const path = 'test.yml'; function makeFile(path, props) { return new File(_.assign({ @@ -34,7 +34,7 @@ describe('File', () => { }, props)); } - var file = makeFile(path, { + const file = makeFile(path, { source: pathFn.join(box.base, path), path, type: 'create', diff --git a/test/scripts/console/clean.js b/test/scripts/console/clean.js index 446a194f13..c86e76e6d0 100644 --- a/test/scripts/console/clean.js +++ b/test/scripts/console/clean.js @@ -1,9 +1,9 @@ -var should = require('chai').should(); // eslint-disable-line -var fs = require('hexo-fs'); +const should = require('chai').should(); // eslint-disable-line +const fs = require('hexo-fs'); describe('clean', () => { - var Hexo = require('../../../lib/hexo'); - var hexo, clean; + const Hexo = require('../../../lib/hexo'); + let hexo, clean; beforeEach(() => { hexo = new Hexo(__dirname, {silent: true}); @@ -11,7 +11,7 @@ describe('clean', () => { }); it('delete database', () => { - var dbPath = hexo.database.options.path; + const dbPath = hexo.database.options.path; return fs.writeFile(dbPath, '').then(() => clean()).then(() => fs.exists(dbPath)).then(exist => { exist.should.be.false; @@ -19,7 +19,7 @@ describe('clean', () => { }); it('delete public folder', () => { - var publicDir = hexo.public_dir; + const publicDir = hexo.public_dir; return fs.mkdirs(publicDir).then(() => clean()).then(() => fs.exists(publicDir)).then(exist => { exist.should.be.false; @@ -27,7 +27,7 @@ describe('clean', () => { }); it('execute corresponding filter', () => { - var extraDbPath = hexo.database.options.path + '.tmp'; + const extraDbPath = hexo.database.options.path + '.tmp'; hexo.extend.filter.register('after_clean', () => { return fs.unlink(extraDbPath); diff --git a/test/scripts/console/config.js b/test/scripts/console/config.js index 2cb6c62b28..eaca427ab6 100644 --- a/test/scripts/console/config.js +++ b/test/scripts/console/config.js @@ -1,16 +1,16 @@ -var should = require('chai').should(); // eslint-disable-line -var fs = require('hexo-fs'); -var pathFn = require('path'); -var yaml = require('js-yaml'); -var _ = require('lodash'); -var rewire = require('rewire'); -var sinon = require('sinon'); +const should = require('chai').should(); // eslint-disable-line +const fs = require('hexo-fs'); +const pathFn = require('path'); +const yaml = require('js-yaml'); +const _ = require('lodash'); +const rewire = require('rewire'); +const sinon = require('sinon'); describe('config', () => { - var Hexo = require('../../../lib/hexo'); - var hexo = new Hexo(pathFn.join(__dirname, 'config_test'), {silent: true}); - var config = require('../../../lib/plugins/console/config').bind(hexo); - var configModule = rewire('../../../lib/plugins/console/config'); + const Hexo = require('../../../lib/hexo'); + const hexo = new Hexo(pathFn.join(__dirname, 'config_test'), {silent: true}); + const config = require('../../../lib/plugins/console/config').bind(hexo); + const configModule = rewire('../../../lib/plugins/console/config'); before(() => fs.mkdirs(hexo.base_dir).then(() => hexo.init())); @@ -19,7 +19,7 @@ describe('config', () => { after(() => fs.rmdir(hexo.base_dir)); it('read all config', () => { - var spy = sinon.spy(); + const spy = sinon.spy(); return configModule.__with__({ console: { @@ -31,7 +31,7 @@ describe('config', () => { }); it('read config', () => { - var spy = sinon.spy(); + const spy = sinon.spy(); return configModule.__with__({ console: { @@ -43,7 +43,7 @@ describe('config', () => { }); it('read nested config', () => { - var spy = sinon.spy(); + const spy = sinon.spy(); hexo.config.server = { port: 12345 @@ -61,7 +61,7 @@ describe('config', () => { }); function writeConfig() { - var args = _.toArray(arguments); + const args = _.toArray(arguments); return config({_: args}).then(() => fs.readFile(hexo.config_path)).then(content => yaml.load(content)); } @@ -91,10 +91,10 @@ describe('config', () => { })); it('write config: json', () => { - var configPath = hexo.config_path = pathFn.join(hexo.base_dir, '_config.json'); + const configPath = hexo.config_path = pathFn.join(hexo.base_dir, '_config.json'); return fs.writeFile(configPath, '{}').then(() => config({_: ['title', 'My Blog']})).then(() => fs.readFile(configPath)).then(content => { - var json = JSON.parse(content); + const json = JSON.parse(content); json.title.should.eql('My Blog'); diff --git a/test/scripts/console/deploy.js b/test/scripts/console/deploy.js index bf97ecdbed..1a9485550d 100644 --- a/test/scripts/console/deploy.js +++ b/test/scripts/console/deploy.js @@ -1,12 +1,12 @@ -var should = require('chai').should(); // eslint-disable-line -var fs = require('hexo-fs'); -var pathFn = require('path'); -var sinon = require('sinon'); +const should = require('chai').should(); // eslint-disable-line +const fs = require('hexo-fs'); +const pathFn = require('path'); +const sinon = require('sinon'); describe('deploy', () => { - var Hexo = require('../../../lib/hexo'); - var hexo = new Hexo(pathFn.join(__dirname, 'deploy_test'), {silent: true}); - var deploy = require('../../../lib/plugins/console/deploy').bind(hexo); + const Hexo = require('../../../lib/hexo'); + const hexo = new Hexo(pathFn.join(__dirname, 'deploy_test'), {silent: true}); + const deploy = require('../../../lib/plugins/console/deploy').bind(hexo); before(() => fs.mkdirs(hexo.public_dir).then(() => hexo.init())); @@ -23,7 +23,7 @@ describe('deploy', () => { foo: 'bar' }; - var deployer = sinon.spy(args => { + const deployer = sinon.spy(args => { args.should.eql({ type: 'foo', foo: 'foo', @@ -31,8 +31,8 @@ describe('deploy', () => { }); }); - var beforeListener = sinon.spy(); - var afterListener = sinon.spy(); + const beforeListener = sinon.spy(); + const afterListener = sinon.spy(); hexo.once('deployBefore', beforeListener); hexo.once('deployAfter', afterListener); @@ -46,7 +46,7 @@ describe('deploy', () => { }); it('multiple deploy setting', () => { - var deployer1 = sinon.spy(args => { + const deployer1 = sinon.spy(args => { args.should.eql({ type: 'foo', foo: 'foo', @@ -54,7 +54,7 @@ describe('deploy', () => { }); }); - var deployer2 = sinon.spy(args => { + const deployer2 = sinon.spy(args => { args.should.eql({ type: 'bar', bar: 'bar', diff --git a/test/scripts/console/generate.js b/test/scripts/console/generate.js index 5ad15ad884..cb5377b4ca 100644 --- a/test/scripts/console/generate.js +++ b/test/scripts/console/generate.js @@ -1,14 +1,13 @@ -var should = require('chai').should(); // eslint-disable-line -var pathFn = require('path'); -var fs = require('hexo-fs'); -var Promise = require('bluebird'); -var sinon = require('sinon'); +const should = require('chai').should(); // eslint-disable-line +const pathFn = require('path'); +const fs = require('hexo-fs'); +const Promise = require('bluebird'); +const sinon = require('sinon'); describe('generate', () => { - var Hexo = require('../../../lib/hexo'); - var generateConsole = require('../../../lib/plugins/console/generate'); - var hexo, - generate; + const Hexo = require('../../../lib/hexo'); + const generateConsole = require('../../../lib/plugins/console/generate'); + let hexo, generate; beforeEach(() => { hexo = new Hexo(pathFn.join(__dirname, 'generate_test'), {silent: true}); @@ -50,9 +49,9 @@ describe('generate', () => { it('default', () => testGenerate()); it('write file if not exist', () => { - var src = pathFn.join(hexo.source_dir, 'test.txt'); - var dest = pathFn.join(hexo.public_dir, 'test.txt'); - var content = 'test'; + const src = pathFn.join(hexo.source_dir, 'test.txt'); + const dest = pathFn.join(hexo.public_dir, 'test.txt'); + const content = 'test'; // Add some source files return fs.writeFile(src, content).then(() => // First generation @@ -70,10 +69,10 @@ describe('generate', () => { }); it('don\'t write if file unchanged', () => { - var src = pathFn.join(hexo.source_dir, 'test.txt'); - var dest = pathFn.join(hexo.public_dir, 'test.txt'); - var content = 'test'; - var newContent = 'newtest'; + const src = pathFn.join(hexo.source_dir, 'test.txt'); + const dest = pathFn.join(hexo.public_dir, 'test.txt'); + const content = 'test'; + const newContent = 'newtest'; // Add some source files return fs.writeFile(src, content).then(() => // First generation @@ -93,10 +92,10 @@ describe('generate', () => { }); it('force regenerate', () => { - var src = pathFn.join(hexo.source_dir, 'test.txt'); - var dest = pathFn.join(hexo.public_dir, 'test.txt'); - var content = 'test'; - var mtime; + const src = pathFn.join(hexo.source_dir, 'test.txt'); + const dest = pathFn.join(hexo.public_dir, 'test.txt'); + const content = 'test'; + let mtime; return fs.writeFile(src, content).then(() => // First generation generate()).then(() => // Read file status @@ -115,9 +114,9 @@ describe('generate', () => { }); it('watch - update', () => { - var src = pathFn.join(hexo.source_dir, 'test.txt'); - var dest = pathFn.join(hexo.public_dir, 'test.txt'); - var content = 'test'; + const src = pathFn.join(hexo.source_dir, 'test.txt'); + const dest = pathFn.join(hexo.public_dir, 'test.txt'); + const content = 'test'; return testGenerate({watch: true}).then(() => // Update the file fs.writeFile(src, content)).delay(300).then(() => fs.readFile(dest)).then(result => { @@ -137,7 +136,7 @@ describe('generate', () => { })); it('deploy', () => { - var deployer = sinon.spy(); + const deployer = sinon.spy(); hexo.extend.deployer.register('test', deployer); @@ -219,7 +218,7 @@ describe('generate', () => { ] ); - var errorCallback = sinon.spy(err => { + const errorCallback = sinon.spy(err => { err.should.have.property('message', 'Testing unhandled exception'); }); diff --git a/test/scripts/console/list_categories.js b/test/scripts/console/list_categories.js index 07f6e88ae1..822bc312a1 100644 --- a/test/scripts/console/list_categories.js +++ b/test/scripts/console/list_categories.js @@ -1,18 +1,18 @@ 'use strict'; -var Promise = require('bluebird'); -var sinon = require('sinon'); -var expect = require('chai').expect; +const Promise = require('bluebird'); +const sinon = require('sinon'); +const expect = require('chai').expect; describe('Console list', () => { - var Hexo = require('../../../lib/hexo'); - var hexo = new Hexo(__dirname); - var Post = hexo.model('Post'); + const Hexo = require('../../../lib/hexo'); + const hexo = new Hexo(__dirname); + const Post = hexo.model('Post'); - var listCategories = require('../../../lib/plugins/console/list/category').bind(hexo); + const listCategories = require('../../../lib/plugins/console/list/category').bind(hexo); before(() => { - var log = console.log; + const log = console.log; sinon.stub(console, 'log').callsFake(function(...args) { return log.apply(log, args); }); @@ -30,7 +30,7 @@ describe('Console list', () => { }); it('categories', () => { - var posts = [ + const posts = [ {source: 'foo', slug: 'foo', title: 'Its', date: 1e8}, {source: 'bar', slug: 'bar', title: 'Math', date: 1e8 + 1}, {source: 'baz', slug: 'baz', title: 'Dude', date: 1e8 - 1} diff --git a/test/scripts/console/list_page.js b/test/scripts/console/list_page.js index 5783d0bd98..d4f2afd1c5 100644 --- a/test/scripts/console/list_page.js +++ b/test/scripts/console/list_page.js @@ -1,17 +1,17 @@ 'use strict'; -var sinon = require('sinon'); -var expect = require('chai').expect; +const sinon = require('sinon'); +const expect = require('chai').expect; describe('Console list', () => { - var Hexo = require('../../../lib/hexo'); - var hexo = new Hexo(); - var Page = hexo.model('Page'); - var listPages = require('../../../lib/plugins/console/list/page').bind(hexo); + const Hexo = require('../../../lib/hexo'); + const hexo = new Hexo(); + const Page = hexo.model('Page'); + const listPages = require('../../../lib/plugins/console/list/page').bind(hexo); hexo.config.permalink = ':title/'; before(() => { - var log = console.log; + const log = console.log; sinon.stub(console, 'log').callsFake(function(...args) { return log.apply(log, args); }); diff --git a/test/scripts/console/list_post.js b/test/scripts/console/list_post.js index 6b5cecf816..96f424fdfb 100644 --- a/test/scripts/console/list_post.js +++ b/test/scripts/console/list_post.js @@ -1,17 +1,17 @@ 'use strict'; -var sinon = require('sinon'); -var expect = require('chai').expect; +const sinon = require('sinon'); +const expect = require('chai').expect; describe('Console list', () => { - var Hexo = require('../../../lib/hexo'); - var hexo = new Hexo(__dirname); - var Post = hexo.model('Post'); + const Hexo = require('../../../lib/hexo'); + const hexo = new Hexo(__dirname); + const Post = hexo.model('Post'); - var listPosts = require('../../../lib/plugins/console/list/post').bind(hexo); + const listPosts = require('../../../lib/plugins/console/list/post').bind(hexo); before(() => { - var log = console.log; + const log = console.log; sinon.stub(console, 'log').callsFake(function(...args) { return log.apply(log, args); }); @@ -32,7 +32,7 @@ describe('Console list', () => { }); it('post', () => { - var posts = [ + const posts = [ {source: 'foo', slug: 'foo', title: 'Its', date: 1e8}, {source: 'bar', slug: 'bar', title: 'Math', date: 1e8 + 1}, {source: 'baz', slug: 'baz', title: 'Dude', date: 1e8 - 1} @@ -48,7 +48,7 @@ describe('Console list', () => { expect(console.log.calledWith(sinon.match('Path'))).to.be.true; expect(console.log.calledWith(sinon.match('Category'))).to.be.true; expect(console.log.calledWith(sinon.match('Tags'))).to.be.true; - for (var i = 0; i < posts.length; i++) { + for (let i = 0; i < posts.length; i++) { expect(console.log.calledWith(sinon.match(posts[i].source))).to.be.true; expect(console.log.calledWith(sinon.match(posts[i].slug))).to.be.true; expect(console.log.calledWith(sinon.match(posts[i].title))).to.be.true; diff --git a/test/scripts/console/list_tags.js b/test/scripts/console/list_tags.js index 8cb395cac8..50b38419f1 100644 --- a/test/scripts/console/list_tags.js +++ b/test/scripts/console/list_tags.js @@ -1,19 +1,19 @@ 'use strict'; -var Promise = require('bluebird'); -var sinon = require('sinon'); -var expect = require('chai').expect; +const Promise = require('bluebird'); +const sinon = require('sinon'); +const expect = require('chai').expect; describe('Console list', () => { - var Hexo = require('../../../lib/hexo'); - var hexo = new Hexo(__dirname); - var Post = hexo.model('Post'); + const Hexo = require('../../../lib/hexo'); + const hexo = new Hexo(__dirname); + const Post = hexo.model('Post'); - var listTags = require('../../../lib/plugins/console/list/tag').bind(hexo); + const listTags = require('../../../lib/plugins/console/list/tag').bind(hexo); hexo.config.permalink = ':title/'; before(() => { - var log = console.log; + const log = console.log; sinon.stub(console, 'log').callsFake(function(...args) { return log.apply(log, args); }); @@ -32,7 +32,7 @@ describe('Console list', () => { }); it('tags', () => { - var posts = [ + const posts = [ {source: 'foo', slug: 'foo', title: 'Its', date: 1e8}, {source: 'bar', slug: 'bar', title: 'Math', date: 1e8 + 1}, {source: 'baz', slug: 'baz', title: 'Dude', date: 1e8 - 1} diff --git a/test/scripts/console/migrate.js b/test/scripts/console/migrate.js index e530b696ed..73ceb01547 100644 --- a/test/scripts/console/migrate.js +++ b/test/scripts/console/migrate.js @@ -1,13 +1,13 @@ -var should = require('chai').should(); // eslint-disable-line -var sinon = require('sinon'); +const should = require('chai').should(); // eslint-disable-line +const sinon = require('sinon'); describe('migrate', () => { - var Hexo = require('../../../lib/hexo'); - var hexo = new Hexo(__dirname, {silent: true}); - var migrate = require('../../../lib/plugins/console/migrate').bind(hexo); + const Hexo = require('../../../lib/hexo'); + const hexo = new Hexo(__dirname, {silent: true}); + const migrate = require('../../../lib/plugins/console/migrate').bind(hexo); it('default', () => { - var migrator = sinon.spy(args => { + const migrator = sinon.spy(args => { args.foo.should.eql(1); args.bar.should.eql(2); }); diff --git a/test/scripts/console/new.js b/test/scripts/console/new.js index 19384a04dc..3d430b887b 100644 --- a/test/scripts/console/new.js +++ b/test/scripts/console/new.js @@ -1,17 +1,17 @@ -var should = require('chai').should(); // eslint-disable-line -var fs = require('hexo-fs'); -var moment = require('moment'); -var pathFn = require('path'); -var Promise = require('bluebird'); -var sinon = require('sinon'); +const should = require('chai').should(); // eslint-disable-line +const fs = require('hexo-fs'); +const moment = require('moment'); +const pathFn = require('path'); +const Promise = require('bluebird'); +const sinon = require('sinon'); describe('new', () => { - var Hexo = require('../../../lib/hexo'); - var hexo = new Hexo(pathFn.join(__dirname, 'new_test'), {silent: true}); - var n = require('../../../lib/plugins/console/new').bind(hexo); - var post = hexo.post; - var now = Date.now(); - var clock; + const Hexo = require('../../../lib/hexo'); + const hexo = new Hexo(pathFn.join(__dirname, 'new_test'), {silent: true}); + const n = require('../../../lib/plugins/console/new').bind(hexo); + const post = hexo.post; + const now = Date.now(); + let clock; before(() => { clock = sinon.useFakeTimers(now); @@ -34,9 +34,9 @@ describe('new', () => { }); it('title', () => { - var date = moment(now); - var path = pathFn.join(hexo.source_dir, '_posts', 'Hello-World.md'); - var body = [ + const date = moment(now); + const path = pathFn.join(hexo.source_dir, '_posts', 'Hello-World.md'); + const body = [ 'title: Hello World', 'date: ' + date.format('YYYY-MM-DD HH:mm:ss'), 'tags:', @@ -52,8 +52,8 @@ describe('new', () => { }); it('layout', () => { - var path = pathFn.join(hexo.source_dir, '_drafts', 'Hello-World.md'); - var body = [ + const path = pathFn.join(hexo.source_dir, '_drafts', 'Hello-World.md'); + const body = [ 'title: Hello World', 'tags:', '---' @@ -68,9 +68,9 @@ describe('new', () => { }); it('slug', () => { - var date = moment(now); - var path = pathFn.join(hexo.source_dir, '_posts', 'foo.md'); - var body = [ + const date = moment(now); + const path = pathFn.join(hexo.source_dir, '_posts', 'foo.md'); + const body = [ 'title: Hello World', 'date: ' + date.format('YYYY-MM-DD HH:mm:ss'), 'tags:', @@ -87,9 +87,9 @@ describe('new', () => { }); it('path', () => { - var date = moment(now); - var path = pathFn.join(hexo.source_dir, '_posts', 'bar.md'); - var body = [ + const date = moment(now); + const path = pathFn.join(hexo.source_dir, '_posts', 'bar.md'); + const body = [ 'title: Hello World', 'date: ' + date.format('YYYY-MM-DD HH:mm:ss'), 'tags:', @@ -107,7 +107,7 @@ describe('new', () => { }); it('rename if target existed', () => { - var path = pathFn.join(hexo.source_dir, '_posts', 'Hello-World-1.md'); + const path = pathFn.join(hexo.source_dir, '_posts', 'Hello-World-1.md'); return post.create({ title: 'Hello World' @@ -124,7 +124,7 @@ describe('new', () => { }); it('replace existing files', () => { - var path = pathFn.join(hexo.source_dir, '_posts', 'Hello-World.md'); + const path = pathFn.join(hexo.source_dir, '_posts', 'Hello-World.md'); return post.create({ title: 'Hello World' @@ -138,9 +138,9 @@ describe('new', () => { }); it('extra data', () => { - var date = moment(now); - var path = pathFn.join(hexo.source_dir, '_posts', 'Hello-World.md'); - var body = [ + const date = moment(now); + const path = pathFn.join(hexo.source_dir, '_posts', 'Hello-World.md'); + const body = [ 'title: Hello World', 'foo: bar', 'date: ' + date.format('YYYY-MM-DD HH:mm:ss'), diff --git a/test/scripts/console/publish.js b/test/scripts/console/publish.js index 29aed5e15e..f470a10a14 100644 --- a/test/scripts/console/publish.js +++ b/test/scripts/console/publish.js @@ -1,17 +1,17 @@ -var should = require('chai').should(); // eslint-disable-line -var fs = require('hexo-fs'); -var moment = require('moment'); -var pathFn = require('path'); -var Promise = require('bluebird'); -var sinon = require('sinon'); +const should = require('chai').should(); // eslint-disable-line +const fs = require('hexo-fs'); +const moment = require('moment'); +const pathFn = require('path'); +const Promise = require('bluebird'); +const sinon = require('sinon'); describe('publish', () => { - var Hexo = require('../../../lib/hexo'); - var hexo = new Hexo(pathFn.join(__dirname, 'publish_test'), {silent: true}); - var publish = require('../../../lib/plugins/console/publish').bind(hexo); - var post = hexo.post; - var now = Date.now(); - var clock; + const Hexo = require('../../../lib/hexo'); + const hexo = new Hexo(pathFn.join(__dirname, 'publish_test'), {silent: true}); + const publish = require('../../../lib/plugins/console/publish').bind(hexo); + const post = hexo.post; + const now = Date.now(); + let clock; before(() => { clock = sinon.useFakeTimers(now); @@ -41,11 +41,11 @@ describe('publish', () => { })); it('slug', () => { - var draftPath = pathFn.join(hexo.source_dir, '_drafts', 'Hello-World.md'); - var path = pathFn.join(hexo.source_dir, '_posts', 'Hello-World.md'); - var date = moment(now); + const draftPath = pathFn.join(hexo.source_dir, '_drafts', 'Hello-World.md'); + const path = pathFn.join(hexo.source_dir, '_posts', 'Hello-World.md'); + const date = moment(now); - var content = [ + const content = [ '---', 'title: Hello World', 'date: ' + date.format('YYYY-MM-DD HH:mm:ss'), @@ -67,10 +67,10 @@ describe('publish', () => { }); it('layout', () => { - var path = pathFn.join(hexo.source_dir, '_posts', 'Hello-World.md'); - var date = moment(now); + const path = pathFn.join(hexo.source_dir, '_posts', 'Hello-World.md'); + const date = moment(now); - var content = [ + const content = [ '---', 'layout: photo', 'title: Hello World', @@ -88,7 +88,7 @@ describe('publish', () => { }); it('rename if target existed', () => { - var path = pathFn.join(hexo.source_dir, '_posts', 'Hello-World-1.md'); + const path = pathFn.join(hexo.source_dir, '_posts', 'Hello-World-1.md'); return post.create({ title: 'Hello World' @@ -105,7 +105,7 @@ describe('publish', () => { }); it('replace existing target', () => { - var path = pathFn.join(hexo.source_dir, '_posts', 'Hello-World.md'); + const path = pathFn.join(hexo.source_dir, '_posts', 'Hello-World.md'); return post.create({ title: 'Hello World' diff --git a/test/scripts/console/render.js b/test/scripts/console/render.js index e9ad1dc287..7b90ad1816 100644 --- a/test/scripts/console/render.js +++ b/test/scripts/console/render.js @@ -1,26 +1,26 @@ -var should = require('chai').should(); // eslint-disable-line -var fs = require('hexo-fs'); -var pathFn = require('path'); -var Promise = require('bluebird'); +const should = require('chai').should(); // eslint-disable-line +const fs = require('hexo-fs'); +const pathFn = require('path'); +const Promise = require('bluebird'); describe('render', () => { - var Hexo = require('../../../lib/hexo'); - var hexo = new Hexo(pathFn.join(__dirname, 'render_test'), {silent: true}); - var render = require('../../../lib/plugins/console/render').bind(hexo); + const Hexo = require('../../../lib/hexo'); + const hexo = new Hexo(pathFn.join(__dirname, 'render_test'), {silent: true}); + const render = require('../../../lib/plugins/console/render').bind(hexo); before(() => fs.mkdirs(hexo.base_dir).then(() => hexo.init())); after(() => fs.rmdir(hexo.base_dir)); - var body = [ + const body = [ 'foo: 1', 'bar:', ' boo: 2' ].join('\n'); it('relative path', () => { - var src = pathFn.join(hexo.base_dir, 'test.yml'); - var dest = pathFn.join(hexo.base_dir, 'result.json'); + const src = pathFn.join(hexo.base_dir, 'test.yml'); + const dest = pathFn.join(hexo.base_dir, 'result.json'); return fs.writeFile(src, body).then(() => render({_: ['test.yml'], output: 'result.json'})).then(() => fs.readFile(dest)).then(result => { JSON.parse(result).should.eql({ @@ -38,8 +38,8 @@ describe('render', () => { }); it('absolute path', () => { - var src = pathFn.join(hexo.base_dir, 'test.yml'); - var dest = pathFn.join(hexo.base_dir, 'result.json'); + const src = pathFn.join(hexo.base_dir, 'test.yml'); + const dest = pathFn.join(hexo.base_dir, 'result.json'); return fs.writeFile(src, body).then(() => render({_: [src], output: 'result.json'})).then(() => fs.readFile(dest)).then(result => { JSON.parse(result).should.eql({ @@ -57,8 +57,8 @@ describe('render', () => { }); it('absolute output', () => { - var src = pathFn.join(hexo.base_dir, 'test.yml'); - var dest = pathFn.join(hexo.base_dir, 'result.json'); + const src = pathFn.join(hexo.base_dir, 'test.yml'); + const dest = pathFn.join(hexo.base_dir, 'result.json'); return fs.writeFile(src, body).then(() => render({_: ['test.yml'], output: dest})).then(() => fs.readFile(dest)).then(result => { JSON.parse(result).should.eql({ @@ -78,8 +78,8 @@ describe('render', () => { it('output'); it('engine', () => { - var src = pathFn.join(hexo.base_dir, 'test'); - var dest = pathFn.join(hexo.base_dir, 'result.json'); + const src = pathFn.join(hexo.base_dir, 'test'); + const dest = pathFn.join(hexo.base_dir, 'result.json'); return fs.writeFile(src, body).then(() => render({_: ['test'], output: 'result.json', engine: 'yaml'})).then(() => fs.readFile(dest)).then(result => { JSON.parse(result).should.eql({ @@ -97,8 +97,8 @@ describe('render', () => { }); it('pretty', () => { - var src = pathFn.join(hexo.base_dir, 'test.yml'); - var dest = pathFn.join(hexo.base_dir, 'result.json'); + const src = pathFn.join(hexo.base_dir, 'test.yml'); + const dest = pathFn.join(hexo.base_dir, 'result.json'); return fs.writeFile(src, body).then(() => render({_: ['test.yml'], output: 'result.json', pretty: true})).then(() => fs.readFile(dest)).then(result => { result.should.eql(JSON.stringify({ diff --git a/test/scripts/extend/console.js b/test/scripts/extend/console.js index f380ce369d..f8f7a313f2 100644 --- a/test/scripts/extend/console.js +++ b/test/scripts/extend/console.js @@ -1,10 +1,10 @@ -var should = require('chai').should(); // eslint-disable-line +const should = require('chai').should(); // eslint-disable-line describe('Console', () => { - var Console = require('../../../lib/extend/console'); + const Console = require('../../../lib/extend/console'); it('register()', () => { - var c = new Console(); + const c = new Console(); // no name try { @@ -62,7 +62,7 @@ describe('Console', () => { }); it('register() - alias', () => { - var c = new Console(); + const c = new Console(); c.register('test', () => {}); @@ -75,7 +75,7 @@ describe('Console', () => { }); it('register() - promisify', () => { - var c = new Console(); + const c = new Console(); c.register('test', (args, callback) => { args.should.eql({foo: 'bar'}); @@ -90,7 +90,7 @@ describe('Console', () => { }); it('list()', () => { - var c = new Console(); + const c = new Console(); c.register('test', () => {}); @@ -98,7 +98,7 @@ describe('Console', () => { }); it('get()', () => { - var c = new Console(); + const c = new Console(); c.register('test', () => {}); diff --git a/test/scripts/extend/deployer.js b/test/scripts/extend/deployer.js index 864cbffe9c..54b287018a 100644 --- a/test/scripts/extend/deployer.js +++ b/test/scripts/extend/deployer.js @@ -1,10 +1,10 @@ -var should = require('chai').should(); // eslint-disable-line +const should = require('chai').should(); // eslint-disable-line describe('Deployer', () => { - var Deployer = require('../../../lib/extend/deployer'); + const Deployer = require('../../../lib/extend/deployer'); it('register()', () => { - var d = new Deployer(); + const d = new Deployer(); // name, fn d.register('test', () => {}); @@ -31,7 +31,7 @@ describe('Deployer', () => { }); it('register() - promisify', () => { - var d = new Deployer(); + const d = new Deployer(); d.register('test', (args, callback) => { args.should.eql({foo: 'bar'}); @@ -46,7 +46,7 @@ describe('Deployer', () => { }); it('register() - Promise.method', () => { - var d = new Deployer(); + const d = new Deployer(); d.register('test', args => { args.should.eql({foo: 'bar'}); @@ -61,7 +61,7 @@ describe('Deployer', () => { }); it('list()', () => { - var d = new Deployer(); + const d = new Deployer(); d.register('test', () => {}); @@ -69,7 +69,7 @@ describe('Deployer', () => { }); it('get()', () => { - var d = new Deployer(); + const d = new Deployer(); d.register('test', () => {}); diff --git a/test/scripts/extend/filter.js b/test/scripts/extend/filter.js index 94ab37c001..0741760c4c 100644 --- a/test/scripts/extend/filter.js +++ b/test/scripts/extend/filter.js @@ -1,11 +1,11 @@ -var should = require('chai').should(); // eslint-disable-line -var sinon = require('sinon'); +const should = require('chai').should(); // eslint-disable-line +const sinon = require('sinon'); describe('Filter', () => { - var Filter = require('../../../lib/extend/filter'); + const Filter = require('../../../lib/extend/filter'); it('register()', () => { - var f = new Filter(); + const f = new Filter(); // type, fn f.register('test', () => {}); @@ -40,7 +40,7 @@ describe('Filter', () => { }); it('register() - type alias', () => { - var f = new Filter(); + const f = new Filter(); // pre f.register('pre', () => {}); @@ -54,7 +54,7 @@ describe('Filter', () => { }); it('register() - priority', () => { - var f = new Filter(); + const f = new Filter(); f.register('test', () => {}); @@ -66,8 +66,8 @@ describe('Filter', () => { }); it('unregister()', () => { - var f = new Filter(); - var filter = sinon.spy(); + const f = new Filter(); + const filter = sinon.spy(); f.register('test', filter); f.unregister('test', filter); @@ -78,8 +78,8 @@ describe('Filter', () => { }); it('unregister() - type is required', () => { - var f = new Filter(); - var errorCallback = sinon.spy(err => { + const f = new Filter(); + const errorCallback = sinon.spy(err => { err.should.have.property('message', 'type is required'); }); @@ -93,8 +93,8 @@ describe('Filter', () => { }); it('unregister() - fn must be a function', () => { - var f = new Filter(); - var errorCallback = sinon.spy(err => { + const f = new Filter(); + const errorCallback = sinon.spy(err => { err.should.have.property('message', 'fn must be a function'); }); @@ -108,7 +108,7 @@ describe('Filter', () => { }); it('list()', () => { - var f = new Filter(); + const f = new Filter(); f.register('test', () => {}); @@ -117,14 +117,14 @@ describe('Filter', () => { }); it('exec()', () => { - var f = new Filter(); + const f = new Filter(); - var filter1 = sinon.spy(data => { + const filter1 = sinon.spy(data => { data.should.eql(''); return data + 'foo'; }); - var filter2 = sinon.spy(data => { + const filter2 = sinon.spy(data => { filter1.calledOnce.should.be.true; data.should.eql('foo'); return data + 'bar'; @@ -141,14 +141,14 @@ describe('Filter', () => { }); it('exec() - pointer', () => { - var f = new Filter(); + const f = new Filter(); - var filter1 = sinon.spy(data => { + const filter1 = sinon.spy(data => { data.should.eql({}); data.foo = 1; }); - var filter2 = sinon.spy(data => { + const filter2 = sinon.spy(data => { filter1.calledOnce.should.be.true; data.should.eql({foo: 1}); data.bar = 2; @@ -165,14 +165,14 @@ describe('Filter', () => { }); it('exec() - args', () => { - var f = new Filter(); + const f = new Filter(); - var filter1 = sinon.spy((data, arg1, arg2) => { + const filter1 = sinon.spy((data, arg1, arg2) => { arg1.should.eql(1); arg2.should.eql(2); }); - var filter2 = sinon.spy((data, arg1, arg2) => { + const filter2 = sinon.spy((data, arg1, arg2) => { arg1.should.eql(1); arg2.should.eql(2); }); @@ -189,14 +189,14 @@ describe('Filter', () => { }); it('exec() - context', () => { - var f = new Filter(); - var ctx = {foo: 1, bar: 2}; + const f = new Filter(); + const ctx = {foo: 1, bar: 2}; - var filter1 = sinon.spy(function(data) { + const filter1 = sinon.spy(function(data) { this.should.eql(ctx); }); - var filter2 = sinon.spy(function(data) { + const filter2 = sinon.spy(function(data) { this.should.eql(ctx); }); @@ -210,14 +210,14 @@ describe('Filter', () => { }); it('execSync()', () => { - var f = new Filter(); + const f = new Filter(); - var filter1 = sinon.spy(data => { + const filter1 = sinon.spy(data => { data.should.eql(''); return data + 'foo'; }); - var filter2 = sinon.spy(data => { + const filter2 = sinon.spy(data => { filter1.calledOnce.should.be.true; data.should.eql('foo'); return data + 'bar'; @@ -232,14 +232,14 @@ describe('Filter', () => { }); it('execSync() - pointer', () => { - var f = new Filter(); + const f = new Filter(); - var filter1 = sinon.spy(data => { + const filter1 = sinon.spy(data => { data.should.eql({}); data.foo = 1; }); - var filter2 = sinon.spy(data => { + const filter2 = sinon.spy(data => { filter1.calledOnce.should.be.true; data.should.eql({foo: 1}); data.bar = 2; @@ -254,14 +254,14 @@ describe('Filter', () => { }); it('execSync() - args', () => { - var f = new Filter(); + const f = new Filter(); - var filter1 = sinon.spy((data, arg1, arg2) => { + const filter1 = sinon.spy((data, arg1, arg2) => { arg1.should.eql(1); arg2.should.eql(2); }); - var filter2 = sinon.spy((data, arg1, arg2) => { + const filter2 = sinon.spy((data, arg1, arg2) => { arg1.should.eql(1); arg2.should.eql(2); }); @@ -278,14 +278,14 @@ describe('Filter', () => { }); it('execSync() - context', () => { - var f = new Filter(); - var ctx = {foo: 1, bar: 2}; + const f = new Filter(); + const ctx = {foo: 1, bar: 2}; - var filter1 = sinon.spy(function(data) { + const filter1 = sinon.spy(function(data) { this.should.eql(ctx); }); - var filter2 = sinon.spy(function(data) { + const filter2 = sinon.spy(function(data) { this.should.eql(ctx); }); diff --git a/test/scripts/extend/generator.js b/test/scripts/extend/generator.js index 245d6578e8..87f9432975 100644 --- a/test/scripts/extend/generator.js +++ b/test/scripts/extend/generator.js @@ -1,10 +1,10 @@ -var should = require('chai').should(); // eslint-disable-line +const should = require('chai').should(); // eslint-disable-line describe('Generator', () => { - var Generator = require('../../../lib/extend/generator'); + const Generator = require('../../../lib/extend/generator'); it('register()', () => { - var g = new Generator(); + const g = new Generator(); // name, fn g.register('test', () => {}); @@ -27,7 +27,7 @@ describe('Generator', () => { }); it('register() - promisify', () => { - var g = new Generator(); + const g = new Generator(); g.register('test', (locals, render, callback) => { callback(null, 'foo'); @@ -39,7 +39,7 @@ describe('Generator', () => { }); it('get()', () => { - var g = new Generator(); + const g = new Generator(); g.register('test', () => {}); @@ -47,7 +47,7 @@ describe('Generator', () => { }); it('list()', () => { - var g = new Generator(); + const g = new Generator(); g.register('test', () => {}); diff --git a/test/scripts/extend/helper.js b/test/scripts/extend/helper.js index 8b9b961cf5..bbafafd673 100644 --- a/test/scripts/extend/helper.js +++ b/test/scripts/extend/helper.js @@ -1,10 +1,10 @@ -var should = require('chai').should(); // eslint-disable-line +const should = require('chai').should(); // eslint-disable-line describe('Helper', () => { - var Helper = require('../../../lib/extend/helper'); + const Helper = require('../../../lib/extend/helper'); it('register()', () => { - var h = new Helper(); + const h = new Helper(); // name, fn h.register('test', () => {}); @@ -31,7 +31,7 @@ describe('Helper', () => { }); it('list()', () => { - var h = new Helper(); + const h = new Helper(); h.register('test', () => {}); @@ -39,7 +39,7 @@ describe('Helper', () => { }); it('get()', () => { - var h = new Helper(); + const h = new Helper(); h.register('test', () => {}); diff --git a/test/scripts/extend/migrator.js b/test/scripts/extend/migrator.js index c4750b0759..7a63c095ac 100644 --- a/test/scripts/extend/migrator.js +++ b/test/scripts/extend/migrator.js @@ -1,10 +1,10 @@ -var should = require('chai').should(); // eslint-disable-line +const should = require('chai').should(); // eslint-disable-line describe('Migrator', () => { - var Migrator = require('../../../lib/extend/migrator'); + const Migrator = require('../../../lib/extend/migrator'); it('register()', () => { - var d = new Migrator(); + const d = new Migrator(); // name, fn d.register('test', () => {}); @@ -31,7 +31,7 @@ describe('Migrator', () => { }); it('register() - promisify', () => { - var d = new Migrator(); + const d = new Migrator(); d.register('test', (args, callback) => { args.should.eql({foo: 'bar'}); @@ -46,7 +46,7 @@ describe('Migrator', () => { }); it('register() - Promise.method', () => { - var d = new Migrator(); + const d = new Migrator(); d.register('test', args => { args.should.eql({foo: 'bar'}); @@ -61,7 +61,7 @@ describe('Migrator', () => { }); it('list()', () => { - var d = new Migrator(); + const d = new Migrator(); d.register('test', () => {}); @@ -69,7 +69,7 @@ describe('Migrator', () => { }); it('get()', () => { - var d = new Migrator(); + const d = new Migrator(); d.register('test', () => {}); diff --git a/test/scripts/extend/processor.js b/test/scripts/extend/processor.js index 07acd2b56e..b81d3a2530 100644 --- a/test/scripts/extend/processor.js +++ b/test/scripts/extend/processor.js @@ -1,10 +1,10 @@ -var should = require('chai').should(); // eslint-disable-line +const should = require('chai').should(); // eslint-disable-line describe('Processor', () => { - var Processor = require('../../../lib/extend/processor'); + const Processor = require('../../../lib/extend/processor'); it('register()', () => { - var p = new Processor(); + const p = new Processor(); // pattern, fn p.register('test', () => {}); @@ -27,7 +27,7 @@ describe('Processor', () => { }); it('list()', () => { - var p = new Processor(); + const p = new Processor(); p.register('test', () => {}); diff --git a/test/scripts/extend/renderer.js b/test/scripts/extend/renderer.js index baf57aa6f7..17e5b8bdec 100644 --- a/test/scripts/extend/renderer.js +++ b/test/scripts/extend/renderer.js @@ -1,10 +1,10 @@ -var should = require('chai').should(); // eslint-disable-line +const should = require('chai').should(); // eslint-disable-line describe('Renderer', () => { - var Renderer = require('../../../lib/extend/renderer'); + const Renderer = require('../../../lib/extend/renderer'); it('register()', () => { - var r = new Renderer(); + const r = new Renderer(); // name, output, fn r.register('yaml', 'json', () => {}); @@ -49,7 +49,7 @@ describe('Renderer', () => { }); it('register() - promisify', () => { - var r = new Renderer(); + const r = new Renderer(); // async r.register('yaml', 'json', (data, options, callback) => { @@ -69,7 +69,7 @@ describe('Renderer', () => { }); it('register() - compile', () => { - var r = new Renderer(); + const r = new Renderer(); function renderer(data, locals) {} @@ -82,7 +82,7 @@ describe('Renderer', () => { }); it('getOutput()', () => { - var r = new Renderer(); + const r = new Renderer(); r.register('yaml', 'json', () => {}); @@ -93,7 +93,7 @@ describe('Renderer', () => { }); it('isRenderable()', () => { - var r = new Renderer(); + const r = new Renderer(); r.register('yaml', 'json', () => {}); @@ -104,7 +104,7 @@ describe('Renderer', () => { }); it('isRenderableSync()', () => { - var r = new Renderer(); + const r = new Renderer(); r.register('yaml', 'json', () => {}); @@ -119,7 +119,7 @@ describe('Renderer', () => { }); it('get()', () => { - var r = new Renderer(); + const r = new Renderer(); r.register('yaml', 'json', () => {}); @@ -136,7 +136,7 @@ describe('Renderer', () => { }); it('list()', () => { - var r = new Renderer(); + const r = new Renderer(); r.register('yaml', 'json', () => {}); diff --git a/test/scripts/extend/tag.js b/test/scripts/extend/tag.js index 975e0d1125..902bac7900 100644 --- a/test/scripts/extend/tag.js +++ b/test/scripts/extend/tag.js @@ -1,13 +1,13 @@ -var should = require('chai').should(); // eslint-disable-line -var sinon = require('sinon'); -var Promise = require('bluebird'); +const should = require('chai').should(); // eslint-disable-line +const sinon = require('sinon'); +const Promise = require('bluebird'); describe('Tag', () => { - var Tag = require('../../../lib/extend/tag'); - var tag = new Tag(); + const Tag = require('../../../lib/extend/tag'); + const tag = new Tag(); it('register()', () => { - var tag = new Tag(); + const tag = new Tag(); tag.register('test', (args, content) => args.join(' ')); @@ -17,7 +17,7 @@ describe('Tag', () => { }); it('register() - async', () => { - var tag = new Tag(); + const tag = new Tag(); tag.register('test', (args, content) => Promise.resolve(args.join(' ')), {async: true}); @@ -27,11 +27,11 @@ describe('Tag', () => { }); it('register() - block', () => { - var tag = new Tag(); + const tag = new Tag(); tag.register('test', (args, content) => args.join(' ') + ' ' + content, true); - var str = [ + const str = [ '{% test foo bar %}', 'test content', '{% endtest %}' @@ -43,11 +43,11 @@ describe('Tag', () => { }); it('register() - async block', () => { - var tag = new Tag(); + const tag = new Tag(); tag.register('test', (args, content) => Promise.resolve(args.join(' ') + ' ' + content), {ends: true, async: true}); - var str = [ + const str = [ '{% test foo bar %}', 'test content', '{% endtest %}' @@ -59,11 +59,11 @@ describe('Tag', () => { }); it('register() - nested test', () => { - var tag = new Tag(); + const tag = new Tag(); tag.register('test', (args, content) => content, true); - var str = [ + const str = [ '{% test %}', '123456', ' {% raw %}', @@ -82,14 +82,14 @@ describe('Tag', () => { }); it('register() - nested async / async test', () => { - var tag = new Tag(); + const tag = new Tag(); tag.register('test', (args, content) => content, {ends: true, async: true}); tag.register('async', (args, content) => { return Promise.resolve(args.join(' ') + ' ' + content); }, {ends: true, async: true}); - var str = [ + const str = [ '{% test %}', '123456', ' {% async %}', @@ -105,11 +105,11 @@ describe('Tag', () => { }); it('register() - strip indention', () => { - var tag = new Tag(); + const tag = new Tag(); tag.register('test', (args, content) => content, true); - var str = [ + const str = [ '{% test %}', ' test content', '{% endtest %}' @@ -121,7 +121,7 @@ describe('Tag', () => { }); it('register() - async callback', () => { - var tag = new Tag(); + const tag = new Tag(); tag.register('test', (args, content, callback) => { callback(null, args.join(' ')); @@ -133,7 +133,7 @@ describe('Tag', () => { }); it('register() - name is required', () => { - var errorCallback = sinon.spy(err => { + const errorCallback = sinon.spy(err => { err.should.have.property('message', 'name is required'); }); @@ -147,7 +147,7 @@ describe('Tag', () => { }); it('register() - fn must be a function', () => { - var errorCallback = sinon.spy(err => { + const errorCallback = sinon.spy(err => { err.should.have.property('message', 'fn must be a function'); }); @@ -161,7 +161,7 @@ describe('Tag', () => { }); it('render() - context', () => { - var tag = new Tag(); + const tag = new Tag(); tag.register('test', function() { return this.foo; diff --git a/test/scripts/filters/backtick_code_block.js b/test/scripts/filters/backtick_code_block.js index 5476be7b4a..b50abe4606 100644 --- a/test/scripts/filters/backtick_code_block.js +++ b/test/scripts/filters/backtick_code_block.js @@ -1,14 +1,14 @@ -var should = require('chai').should(); // eslint-disable-line -var util = require('hexo-util'); -var _ = require('lodash'); -var defaultConfig = require('../../../lib/hexo/default_config'); +const should = require('chai').should(); // eslint-disable-line +const util = require('hexo-util'); +const _ = require('lodash'); +const defaultConfig = require('../../../lib/hexo/default_config'); describe('Backtick code block', () => { - var Hexo = require('../../../lib/hexo'); - var hexo = new Hexo(); - var codeBlock = require('../../../lib/plugins/filter/before_post_render/backtick_code_block').bind(hexo); + const Hexo = require('../../../lib/hexo'); + const hexo = new Hexo(); + const codeBlock = require('../../../lib/plugins/filter/before_post_render/backtick_code_block').bind(hexo); - var code = [ + const code = [ 'if (tired && night){', ' sleep();', '}' @@ -26,13 +26,13 @@ describe('Backtick code block', () => { }); it('disabled', () => { - var content = [ + const content = [ '``` js', code, '```' ].join('\n'); - var data = {content}; + const data = {content}; hexo.config.highlight.enable = false; codeBlock(data); @@ -40,15 +40,15 @@ describe('Backtick code block', () => { }); it('with no config (disabled)', () => { - var content = [ + const content = [ '``` js', code, '```' ].join('\n'); - var data = {content}; + const data = {content}; - var oldConfig = hexo.config.highlight; + const oldConfig = hexo.config.highlight; delete hexo.config.highlight; codeBlock(data); @@ -58,7 +58,7 @@ describe('Backtick code block', () => { }); it('default', () => { - var data = { + const data = { content: [ '``` js', code, @@ -71,7 +71,7 @@ describe('Backtick code block', () => { }); it('without language name', () => { - var data = { + const data = { content: [ '```', code, @@ -79,14 +79,14 @@ describe('Backtick code block', () => { ].join('\n') }; - var expected = highlight(code); + const expected = highlight(code); codeBlock(data); data.content.should.eql('' + expected + ''); }); it('without language name - ignore tab character', () => { - var data = { + const data = { content: [ '``` \t', code, @@ -94,14 +94,14 @@ describe('Backtick code block', () => { ].join('\n') }; - var expected = highlight(code); + const expected = highlight(code); codeBlock(data); data.content.should.eql('' + expected + ''); }); it('title', () => { - var data = { + const data = { content: [ '``` js Hello world', code, @@ -109,7 +109,7 @@ describe('Backtick code block', () => { ].join('\n') }; - var expected = highlight(code, { + const expected = highlight(code, { lang: 'js', caption: 'Hello world' }); @@ -119,7 +119,7 @@ describe('Backtick code block', () => { }); it('url', () => { - var data = { + const data = { content: [ '``` js Hello world http://hexo.io/', code, @@ -127,7 +127,7 @@ describe('Backtick code block', () => { ].join('\n') }; - var expected = highlight(code, { + const expected = highlight(code, { lang: 'js', caption: 'Hello worldlink' }); @@ -137,7 +137,7 @@ describe('Backtick code block', () => { }); it('link text', () => { - var data = { + const data = { content: [ '``` js Hello world http://hexo.io/ Hexo', code, @@ -145,7 +145,7 @@ describe('Backtick code block', () => { ].join('\n') }; - var expected = highlight(code, { + const expected = highlight(code, { lang: 'js', caption: 'Hello worldHexo' }); @@ -155,9 +155,9 @@ describe('Backtick code block', () => { }); it('indent', () => { - var indentCode = code.split('\n').map(line => ' ' + line).join('\n'); + const indentCode = code.split('\n').map(line => ' ' + line).join('\n'); - var data = { + const data = { content: [ '``` js Hello world http://hexo.io/', indentCode, @@ -165,7 +165,7 @@ describe('Backtick code block', () => { ].join('\n') }; - var expected = highlight(code, { + const expected = highlight(code, { lang: 'js', caption: 'Hello worldlink' }); @@ -177,7 +177,7 @@ describe('Backtick code block', () => { it('line number false', () => { hexo.config.highlight.line_number = false; - var data = { + const data = { content: [ '``` js', code, @@ -185,7 +185,7 @@ describe('Backtick code block', () => { ].join('\n') }; - var expected = highlight(code, { + const expected = highlight(code, { lang: 'js', gutter: false }); @@ -198,7 +198,7 @@ describe('Backtick code block', () => { hexo.config.highlight.line_number = false; hexo.config.highlight.first_line_number = 'always1'; - var data = { + const data = { content: [ '``` js', code, @@ -206,7 +206,7 @@ describe('Backtick code block', () => { ].join('\n') }; - var expected = highlight(code, { + const expected = highlight(code, { lang: 'js', gutter: false }); @@ -219,7 +219,7 @@ describe('Backtick code block', () => { hexo.config.highlight.line_number = false; hexo.config.highlight.first_line_number = 'inilne'; - var data = { + const data = { content: [ '``` js', code, @@ -227,7 +227,7 @@ describe('Backtick code block', () => { ].join('\n') }; - var expected = highlight(code, { + const expected = highlight(code, { lang: 'js', gutter: false }); @@ -239,7 +239,7 @@ describe('Backtick code block', () => { it('line number true', () => { hexo.config.highlight.line_number = true; - var data = { + const data = { content: [ '``` js', code, @@ -247,7 +247,7 @@ describe('Backtick code block', () => { ].join('\n') }; - var expected = highlight(code, { + const expected = highlight(code, { lang: 'js', gutter: true }); @@ -260,7 +260,7 @@ describe('Backtick code block', () => { hexo.config.highlight.line_number = true; hexo.config.highlight.first_line_number = 'always1'; - var data = { + const data = { content: [ '``` js=', code, @@ -268,7 +268,7 @@ describe('Backtick code block', () => { ].join('\n') }; - var expected = highlight(code, { + const expected = highlight(code, { lang: 'js', gutter: true, firstLine: 1 @@ -282,7 +282,7 @@ describe('Backtick code block', () => { hexo.config.highlight.line_number = true; hexo.config.highlight.first_line_number = 'inline'; - var data = { + const data = { content: [ '``` js', code, @@ -290,7 +290,7 @@ describe('Backtick code block', () => { ].join('\n') }; - var expected = highlight(code, { + const expected = highlight(code, { lang: 'js', gutter: false, firstLine: 0 @@ -304,7 +304,7 @@ describe('Backtick code block', () => { hexo.config.highlight.line_number = true; hexo.config.highlight.first_line_number = 'inline'; - var data = { + const data = { content: [ '``` js=1', code, @@ -312,7 +312,7 @@ describe('Backtick code block', () => { ].join('\n') }; - var expected = highlight(code, { + const expected = highlight(code, { lang: 'js', gutter: true, firstLine: 1 @@ -326,7 +326,7 @@ describe('Backtick code block', () => { hexo.config.highlight.line_number = true; hexo.config.highlight.first_line_number = 'inline'; - var data = { + const data = { content: [ '``` js=2', code, @@ -334,7 +334,7 @@ describe('Backtick code block', () => { ].join('\n') }; - var expected = highlight(code, { + const expected = highlight(code, { lang: 'js', gutter: true, firstLine: 2 @@ -347,13 +347,13 @@ describe('Backtick code block', () => { it('tab replace', () => { hexo.config.highlight.tab_replace = ' '; - var code = [ + const code = [ 'if (tired && night){', '\tsleep();', '}' ].join('\n'); - var data = { + const data = { content: [ '``` js', code, @@ -361,7 +361,7 @@ describe('Backtick code block', () => { ].join('\n') }; - var expected = highlight(code, { + const expected = highlight(code, { lang: 'js', tab: ' ' }); diff --git a/test/scripts/filters/excerpt.js b/test/scripts/filters/excerpt.js index 48072ca9d2..9af0d84076 100644 --- a/test/scripts/filters/excerpt.js +++ b/test/scripts/filters/excerpt.js @@ -1,18 +1,18 @@ -var should = require('chai').should(); // eslint-disable-line +const should = require('chai').should(); // eslint-disable-line describe('Excerpt', () => { - var Hexo = require('../../../lib/hexo'); - var hexo = new Hexo(); - var excerpt = require('../../../lib/plugins/filter/after_post_render/excerpt').bind(hexo); + const Hexo = require('../../../lib/hexo'); + const hexo = new Hexo(); + const excerpt = require('../../../lib/plugins/filter/after_post_render/excerpt').bind(hexo); it('without ', () => { - var content = [ + const content = [ 'foo', 'bar', 'baz' ].join('\n'); - var data = { + const data = { content }; @@ -27,24 +27,20 @@ describe('Excerpt', () => { _moreCases().forEach(_test); function _moreCases() { - var template = ''; + const template = ''; // see: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/RegExp#Special_characters_meaning_in_regular_expressions - var spaces = ' \f\n\r\t\v\u00a0\u1680\u2000\u2001\u2002\u2003\u2004\u2005\u2006\u2007\u2008\u2009\u200a\u2028\u2029\u202f\u205f\u3000\ufeff'; - var cases = []; - var more, - lead, - tail, - s, - e; - - for (var i = 0; i < spaces.length; ++i) { + const spaces = ' \f\n\r\t\v\u00a0\u1680\u2000\u2001\u2002\u2003\u2004\u2005\u2006\u2007\u2008\u2009\u200a\u2028\u2029\u202f\u205f\u3000\ufeff'; + const cases = []; + let more, lead, tail, s, e; + + for (let i = 0; i < spaces.length; ++i) { lead = spaces[i]; - for (var k = 0; k < spaces.length; ++k) { + for (let k = 0; k < spaces.length; ++k) { tail = spaces[k]; s = ''; - for (var m = 0; m < 3; ++m) { + for (let m = 0; m < 3; ++m) { e = ''; - for (var n = 0; n < 3; ++n) { + for (let n = 0; n < 3; ++n) { more = template.replace('{{lead}}', s).replace('{{tail}}', e); cases.push(more); e += tail; @@ -59,14 +55,14 @@ describe('Excerpt', () => { } function _test(more) { - var content = [ + const content = [ 'foo', 'bar', more, 'baz' ].join('\n'); - var data = { + const data = { content }; @@ -91,7 +87,7 @@ describe('Excerpt', () => { }); it('multiple ', () => { - var content = [ + const content = [ 'foo', '', 'bar', @@ -99,7 +95,7 @@ describe('Excerpt', () => { 'baz' ].join('\n'); - var data = { + const data = { content }; diff --git a/test/scripts/filters/external_link.js b/test/scripts/filters/external_link.js index 75ef8f9e51..9705852f20 100644 --- a/test/scripts/filters/external_link.js +++ b/test/scripts/filters/external_link.js @@ -1,19 +1,19 @@ -var should = require('chai').should(); // eslint-disable-line +const should = require('chai').should(); // eslint-disable-line describe('External link', () => { - var Hexo = require('../../../lib/hexo'); - var hexo = new Hexo(); - var externalLink = require('../../../lib/plugins/filter/after_post_render/external_link').bind(hexo); + const Hexo = require('../../../lib/hexo'); + const hexo = new Hexo(); + const externalLink = require('../../../lib/plugins/filter/after_post_render/external_link').bind(hexo); hexo.config.external_link = true; hexo.config.url = 'http://maji.moe'; it('disabled', () => { - var content = 'foo' + const content = 'foo' + 'Hexo' + 'bar'; - var data = {content}; + const data = {content}; hexo.config.external_link = false; externalLink(data); @@ -22,7 +22,7 @@ describe('External link', () => { }); it('enabled', () => { - var content = [ + const content = [ '# External link test', '1. External link', 'Hexo', @@ -36,7 +36,7 @@ describe('External link', () => { 'moe' ].join('\n'); - var data = {content}; + const data = {content}; externalLink(data); diff --git a/test/scripts/filters/i18n_locals.js b/test/scripts/filters/i18n_locals.js index b4f1f96b39..5a2b10fdc2 100644 --- a/test/scripts/filters/i18n_locals.js +++ b/test/scripts/filters/i18n_locals.js @@ -1,11 +1,11 @@ -var should = require('chai').should(); // eslint-disable-line +const should = require('chai').should(); // eslint-disable-line describe('i18n locals', () => { - var Hexo = require('../../../lib/hexo'); - var hexo = new Hexo(); - var i18nFilter = require('../../../lib/plugins/filter/template_locals/i18n').bind(hexo); - var theme = hexo.theme; - var i18n = theme.i18n; + const Hexo = require('../../../lib/hexo'); + const hexo = new Hexo(); + const i18nFilter = require('../../../lib/plugins/filter/template_locals/i18n').bind(hexo); + const theme = hexo.theme; + const i18n = theme.i18n; // Default language i18n.languages = ['en', 'default']; @@ -28,7 +28,7 @@ describe('i18n locals', () => { }); it('page.lang set', () => { - var locals = { + const locals = { config: hexo.config, page: { lang: 'zh-tw' @@ -41,7 +41,7 @@ describe('i18n locals', () => { }); it('page.language set', () => { - var locals = { + const locals = { config: hexo.config, page: { language: 'zh-tw' @@ -54,7 +54,7 @@ describe('i18n locals', () => { }); it('detect by path (lang found)', () => { - var locals = { + const locals = { config: hexo.config, page: {}, path: 'zh-tw/index.html' @@ -68,7 +68,7 @@ describe('i18n locals', () => { }); it('detect by path (lang not found)', () => { - var locals = { + const locals = { config: hexo.config, page: {}, path: 'news/index.html' @@ -82,7 +82,7 @@ describe('i18n locals', () => { }); it('use config by default', () => { - var locals = { + const locals = { config: hexo.config, page: {}, path: 'index.html' @@ -96,10 +96,10 @@ describe('i18n locals', () => { }); it('use config by default - with multiple languages, first language should be used', () => { - var oldConfig = i18n.languages; + const oldConfig = i18n.languages; i18n.languages = ['zh-tw', 'en', 'default']; - var locals = { + const locals = { config: hexo.config, page: {}, path: 'index.html' @@ -115,10 +115,10 @@ describe('i18n locals', () => { }); it('use config by default - with no languages, default language should be used', () => { - var oldConfig = i18n.language; + const oldConfig = i18n.language; i18n.languages = ['default']; - var locals = { + const locals = { config: hexo.config, page: {}, path: 'index.html' @@ -134,10 +134,10 @@ describe('i18n locals', () => { }); it('use config by default - with unknown language, default language should be used', () => { - var oldConfig = i18n.languages; + const oldConfig = i18n.languages; i18n.languages = ['fr', 'default']; - var locals = { + const locals = { config: hexo.config, page: {}, path: 'index.html' @@ -153,12 +153,12 @@ describe('i18n locals', () => { }); it('use config by default - with no set language and no default file take first available', () => { - var oldConfig = i18n.languages; - var oldSet = i18n.get('default'); + const oldConfig = i18n.languages; + const oldSet = i18n.get('default'); i18n.remove('default'); i18n.languages = ['default']; - var locals = { + const locals = { config: hexo.config, page: {}, path: 'index.html' diff --git a/test/scripts/filters/new_post_path.js b/test/scripts/filters/new_post_path.js index b284072a4d..19d11bcc4e 100644 --- a/test/scripts/filters/new_post_path.js +++ b/test/scripts/filters/new_post_path.js @@ -1,19 +1,19 @@ -var should = require('chai').should(); // eslint-disable-line -var sinon = require('sinon'); -var pathFn = require('path'); -var moment = require('moment'); -var Promise = require('bluebird'); -var fs = require('hexo-fs'); +const should = require('chai').should(); // eslint-disable-line +const sinon = require('sinon'); +const pathFn = require('path'); +const moment = require('moment'); +const Promise = require('bluebird'); +const fs = require('hexo-fs'); -var NEW_POST_NAME = ':title.md'; +const NEW_POST_NAME = ':title.md'; describe('new_post_path', () => { - var Hexo = require('../../../lib/hexo'); - var hexo = new Hexo(pathFn.join(__dirname, 'new_post_path_test')); - var newPostPath = require('../../../lib/plugins/filter/new_post_path').bind(hexo); - var sourceDir = hexo.source_dir; - var draftDir = pathFn.join(sourceDir, '_drafts'); - var postDir = pathFn.join(sourceDir, '_posts'); + const Hexo = require('../../../lib/hexo'); + const hexo = new Hexo(pathFn.join(__dirname, 'new_post_path_test')); + const newPostPath = require('../../../lib/plugins/filter/new_post_path').bind(hexo); + const sourceDir = hexo.source_dir; + const draftDir = pathFn.join(sourceDir, '_drafts'); + const postDir = pathFn.join(sourceDir, '_posts'); before(() => { hexo.config.new_post_name = NEW_POST_NAME; @@ -58,7 +58,7 @@ describe('new_post_path', () => { })); it('default layout + slug', () => { - var now = moment(); + const now = moment(); hexo.config.new_post_name = ':year-:month-:day-:title.md'; return newPostPath({ @@ -70,7 +70,7 @@ describe('new_post_path', () => { }); it('date', () => { - var date = moment([2014, 0, 1]); + const date = moment([2014, 0, 1]); hexo.config.new_post_name = ':year-:i_month-:i_day-:title.md'; return newPostPath({ @@ -113,8 +113,8 @@ describe('new_post_path', () => { })); it('replace existing files', () => { - var filename = 'test.md'; - var path = pathFn.join(postDir, filename); + const filename = 'test.md'; + const path = pathFn.join(postDir, filename); return fs.writeFile(path, '').then(() => newPostPath({ path: filename @@ -125,14 +125,14 @@ describe('new_post_path', () => { }); it('rename if target existed', () => { - var filename = [ + const filename = [ 'test.md', 'test-1.md', 'test-2.md', 'test-foo.md' ]; - var path = filename.map(item => pathFn.join(postDir, item)); + const path = filename.map(item => pathFn.join(postDir, item)); return Promise.map(path, item => fs.writeFile(item, '')).then(() => newPostPath({ path: filename[0] @@ -143,7 +143,7 @@ describe('new_post_path', () => { }); it('data is required', () => { - var errorCallback = sinon.spy(err => { + const errorCallback = sinon.spy(err => { err.should.have.property('message', 'Either data.path or data.slug is required!'); }); diff --git a/test/scripts/filters/post_permalink.js b/test/scripts/filters/post_permalink.js index f663d46f17..e497af1c9e 100644 --- a/test/scripts/filters/post_permalink.js +++ b/test/scripts/filters/post_permalink.js @@ -1,19 +1,19 @@ -var should = require('chai').should(); // eslint-disable-line -var moment = require('moment'); +const should = require('chai').should(); // eslint-disable-line +const moment = require('moment'); -var PERMALINK = ':year/:month/:day/:title/'; +const PERMALINK = ':year/:month/:day/:title/'; describe('post_permalink', () => { - var Hexo = require('../../../lib/hexo'); - var hexo = new Hexo(); - var postPermalink = require('../../../lib/plugins/filter/post_permalink').bind(hexo); - var Post = hexo.model('Post'); - var post; + const Hexo = require('../../../lib/hexo'); + const hexo = new Hexo(); + const postPermalink = require('../../../lib/plugins/filter/post_permalink').bind(hexo); + const Post = hexo.model('Post'); + let post; hexo.config.permalink = PERMALINK; before(() => { - var id; + let id; return hexo.init().then(() => Post.insert({ source: 'foo.md', diff --git a/test/scripts/filters/render_post.js b/test/scripts/filters/render_post.js index ae34802ecc..9ec1db3e32 100644 --- a/test/scripts/filters/render_post.js +++ b/test/scripts/filters/render_post.js @@ -1,17 +1,17 @@ -var should = require('chai').should(); // eslint-disable-line -var fixture = require('../../fixtures/post_render'); +const should = require('chai').should(); // eslint-disable-line +const fixture = require('../../fixtures/post_render'); describe('Render post', () => { - var Hexo = require('../../../lib/hexo'); - var hexo = new Hexo(); - var Post = hexo.model('Post'); - var Page = hexo.model('Page'); - var renderPost = require('../../../lib/plugins/filter/before_generate/render_post').bind(hexo); + const Hexo = require('../../../lib/hexo'); + const hexo = new Hexo(); + const Post = hexo.model('Post'); + const Page = hexo.model('Page'); + const renderPost = require('../../../lib/plugins/filter/before_generate/render_post').bind(hexo); before(() => hexo.init().then(() => hexo.loadPlugin(require.resolve('hexo-renderer-marked')))); it('post', () => { - var id; + let id; return Post.insert({ source: 'foo.md', @@ -21,7 +21,7 @@ describe('Render post', () => { id = post._id; return renderPost(); }).then(() => { - var post = Post.findById(id); + const post = Post.findById(id); post.content.trim().should.eql(fixture.expected); return post.remove(); @@ -29,7 +29,7 @@ describe('Render post', () => { }); it('page', () => { - var id; + let id; return Page.insert({ source: 'foo.md', @@ -39,7 +39,7 @@ describe('Render post', () => { id = page._id; return renderPost(); }).then(() => { - var page = Page.findById(id); + const page = Page.findById(id); page.content.trim().should.eql(fixture.expected); return page.remove(); @@ -47,7 +47,7 @@ describe('Render post', () => { }); it('use data variables', () => { - var id; + let id; return Page.insert({ source: 'foo.md', @@ -57,7 +57,7 @@ describe('Render post', () => { id = page._id; return renderPost({foo: {name: 'Hexo'}}); }).then(() => { - var page = Page.findById(id); + const page = Page.findById(id); page.content.trim().should.eql('

Hello Hexo

'); return page.remove(); diff --git a/test/scripts/filters/save_database.js b/test/scripts/filters/save_database.js index 05d4ff3c9a..d854805e45 100644 --- a/test/scripts/filters/save_database.js +++ b/test/scripts/filters/save_database.js @@ -1,12 +1,12 @@ -var should = require('chai').should(); // eslint-disable-line -var fs = require('hexo-fs'); -var Promise = require('bluebird'); +const should = require('chai').should(); // eslint-disable-line +const fs = require('hexo-fs'); +const Promise = require('bluebird'); describe('Save database', () => { - var Hexo = require('../../../lib/hexo'); - var hexo = new Hexo(); - var saveDatabase = Promise.method(require('../../../lib/plugins/filter/before_exit/save_database')).bind(hexo); - var dbPath = hexo.database.options.path; + const Hexo = require('../../../lib/hexo'); + const hexo = new Hexo(); + const saveDatabase = Promise.method(require('../../../lib/plugins/filter/before_exit/save_database')).bind(hexo); + const dbPath = hexo.database.options.path; it('default', () => { hexo.env.init = true; diff --git a/test/scripts/filters/titlecase.js b/test/scripts/filters/titlecase.js index 179178de8c..e7d5240d7b 100644 --- a/test/scripts/filters/titlecase.js +++ b/test/scripts/filters/titlecase.js @@ -1,13 +1,13 @@ -var should = require('chai').should(); // eslint-disable-line +const should = require('chai').should(); // eslint-disable-line describe('Titlecase', () => { - var Hexo = require('../../../lib/hexo'); - var hexo = new Hexo(); - var titlecase = require('../../../lib/plugins/filter/before_post_render/titlecase').bind(hexo); + const Hexo = require('../../../lib/hexo'); + const hexo = new Hexo(); + const titlecase = require('../../../lib/plugins/filter/before_post_render/titlecase').bind(hexo); it('disabled', () => { - var title = 'Today is a good day'; - var data = {title}; + const title = 'Today is a good day'; + const data = {title}; hexo.config.titlecase = false; titlecase(data); @@ -15,8 +15,8 @@ describe('Titlecase', () => { }); it('enabled', () => { - var title = 'Today is a good day'; - var data = {title}; + const title = 'Today is a good day'; + const data = {title}; hexo.config.titlecase = true; titlecase(data); diff --git a/test/scripts/generators/asset.js b/test/scripts/generators/asset.js index a1bacf7c15..69b2d72705 100644 --- a/test/scripts/generators/asset.js +++ b/test/scripts/generators/asset.js @@ -1,14 +1,14 @@ -var should = require('chai').should(); // eslint-disable-line -var Promise = require('bluebird'); -var pathFn = require('path'); -var fs = require('hexo-fs'); -var testUtil = require('../../util'); +const should = require('chai').should(); // eslint-disable-line +const Promise = require('bluebird'); +const pathFn = require('path'); +const fs = require('hexo-fs'); +const testUtil = require('../../util'); describe('asset', () => { - var Hexo = require('../../../lib/hexo'); - var hexo = new Hexo(pathFn.join(__dirname, 'asset_test'), {silent: true}); - var generator = require('../../../lib/plugins/generator/asset').bind(hexo); - var Asset = hexo.model('Asset'); + const Hexo = require('../../../lib/hexo'); + const hexo = new Hexo(pathFn.join(__dirname, 'asset_test'), {silent: true}); + const generator = require('../../../lib/plugins/generator/asset').bind(hexo); + const Asset = hexo.model('Asset'); function checkStream(stream, expected) { return testUtil.stream.read(stream).then(data => { @@ -21,9 +21,9 @@ describe('asset', () => { after(() => fs.rmdir(hexo.base_dir)); it('renderable', () => { - var path = 'test.yml'; - var source = pathFn.join(hexo.base_dir, path); - var content = 'foo: bar'; + const path = 'test.yml'; + const source = pathFn.join(hexo.base_dir, path); + const content = 'foo: bar'; return Promise.all([ Asset.insert({_id: path, path}), @@ -42,9 +42,9 @@ describe('asset', () => { }); it('not renderable', () => { - var path = 'test.txt'; - var source = pathFn.join(hexo.base_dir, path); - var content = 'test content'; + const path = 'test.txt'; + const source = pathFn.join(hexo.base_dir, path); + const content = 'test content'; return Promise.all([ Asset.insert({_id: path, path}), @@ -61,9 +61,9 @@ describe('asset', () => { }); it('skip render', () => { - var path = 'test.yml'; - var source = pathFn.join(hexo.base_dir, path); - var content = 'foo: bar'; + const path = 'test.yml'; + const source = pathFn.join(hexo.base_dir, path); + const content = 'foo: bar'; return Promise.all([ Asset.insert({_id: path, path, renderable: false}), @@ -80,7 +80,7 @@ describe('asset', () => { }); it('remove assets which does not exist', () => { - var path = 'test.txt'; + const path = 'test.txt'; return Asset.insert({ _id: path, @@ -91,8 +91,8 @@ describe('asset', () => { }); it('don\'t remove extension name', () => { - var path = 'test.min.js'; - var source = pathFn.join(hexo.base_dir, path); + const path = 'test.min.js'; + const source = pathFn.join(hexo.base_dir, path); return Promise.all([ Asset.insert({_id: path, path}), diff --git a/test/scripts/generators/page.js b/test/scripts/generators/page.js index 59b69eb524..b04f3a7c1c 100644 --- a/test/scripts/generators/page.js +++ b/test/scripts/generators/page.js @@ -1,11 +1,11 @@ -var should = require('chai').should(); // eslint-disable-line -var Promise = require('bluebird'); +const should = require('chai').should(); // eslint-disable-line +const Promise = require('bluebird'); describe('page', () => { - var Hexo = require('../../../lib/hexo'); - var hexo = new Hexo(__dirname, {silent: true}); - var Page = hexo.model('Page'); - var generator = Promise.method(require('../../../lib/plugins/generator/page').bind(hexo)); + const Hexo = require('../../../lib/hexo'); + const hexo = new Hexo(__dirname, {silent: true}); + const Page = hexo.model('Page'); + const generator = Promise.method(require('../../../lib/plugins/generator/page').bind(hexo)); function locals() { hexo.locals.invalidate(); diff --git a/test/scripts/generators/post.js b/test/scripts/generators/post.js index 84d08c4425..38e546b7ef 100644 --- a/test/scripts/generators/post.js +++ b/test/scripts/generators/post.js @@ -1,11 +1,11 @@ -var should = require('chai').should(); // eslint-disable-line -var Promise = require('bluebird'); +const should = require('chai').should(); // eslint-disable-line +const Promise = require('bluebird'); describe('post', () => { - var Hexo = require('../../../lib/hexo'); - var hexo = new Hexo(__dirname, {silent: true}); - var Post = hexo.model('Post'); - var generator = Promise.method(require('../../../lib/plugins/generator/post').bind(hexo)); + const Hexo = require('../../../lib/hexo'); + const hexo = new Hexo(__dirname, {silent: true}); + const Post = hexo.model('Post'); + const generator = Promise.method(require('../../../lib/plugins/generator/post').bind(hexo)); hexo.config.permalink = ':title/'; diff --git a/test/scripts/helpers/css.js b/test/scripts/helpers/css.js index 2c4f2b44d8..a04530942b 100644 --- a/test/scripts/helpers/css.js +++ b/test/scripts/helpers/css.js @@ -1,21 +1,21 @@ -var should = require('chai').should(); // eslint-disable-line +const should = require('chai').should(); // eslint-disable-line describe('css', () => { - var Hexo = require('../../../lib/hexo'); - var hexo = new Hexo(__dirname); + const Hexo = require('../../../lib/hexo'); + const hexo = new Hexo(__dirname); - var ctx = { + const ctx = { config: hexo.config }; ctx.url_for = require('../../../lib/plugins/helper/url_for').bind(ctx); - var css = require('../../../lib/plugins/helper/css').bind(ctx); + const css = require('../../../lib/plugins/helper/css').bind(ctx); function assertResult(result) { - var expected = ''; + let expected = ''; - for (var i = 1, len = arguments.length; i < len; i++) { + for (let i = 1, len = arguments.length; i < len; i++) { expected += '\n'; } diff --git a/test/scripts/helpers/date.js b/test/scripts/helpers/date.js index ed570de6c4..d77179f2c0 100644 --- a/test/scripts/helpers/date.js +++ b/test/scripts/helpers/date.js @@ -1,14 +1,14 @@ 'use strict'; -var moment = require('moment-timezone'); -var should = require('chai').should(); // eslint-disable-line -var sinon = require('sinon'); +const moment = require('moment-timezone'); +const should = require('chai').should(); // eslint-disable-line +const sinon = require('sinon'); describe('date', () => { - var Hexo = require('../../../lib/hexo'); - var hexo = new Hexo(); - var dateHelper = require('../../../lib/plugins/helper/date'); - var clock; + const Hexo = require('../../../lib/hexo'); + const hexo = new Hexo(); + const dateHelper = require('../../../lib/plugins/helper/date'); + let clock; before(() => { clock = sinon.useFakeTimers(Date.now()); @@ -19,12 +19,12 @@ describe('date', () => { }); it('date', () => { - var ctx = { + const ctx = { config: hexo.config, page: {} }; - var date = dateHelper.date.bind(ctx); + const date = dateHelper.date.bind(ctx); // now date().should.eql(moment().format(hexo.config.date_format)); @@ -58,7 +58,7 @@ describe('date', () => { }); it('date_xml', () => { - var dateXML = dateHelper.date_xml; + const dateXML = dateHelper.date_xml; // now dateXML().should.eql(moment().toISOString()); @@ -74,12 +74,12 @@ describe('date', () => { }); it('relative_date', () => { - var ctx = { + const ctx = { config: hexo.config, page: {} }; - var relativeDate = dateHelper.relative_date.bind(ctx); + const relativeDate = dateHelper.relative_date.bind(ctx); // now relativeDate().should.eql(moment().fromNow()); @@ -95,12 +95,12 @@ describe('date', () => { }); it('time', () => { - var ctx = { + const ctx = { config: hexo.config, page: {} }; - var time = dateHelper.time.bind(ctx); + const time = dateHelper.time.bind(ctx); // now time().should.eql(moment().format(hexo.config.time_format)); @@ -134,15 +134,15 @@ describe('date', () => { }); it('full_date', () => { - var ctx = { + const ctx = { config: hexo.config, date: dateHelper.date, time: dateHelper.time, page: {} }; - var fullDate = dateHelper.full_date.bind(ctx); - var fullDateFormat = hexo.config.date_format + ' ' + hexo.config.time_format; + const fullDate = dateHelper.full_date.bind(ctx); + const fullDateFormat = hexo.config.date_format + ' ' + hexo.config.time_format; // now fullDate().should.eql(moment().format(fullDateFormat)); @@ -176,13 +176,13 @@ describe('date', () => { }); it('time_tag', () => { - var ctx = { + const ctx = { config: hexo.config, date: dateHelper.date, page: {} }; - var timeTag = dateHelper.time_tag.bind(ctx); + const timeTag = dateHelper.time_tag.bind(ctx); function result(date, format) { date = date || new Date(); diff --git a/test/scripts/helpers/debug.js b/test/scripts/helpers/debug.js index 34905b1d1c..81458f33e3 100644 --- a/test/scripts/helpers/debug.js +++ b/test/scripts/helpers/debug.js @@ -1,31 +1,31 @@ -var should = require('chai').should(); // eslint-disable-line -var rewire = require('rewire'); -var sinon = require('sinon'); +const should = require('chai').should(); // eslint-disable-line +const rewire = require('rewire'); +const sinon = require('sinon'); describe('debug', () => { - var debug = require('../../../lib/plugins/helper/debug'); - var debugModule = rewire('../../../lib/plugins/helper/debug'); - var inspect = require('util').inspect; + const debug = require('../../../lib/plugins/helper/debug'); + const debugModule = rewire('../../../lib/plugins/helper/debug'); + const inspect = require('util').inspect; it('inspect simple object', () => { - var obj = { foo: 'bar' }; + const obj = { foo: 'bar' }; debug.inspectObject(obj).should.eql(inspect(obj)); }); it('inspect circular object', () => { - var obj = { foo: 'bar' }; + const obj = { foo: 'bar' }; obj.circular = obj; debug.inspectObject(obj).should.eql(inspect(obj)); }); it('inspect deep object', () => { - var obj = { baz: { thud: 'narf', dur: { foo: 'bar', baz: { bang: 'zoom' } } } }; + const obj = { baz: { thud: 'narf', dur: { foo: 'bar', baz: { bang: 'zoom' } } } }; debug.inspectObject(obj).should.not.eql(inspect(obj, {depth: 5})); debug.inspectObject(obj, {depth: 5}).should.eql(inspect(obj, {depth: 5})); }); it('log should print to console', () => { - var spy = sinon.spy(); + const spy = sinon.spy(); debugModule.__with__({ console: { diff --git a/test/scripts/helpers/favicon_tag.js b/test/scripts/helpers/favicon_tag.js index 0c723fd74a..f0ce58de0c 100644 --- a/test/scripts/helpers/favicon_tag.js +++ b/test/scripts/helpers/favicon_tag.js @@ -1,16 +1,16 @@ -var should = require('chai').should(); // eslint-disable-line +const should = require('chai').should(); // eslint-disable-line describe('favicon_tag', () => { - var Hexo = require('../../../lib/hexo'); - var hexo = new Hexo(__dirname); + const Hexo = require('../../../lib/hexo'); + const hexo = new Hexo(__dirname); - var ctx = { + const ctx = { config: hexo.config }; ctx.url_for = require('../../../lib/plugins/helper/url_for').bind(ctx); - var favicon = require('../../../lib/plugins/helper/favicon_tag').bind(ctx); + const favicon = require('../../../lib/plugins/helper/favicon_tag').bind(ctx); it('path', () => { favicon('favicon.ico').should.eql(''); diff --git a/test/scripts/helpers/feed_tag.js b/test/scripts/helpers/feed_tag.js index 01cc50ae4a..0faf4f0888 100644 --- a/test/scripts/helpers/feed_tag.js +++ b/test/scripts/helpers/feed_tag.js @@ -1,16 +1,16 @@ -var should = require('chai').should(); // eslint-disable-line +const should = require('chai').should(); // eslint-disable-line describe('feed_tag', () => { - var Hexo = require('../../../lib/hexo'); - var hexo = new Hexo(__dirname); + const Hexo = require('../../../lib/hexo'); + const hexo = new Hexo(__dirname); - var ctx = { + const ctx = { config: hexo.config }; ctx.url_for = require('../../../lib/plugins/helper/url_for').bind(ctx); - var feed = require('../../../lib/plugins/helper/feed_tag').bind(ctx); + const feed = require('../../../lib/plugins/helper/feed_tag').bind(ctx); it('path', () => { feed('atom.xml').should.eql(''); diff --git a/test/scripts/helpers/fragment_cache.js b/test/scripts/helpers/fragment_cache.js index df837b9821..a32876ce5a 100644 --- a/test/scripts/helpers/fragment_cache.js +++ b/test/scripts/helpers/fragment_cache.js @@ -1,7 +1,7 @@ -var should = require('chai').should(); // eslint-disable-line +const should = require('chai').should(); // eslint-disable-line describe('fragment_cache', () => { - var fragment_cache = require('../../../lib/plugins/helper/fragment_cache')(); + const fragment_cache = require('../../../lib/plugins/helper/fragment_cache')(); fragment_cache.call({cache: true}, 'foo', () => 123); diff --git a/test/scripts/helpers/gravatar.js b/test/scripts/helpers/gravatar.js index 2553eff29f..222df76f43 100644 --- a/test/scripts/helpers/gravatar.js +++ b/test/scripts/helpers/gravatar.js @@ -1,17 +1,17 @@ 'use strict'; -var crypto = require('crypto'); -var should = require('chai').should(); // eslint-disable-line +const crypto = require('crypto'); +const should = require('chai').should(); // eslint-disable-line describe('gravatar', () => { - var gravatar = require('../../../lib/plugins/helper/gravatar'); + const gravatar = require('../../../lib/plugins/helper/gravatar'); function md5(str) { return crypto.createHash('md5').update(str).digest('hex'); } - var email = 'abc@abc.com'; - var hash = md5(email); + const email = 'abc@abc.com'; + const hash = md5(email); it('default', () => { gravatar(email).should.eql('https://www.gravatar.com/avatar/' + hash); diff --git a/test/scripts/helpers/image_tag.js b/test/scripts/helpers/image_tag.js index 4a2eaa5b67..8e52b4066c 100644 --- a/test/scripts/helpers/image_tag.js +++ b/test/scripts/helpers/image_tag.js @@ -1,16 +1,16 @@ -var should = require('chai').should(); // eslint-disable-line +const should = require('chai').should(); // eslint-disable-line describe('image_tag', () => { - var Hexo = require('../../../lib/hexo'); - var hexo = new Hexo(__dirname); + const Hexo = require('../../../lib/hexo'); + const hexo = new Hexo(__dirname); - var ctx = { + const ctx = { config: hexo.config }; ctx.url_for = require('../../../lib/plugins/helper/url_for').bind(ctx); - var img = require('../../../lib/plugins/helper/image_tag').bind(ctx); + const img = require('../../../lib/plugins/helper/image_tag').bind(ctx); it('path', () => { img('http://hexo.io/image.jpg').should.eql(''); diff --git a/test/scripts/helpers/is.js b/test/scripts/helpers/is.js index 1ab4b751f9..bd4b3a5be5 100644 --- a/test/scripts/helpers/is.js +++ b/test/scripts/helpers/is.js @@ -1,9 +1,9 @@ -var should = require('chai').should(); // eslint-disable-line +const should = require('chai').should(); // eslint-disable-line describe('is', () => { - var Hexo = require('../../../lib/hexo'); - var hexo = new Hexo(__dirname); - var is = require('../../../lib/plugins/helper/is'); + const Hexo = require('../../../lib/hexo'); + const hexo = new Hexo(__dirname); + const is = require('../../../lib/plugins/helper/is'); it('is_current', () => { is.current.call({path: 'index.html', config: hexo.config}).should.be.true; diff --git a/test/scripts/helpers/js.js b/test/scripts/helpers/js.js index 20c9ff207c..4ce7d98290 100644 --- a/test/scripts/helpers/js.js +++ b/test/scripts/helpers/js.js @@ -1,21 +1,21 @@ -var should = require('chai').should(); // eslint-disable-line +const should = require('chai').should(); // eslint-disable-line describe('js', () => { - var Hexo = require('../../../lib/hexo'); - var hexo = new Hexo(__dirname); + const Hexo = require('../../../lib/hexo'); + const hexo = new Hexo(__dirname); - var ctx = { + const ctx = { config: hexo.config }; ctx.url_for = require('../../../lib/plugins/helper/url_for').bind(ctx); - var js = require('../../../lib/plugins/helper/js').bind(ctx); + const js = require('../../../lib/plugins/helper/js').bind(ctx); function assertResult(result) { - var expected = ''; + let expected = ''; - for (var i = 1, len = arguments.length; i < len; i++) { + for (let i = 1, len = arguments.length; i < len; i++) { expected += '\n'; } diff --git a/test/scripts/helpers/link_to.js b/test/scripts/helpers/link_to.js index 4d29ad75cb..1e7ee44595 100644 --- a/test/scripts/helpers/link_to.js +++ b/test/scripts/helpers/link_to.js @@ -1,16 +1,16 @@ -var should = require('chai').should(); // eslint-disable-line +const should = require('chai').should(); // eslint-disable-line describe('link_to', () => { - var Hexo = require('../../../lib/hexo'); - var hexo = new Hexo(__dirname); + const Hexo = require('../../../lib/hexo'); + const hexo = new Hexo(__dirname); - var ctx = { + const ctx = { config: hexo.config }; ctx.url_for = require('../../../lib/plugins/helper/url_for').bind(ctx); - var linkTo = require('../../../lib/plugins/helper/link_to').bind(ctx); + const linkTo = require('../../../lib/plugins/helper/link_to').bind(ctx); it('path', () => { linkTo('http://hexo.io/').should.eql('hexo.io'); diff --git a/test/scripts/helpers/list_archives.js b/test/scripts/helpers/list_archives.js index 187c504af0..8b5d3674f6 100644 --- a/test/scripts/helpers/list_archives.js +++ b/test/scripts/helpers/list_archives.js @@ -1,18 +1,18 @@ -var should = require('chai').should(); // eslint-disable-line +const should = require('chai').should(); // eslint-disable-line describe('list_archives', () => { - var Hexo = require('../../../lib/hexo'); - var hexo = new Hexo(__dirname); - var Post = hexo.model('Post'); + const Hexo = require('../../../lib/hexo'); + const hexo = new Hexo(__dirname); + const Post = hexo.model('Post'); - var ctx = { + const ctx = { config: hexo.config, page: {} }; ctx.url_for = require('../../../lib/plugins/helper/url_for').bind(ctx); - var listArchives = require('../../../lib/plugins/helper/list_archives').bind(ctx); + const listArchives = require('../../../lib/plugins/helper/list_archives').bind(ctx); function resetLocals() { hexo.locals.invalidate(); @@ -29,7 +29,7 @@ describe('list_archives', () => { })); it('default', () => { - var result = listArchives(); + const result = listArchives(); result.should.eql([ '