This repository was archived by the owner on Feb 12, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 1.2k
/
Copy pathadd-all.spec.js
76 lines (61 loc) · 2.37 KB
/
add-all.spec.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
/* eslint max-nested-callbacks: ["error", 8] */
/* eslint-env mocha */
import { expect } from 'aegir/chai'
import * as utils from '../src/components/add-all/utils.js'
describe('add-all/utils', () => {
describe('parseChunkerString', () => {
it('handles an empty string', () => {
const options = utils.parseChunkerString('')
expect(options.chunker).to.equal('fixed')
})
it('handles a null chunker string', () => {
// @ts-expect-error null is not string | undefined
const options = utils.parseChunkerString(null)
expect(options.chunker).to.equal('fixed')
})
it('parses a fixed size string', () => {
const options = utils.parseChunkerString('size-512')
expect(options.chunker).to.equal('fixed')
expect(options.maxChunkSize).to.equal(512)
})
it('parses a rabin string without size', () => {
const options = utils.parseChunkerString('rabin')
expect(options.chunker).to.equal('rabin')
if (options.chunker === 'rabin') {
expect(options.avgChunkSize).to.equal(262144)
}
})
it('parses a rabin string with only avg size', () => {
const options = utils.parseChunkerString('rabin-512')
expect(options.chunker).to.equal('rabin')
if (options.chunker === 'rabin') {
expect(options.avgChunkSize).to.equal(512)
}
})
it('parses a rabin string with min, avg, and max', () => {
const options = utils.parseChunkerString('rabin-42-92-184')
expect(options.chunker).to.equal('rabin')
if (options.chunker === 'rabin') {
expect(options.minChunkSize).to.equal(42)
expect(options.avgChunkSize).to.equal(92)
}
expect(options.maxChunkSize).to.equal(184)
})
it('throws an error for unsupported chunker type', () => {
const fn = () => utils.parseChunkerString('fake-512')
expect(fn).to.throw(Error)
})
it('throws an error for incorrect format string', () => {
const fn = () => utils.parseChunkerString('fixed-abc')
expect(fn).to.throw(Error)
})
it('throws an error for incorrect rabin format string', () => {
const fn = () => utils.parseChunkerString('rabin-1-2-3-4')
expect(fn).to.throw(Error)
})
it('throws an error for non integer rabin parameters', () => {
const fn = () => utils.parseChunkerString('rabin-abc')
expect(fn).to.throw(Error)
})
})
})