bonsai-analyzer
Version:
Trim your dependency tree.
72 lines (67 loc) • 2.08 kB
JavaScript
;
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
var _getEntryHierarchy = _interopRequireDefault(require("../getEntryHierarchy"));
var _getParentChunks = _interopRequireDefault(require("../getParentChunks"));
var _defaults = require("../../__test_helpers__/defaults");
const stats = {
chunks: [(0, _defaults.defaultChunk)({
id: 0,
names: ['chunk-zero']
}), (0, _defaults.defaultChunk)({
id: 1,
names: ['chunk-one'],
parents: [0]
}), (0, _defaults.defaultChunk)({
id: 2,
names: ['chunk-two'],
parents: [0, 1]
}), (0, _defaults.defaultChunk)({
id: 3,
names: ['chunk-three'],
parents: []
}), (0, _defaults.defaultChunk)({
id: 4,
names: ['chunk-four'],
parents: [0, 1, 3]
}), (0, _defaults.defaultChunk)({
id: 5,
names: ['chunk-five'],
parents: [4]
})],
modules: []
};
const chunksByParent = (0, _getEntryHierarchy.default)(stats);
describe('getParentChunks', () => {
it('should list some for a chunk in the middle', () => {
const result = (0, _getParentChunks.default)(chunksByParent, 1);
expect(result).toEqual([expect.objectContaining({
id: 0
}), expect.objectContaining({
id: 1
})]);
});
it('should dive down to the bottom chunkIds', () => {
const result = (0, _getParentChunks.default)(chunksByParent, 5);
expect(result).toEqual([expect.objectContaining({
id: 0
}), expect.objectContaining({
id: 1
}), expect.objectContaining({
id: 4
}), expect.objectContaining({
id: 5
})]);
});
it('should list just one for the top-level chunkId', () => {
expect((0, _getParentChunks.default)(chunksByParent, 0)).toEqual([expect.objectContaining({
id: 0
})]);
expect((0, _getParentChunks.default)(chunksByParent, 3)).toEqual([expect.objectContaining({
id: 3
})]);
});
it('should list nothing for a bad chunkId', () => {
const result = (0, _getParentChunks.default)(chunksByParent, -100);
expect(result).toEqual(null);
});
});