diff --git a/test/scripts/console/render.js b/test/scripts/console/render.js index 0d1ede1476..d5bd37d6bd 100644 --- a/test/scripts/console/render.js +++ b/test/scripts/console/render.js @@ -1,17 +1,20 @@ 'use strict'; -const fs = require('hexo-fs'); -const pathFn = require('path'); +const { mkdirs, readFile, rmdir, unlink, writeFile } = require('hexo-fs'); +const { join } = require('path'); const Promise = require('bluebird'); describe('render', () => { const Hexo = require('../../../lib/hexo'); - const hexo = new Hexo(pathFn.join(__dirname, 'render_test'), {silent: true}); + const hexo = new Hexo(join(__dirname, 'render_test'), {silent: true}); const render = require('../../../lib/plugins/console/render').bind(hexo); - before(() => fs.mkdirs(hexo.base_dir).then(() => hexo.init())); + before(async () => { + await mkdirs(hexo.base_dir); + hexo.init(); + }); - after(() => fs.rmdir(hexo.base_dir)); + after(() => rmdir(hexo.base_dir)); const body = [ 'foo: 1', @@ -19,100 +22,109 @@ describe('render', () => { ' boo: 2' ].join('\n'); - it('relative path', () => { - 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({ - foo: 1, - bar: { - boo: 2 - } - }); - - return Promise.all([ - fs.unlink(src), - fs.unlink(dest) - ]); + it('relative path', async () => { + const src = join(hexo.base_dir, 'test.yml'); + const dest = join(hexo.base_dir, 'result.json'); + + await writeFile(src, body); + await render({_: ['test.yml'], output: 'result.json'}); + const result = await readFile(dest); + JSON.parse(result).should.eql({ + foo: 1, + bar: { + boo: 2 + } }); + + await Promise.all([ + unlink(src), + unlink(dest) + ]); }); - it('absolute path', () => { - 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({ - foo: 1, - bar: { - boo: 2 - } - }); - - return Promise.all([ - fs.unlink(src), - fs.unlink(dest) - ]); + it('absolute path', async () => { + const src = join(hexo.base_dir, 'test.yml'); + const dest = join(hexo.base_dir, 'result.json'); + + await writeFile(src, body); + await render({_: [src], output: 'result.json'}); + + const result = await readFile(dest); + JSON.parse(result).should.eql({ + foo: 1, + bar: { + boo: 2 + } }); + + await Promise.all([ + unlink(src), + unlink(dest) + ]); }); - it('absolute output', () => { - 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({ - foo: 1, - bar: { - boo: 2 - } - }); - - return Promise.all([ - fs.unlink(src), - fs.unlink(dest) - ]); + it('absolute output', async () => { + const src = join(hexo.base_dir, 'test.yml'); + const dest = join(hexo.base_dir, 'result.json'); + + await writeFile(src, body); + await render({_: ['test.yml'], output: dest}); + + const result = await readFile(dest); + JSON.parse(result).should.eql({ + foo: 1, + bar: { + boo: 2 + } }); + + await Promise.all([ + unlink(src), + unlink(dest) + ]); }); // it('output'); missing-unit-test - it('engine', () => { - 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({ - foo: 1, - bar: { - boo: 2 - } - }); - - return Promise.all([ - fs.unlink(src), - fs.unlink(dest) - ]); + it('engine', async () => { + const src = join(hexo.base_dir, 'test'); + const dest = join(hexo.base_dir, 'result.json'); + + await writeFile(src, body); + await render({_: ['test'], output: 'result.json', engine: 'yaml'}); + + const result = await readFile(dest); + JSON.parse(result).should.eql({ + foo: 1, + bar: { + boo: 2 + } }); + + await Promise.all([ + unlink(src), + unlink(dest) + ]); }); - it('pretty', () => { - 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({ - foo: 1, - bar: { - boo: 2 - } - }, null, ' ')); - - return Promise.all([ - fs.unlink(src), - fs.unlink(dest) - ]); - }); + it('pretty', async () => { + const src = join(hexo.base_dir, 'test.yml'); + const dest = join(hexo.base_dir, 'result.json'); + + await writeFile(src, body); + await render({_: ['test.yml'], output: 'result.json', pretty: true}); + + const result = await readFile(dest); + result.should.eql(JSON.stringify({ + foo: 1, + bar: { + boo: 2 + } + }, null, ' ')); + + await Promise.all([ + unlink(src), + unlink(dest) + ]); }); });