var assert = require("assert"); var path = require("path"); var fs = require("fs"); var promises = require("../lib/promises"); var mammoth = require("../") var htmlPaths = require("../lib/html-paths"); var documentMatchers = require("../lib/document-matchers"); 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 paragraph to single p element', function() { var docxPath = path.join(__dirname, "test-data/single-paragraph.docx"); return mammoth.convertToHtml({path: docxPath}).then(function(result) { assert.equal(result.value, "
Walking on imported air
"); assert.deepEqual(result.messages, []); }); }); test('style map can be expressed as string', function() { var docxFile = createFakeDocxFile({ "word/document.xml": testData("simple/word/document.xml") }); var options = { styleMap: "p => h1" }; return mammoth.convertToHtml({file: docxFile}, options).then(function(result) { assert.equal("Above
" + "Top left | Top right |
Bottom left | Bottom right |
Below
"; assert.equal(result.value, expectedHtml); assert.deepEqual(result.messages, []); }); }); test('footnotes are appended to text', function() { // TODO: don't duplicate footnotes with multiple references var docxPath = path.join(__dirname, "test-data/footnotes.docx"); var options = { generateUniquifier: function() { return 42; } }; return mammoth.convertToHtml({path: docxPath}, options).then(function(result) { var expectedOutput = '' + '' assert.equal(result.value, expectedOutput); // TODO: get rid of warnings //~ assert.deepEqual(result.messages, []); }); }); test('indentation is used if prettyPrint is true', function() { var docxPath = path.join(__dirname, "test-data/single-paragraph.docx"); return mammoth.convertToHtml({path: docxPath}, {prettyPrint: true}).then(function(result) { assert.equal(result.value, "\n Walking on imported air\n
"); assert.deepEqual(result.messages, []); }); }); test('using styleMapping throws error', function() { try { mammoth.styleMapping() } catch (error) { assert.equal( error.message, 'Use a raw string instead of mammoth.styleMapping e.g. "p[style-naming=\'Title\'] => h1" instead of mammoth.styleMapping("p[style-naming=\'Title\'] => h1")' ); } }); })