-
Notifications
You must be signed in to change notification settings - Fork 9
/
sync.spec.ts
90 lines (64 loc) · 2.61 KB
/
sync.spec.ts
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
77
78
79
80
81
82
83
84
85
86
87
88
89
90
import * as assert from 'assert';
import * as sinon from 'sinon';
import { Stats } from '../../../fs.macchiato';
import Settings from '../settings';
import * as provider from './sync';
describe('Providers → Sync', () => {
describe('.read', () => {
it('should return lstat for non-symlink entry', () => {
const lstatSync = sinon.stub().returns(new Stats());
const settings = new Settings({
fs: { lstatSync }
});
const actual = provider.read('filepath', settings);
assert.strictEqual(actual.ino, 0);
});
it('should return lstat for symlink entry when the "followSymbolicLink" option is disabled', () => {
const lstatSync = sinon.stub().returns(new Stats({ isSymbolicLink: true }));
const settings = new Settings({
followSymbolicLink: false,
fs: { lstatSync }
});
const actual = provider.read('filepath', settings);
assert.strictEqual(actual.ino, 0);
});
it('should return stat for symlink entry', () => {
const lstatSync = sinon.stub().returns(new Stats({ isSymbolicLink: true }));
const statSync = sinon.stub().returns(new Stats({ ino: 1 }));
const settings = new Settings({
fs: { lstatSync, statSync }
});
const actual = provider.read('filepath', settings);
assert.strictEqual(actual.ino, 1);
});
it('should return marked stat for symlink entry when the "markSymbolicLink" option is enabled', () => {
const lstatSync = sinon.stub().returns(new Stats({ isSymbolicLink: true }));
const statSync = sinon.stub().returns(new Stats({ ino: 1 }));
const settings = new Settings({
markSymbolicLink: true,
fs: { lstatSync, statSync }
});
const actual = provider.read('filepath', settings);
assert.strictEqual(actual.isSymbolicLink(), true);
});
it('should return lstat for broken symlink entry when the "throwErrorOnBrokenSymbolicLink" option is disabled', () => {
const lstatSync = sinon.stub().returns(new Stats({ isSymbolicLink: true }));
const statSync = sinon.stub().throws(new Error('error'));
const settings = new Settings({
fs: { lstatSync, statSync },
throwErrorOnBrokenSymbolicLink: false
});
const actual = provider.read('filepath', settings);
assert.strictEqual(actual.ino, 0);
});
it('should throw an error when symlink entry is broken', () => {
const lstatSync = sinon.stub().returns(new Stats({ isSymbolicLink: true }));
const statSync = sinon.stub().throws(new Error('broken'));
const settings = new Settings({
fs: { lstatSync, statSync }
});
const expectedErrorMessageRe = /broken/;
assert.throws(() => provider.read('filepath', settings), expectedErrorMessageRe);
});
});
});