Skip to content

feat: Enable to use defaultDagBuilder with custom builders #413

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

Merged
merged 9 commits into from
Jun 18, 2025
Prev Previous commit
Next Next commit
feat(test): dag builder custom params
  • Loading branch information
clostao committed Sep 15, 2024
commit 284f6b1e352aaffe7a74fa29e07f212ea31aabbb
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
import { chai } from 'aegir/chai'
import { MemoryBlockstore } from 'blockstore-core'
import { defaultDirBuilder, type DirBuilder } from '../src/dag-builder/dir.js'
import {
defaultFileBuilder,
type FileBuilder
} from '../src/dag-builder/file.js'
import { importer } from '../src/index.js'

describe('CustomParamsDagBuilder', () => {
it('should build a dag with custom dir builder', async () => {
const counter = { dirCounter: 0, fileCounter: 0 }
const customDirBuilder: DirBuilder = async (...args) => {
counter.dirCounter++
return defaultDirBuilder(...args)
}

const customFileBuilder: FileBuilder = async (...args) => {
counter.fileCounter++
return defaultFileBuilder(...args)
}

const blockstore = new MemoryBlockstore()
const files = []
for await (const file of importer(
[
{
path: './src/file.txt',
content: new Uint8Array(
'hello world'.split('').map((char) => char.charCodeAt(0))
)
},
{
path: './src'
}
],
blockstore,
{
dirBuilder: customDirBuilder,
fileBuilder: customFileBuilder
}
)) {
files.push(file)
}

chai.expect(counter.dirCounter).to.equal(1)
})
})
Loading