vue-styleguidist
Version:
Vue components style guide generator
262 lines (260 loc) • 9.64 kB
JavaScript
;
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
var _typeof = require("@babel/runtime/helpers/typeof");
var _regenerator = _interopRequireDefault(require("@babel/runtime/regenerator"));
var _asyncToGenerator2 = _interopRequireDefault(require("@babel/runtime/helpers/asyncToGenerator"));
var _path = _interopRequireDefault(require("path"));
var _getSections = _interopRequireWildcard(require("./getSections"));
var _cleanFilePathSnapshot = _interopRequireDefault(require("./cleanFilePathSnapshot"));
function _getRequireWildcardCache(nodeInterop) { if (typeof WeakMap !== "function") return null; var cacheBabelInterop = new WeakMap(); var cacheNodeInterop = new WeakMap(); return (_getRequireWildcardCache = function _getRequireWildcardCache(nodeInterop) { return nodeInterop ? cacheNodeInterop : cacheBabelInterop; })(nodeInterop); }
function _interopRequireWildcard(obj, nodeInterop) { if (!nodeInterop && obj && obj.__esModule) { return obj; } if (obj === null || _typeof(obj) !== "object" && typeof obj !== "function") { return { "default": obj }; } var cache = _getRequireWildcardCache(nodeInterop); if (cache && cache.has(obj)) { return cache.get(obj); } var newObj = {}; var hasPropertyDescriptor = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var key in obj) { if (key !== "default" && Object.prototype.hasOwnProperty.call(obj, key)) { var desc = hasPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : null; if (desc && (desc.get || desc.set)) { Object.defineProperty(newObj, key, desc); } else { newObj[key] = obj[key]; } } } newObj["default"] = obj; if (cache) { cache.set(obj, newObj); } return newObj; }
var configDir = _path["default"].resolve(__dirname, '../../../../../test');
var config = {
configDir: configDir,
exampleMode: 'collapse',
usageMode: 'collapse',
getExampleFilename: function getExampleFilename(a) {
return a;
},
getComponentPathLine: function getComponentPathLine(a) {
return a;
}
};
var sections = [{
name: 'Readme',
content: 'components/ReadMe.md'
}, {
name: 'Components',
components: 'components/**/[A-Z]*.vue'
}, {
name: 'Ignore',
components: 'components/**/*.vue',
ignore: '**/components/Annotation/*'
}];
var sectionsWithDepth = [{
name: 'Documentation',
sections: [{
name: 'Files',
sections: [{
name: 'First File'
}]
}],
sectionDepth: 2
}, {
name: 'Components',
sections: [{
name: 'Buttons'
}],
sectionDepth: 0
}];
var sectionsWithBadDepth = [{
name: 'Documentation',
sections: [{
name: 'Files',
sections: [{
name: 'First File'
}],
sectionDepth: 2
}]
}];
function filterSectionDepth(section) {
if (section.sections && section.sections.length) {
return {
sectionDepth: section.sectionDepth,
sections: section.sections.map(filterSectionDepth)
};
}
return {
sectionDepth: section.sectionDepth
};
}
describe('processSection', function () {
it('should return an object for section with content', /*#__PURE__*/(0, _asyncToGenerator2["default"])( /*#__PURE__*/_regenerator["default"].mark(function _callee() {
var result;
return _regenerator["default"].wrap(function _callee$(_context) {
while (1) {
switch (_context.prev = _context.next) {
case 0:
_context.next = 2;
return (0, _getSections.processSection)(sections[0], {
config: config,
componentFiles: []
});
case 2:
result = _context.sent;
expect((0, _cleanFilePathSnapshot["default"])(result)).toMatchSnapshot();
case 4:
case "end":
return _context.stop();
}
}
}, _callee);
})));
it('should return an object for section with components', /*#__PURE__*/(0, _asyncToGenerator2["default"])( /*#__PURE__*/_regenerator["default"].mark(function _callee2() {
var result;
return _regenerator["default"].wrap(function _callee2$(_context2) {
while (1) {
switch (_context2.prev = _context2.next) {
case 0:
_context2.next = 2;
return (0, _getSections.processSection)(sections[1], {
config: config,
componentFiles: []
});
case 2:
result = _context2.sent;
expect((0, _cleanFilePathSnapshot["default"])(result)).toMatchSnapshot();
case 4:
case "end":
return _context2.stop();
}
}
}, _callee2);
})));
it('should return an object for section without ignored components', /*#__PURE__*/(0, _asyncToGenerator2["default"])( /*#__PURE__*/_regenerator["default"].mark(function _callee3() {
var result;
return _regenerator["default"].wrap(function _callee3$(_context3) {
while (1) {
switch (_context3.prev = _context3.next) {
case 0:
_context3.next = 2;
return (0, _getSections.processSection)(sections[2], {
config: config,
componentFiles: []
});
case 2:
result = _context3.sent;
expect((0, _cleanFilePathSnapshot["default"])(result)).toMatchSnapshot();
case 4:
case "end":
return _context3.stop();
}
}
}, _callee3);
})));
});
describe('getSections', function () {
it('should return an array', /*#__PURE__*/(0, _asyncToGenerator2["default"])( /*#__PURE__*/_regenerator["default"].mark(function _callee4() {
var result;
return _regenerator["default"].wrap(function _callee4$(_context4) {
while (1) {
switch (_context4.prev = _context4.next) {
case 0:
_context4.next = 2;
return (0, _getSections["default"])(sections, {
config: config,
componentFiles: []
});
case 2:
result = _context4.sent;
expect((0, _cleanFilePathSnapshot["default"])(result)).toMatchSnapshot();
case 4:
case "end":
return _context4.stop();
}
}
}, _callee4);
})));
it('should return an array of sectionsWithDepth with sectionDepth decreasing', /*#__PURE__*/(0, _asyncToGenerator2["default"])( /*#__PURE__*/_regenerator["default"].mark(function _callee5() {
var result;
return _regenerator["default"].wrap(function _callee5$(_context5) {
while (1) {
switch (_context5.prev = _context5.next) {
case 0:
_context5.next = 2;
return (0, _getSections["default"])(sectionsWithDepth, {
config: config,
componentFiles: []
});
case 2:
result = _context5.sent;
expect(result.map(filterSectionDepth)).toEqual([{
sectionDepth: 2,
sections: [{
sectionDepth: 1,
sections: [{
sectionDepth: 0
}]
}]
}, {
sectionDepth: 0,
sections: [{
sectionDepth: 0
}]
}]);
case 4:
case "end":
return _context5.stop();
}
}
}, _callee5);
})));
it('should return an array of sectionsWithBadDepth taking the sectionDepth of the first depth of the sections', /*#__PURE__*/(0, _asyncToGenerator2["default"])( /*#__PURE__*/_regenerator["default"].mark(function _callee6() {
var result;
return _regenerator["default"].wrap(function _callee6$(_context6) {
while (1) {
switch (_context6.prev = _context6.next) {
case 0:
_context6.next = 2;
return (0, _getSections["default"])(sectionsWithBadDepth, {
config: config,
componentFiles: []
});
case 2:
result = _context6.sent;
expect(result.map(filterSectionDepth)).toEqual([{
sectionDepth: 0,
sections: [{
sectionDepth: 0,
sections: [{
sectionDepth: 0
}]
}]
}]);
case 4:
case "end":
return _context6.stop();
}
}
}, _callee6);
})));
});
vi.mock('vue-docgen-api', function () {
return {
parseMulti: function parseMulti() {
return Promise.resolve([{
tags: {
requires: [{
description: 'path/to/require1'
},
//
{
description: 'path/to/require2'
} //
]
}
}]);
},
ScriptHandlers: {}
};
});
describe('getRequiredComponents', function () {
it('should return an array of all requires tags contents', /*#__PURE__*/(0, _asyncToGenerator2["default"])( /*#__PURE__*/_regenerator["default"].mark(function _callee7() {
var requiredFiles;
return _regenerator["default"].wrap(function _callee7$(_context7) {
while (1) {
switch (_context7.prev = _context7.next) {
case 0:
_context7.next = 2;
return (0, _getSections.getRequiredComponents)(['source/of/file'], false);
case 2:
requiredFiles = _context7.sent;
expect((0, _cleanFilePathSnapshot["default"])(requiredFiles)).toMatchInlineSnapshot("\n\t\t\t{\n\t\t\t \"source/of/file\": [\n\t\t\t \"~/source/of/path/to/require1\",\n\t\t\t \"~/source/of/path/to/require2\",\n\t\t\t ],\n\t\t\t}\n\t\t");
case 4:
case "end":
return _context7.stop();
}
}
}, _callee7);
})));
});