UNPKG

bonsai-analyzer

Version:
83 lines (79 loc) 2.27 kB
"use strict"; var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault"); var _defaults = require("../../__test_helpers__/defaults"); var _collapseModulesToRows = _interopRequireDefault(require("../collapseModulesToRows")); describe('collapseModulesToRows', () => { it('should take some modules and reformat them', () => { const m1 = (0, _defaults.defaultExtendedModule)({ id: 1 }); const m2 = (0, _defaults.defaultExtendedModule)({ id: 2 }); const modules = [m1, m2]; expect((0, _collapseModulesToRows.default)(modules)).toEqual([{ collapsedSizeBytes: 0, displayModule: m1, records: [m1] }, { collapsedSizeBytes: 0, displayModule: m2, records: [m2] }]); }); it('should collapse a single dependency', () => { const m1 = (0, _defaults.defaultExtendedModule)({ id: 1, requirements: [(0, _defaults.defaultModule)({ id: 2 })], requirementsCount: 1 }); const m2 = (0, _defaults.defaultExtendedModule)({ id: 2, requiredBy: [(0, _defaults.defaultModule)({ id: 1 })], requiredByCount: 1 }); const modules = [m1, m2]; expect((0, _collapseModulesToRows.default)(modules)).toEqual([{ collapsedSizeBytes: 0, displayModule: m1, records: [m1, m2] }]); }); it('should collapse a recursive dependency tree', () => { const m1 = (0, _defaults.defaultExtendedModule)({ id: 1, requirements: [(0, _defaults.defaultModule)({ id: 2 })], requirementsCount: 1 }); const m2 = (0, _defaults.defaultExtendedModule)({ id: 2, requiredBy: [(0, _defaults.defaultModule)({ id: 1 })], requiredByCount: 1, requirements: [(0, _defaults.defaultModule)({ id: 3 })], requirementsCount: 1 }); const m3 = (0, _defaults.defaultExtendedModule)({ id: 3, requiredBy: [(0, _defaults.defaultModule)({ id: 2 })], requiredByCount: 1 }); const modules = [m1, m2, m3]; expect((0, _collapseModulesToRows.default)(modules)).toEqual([{ collapsedSizeBytes: 0, displayModule: m1, records: [m1, m2, m3] }]); }); });