diff options
| author | Michael Williamson <mike@zwobble.org> | 2016-07-03 19:19:21 +0100 |
|---|---|---|
| committer | Michael Williamson <mike@zwobble.org> | 2016-07-03 19:20:00 +0100 |
| commit | 0b56dfce42c3944cce47e284608e6806f4c839c3 (patch) | |
| tree | 5f96f9c2908f1c5b00a7192e71d4c192abd7cf47 /tests/testing.js | |
| parent | 627c4a755395e313234bdb1914d168392006c483 (diff) | |
Move tests to test for easier Mocha usage
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; -} |
