-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtest.js
More file actions
64 lines (57 loc) · 1.69 KB
/
test.js
File metadata and controls
64 lines (57 loc) · 1.69 KB
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
const test = require("ava");
const fs = require("fs-extra");
const path = require("path");
const convert = require("./index.js");
const fileExists = (s) => new Promise(r => fs.access(s, fs.F_OK, e => r(!e)));
const allFilesExist = (f) => Promise.all(f.map(fileExists)).then(r => r.every(v => v === true));
test.beforeEach(async () => {
const outDir = path.join(__dirname, "test/out");
return fs.remove(outDir);
});
test.serial("Convert a single document", async t => {
const options = {
input: "test\\src\\test.docx",
output: "test\\out\\test.doc",
format: "wdFormatDocument97"
};
await convert(options);
const exists = await fileExists(options.output);
t.true(exists);
});
test.serial("Guess format from outputExt", async t => {
const options = {
input: "test\\src\\test.docx",
output: "test\\out\\test.doc",
outputExt: "doc"
};
await convert(options);
const exists = await fileExists(options.output);
t.true(exists);
});
test.serial("Convert directory", async t => {
const options = {
input: "./test/src",
inputExt: "\"*.docx\"",
output: "./test/out",
outputExt: "doc",
format: "wdFormatDocument97"
};
await convert(options);
const exists = await allFilesExist([
"test\\out\\test.doc",
"test\\out\\test2.doc"
]);
t.true(exists);
});
test.serial("Define output encoding", async t => {
const options = {
input: "test\\src\\test.docx",
output: "test\\out\\test.html",
format: "wdFormatHTML",
encoding: "UTF-8"
};
await convert(options);
const html = await fs.readFile(options.output);
const isUTF8 = html.includes("<meta http-equiv=Content-Type content=\"text/html; charset=utf-8\">");
t.true(isUTF8);
});