/
githubmirror
/
hexo
Обзор
Документация
Войти
/
githubmirror
/
hexo
Код
Запросы
0
Пакеты
0
Релизы
0
Аналитика
Безопасность
master
test/scripts/box/file.ts
83 строки
2 KB
yoshinorin
test(box/file): extend the mocha timeout to prevent the async file read test from failing (#5601)
07 янв 2025, 18:16
Не верифицирован
07 янв 2025, 18:16
bb2a874
Код
Авторство
О чём код?
import { join } from 'path'; import { rmdir, stat, statSync, writeFile } from 'hexo-fs'; import { load } from 'js-yaml'; import Hexo from '../../../lib/hexo'; import Box from '../../../lib/box'; describe('File', () => { const hexo = new Hexo(__dirname); const box = new Box(hexo, join(hexo.base_dir, 'file_test')); const { File } = box; const body = [ 'name:', ' first: John', ' last: Doe', '', 'age: 23', '', 'list:', '- Apple', '- Banana' ].join('\n'); const obj = load(body); const path = 'test.yml'; const makeFile = (path, props) => { return new File(Object.assign({ source: join(box.base, path), path }, props)); }; const file = makeFile(path, { source: join(box.base, path), path, type: 'create', params: {foo: 'bar'} }); // NOTE: Do not use `arrow function` here. // See https://mochajs.org/#arrow-functions before(async function() { this.timeout(20000); await Promise.all([ writeFile(file.source, body), hexo.init() ]); stat(file.source); }); after(() => rmdir(box.base)); it('read()', async () => { const result = await file.read(); result.should.eql(body); }); it('readSync()', () => { file.readSync().should.eql(body); }); it('stat()', async () => { const stats = await Promise.all([ stat(file.source), file.stat() ]); stats[0].should.eql(stats[1]); }); it('statSync()', () => { file.statSync().should.eql(statSync(file.source)); }); it('render()', async () => { const result = await file.render(); result.should.eql(obj); }); it('renderSync()', () => { file.renderSync().should.eql(obj); }); });