diff options
Diffstat (limited to 'tests/testing.js')
| -rw-r--r-- | tests/testing.js | 65 |
1 files changed, 0 insertions, 65 deletions
diff --git a/tests/testing.js b/tests/testing.js deleted file mode 100644 index d70f86e..0000000 --- a/tests/testing.js +++ /dev/null @@ -1,65 +0,0 @@ -var path = require("path"); -var fs = require("fs"); -var promises = require("../lib/promises"); -var _ = require("underscore"); - -exports.test = test; -exports.testPath = testPath; -exports.testData = testData; -exports.createFakeDocxFile = createFakeDocxFile; -exports.createFakeFiles = createFakeFiles; - - -function test(name, func) { - it(name, function(done) { - var result = func(); - promises.when(result).then(function() { - done(); - }).done(); - }); -} - -function testPath(filename) { - return path.join(__dirname, "test-data", filename); -} - -function testData(testDataPath) { - var fullPath = testPath(testDataPath); - return promises.nfcall(fs.readFile, fullPath, "utf-8"); -} - -function createFakeDocxFile(files) { - function exists(path) { - return !!files[path]; - } - - return { - read: createRead(files), - exists: exists - }; -} - -function createFakeFiles(files) { - return { - read: createRead(files) - }; -} - -function createRead(files) { - function read(path, encoding) { - return promises.when(files[path], function(buffer) { - if (_.isString(buffer)) { - buffer = new Buffer(buffer); - } - - if (!Buffer.isBuffer(buffer)) { - return promises.reject(new Error("file was not a buffer")); - } else if (encoding) { - return promises.when(buffer.toString(encoding)); - } else { - return promises.when(buffer); - } - }); - } - return read; -} |
