This repository has been archived by the owner on May 25, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
proload.test.js
120 lines (103 loc) · 3.02 KB
/
proload.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
119
120
const fs = require("fs");
const mockProcess = require("jest-mock-process");
const ora = require("ora");
// eslint-disable-next-line no-underscore-dangle
const _rimraf = require("rimraf");
const { promisify } = require("util");
const proload = require("./proload");
const rimraf = promisify(_rimraf);
const TEST_DIR_PATH = "./.test";
const TEST_TIMEOUT = 120000;
const FILES = [
{
dirPath: TEST_DIR_PATH,
fileName: "test.zip",
fileSize: 3410026,
fileUri: "https://www.gutenberg.org/files/308/308-h.zip"
},
{
dirPath: TEST_DIR_PATH,
fileName: "test.tsv",
fileSize: 25850780,
fileUri: "http://www.lexique.org/databases/Lexique383/Lexique383.tsv"
}
];
describe("proload()", () => {
let mockStderr;
beforeAll(() => {
mockStderr = mockProcess.mockProcessStderr();
});
afterAll(async () => {
mockStderr.mockRestore();
await rimraf(TEST_DIR_PATH);
});
FILES.forEach(({ dirPath, fileName, fileSize, fileUri }) => {
const filePath = `${dirPath}/${fileName}`;
describe(fileUri, () => {
beforeEach(async () => {
await rimraf(dirPath);
});
describe("Buffer", () => {
test(
"should match the expected buffer size",
async () => {
const dataBuffer = await proload(fileUri);
expect(mockStderr).toHaveBeenCalled();
expect(dataBuffer.length).toStrictEqual(fileSize);
},
TEST_TIMEOUT
);
});
describe("File", () => {
test(
"should match the expected file size",
async () => {
await proload(fileUri, filePath);
expect(mockStderr).toHaveBeenCalled();
expect(fs.readFileSync(filePath).length).toStrictEqual(fileSize);
},
TEST_TIMEOUT
);
});
// eslint-disable-next-line no-loop-func
describe("Ora", () => {
describe("Buffer", () => {
test(
"should match the expected buffer size",
async () => {
const spinner = ora();
const options = {
spinner: {
instance: spinner
}
};
const dataBuffer = await proload(fileUri, options);
spinner.stop();
expect(mockStderr).toHaveBeenCalled();
expect(dataBuffer.length).toStrictEqual(fileSize);
},
TEST_TIMEOUT
);
});
describe("File", () => {
test(
"should match the expected file size",
async () => {
const spinner = ora();
const options = {
spinner: {
instance: spinner
}
};
await proload(fileUri, filePath, options);
spinner.stop();
expect(mockStderr).toHaveBeenCalled();
expect(fs.readFileSync(filePath).length).toStrictEqual(fileSize);
},
TEST_TIMEOUT
);
});
});
});
});
});