aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMichael Williamson <mike@zwobble.org>2013-03-30 22:14:12 +0000
committerMichael Williamson <mike@zwobble.org>2013-03-30 22:14:12 +0000
commitc127f0d75175d2ab06682bac1bb22dcf31de2b81 (patch)
treeb7fcb52848ed4413b658d0ebe1b76cfc4ada2599
parent6ebcdcfad1ff8584fe4ee4f49aae0e1d51dd164a (diff)
Add test for docx-reader
-rw-r--r--tests/docx-reader.tests.js28
-rw-r--r--tests/mammoth.tests.js25
-rw-r--r--tests/testing.js21
3 files changed, 54 insertions, 20 deletions
diff --git a/tests/docx-reader.tests.js b/tests/docx-reader.tests.js
new file mode 100644
index 0000000..b7e1c29
--- /dev/null
+++ b/tests/docx-reader.tests.js
@@ -0,0 +1,28 @@
+var assert = require("assert");
+
+var docxReader = require("../lib/docx-reader");
+var documents = require("../lib/documents");
+
+var testing = require("./testing");
+var test = testing.test;
+var testData = testing.testData;
+var createFakeDocxFile = testing.createFakeDocxFile;
+
+
+describe("docx-reader", function() {
+ test("can read document with single paragraph with single run of text", function() {
+ var expectedDocument = documents.Document([
+ documents.Paragraph([
+ documents.Run([
+ documents.Text("Hello.")
+ ])
+ ])
+ ]);
+ var docxFile = createFakeDocxFile({
+ "word/document.xml": testData("simple/word/document.xml")
+ });
+ return docxReader.read(docxFile).then(function(result) {
+ assert.deepEqual(expectedDocument, result);
+ });
+ });
+});
diff --git a/tests/mammoth.tests.js b/tests/mammoth.tests.js
index 2fb7199..e963257 100644
--- a/tests/mammoth.tests.js
+++ b/tests/mammoth.tests.js
@@ -1,11 +1,13 @@
var assert = require("assert");
-var path = require("path");
-var fs = require("fs");
+
var mammoth = require("../")
-var q = require("q");
-var test = require("./testing").test;
var styles = require("../lib/styles");
+var testing = require("./testing");
+var test = testing.test;
+var testData = testing.testData;
+var createFakeDocxFile = testing.createFakeDocxFile;
+
describe('mammoth', function() {
test('should convert docx containing one one paragraph to single p element', function() {
@@ -30,18 +32,3 @@ describe('mammoth', function() {
});
});
})
-
-function createFakeDocxFile(files) {
- function read(path) {
- return files[path];
- }
-
- return {
- read: read
- };
-}
-
-function testData(testDataPath) {
- var fullPath = path.join(__dirname, "test-data", testDataPath);
- return q.nfcall(fs.readFile, fullPath, "utf-8");
-}
diff --git a/tests/testing.js b/tests/testing.js
index 0e371d9..f2cf55a 100644
--- a/tests/testing.js
+++ b/tests/testing.js
@@ -1,7 +1,11 @@
+var path = require("path");
+var fs = require("fs");
var q = require("q");
-
exports.test = test;
+exports.testData = testData;
+exports.createFakeDocxFile = createFakeDocxFile;
+
function test(name, func) {
it(name, function(done) {
@@ -11,3 +15,18 @@ function test(name, func) {
}).done();
});
}
+
+function testData(testDataPath) {
+ var fullPath = path.join(__dirname, "test-data", testDataPath);
+ return q.nfcall(fs.readFile, fullPath, "utf-8");
+}
+
+function createFakeDocxFile(files) {
+ function read(path) {
+ return files[path];
+ }
+
+ return {
+ read: read
+ };
+}