From f63505547ee02e1f31eb9d0f5493c80f43625d8e Mon Sep 17 00:00:00 2001 From: awongCM Date: Mon, 29 Apr 2024 23:43:36 +1000 Subject: [PATCH] fixed failing test suite --- lib/plugins/console/unpublish.js | 2 +- test/scripts/console/unpublish.js | 97 ++++++++++++++++++------------- 2 files changed, 56 insertions(+), 43 deletions(-) diff --git a/lib/plugins/console/unpublish.js b/lib/plugins/console/unpublish.js index 2fdce8137c..4cb8fd8c65 100644 --- a/lib/plugins/console/unpublish.js +++ b/lib/plugins/console/unpublish.js @@ -11,7 +11,7 @@ function unPublishConsole(args) { return this.post.unpublish({ slug: args._.pop(), - layout: args._.length ? args._[0] : this.config.default_layout + layout: 'draft' // assumes only published posts to be reverteds }, args.r || args.replace).then(post => { this.log.info('Unpublished: %s', magenta(tildify(post.path))); }); diff --git a/test/scripts/console/unpublish.js b/test/scripts/console/unpublish.js index 433be4e7f8..7145edbf7a 100644 --- a/test/scripts/console/unpublish.js +++ b/test/scripts/console/unpublish.js @@ -8,8 +8,10 @@ const { useFakeTimers, spy } = require('sinon'); describe('unpublish', () => { const Hexo = require('../../../lib/hexo'); - const hexo = new Hexo(join(__dirname, 'unpublish_test'), {silent: true}); - const unpublish = require('../../../lib/plugins/console/unpublish').bind(hexo); + const hexo = new Hexo(join(__dirname, 'unpublish_test'), { silent: true }); + const unpublish = require('../../../lib/plugins/console/unpublish').bind( + hexo + ); const post = hexo.post; const now = Date.now(); let clock; @@ -19,19 +21,16 @@ describe('unpublish', () => { await mkdirs(hexo.base_dir); await hexo.init(); - await hexo.scaffold.set('post', [ - '---', - 'title: {{ title }}', - 'date: {{ date }}', - 'tags:', - '---' - ].join('\n')); - await hexo.scaffold.set('draft', [ - '---', - 'title: {{ title }}', - 'tags:', - '---' - ].join('\n')); + await hexo.scaffold.set( + 'post', + ['---', 'title: {{ title }}', 'date: {{ date }}', 'tags:', '---'].join( + '\n' + ) + ); + await hexo.scaffold.set( + 'draft', + ['---', 'title: {{ title }}', 'tags:', '---'].join('\n') + ); }); after(() => { @@ -39,22 +38,20 @@ describe('unpublish', () => { return rmdir(hexo.base_dir); }); - beforeEach(() => post.create({ - title: 'Hello World', - layout: 'post', - date: moment(now).format('YYYY-MM-DD HH:mm:ss') - })); + beforeEach(() => + post.create({ + title: 'Hello World', + layout: 'post', + date: moment(now).format('YYYY-MM-DD HH:mm:ss') + }) + ); it('slug', async () => { const postPath = join(hexo.source_dir, '_posts', 'Hello-World.md'); const path = join(hexo.source_dir, '_drafts', 'Hello-World.md'); - const content = [ - '---', - 'title: Hello World', - 'tags:', - '---' - ].join('\n') + '\n'; + const content + = ['---', 'title: Hello World', 'tags:', '---'].join('\n') + '\n'; await unpublish({ _: ['Hello-World'] @@ -70,11 +67,13 @@ describe('unpublish', () => { }); it('no args', async () => { - const hexo = new Hexo(join(__dirname, 'unpublish_test'), {silent: true}); + const hexo = new Hexo(join(__dirname, 'unpublish_test'), { silent: true }); hexo.call = spy(); - const unpublish = require('../../../lib/plugins/console/unpublish').bind(hexo); + const unpublish = require('../../../lib/plugins/console/unpublish').bind( + hexo + ); - await unpublish({_: []}); + await unpublish({ _: [] }); hexo.call.calledOnce.should.be.true; hexo.call.args[0][0].should.eql('help'); @@ -85,13 +84,14 @@ describe('unpublish', () => { const path = join(hexo.source_dir, '_posts', 'Hello-World.md'); const date = moment(now); - const content = [ - '---', - 'title: Hello World', - 'date: ' + date.format('YYYY-MM-DD HH:mm:ss'), - 'tags:', - '---' - ].join('\n') + '\n'; + const content + = [ + '---', + 'title: Hello World', + 'date: ' + date.format('YYYY-MM-DD HH:mm:ss'), + 'tags:', + '---' + ].join('\n') + '\n'; await unpublish({ _: ['photo', 'Hello-World'] @@ -103,10 +103,15 @@ describe('unpublish', () => { }); it('rename if target existed', async () => { - const path = join(hexo.source_dir, '_posts', 'Hello-World.md'); + const path = join(hexo.source_dir, '_drafts', 'Hello-World-1.md'); + const publish = require('../../../lib/plugins/console/publish').bind(hexo); await post.create({ - title: 'Hello World' + title: 'Hello World', + layout: 'draft' + }); + await publish({ + _: ['Hello-World'] }); await unpublish({ _: ['Hello-World'] @@ -117,21 +122,29 @@ describe('unpublish', () => { await Promise.all([ unlink(path), - unlink(join(hexo.source_dir, '_posts', 'Hello-World.md')) + unlink(join(hexo.source_dir, '_drafts', 'Hello-World.md')) ]); }); it('replace existing target', async () => { - const path = join(hexo.source_dir, '_posts', 'Hello-World.md'); + const path = join(hexo.source_dir, '_drafts', 'Hello-World.md'); + const publish = require('../../../lib/plugins/console/publish').bind(hexo); await post.create({ - title: 'Hello World' + title: 'Hello World', + layout: 'draft' + }); + await publish({ + _: ['Hello-World'] }); await unpublish({ _: ['Hello-World'], replace: true }); - const exist = await exists(join(hexo.source_dir, '_drafts', 'Hello-World-1.md')); + + const exist = await exists( + join(hexo.source_dir, '_drafts', 'Hello-World-1.md') + ); exist.should.be.false; await unlink(path);