forked from Claviz/bellboy
-
Notifications
You must be signed in to change notification settings - Fork 0
/
delimited-source.spec.ts
56 lines (48 loc) · 1.32 KB
/
delimited-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
56
import * as fs from 'fs';
import { DelimitedProcessor, Job } from '../src';
import { CustomDestination } from './helpers';
const filePath = 'test.txt';
beforeAll(async () => {
});
beforeEach(async () => {
});
afterEach(async () => {
if (fs.existsSync(filePath)) {
fs.unlinkSync(filePath);
}
});
afterAll(async () => {
});
it('reads data from file delimited by new lines', async () => {
fs.appendFileSync(filePath, 'First line\n');
fs.appendFileSync(filePath, 'Second line\n');
const destination = new CustomDestination();
const processor = new DelimitedProcessor({
path: './',
files: [filePath],
delimiter: '\n',
rowLimit: 2,
});
const job = new Job(processor, [destination]);
await job.run();
expect(destination.getData()).toEqual([
'First line',
'Second line',
]);
});
it('reads data from file delimited by commas', async () => {
fs.appendFileSync(filePath, 'Hello, world!');
const destination = new CustomDestination();
const processor = new DelimitedProcessor({
path: './',
files: [filePath],
delimiter: ',',
rowLimit: 2,
});
const job = new Job(processor, [destination]);
await job.run();
expect(destination.getData()).toEqual([
'Hello',
' world!',
]);
});