/
githubmirror
/
hexo
Обзор
Документация
Войти
/
githubmirror
/
hexo
Код
Запросы
0
Пакеты
0
Релизы
0
Аналитика
Безопасность
master
test/scripts/processors/source_id_index.ts
40 строк
1 KB
Mimi
perf: speed up hot processing (#5803)
08 авг 2026, 10:37
Не верифицирован
08 авг 2026, 10:37
b9ea5de
Код
Авторство
О чём код?
import { join } from 'path'; import { assert as sinonAssert, spy } from 'sinon'; import Hexo from '../../../lib/hexo'; import SourceIdIndex from '../../../lib/plugins/processor/source_id_index'; import chai from 'chai'; chai.should(); describe('SourceIdIndex', () => { it('uses the document id for an indexed source', async () => { const hexo = new Hexo(join(__dirname, 'source_id_index_test')); const Post = hexo.model('Post'); const doc = await Post.insert({source: '_posts/foo.md', slug: 'foo'}); const index = new SourceIdIndex(Post); const findOne = spy(Post, 'findOne'); const result = index.find(doc.source); result._id.should.eql(doc._id); sinonAssert.notCalled(findOne); findOne.restore(); }); it('recovers if a cached document was replaced externally', async () => { const hexo = new Hexo(join(__dirname, 'source_id_index_test')); const Post = hexo.model('Post'); const first = await Post.insert({source: '_posts/foo.md', slug: 'foo'}); const index = new SourceIdIndex(Post); index.find(first.source)._id.should.eql(first._id); await first.remove(); const second = await Post.insert({source: '_posts/foo.md', slug: 'foo'}); const findOne = spy(Post, 'findOne'); index.find(second.source)._id.should.eql(second._id); index.find(second.source)._id.should.eql(second._id); sinonAssert.calledOnce(findOne); findOne.restore(); }); });