aboutsummaryrefslogtreecommitdiff
path: root/test
diff options
context:
space:
mode:
authorMichael Williamson <mike@zwobble.org>2026-09-16 23:08:58 +0100
committerMichael Williamson <mike@zwobble.org>2026-09-16 23:09:31 +0100
commit36d98ebbd6463899737008eaa5147449c9d8e7f2 (patch)
tree80adf97bc0394495432aae6d31f805dd8c2f2b3e /test
parent0d13c71b3b8d4adb8d59e5e586f6e5f1a284107d (diff)
Prefer fs.promises to promisfying fs functions
Diffstat (limited to 'test')
-rw-r--r--test/docx/files.tests.js9
-rw-r--r--test/mammoth.tests.js13
-rw-r--r--test/testing.js7
-rw-r--r--test/unzip.tests.js5
4 files changed, 15 insertions, 19 deletions
diff --git a/test/docx/files.tests.js b/test/docx/files.tests.js
index 5ddda4a..91de108 100644
--- a/test/docx/files.tests.js
+++ b/test/docx/files.tests.js
@@ -1,16 +1,13 @@
var path = require("path");
-var fs = require("fs");
var assert = require("assert");
-var promises = require("../../lib/promises");
var Files = require("../../lib/docx/files").Files;
var uriToPath = require("../../lib/docx/files").uriToPath;
+var fs = require("../../lib/fs");
var testing = require("../testing");
var test = require("../test")(module);
-var readFile = promises.promisify(fs.readFile.bind(fs));
-
test("Files", {
"when external file access is disabled then reading file raises error": function() {
@@ -24,7 +21,7 @@ test("Files", {
var filePath = path.resolve(testing.testPath("tiny-picture.png"));
var files = new Files({externalFileAccess: true});
return files.read("file:///" + filePath.replace(/^\//, ""), "base64").then(function(contents) {
- return readFile(filePath, "base64").then(function(expectedContents) {
+ return fs.readFile(filePath, "base64").then(function(expectedContents) {
assert.deepEqual(contents, expectedContents);
});
});
@@ -37,7 +34,7 @@ test("Files", {
relativeToFile: testing.testPath("./document.docx")
});
return files.read("tiny-picture.png", "base64").then(function(contents) {
- return readFile(filePath, "base64").then(function(expectedContents) {
+ return fs.readFile(filePath, "base64").then(function(expectedContents) {
assert.deepEqual(contents, expectedContents);
});
});
diff --git a/test/mammoth.tests.js b/test/mammoth.tests.js
index 038cbdf..0291c6a 100644
--- a/test/mammoth.tests.js
+++ b/test/mammoth.tests.js
@@ -1,10 +1,9 @@
var assert = require("assert");
var path = require("path");
-var fs = require("fs");
var _ = require("underscore");
var mammoth = require("../");
-var promises = require("../lib/promises");
+var fs = require("../lib/fs");
var results = require("../lib/results");
var testing = require("./testing");
@@ -23,7 +22,7 @@ test('should convert docx containing one paragraph to single p element', functio
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)
+ return fs.readFile(docxPath)
.then(function(buffer) {
return mammoth.convertToHtml({buffer: buffer});
})
@@ -124,7 +123,7 @@ test('embedded style maps can be disabled', function() {
test('embedded style map can be written using toBuffer() and then read', function() {
var docxPath = path.join(__dirname, "test-data/single-paragraph.docx");
- return promises.nfcall(fs.readFile, docxPath)
+ return fs.readFile(docxPath)
.then(function(buffer) {
return mammoth.embedStyleMap({buffer: buffer}, "p => h1");
})
@@ -141,7 +140,7 @@ test('embedded style map can be written using toBuffer() and then read', functio
test('embedded style map can be written using toArrayBuffer() and then read', function() {
var docxPath = path.join(__dirname, "test-data/single-paragraph.docx");
- return promises.nfcall(fs.readFile, docxPath)
+ return fs.readFile(docxPath)
.then(function(buffer) {
return mammoth.embedStyleMap({buffer: buffer}, "p => h1");
})
@@ -158,7 +157,7 @@ test('embedded style map can be written using toArrayBuffer() and then read', fu
test('embedded style map can be retrieved', function() {
var docxPath = path.join(__dirname, "test-data/single-paragraph.docx");
- return promises.nfcall(fs.readFile, docxPath)
+ return fs.readFile(docxPath)
.then(function(buffer) {
return mammoth.embedStyleMap({buffer: buffer}, "p => h1");
})
@@ -495,7 +494,7 @@ test('extractRawText only retains raw text', function() {
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)
+ return fs.readFile(docxPath)
.then(function(buffer) {
return mammoth.extractRawText({buffer: buffer});
})
diff --git a/test/testing.js b/test/testing.js
index 3948556..ef21ba9 100644
--- a/test/testing.js
+++ b/test/testing.js
@@ -1,8 +1,9 @@
var path = require("path");
-var fs = require("fs");
-var promises = require("../lib/promises");
var _ = require("underscore");
+var fs = require("../lib/fs");
+var promises = require("../lib/promises");
+
exports.testPath = testPath;
exports.testData = testData;
exports.createFakeDocxFile = createFakeDocxFile;
@@ -15,7 +16,7 @@ function testPath(filename) {
function testData(testDataPath) {
var fullPath = testPath(testDataPath);
- return promises.nfcall(fs.readFile, fullPath, "utf-8");
+ return fs.readFile(fullPath, "utf-8");
}
function createFakeDocxFile(files) {
diff --git a/test/unzip.tests.js b/test/unzip.tests.js
index 4e1bd61..f3a0fef 100644
--- a/test/unzip.tests.js
+++ b/test/unzip.tests.js
@@ -1,10 +1,9 @@
-var fs = require("fs");
var assert = require("assert");
var path = require("path");
var test = require("./test")(module);
+var fs = require("../lib/fs");
var unzip = require("../lib/unzip");
-var promises = require("../lib/promises");
test("unzip fails if given empty object", function() {
return unzip.openZip({}).then(function() {
@@ -25,7 +24,7 @@ test("unzip can open local zip file", function() {
test('unzip can open Buffer', function() {
var zipPath = path.join(__dirname, "test-data/hello.zip");
- return promises.nfcall(fs.readFile, zipPath)
+ return fs.readFile(zipPath)
.then(function(buffer) {
return unzip.openZip({buffer: buffer});
})