utility.js 822 B

1234567891011121314151617181920212223242526272829
  1. 'use strict';
  2. let _ = require('lodash');
  3. let bluebird = require('bluebird');
  4. let readFile = bluebird.promisify(require('fs').readFile);
  5. let path = require('path');
  6. // Build a path relative to `test/`
  7. exports.buildPath = function() {
  8. const args = _.slice(arguments, 0),
  9. paths = [__dirname].concat(args);
  10. return path.join.apply(this, paths);
  11. };
  12. exports.numberToString = _.method('toString');
  13. exports.expectedFile = function(filename, encoding, actual) {
  14. return readFile(filename, encoding)
  15. .then(expected => actual.trim().should.equal(expected.trim()));
  16. };
  17. exports.setupFile = function(filename, encoding, that, testHTML) {
  18. return readFile(filename, encoding)
  19. .then(expected => {
  20. that.expected = expected.trim();
  21. that.blocks = _.map(testHTML, 'innerHTML');
  22. });
  23. };