mirror of
https://github.com/tenrok/BBob.git
synced 2026-05-15 11:59:37 +03:00
8797f7f363
* feat: initial typescript support * feat: typescript support * feat(plugin-helper): move files to typescript * chore: update lock files * feat: preset types * fix: build * fix: benchmark * fix: remove pnpm cache * fix: bench action * fix: pnpm recursive install * fix: nx cache * fix: lock file * fix: workflows * fix: lerna support in pnpm * fix: pnpm workspace * fix: remove unused files * fix: pnpm lock file * fix: update lerna for support pnpm * fix: lerna bootstrap * fix: rollup build * fix: update nx * fix: build * fix: add nx dep target * fix: remove nx cache * fix: workflow run on push only for master * fix: test workflow run on push only for master * fix: remove parallel for gen types * fix: benchmark * fix: benchmark imports * fix: pnpm * fix: types errors and pnpm * fix: types * fix: types * refactor: parser * fix(parser): tests * fix: preset tests * fix: react types * fix: react type declarations * fix: pnpm lock file * fix: react preset types * fix: lock file * fix: vue2 types * feat: dev container support * fix: types * fix: types * refactor: rewrite pkg-task, add nx gen-types deps, fix react/render.ts * refactor: types * fix: types * fix: rename gen-types to types * fix: nx build order * fix: nx reset * fix: define nx deps explicit * fix: build * fix: nx * fix: nx order build * fix: nx deps * fix: bbob cli tests * fix: tests * fix: cli tests and import * fix: test cover * fix: cli cover
91 lines
2.1 KiB
TypeScript
91 lines
2.1 KiB
TypeScript
import { iterate, match, same } from '../src/utils';
|
|
import { isTagNode } from "@bbob/plugin-helper";
|
|
|
|
describe('@bbob/core utils', () => {
|
|
test('iterate', () => {
|
|
const testArr = [{
|
|
one: true,
|
|
content: [{ oneInside: true }]
|
|
}, {
|
|
two: true,
|
|
content: [{ twoInside: true }]
|
|
}];
|
|
|
|
const resultArr = iterate(testArr, node => {
|
|
if (typeof node === 'object' && node !== null) {
|
|
return {
|
|
...node,
|
|
pass: 1
|
|
}
|
|
}
|
|
|
|
return node;
|
|
});
|
|
|
|
const expected = [
|
|
{
|
|
one: true,
|
|
content: [{ oneInside: true, pass: 1, }],
|
|
pass: 1,
|
|
}, {
|
|
two: true,
|
|
content: [{ twoInside: true, pass: 1, }],
|
|
pass: 1,
|
|
}
|
|
];
|
|
|
|
expect(resultArr).toEqual(expected);
|
|
});
|
|
test('match', () => {
|
|
const testArr = [
|
|
{ tag: 'mytag1', one: 1 },
|
|
{ tag: 'mytag2', two: 1 },
|
|
{ tag: 'mytag3', three: 1 },
|
|
{ tag: 'mytag4', four: 1 },
|
|
{ tag: 'mytag5', five: 1 },
|
|
{ tag: 'mytag6', six: 1 },
|
|
];
|
|
|
|
const resultArr = match(testArr, [{ tag: 'mytag1' }, { tag: 'mytag2' }], node => {
|
|
if (isTagNode(node)) {
|
|
node.attrs = node.attrs || {}
|
|
node.attrs.pass = 1
|
|
}
|
|
|
|
return node;
|
|
});
|
|
|
|
const expected = [
|
|
{ tag: 'mytag1', one: 1, attrs: { pass: 1 } },
|
|
{ tag: 'mytag2', two: 1, attrs: { pass: 1 } },
|
|
{ tag: 'mytag3', three: 1 },
|
|
{ tag: 'mytag4', four: 1 },
|
|
{ tag: 'mytag5', five: 1 },
|
|
{ tag: 'mytag6', six: 1 },
|
|
];
|
|
|
|
expect(resultArr).toEqual(expected)
|
|
})
|
|
|
|
describe('same', () => {
|
|
test('same not same typeof', () => {
|
|
expect(same(1, {})).toBe(false)
|
|
})
|
|
test('same boolean', () => {
|
|
expect(same(true, true)).toBe(true)
|
|
})
|
|
test('same null', () => {
|
|
expect(same(null, null)).toBe(true)
|
|
})
|
|
test('same array', () => {
|
|
expect(same([1, 2, 3], [1, 2, 3, 4])).toBe(true)
|
|
})
|
|
test('same object', () => {
|
|
expect(same({ foo: true, bar: 'test' }, { foo: true, bar: 'test', ext: true })).toBe(true)
|
|
})
|
|
test('same string', () => {
|
|
expect(same('bar', 'bar')).toBe(true)
|
|
})
|
|
})
|
|
});
|