diff options
| author | Michael Williamson <mike@zwobble.org> | 2016-07-07 22:17:34 +0100 |
|---|---|---|
| committer | Michael Williamson <mike@zwobble.org> | 2016-07-07 22:17:34 +0100 |
| commit | a080fc59a3fca08bdc6e23a2eeae440f5c7047b3 (patch) | |
| tree | 3d56033c294c617eb7de6b693750efb70a81dd4f /test/main.tests.js | |
| parent | 28a0e40b645c051d91626ca90959e847b061c8da (diff) | |
Use exports for all tests
Diffstat (limited to 'test/main.tests.js')
| -rw-r--r-- | test/main.tests.js | 96 |
1 files changed, 47 insertions, 49 deletions
diff --git a/test/main.tests.js b/test/main.tests.js index d603626..505c31f 100644 --- a/test/main.tests.js +++ b/test/main.tests.js @@ -6,69 +6,67 @@ var fs = require("fs"); var temp = require('temp').track(); var promises = require("../lib/promises"); -var test = require("./testing").test; +var test = require("./test")(module); var testPath = require("./testing").testPath; -describe("CLI", function() { - test("HTML is printed to stdout if output file is not set", function() { - return runMammoth(testPath("single-paragraph.docx")).then(function(result) { - assert.equal(result.stderrOutput, ""); - assert.equal(result.output, "<p>Walking on imported air</p>"); - }); - }); - - test("HTML is written to file if output file is set", function() { - return createTempDir().then(function(tempDir) { - var outputPath = path.join(tempDir, "output.html"); - return runMammoth(testPath("single-paragraph.docx"), outputPath).then(function(result) { - assert.equal(result.stderrOutput, ""); - assert.equal(result.output, ""); - assert.equal(fs.readFileSync(outputPath, "utf8"), "<p>Walking on imported air</p>"); - }); - }); +test("HTML is printed to stdout if output file is not set", function() { + return runMammoth(testPath("single-paragraph.docx")).then(function(result) { + assert.equal(result.stderrOutput, ""); + assert.equal(result.output, "<p>Walking on imported air</p>"); }); - - var imageBase64 = "iVBORw0KGgoAAAANSUhEUgAAAAoAAAAKCAIAAAACUFjqAAAAAXNSR0IArs4c6QAAAAlwSFlzAAAOvgAADr4B6kKxwAAAABNJREFUKFNj/M+ADzDhlWUYqdIAQSwBE8U+X40AAAAASUVORK5CYII="; - - test("inline images are included in output if writing to single file", function() { - return runMammoth(testPath("tiny-picture.docx")).then(function(result) { +}); + +test("HTML is written to file if output file is set", function() { + return createTempDir().then(function(tempDir) { + var outputPath = path.join(tempDir, "output.html"); + return runMammoth(testPath("single-paragraph.docx"), outputPath).then(function(result) { assert.equal(result.stderrOutput, ""); - assert.equal(result.output, '<p><img src="data:image/png;base64,' + imageBase64 + '" /></p>'); + assert.equal(result.output, ""); + assert.equal(fs.readFileSync(outputPath, "utf8"), "<p>Walking on imported air</p>"); }); }); - - test("images are written to separate files if output dir is set", function() { - return createTempDir().then(function(tempDir) { - var outputPath = path.join(tempDir, "tiny-picture.html"); - var imagePath = path.join(tempDir, "1.png"); - return runMammoth(testPath("tiny-picture.docx"), "--output-dir", tempDir).then(function(result) { - assert.equal(result.stderrOutput, ""); - assert.equal(result.output, ""); - assert.equal(fs.readFileSync(outputPath, "utf8"), '<p><img src="1.png" /></p>'); - assert.equal(fs.readFileSync(imagePath, "base64"), imageBase64); - }); - }); +}); + +var imageBase64 = "iVBORw0KGgoAAAANSUhEUgAAAAoAAAAKCAIAAAACUFjqAAAAAXNSR0IArs4c6QAAAAlwSFlzAAAOvgAADr4B6kKxwAAAABNJREFUKFNj/M+ADzDhlWUYqdIAQSwBE8U+X40AAAAASUVORK5CYII="; + +test("inline images are included in output if writing to single file", function() { + return runMammoth(testPath("tiny-picture.docx")).then(function(result) { + assert.equal(result.stderrOutput, ""); + assert.equal(result.output, '<p><img src="data:image/png;base64,' + imageBase64 + '" /></p>'); }); - - test("style map is used if set", function() { - return createTempDir().then(function(tempDir) { - var styleMapPath = path.join(tempDir, "style-map"); - fs.writeFileSync(styleMapPath, "p => span:fresh"); - return runMammoth(testPath("single-paragraph.docx"), "--style-map", styleMapPath).then(function(result) { - assert.equal(result.stderrOutput, ""); - assert.equal(result.output, "<span>Walking on imported air</span>"); - }); +}); + +test("images are written to separate files if output dir is set", function() { + return createTempDir().then(function(tempDir) { + var outputPath = path.join(tempDir, "tiny-picture.html"); + var imagePath = path.join(tempDir, "1.png"); + return runMammoth(testPath("tiny-picture.docx"), "--output-dir", tempDir).then(function(result) { + assert.equal(result.stderrOutput, ""); + assert.equal(result.output, ""); + assert.equal(fs.readFileSync(outputPath, "utf8"), '<p><img src="1.png" /></p>'); + assert.equal(fs.readFileSync(imagePath, "base64"), imageBase64); }); }); - - test("--output-format=markdown option generate markdown output", function() { - return runMammoth(testPath("single-paragraph.docx"), "--output-format=markdown").then(function(result) { +}); + +test("style map is used if set", function() { + return createTempDir().then(function(tempDir) { + var styleMapPath = path.join(tempDir, "style-map"); + fs.writeFileSync(styleMapPath, "p => span:fresh"); + return runMammoth(testPath("single-paragraph.docx"), "--style-map", styleMapPath).then(function(result) { assert.equal(result.stderrOutput, ""); - assert.equal(result.output, "Walking on imported air\n\n"); + assert.equal(result.output, "<span>Walking on imported air</span>"); }); }); }); +test("--output-format=markdown option generate markdown output", function() { + return runMammoth(testPath("single-paragraph.docx"), "--output-format=markdown").then(function(result) { + assert.equal(result.stderrOutput, ""); + assert.equal(result.output, "Walking on imported air\n\n"); + }); +}); + function runMammoth() { var args = Array.prototype.slice.call(arguments, 0); |
