feat: pipeline improvements

This commit is contained in:
2023-11-07 18:00:17 +01:00
parent 8a421cb2fb
commit 51602ffa0f
38 changed files with 183 additions and 130 deletions

View File

@@ -12,17 +12,17 @@
* You should have received a copy of the GNU General Public License along with
* this program. If not, see <https://www.gnu.org/licenses/>.
*/
import {treeGroupBy} from '../src/index.js';
import {expect} from 'chai';
import {Tree, treeGroupBy} from '../src/index.js';
interface TestItem {
id: number;
path?: string[];
}
/**
* @typedef {{id: number; path?: string[]}} TestItem
* @typedef {import('../src/types.js').Tree<TestItem>} TestItemTree
*/
describe('tree-group', function () {
it('should create a tree', function () {
const items: Array<TestItem> = [
/** @type {TestItem[]} */
const items = [
{
id: 1,
path: ['a', 'b', 'c'],
@@ -35,20 +35,22 @@ describe('tree-group', function () {
const tree = treeGroupBy(items, item => item.path ?? []);
const expectedTree: Tree<TestItem> = {
a: {
/** @type {TestItemTree} */
const expectedTree = {
a: /** @type {TestItemTree} */ ({
b: {
c: {_: [items[0]]},
d: {_: [items[1]]},
} as Tree<TestItem>,
} as Tree<TestItem>,
} as Tree<TestItem>;
},
}),
};
expect(tree).to.deep.equal(expectedTree);
});
it('should also sort empty paths', () => {
const items: Array<TestItem> = [
/** @type {TestItem[]} */
const items = [
{
id: 1,
path: ['a', 'b', 'c'],
@@ -60,14 +62,14 @@ describe('tree-group', function () {
const tree = treeGroupBy(items, item => item.path ?? []);
const expectedTree: Tree<TestItem> = {
const expectedTree = /** @type {TestItemTree} */ ({
a: {
b: {
c: {_: [items[0]]},
} as Tree<TestItem>,
} as Tree<TestItem>,
},
},
_: [items[1]],
} as Tree<TestItem>;
});
expect(tree).to.deep.equal(expectedTree);
});