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

refactor(test-filters-save_database): async/await #3958

Merged
merged 3 commits into from
Jan 5, 2020
Merged
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
29 changes: 15 additions & 14 deletions test/scripts/filters/save_database.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
'use strict';

const fs = require('hexo-fs');
const { exists, unlink } = require('hexo-fs');
const Promise = require('bluebird');

describe('Save database', () => {
Expand All @@ -9,31 +9,32 @@ describe('Save database', () => {
const saveDatabase = Promise.method(require('../../../lib/plugins/filter/before_exit/save_database')).bind(hexo);
const dbPath = hexo.database.options.path;

it('default', () => {
it('default', async () => {
hexo.env.init = true;
hexo._dbLoaded = true;

return saveDatabase().then(() => fs.exists(dbPath)).then(exist => {
exist.should.be.true;
return fs.unlink(dbPath);
});
await saveDatabase();
const exist = await exists(dbPath);
exist.should.eql(true);

unlink(dbPath);
});

it('do nothing if hexo is not initialized', () => {
it('do nothing if hexo is not initialized', async () => {
hexo.env.init = false;
hexo._dbLoaded = true;

return saveDatabase().then(() => fs.exists(dbPath)).then(exist => {
exist.should.be.false;
});
await saveDatabase();
const exist = await exists(dbPath);
exist.should.eql(false);
});

it('do nothing if database is not loaded', () => {
it('do nothing if database is not loaded', async () => {
hexo.env.init = true;
hexo._dbLoaded = false;

return saveDatabase().then(() => fs.exists(dbPath)).then(exist => {
exist.should.be.false;
});
await saveDatabase();
const exist = await exists(dbPath);
exist.should.eql(false);
});
});