Repository navigation
Expand file tree
/
Copy pathfilter.test.js
More file actions
60 lines (51 loc) · 1.51 KB
/
Copy pathfilter.test.js
File metadata and controls
60 lines (51 loc) · 1.51 KB
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
import {filter, MAX_PATCH_CHARS} from '../../../lib/models/patch/filter';
describe('patch filter', function() {
it('passes through small patches as-is', function() {
const original = new PatchBuilder()
.addSmallPatch('path-a.txt')
.addSmallPatch('path-b.txt')
.toString();
const {filtered, removed} = filter(original);
assert.strictEqual(filtered, original);
assert.sameMembers(Array.from(removed), []);
});
it('removes files from the patch that exceed the size threshold', function() {
const original = new PatchBuilder()
.addLargePatch('path-a.txt')
.addSmallPatch('path-b.txt')
.toString();
const expected = new PatchBuilder()
.addSmallPatch('path-b.txt')
.toString();
const {filtered, removed} = filter(original);
assert.strictEqual(filtered, expected);
assert.sameMembers(Array.from(removed), ['path-a.txt']);
});
});
class PatchBuilder {
constructor() {
this.text = '';
}
addSmallPatch(fileName) {
this.text += `diff --git a/${fileName} b/${fileName}\n`;
this.text += '+aaaa\n';
this.text += '+bbbb\n';
this.text += '+cccc\n';
this.text += '+dddd\n';
this.text += '+eeee\n';
return this;
}
addLargePatch(fileName) {
this.text += `diff --git a/${fileName} b/${fileName}\n`;
const line = '+yyyy\n';
let totalSize = 0;
while (totalSize < MAX_PATCH_CHARS) {
this.text += line;
totalSize += line.length;
}
return this;
}
toString() {
return this.text;
}
}