-
Notifications
You must be signed in to change notification settings - Fork 19
/
entry-test.ts
93 lines (73 loc) · 2.71 KB
/
entry-test.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
91
92
93
import fs = require('fs-extra');
import chai = require('chai');
import Entry from '../src/entry';
const { expect } = chai;
const FIXTURE_DIR = 'fixture';
require('chai').config.truncateThreshold = 0;
describe('Entry', function() {
describe('constructor', function() {
const size = 1337;
const mtime = Date.now();
it('supports omitting mode for files', function() {
const entry = new Entry('/foo.js', size, mtime);
expect(entry.relativePath).to.equal('/foo.js');
expect(entry.size).to.equal(size);
expect(entry.mtime).to.equal(mtime);
expect(entry.mode).to.equal(0);
expect(entry.isDirectory()).to.not.be.ok;
});
it('supports omitting mode for directories', function() {
const entry = new Entry('/foo/', size, mtime);
expect(entry.relativePath).to.equal('/foo/');
expect(entry.size).to.equal(size);
expect(entry.mtime).to.equal(mtime);
expect(entry.mode).to.equal(16877);
expect(entry.isDirectory()).to.be.ok;
});
it('supports including manually defined mode', function() {
const entry = new Entry('/foo.js', size, mtime, 1);
expect(entry.relativePath).to.equal('/foo.js');
expect(entry.size).to.equal(size);
expect(entry.mtime).to.equal(mtime);
expect(entry.mode).to.equal(1);
expect(entry.isDirectory()).to.not.be.ok;
});
it('errors on a non-number mode', function() {
expect(function() {
// @ts-ignore
return new Entry('/foo.js', size, mtime, '1');
}).to.throw(`Expected 'mode' to be of type 'number' but was of type 'string' instead.`);
});
});
describe('.fromStat', function() {
afterEach(function() {
fs.removeSync(FIXTURE_DIR);
});
it('creates a correct entry for a file', function() {
const path = FIXTURE_DIR + '/index.js';
fs.outputFileSync(path, '');
try {
const stat = fs.statSync(path);
const entry = Entry.fromStat(path, stat);
expect(entry.isDirectory()).to.not.be.ok;
expect(entry.mode).to.equal(stat.mode);
expect(entry.size).to.equal(stat.size);
expect(entry.mtime).to.equal(stat.mtime);
expect(entry.relativePath).to.equal(path);
} finally {
fs.unlinkSync(path);
}
});
it('creates a correct entry for a directory', function() {
const path = FIXTURE_DIR + '/foo/';
fs.mkdirpSync(path);
const stat = fs.statSync(path);
const entry = Entry.fromStat(path, stat);
expect(entry.isDirectory()).to.be.ok;
expect(entry.mode).to.equal(stat.mode);
expect(entry.size).to.equal(stat.size);
expect(entry.mtime).to.equal(stat.mtime);
expect(entry.relativePath).to.equal(path);
});
});
});