-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathtest.js
118 lines (97 loc) · 2.49 KB
/
test.js
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
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
'use strict';
const fs = require('fs');
const path = require('path');
const test = require('tape');
const { fork } = require('child_process');
test('calculates the checksum of the FRITZ!Box backup file', function (t) {
const source = fs.createReadStream(
path.join(
__dirname,
'fixtures',
'FRITZ.Box 7490 113.07.12i_01.01.70_0106.export'
)
);
const chunks = [];
const subprocess = fork(path.join(__dirname, '..', 'cli.js'), {
stdio: 'pipe'
});
subprocess.stdout.on('data', function (chunk) {
chunks.push(chunk);
});
subprocess.on('close', function (code) {
t.equal(code, 0);
t.deepEqual(Buffer.concat(chunks), Buffer.from('099C13BE\n'));
t.end();
});
source.pipe(subprocess.stdin);
});
test('honors the --print-config argument', function (t) {
const inputChunks = [];
const outputChunks = [];
const source = fs.createReadStream(
path.join(
__dirname,
'fixtures',
'FRITZ.Box 7490 113.07.12i_01.01.70_0106.export'
)
);
const subprocess = fork(
path.join(__dirname, '..', 'cli.js'),
['--print-config'],
{
stdio: 'pipe'
}
);
subprocess.stdout.on('data', function (chunk) {
outputChunks.push(chunk);
});
subprocess.on('close', function (code) {
t.equal(code, 0);
t.deepEqual(Buffer.concat(inputChunks), Buffer.concat(outputChunks));
t.end();
});
source.on('data', function (chunk) {
inputChunks.push(chunk);
});
source.pipe(subprocess.stdin);
});
test('honors the --output argument', function (t) {
const source = fs.createReadStream(
path.join(
__dirname,
'fixtures',
'FRITZ.Box 7490 113.07.12i_01.01.70_0106.export'
)
);
const subprocess = fork(
path.join(__dirname, '..', 'cli.js'),
['--output', process.platform === 'win32' ? '\\\\.\\nul' : '/dev/null'],
{
stdio: 'pipe'
}
);
subprocess.on('close', function (code) {
t.equal(code, 0);
t.end();
});
source.pipe(subprocess.stdin);
});
test('honors the FILE argument', function (t) {
const file = path.join(
__dirname,
'fixtures',
'FRITZ.Box 7490 113.07.21i_01.01.70_0111.export'
);
const chunks = [];
const subprocess = fork(path.join(__dirname, '..', 'cli.js'), [file], {
stdio: 'pipe'
});
subprocess.stdout.on('data', function (chunk) {
chunks.push(chunk);
});
subprocess.on('close', function (code) {
t.equal(code, 0);
t.deepEqual(Buffer.concat(chunks), Buffer.from('448A9496\n'));
t.end();
});
});