-
Notifications
You must be signed in to change notification settings - Fork 0
/
converter.test.ts
56 lines (44 loc) · 1.5 KB
/
converter.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
import * as fs from "fs";
import { promisify } from "util";
import * as path from "path";
import { convertHeicInFolder } from "./converter";
const testInputFolderPath = "./test-images";
const testOutputFolderPath = "./test-converted-images";
async function removeFolder(folderPath: string) {
if (fs.existsSync(folderPath)) {
for (const entry of await promisify(fs.readdir)(folderPath)) {
const entryPath = path.join(folderPath, entry);
const stat = await promisify(fs.stat)(entryPath);
if (stat.isDirectory()) {
await removeFolder(entryPath);
} else {
await promisify(fs.unlink)(entryPath);
}
}
await promisify(fs.rmdir)(folderPath);
}
}
beforeAll(async () => {
if (!fs.existsSync(testInputFolderPath)) {
fs.mkdirSync(testInputFolderPath);
}
});
afterEach(async () => {
await removeFolder(testOutputFolderPath);
});
describe("convertHeicInFolder", () => {
beforeAll(() => {
if (!fs.existsSync(testOutputFolderPath)) {
fs.mkdirSync(testOutputFolderPath, { recursive: true });
}
});
it("should convert all .heic files in a directory", async () => {
const testHeicFilePath = path.join(testInputFolderPath, "test.heic");
await convertHeicInFolder(testInputFolderPath, testOutputFolderPath);
const outputFiles = await promisify(fs.readdir)(testOutputFolderPath);
expect(outputFiles.length).toBeGreaterThan(0);
outputFiles.forEach((file) => {
expect(path.extname(file).toLowerCase()).toBe(".jpg");
});
});
});