-
Notifications
You must be signed in to change notification settings - Fork 14
/
Copy pathtail-source.spec.ts
56 lines (47 loc) · 1.43 KB
/
tail-source.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
import { promises as fs } from 'fs';
import { Job, TailProcessor } from '../src';
import { CustomDestination } from './helpers';
const filePath = 'test.txt';
let interval: any;
beforeAll(async () => {
});
beforeEach(async () => {
await fs.appendFile(filePath, 'First line\n');
await fs.appendFile(filePath, 'Second line\n');
interval = setInterval(async function () {
await fs.appendFile(filePath, 'Hello, world!\n');
}, 1000);
});
afterEach(async () => {
clearInterval(interval);
await fs.unlink(filePath);
});
afterAll(async () => {
});
it('tails file', async () => {
const destination = new CustomDestination();
const processor = new TailProcessor({
path: './',
files: [filePath],
rowLimit: 1,
});
const job = new Job(processor, [destination]);
await job.run();
expect(destination.getData()).toEqual([{ file: filePath, data: 'Hello, world!' }]);
});
it('tails file from beginning', async () => {
const destination = new CustomDestination();
const processor = new TailProcessor({
path: './',
files: [filePath],
fromBeginning: true,
rowLimit: 3,
});
const job = new Job(processor, [destination]);
await job.run();
expect(destination.getData()).toEqual([
{ file: filePath, data: 'First line' },
{ file: filePath, data: 'Second line' },
{ file: filePath, data: 'Hello, world!' },
]);
});