From e09ae27ca28ea2c9bff2595644465e448fedb5bb Mon Sep 17 00:00:00 2001 From: curbengh <43627182+curbengh@users.noreply.github.com> Date: Fri, 3 Jan 2020 21:20:31 +1030 Subject: [PATCH] refactor(test-helpers-tagcloud): async/await (#4028) --- test/scripts/helpers/tagcloud.js | 22 +++++++++++++--------- 1 file changed, 13 insertions(+), 9 deletions(-) diff --git a/test/scripts/helpers/tagcloud.js b/test/scripts/helpers/tagcloud.js index 5a3e417970..7b4288a46e 100644 --- a/test/scripts/helpers/tagcloud.js +++ b/test/scripts/helpers/tagcloud.js @@ -16,21 +16,25 @@ describe('tagcloud', () => { const tagcloud = require('../../../lib/plugins/helper/tagcloud').bind(ctx); - before(() => hexo.init().then(() => Post.insert([ - {source: 'foo', slug: 'foo'}, - {source: 'bar', slug: 'bar'}, - {source: 'baz', slug: 'baz'}, - {source: 'boo', slug: 'boo'} - ])).then(posts => // TODO: Warehouse needs to add a mutex lock when writing data to avoid data sync problem - Promise.each([ + before(async () => { + await hexo.init(); + const posts = await Post.insert([ + {source: 'foo', slug: 'foo'}, + {source: 'bar', slug: 'bar'}, + {source: 'baz', slug: 'baz'}, + {source: 'boo', slug: 'boo'} + ]); + // TODO: Warehouse needs to add a mutex lock when writing data to avoid data sync problem + await Promise.all([ ['bcd'], ['bcd', 'cde'], ['bcd', 'cde', 'abc'], ['bcd', 'cde', 'abc', 'def'] - ], (tags, i) => posts[i].setTags(tags))).then(() => { + ].map((tags, i) => posts[i].setTags(tags))); + hexo.locals.invalidate(); ctx.site = hexo.locals.toObject(); - })); + }); it('default', () => { const result = tagcloud();