diff --git a/test/scripts/theme_processors/config.js b/test/scripts/theme_processors/config.js index 5e8dd68d62..9444e99a76 100644 --- a/test/scripts/theme_processors/config.js +++ b/test/scripts/theme_processors/config.js @@ -1,28 +1,33 @@ 'use strict'; -const sinon = require('sinon'); -const pathFn = require('path'); -const fs = require('hexo-fs'); +const { spy } = require('sinon'); +const { join } = require('path'); +const { mkdirs, rmdir, unlink, writeFile} = require('hexo-fs'); const Promise = require('bluebird'); describe('config', () => { const Hexo = require('../../../lib/hexo'); - const hexo = new Hexo(pathFn.join(__dirname, 'config_test'), {silent: true}); + const hexo = new Hexo(join(__dirname, 'config_test'), {silent: true}); const processor = require('../../../lib/theme/processors/config'); const process = Promise.method(processor.process.bind(hexo)); - const themeDir = pathFn.join(hexo.base_dir, 'themes', 'test'); + const themeDir = join(hexo.base_dir, 'themes', 'test'); function newFile(options) { - options.source = pathFn.join(themeDir, options.path); + options.source = join(themeDir, options.path); return new hexo.theme.File(options); } - before(() => Promise.all([ - fs.mkdirs(themeDir), - fs.writeFile(hexo.config_path, 'theme: test') - ]).then(() => hexo.init())); + before(async () => { + await Promise.all([ + mkdirs(themeDir), + writeFile(hexo.config_path, 'theme: test') + ]); + hexo.init(); + }); + + beforeEach(() => { hexo.theme.config = {}; }); - after(() => fs.rmdir(hexo.base_dir)); + after(() => rmdir(hexo.base_dir)); it('pattern', () => { const pattern = processor.pattern; @@ -33,7 +38,7 @@ describe('config', () => { should.not.exist(pattern.match('foo.yml')); }); - it('type: create', () => { + it('type: create', async () => { const body = [ 'name:', ' first: John', @@ -46,17 +51,16 @@ describe('config', () => { content: body }); - return fs.writeFile(file.source, body).then(() => process(file)).then(() => { - hexo.theme.config.should.eql({ - name: {first: 'John', last: 'Doe'} - }); - }).finally(() => { - hexo.theme.config = {}; - return fs.unlink(file.source); + await writeFile(file.source, body); + await process(file); + hexo.theme.config.should.eql({ + name: {first: 'John', last: 'Doe'} }); + + unlink(file.source); }); - it('type: delete', () => { + it('type: delete', async () => { const file = newFile({ path: '_config.yml', type: 'delete' @@ -64,9 +68,8 @@ describe('config', () => { hexo.theme.config = {foo: 'bar'}; - return process(file).then(() => { - hexo.theme.config.should.eql({}); - }); + await process(file); + hexo.theme.config.should.eql({}); }); it('load failed', () => { @@ -75,7 +78,7 @@ describe('config', () => { type: 'create' }); - const errorCallback = sinon.spy(err => { + const errorCallback = spy(err => { err.should.have.property('message', 'Theme config load failed.'); });