helpers.js 2.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394
  1. "use strict";
  2. exports.__esModule = true;
  3. exports.test = test;
  4. exports.nodeVersionAtLeast = nodeVersionAtLeast;
  5. exports.nodeVersionBefore = nodeVersionBefore;
  6. exports["throws"] = exports.parse = void 0;
  7. var _process = _interopRequireDefault(require("process"));
  8. var _util = _interopRequireDefault(require("util"));
  9. var _ava = _interopRequireDefault(require("ava"));
  10. var _semver = _interopRequireDefault(require("semver"));
  11. var _index = _interopRequireDefault(require("../../index"));
  12. function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { "default": obj }; }
  13. var parse = function parse(input, transform) {
  14. return (0, _index["default"])(transform).processSync(input);
  15. };
  16. exports.parse = parse;
  17. function test(spec, input, callback, only, disabled, serial) {
  18. var _this = this;
  19. if (only === void 0) {
  20. only = false;
  21. }
  22. if (disabled === void 0) {
  23. disabled = false;
  24. }
  25. if (serial === void 0) {
  26. serial = false;
  27. }
  28. var tester = only ? _ava["default"].only : _ava["default"];
  29. tester = disabled ? tester.skip : tester;
  30. tester = serial ? tester.serial : tester;
  31. if (callback) {
  32. tester(spec + " (tree)", function (t) {
  33. var tree = (0, _index["default"])().astSync(input);
  34. var debug = _util["default"].inspect(tree, false, null);
  35. return callback.call(_this, t, tree, debug);
  36. });
  37. }
  38. tester(spec + " (toString)", function (t) {
  39. var result = (0, _index["default"])().processSync(input);
  40. t.deepEqual(result, input);
  41. });
  42. }
  43. test.only = function (spec, input, callback) {
  44. return test(spec, input, callback, true);
  45. };
  46. test.skip = function (spec, input, callback) {
  47. return test(spec, input, callback, false, true);
  48. };
  49. test.serial = function (spec, input, callback) {
  50. return test(spec, input, callback, false, false, true);
  51. };
  52. var _throws = function _throws(spec, input, validator) {
  53. (0, _ava["default"])(spec + " (throws)", function (t) {
  54. t["throws"](function () {
  55. return (0, _index["default"])().processSync(input);
  56. }, validator ? {
  57. message: validator
  58. } : {
  59. instanceOf: Error
  60. });
  61. });
  62. };
  63. exports["throws"] = _throws;
  64. function nodeVersionAtLeast(version) {
  65. return _semver["default"].gte(_process["default"].versions.node, version);
  66. }
  67. function nodeVersionBefore(version) {
  68. return _semver["default"].lt(_process["default"].versions.node, version);
  69. }