Skip to content

Commit

Permalink
Merge pull request #4069 from curbengh/db-load-windows-2
Browse files Browse the repository at this point in the history
test(load-database): fix EPERM error in windows CI
  • Loading branch information
curbengh authored Jan 13, 2020
2 parents da5723c + 1cd60a1 commit 05a8a47
Show file tree
Hide file tree
Showing 3 changed files with 74 additions and 12 deletions.
72 changes: 61 additions & 11 deletions test/scripts/console/generate.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ describe('generate', () => {
generate = generateConsole.bind(hexo);

await mkdirs(hexo.base_dir);
hexo.init();
await hexo.init();
});

afterEach(async () => {
Expand Down Expand Up @@ -163,16 +163,6 @@ describe('generate', () => {
await hexo.unwatch();
});

it('watch - delete', async () => {
await testGenerate({ watch: true });

await unlink(join(hexo.source_dir, 'test.txt'));
await Promise.delay(300);

const exist = await exists(join(hexo.public_dir, 'test.txt'));
exist.should.eql(false);
});

it('deploy', async () => {
const deployer = spy();

Expand Down Expand Up @@ -206,6 +196,8 @@ describe('generate', () => {
// Generate again
await generate();

await Promise.delay(300);

// Read the updated source file
const result = await Promise.all([
readFile(join(hexo.public_dir, 'b.txt')),
Expand Down Expand Up @@ -282,3 +274,61 @@ describe('generate', () => {
return generate({ concurrency: 2 });
});
});

// #3975 workaround for Windows
describe('generate - watch (delete)', () => {
const Hexo = require('../../../lib/hexo');
const generateConsole = require('../../../lib/plugins/console/generate');
const hexo = new Hexo(join(__dirname, 'generate_test'), {silent: true});
const generate = generateConsole.bind(hexo);

beforeEach(async () => {
await mkdirs(hexo.base_dir);
await hexo.init();
});

afterEach(async () => {
const exist = await exists(hexo.base_dir);
if (exist) {
await emptyDir(hexo.base_dir);
await rmdir(hexo.base_dir);
}
});

const testGenerate = async options => {
await Promise.all([
// Add some source files
writeFile(join(hexo.source_dir, 'test.txt'), 'test'),
writeFile(join(hexo.source_dir, 'faz', 'yo.txt'), 'yoooo'),
// Add some files to public folder
writeFile(join(hexo.public_dir, 'foo.txt'), 'foo'),
writeFile(join(hexo.public_dir, 'bar', 'boo.txt'), 'boo'),
writeFile(join(hexo.public_dir, 'faz', 'yo.txt'), 'yo')
]);
await generate(options);

const result = await Promise.all([
readFile(join(hexo.public_dir, 'test.txt')),
readFile(join(hexo.public_dir, 'faz', 'yo.txt')),
exists(join(hexo.public_dir, 'foo.txt')),
exists(join(hexo.public_dir, 'bar', 'boo.txt'))
]);
// Check the new file
result[0].should.eql('test');
// Check the updated file
result[1].should.eql('yoooo');
// Old files should not be deleted
result[2].should.eql(true);
result[3].should.eql(true);
};

it('watch - delete', async () => {
await testGenerate({ watch: true });

await unlink(join(hexo.source_dir, 'test.txt'));
await Promise.delay(300);

const exist = await exists(join(hexo.public_dir, 'test.txt'));
exist.should.eql(false);
});
});
12 changes: 12 additions & 0 deletions test/scripts/hexo/load_database.js
Original file line number Diff line number Diff line change
Expand Up @@ -57,8 +57,20 @@ describe('Load database', () => {

await unlink(dbPath);
});
});

// #3975 workaround for Windows
// Clean-up is not necessary (unlike the above tests),
// because the db file is already removed if invalid
describe('Load database - load failed', () => {
const Hexo = require('../../../lib/hexo');
const hexo = new Hexo(join(__dirname), {silent: true});
const loadDatabase = require('../../../lib/hexo/load_database');
const dbPath = hexo.database.options.path;

it('database load failed', async () => {
hexo._dbLoaded = false;

await writeFile(dbPath, '{1423432: 324');
await loadDatabase(hexo);
hexo._dbLoaded.should.eql(false);
Expand Down
2 changes: 1 addition & 1 deletion test/scripts/theme_processors/source.js
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ describe('source', () => {
mkdirs(themeDir),
writeFile(hexo.config_path, 'theme: test')
]);
hexo.init();
await hexo.init();
});

after(() => rmdir(hexo.base_dir));
Expand Down

0 comments on commit 05a8a47

Please sign in to comment.