diff options
| author | Michael Williamson <mike@zwobble.org> | 2014-08-18 12:51:51 +0100 |
|---|---|---|
| committer | Michael Williamson <mike@zwobble.org> | 2014-08-18 12:51:51 +0100 |
| commit | 275b87161b64d0ee2932acc488611d46f280ae75 (patch) | |
| tree | 51748726cde9fb08aafa2560ee18eca3e3a966f7 | |
| parent | 86564e37ae9433d9678e0c00c66e342afd8884b0 (diff) | |
Rearrange buffer tests
| -rw-r--r-- | tests/buffer-tests.js | 27 | ||||
| -rw-r--r-- | tests/mammoth.tests.js | 26 | ||||
| -rw-r--r-- | tests/unzip.tests.js | 16 |
3 files changed, 42 insertions, 27 deletions
diff --git a/tests/buffer-tests.js b/tests/buffer-tests.js deleted file mode 100644 index 3b4a6c1..0000000 --- a/tests/buffer-tests.js +++ /dev/null @@ -1,27 +0,0 @@ -var assert = require("assert"); -var test = require("./testing").test; - -var fs = require("fs"); -var path = require("path"); - -var mammoth = require("../lib"); - -describe("buffer-tests", function() { - test('should convert docx as Buffer to one HTML paragraph', function() { - var docxPath = path.join(__dirname, "test-data/single-paragraph.docx"); - var buffer = fs.readFileSync(docxPath); - return mammoth.convertToHtml({buffer: buffer}).then(function(result) { - assert.equal(result.value, "<p>Walking on imported air</p>"); - assert.deepEqual(result.messages, []); - }); - }); - - test('should convert docx as Buffer to plain text', function() { - var docxPath = path.join(__dirname, "test-data/single-paragraph.docx"); - var buffer = fs.readFileSync(docxPath); - return mammoth.extractRawText({buffer: buffer}).then(function(result) { - assert.equal(result.value, "Walking on imported air\n\n"); - assert.deepEqual(result.messages, []); - }); - }); -}); diff --git a/tests/mammoth.tests.js b/tests/mammoth.tests.js index a14639d..e0c1f6c 100644 --- a/tests/mammoth.tests.js +++ b/tests/mammoth.tests.js @@ -1,7 +1,9 @@ var assert = require("assert"); var path = require("path"); +var fs = require("fs"); var mammoth = require("../"); +var promises = require("../lib/promises"); var testing = require("./testing"); var test = testing.test; @@ -18,6 +20,18 @@ describe('mammoth', function() { }); }); + test('should convert docx represented by a Buffer', function() { + var docxPath = path.join(__dirname, "test-data/single-paragraph.docx"); + return promises.nfcall(fs.readFile, docxPath) + .then(function(buffer) { + return mammoth.convertToHtml({buffer: buffer}); + }) + .then(function(result) { + assert.equal(result.value, "<p>Walking on imported air</p>"); + assert.deepEqual(result.messages, []); + }); + }); + test('style map can be expressed as string', function() { var docxFile = createFakeDocxFile({ "word/document.xml": testData("simple/word/document.xml") @@ -167,4 +181,16 @@ describe('mammoth', function() { assert.equal(result.value, 'Apple\n\nBanana\n\n'); }); }); + + test('extractRawText can use .docx files represented by a Buffer', function() { + var docxPath = path.join(__dirname, "test-data/single-paragraph.docx"); + return promises.nfcall(fs.readFile, docxPath) + .then(function(buffer) { + return mammoth.extractRawText({buffer: buffer}); + }) + .then(function(result) { + assert.equal(result.value, "Walking on imported air\n\n"); + assert.deepEqual(result.messages, []); + }); + }); }); diff --git a/tests/unzip.tests.js b/tests/unzip.tests.js index b505840..994fb68 100644 --- a/tests/unzip.tests.js +++ b/tests/unzip.tests.js @@ -1,8 +1,10 @@ +var fs = require("fs"); var assert = require("assert"); var path = require("path"); var test = require("./testing").test; var unzip = require("../lib/unzip"); +var promises = require("../lib/promises"); describe("unzip", function() { test("unzip fails if given empty object", function() { @@ -21,4 +23,18 @@ describe("unzip", function() { assert.equal(contents, "Hello world\n"); }); }); + + test('unzip can open Buffer', function() { + var zipPath = path.join(__dirname, "test-data/hello.zip"); + return promises.nfcall(fs.readFile, zipPath) + .then(function(buffer) { + return unzip.openZip({buffer: buffer}); + }) + .then(function(zipFile) { + return zipFile.read("hello", "utf8"); + }) + .then(function(contents) { + assert.equal(contents, "Hello world\n"); + }); + }); }); |
