Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

test: improve coverage #4421

Merged
merged 1 commit into from
Jul 15, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 22 additions & 4 deletions test/scripts/console/deploy.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ describe('deploy', () => {

beforeEach(() => {
hexo.config.deploy = { type: 'foo' };
hexo.extend.deployer.register('foo', () => {});
hexo.extend.deployer.register('foo', () => { });
});

after(() => rmdir(hexo.base_dir));
Expand Down Expand Up @@ -69,8 +69,8 @@ describe('deploy', () => {
const deployer2 = spy();

hexo.config.deploy = [
{type: 'foo', foo: 'foo'},
{type: 'bar', bar: 'bar'}
{ type: 'foo', foo: 'foo' },
{ type: 'bar', bar: 'bar' }
];

hexo.extend.deployer.register('foo', deployer1);
Expand All @@ -92,7 +92,25 @@ describe('deploy', () => {
});
});

// it('deployer not found'); missing-unit-test
it('deployer not found', async () => {
const logSpy = spy();
const hexo = new Hexo(join(__dirname, 'deploy_test'));
hexo.log.error = logSpy;

const deploy = require('../../../lib/plugins/console/deploy').bind(hexo);

hexo.extend.deployer.register('baz', () => { });
hexo.config.deploy = {
type: 'foo',
foo: 'bar'
};

await deploy({});

logSpy.called.should.be.true;
logSpy.args[0][0].should.contains('Deployer not found: %s');
logSpy.args[0][1].should.contains('foo');
});

it('generate', async () => {
await writeFile(join(hexo.source_dir, 'test.txt'), 'test');
Expand Down
1 change: 1 addition & 0 deletions test/scripts/console/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ describe('Console', () => {
require('./new');
require('./publish');
require('./render');
require('./list');
require('./list_post');
require('./list_categories');
require('./list_tags');
Expand Down
32 changes: 32 additions & 0 deletions test/scripts/console/list.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
'use strict';

const { spy } = require('sinon');

describe('Console list', () => {
const Hexo = require('../../../lib/hexo');
const hexo = new Hexo(__dirname);

it('no args', () => {
hexo.call = spy();

const list = require('../../../lib/plugins/console/list').bind(hexo);

list({ _: [''] });

hexo.call.calledOnce.should.be.true;
hexo.call.args[0][0].should.eql('help');
hexo.call.args[0][1]._[0].should.eql('list');
});

it('list type not found', () => {
hexo.call = spy();

const list = require('../../../lib/plugins/console/list').bind(hexo);

list({ _: ['test'] });

hexo.call.calledOnce.should.be.true;
hexo.call.args[0][0].should.eql('help');
hexo.call.args[0][1]._[0].should.eql('list');
});
});
13 changes: 13 additions & 0 deletions test/scripts/hexo/render.js
Original file line number Diff line number Diff line change
Expand Up @@ -190,6 +190,19 @@ describe('Render', () => {
});
});

it('render() - options as callback', () => {
const cbSpy = spy();

const data = {
text: ' <strong>123456</strong> ',
engine: 'njk'
};

return hexo.render.render(data, cbSpy).then(() => {
cbSpy.calledOnce.should.be.true;
});
});

it('renderSync() - path', () => {
const result = hexo.render.renderSync({path});
result.should.eql(obj);
Expand Down
2 changes: 1 addition & 1 deletion test/scripts/processors/post.js
Original file line number Diff line number Diff line change
Expand Up @@ -825,7 +825,7 @@ describe('post', () => {
it('post - tag is an alias for tags', async () => {
const body = [
'title: "Hello world"',
'tags:',
'tag:',
'- foo',
'- bar',
'---'
Expand Down