Skip to content

Commit 284f6b1

Browse files
committed
feat(test): dag builder custom params
1 parent 8c46954 commit 284f6b1

File tree

1 file changed

+48
-0
lines changed

1 file changed

+48
-0
lines changed
Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
import { chai } from 'aegir/chai'
2+
import { MemoryBlockstore } from 'blockstore-core'
3+
import { defaultDirBuilder, type DirBuilder } from '../src/dag-builder/dir.js'
4+
import {
5+
defaultFileBuilder,
6+
type FileBuilder
7+
} from '../src/dag-builder/file.js'
8+
import { importer } from '../src/index.js'
9+
10+
describe('CustomParamsDagBuilder', () => {
11+
it('should build a dag with custom dir builder', async () => {
12+
const counter = { dirCounter: 0, fileCounter: 0 }
13+
const customDirBuilder: DirBuilder = async (...args) => {
14+
counter.dirCounter++
15+
return defaultDirBuilder(...args)
16+
}
17+
18+
const customFileBuilder: FileBuilder = async (...args) => {
19+
counter.fileCounter++
20+
return defaultFileBuilder(...args)
21+
}
22+
23+
const blockstore = new MemoryBlockstore()
24+
const files = []
25+
for await (const file of importer(
26+
[
27+
{
28+
path: './src/file.txt',
29+
content: new Uint8Array(
30+
'hello world'.split('').map((char) => char.charCodeAt(0))
31+
)
32+
},
33+
{
34+
path: './src'
35+
}
36+
],
37+
blockstore,
38+
{
39+
dirBuilder: customDirBuilder,
40+
fileBuilder: customFileBuilder
41+
}
42+
)) {
43+
files.push(file)
44+
}
45+
46+
chai.expect(counter.dirCounter).to.equal(1)
47+
})
48+
})

0 commit comments

Comments
 (0)