-
Notifications
You must be signed in to change notification settings - Fork 207
/
test.ts
34 lines (33 loc) · 1.22 KB
/
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
import 'mocha';
import * as assert from 'assert';
import * as fs from 'fs';
import * as WORD from "./src";
import { sync } from 'glob';
const formats = process.env.FMTS ? process.env.FMTS.split(",") : ["doc", "docx", "htm", "html", "mht", "odt", "rtf", "xml", "txt"];
describe("test_files", () => {
formats.filter(fmt => fmt != "txt").forEach(fmt => {
describe(fmt, () => {
const files = sync(`test_files/**/*.${fmt}`);
files.forEach(fn => {
if(fs.existsSync(fn + ".skip")) return;
(fs.existsSync(fn + ".txt") ? it : it.skip)(fn, () => {
const doc: WORD.WJSDoc = WORD.readFile(fn);
const result: string = "\ufeff" + WORD.to_text(doc, { RS: "\r" });
const baseline = fs.readFileSync(fn + ".txt", "utf8");
assert.equal(result, baseline);
});
});
});
});
if(formats.indexOf("txt") > -1) describe("txt", () => {
const files = sync(`test_files/**/*.txt`);
files.forEach(fn => {
it(fn, () => {
const doc: WORD.WJSDoc = WORD.readFile(fn);
const result: string = "\ufeff" + WORD.to_text(doc, { RS: "\r" });
const baseline = fs.readFileSync(fn, "utf8");
assert.equal(result, baseline);
});
});
});
});