aboutsummaryrefslogtreecommitdiff
path: root/tests
diff options
context:
space:
mode:
authorMichael Williamson <mike@zwobble.org>2015-09-07 20:39:54 +0100
committerMichael Williamson <mike@zwobble.org>2015-09-07 20:39:54 +0100
commit2596c1c7122096874d00d7c5392d4ffb482e31b6 (patch)
tree9eea4c367538cc5b7c0554e7f7d3299dc82d166d /tests
parent20406f3b17d2bb188b78c22602b79684086798d1 (diff)
Continue with warning when failing to read image
Diffstat (limited to 'tests')
-rw-r--r--tests/docx/files.tests.js13
-rw-r--r--tests/mammoth.tests.js11
2 files changed, 23 insertions, 1 deletions
diff --git a/tests/docx/files.tests.js b/tests/docx/files.tests.js
index e37df6b..a00b60b 100644
--- a/tests/docx/files.tests.js
+++ b/tests/docx/files.tests.js
@@ -32,8 +32,21 @@ describe("Files", function() {
});
});
});
+
+ test("given base is not set when opening relative uri then error is raised", function() {
+ var files = new Files(null);
+ return assertError(files.read("not-a-real-file.png", "base64"), function(err) {
+ assert.equal(err.message, "could not find external image 'not-a-real-file.png', path of input document is unknown");
+ });
+ });
});
+function assertError(promise, func) {
+ return promise.then(function() {
+ assert(false, "Expected error");
+ }, func);
+}
+
describe("uriToPath", function() {
test("leading slash is retained on non-Windows file URIs", function() {
diff --git a/tests/mammoth.tests.js b/tests/mammoth.tests.js
index bb3dca2..10b95ef 100644
--- a/tests/mammoth.tests.js
+++ b/tests/mammoth.tests.js
@@ -188,7 +188,16 @@ describe('mammoth', function() {
var docxPath = path.join(__dirname, "test-data/external-picture.docx");
return mammoth.convertToHtml({path: docxPath}).then(function(result) {
assert.equal(result.value, '<p><img src="data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAAoAAAAKCAIAAAACUFjqAAAAAXNSR0IArs4c6QAAAAlwSFlzAAAOvgAADr4B6kKxwAAAABNJREFUKFNj/M+ADzDhlWUYqdIAQSwBE8U+X40AAAAASUVORK5CYII=" /></p>');
- assert.deepEqual([], result.messages);
+ assert.deepEqual(result.messages, []);
+ });
+ });
+
+ test('warn if images stored outside of document are specified when passing file without path', function() {
+ var docxPath = path.join(__dirname, "test-data/external-picture.docx");
+ var buffer = fs.readFileSync(docxPath);
+ return mammoth.convertToHtml({buffer: buffer}).then(function(result) {
+ assert.equal(result.value, '');
+ assert.deepEqual(result.messages, [results.warning("could not find external image 'tiny-picture.png', path of input document is unknown")]);
});
});