mirror of
https://github.com/tenrok/BBob.git
synced 2026-06-17 19:21:20 +03:00
feat: typescript support (#185)
* 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
This commit is contained in:
+31
@@ -13,6 +13,37 @@ describe('@bbob/plugin-helper/TagNode', () => {
|
||||
expect(TagNode.isOf(tagNode, 'test')).toBe(true);
|
||||
});
|
||||
|
||||
test('attr', () => {
|
||||
const tagNode = TagNode.create('test', {test: 1}, ['Hello']);
|
||||
|
||||
tagNode.attr('foo', 'bar')
|
||||
|
||||
expect(tagNode.attrs.foo).toBe('bar');
|
||||
});
|
||||
|
||||
test('append', () => {
|
||||
const tagNode = TagNode.create('test', {test: 1}, ['Hello']);
|
||||
|
||||
tagNode.append('World')
|
||||
|
||||
expect(tagNode.content).toEqual(['Hello', 'World']);
|
||||
});
|
||||
|
||||
test('length', () => {
|
||||
const tagNode = TagNode.create('test', {test: 1}, ['Hello', 'World']);
|
||||
|
||||
expect(tagNode.length).toEqual('HelloWorld'.length);
|
||||
});
|
||||
|
||||
test('toTagNode', () => {
|
||||
const tagNode = TagNode.create('test', {test: 1}, ['Hello']);
|
||||
const newTagNode = tagNode.toTagNode()
|
||||
|
||||
expect(newTagNode !== tagNode).toBe(true);
|
||||
expect(newTagNode.tag).toEqual(tagNode.tag);
|
||||
expect(newTagNode.content).toEqual(tagNode.content);
|
||||
});
|
||||
|
||||
describe('toString', () => {
|
||||
test('tag with content and params', () => {
|
||||
const tagNode = TagNode.create('test', {test: 1}, ['Hello']);
|
||||
@@ -1,116 +0,0 @@
|
||||
import {
|
||||
attrsToString,
|
||||
attrValue,
|
||||
appendToNode,
|
||||
getNodeLength,
|
||||
getUniqAttr,
|
||||
isTagNode,
|
||||
isStringNode,
|
||||
isEOL,
|
||||
} from '../src';
|
||||
|
||||
describe('@bbob/plugin-helper/helpers', () => {
|
||||
test('appendToNode', () => {
|
||||
const value = 'test';
|
||||
const node = { content: [] };
|
||||
|
||||
appendToNode(node, value);
|
||||
expect(node.content.pop()).toBe(value);
|
||||
});
|
||||
|
||||
test('getNodeLength', () => {
|
||||
const node = {
|
||||
tag: 'test',
|
||||
content: [
|
||||
'123',
|
||||
{
|
||||
tag: 'test2',
|
||||
content: ['123']
|
||||
}
|
||||
]
|
||||
};
|
||||
|
||||
expect(getNodeLength(node)).toBe(6)
|
||||
});
|
||||
|
||||
test('isTagNode', () => {
|
||||
const node = {
|
||||
tag: 'test',
|
||||
content: []
|
||||
};
|
||||
|
||||
expect(isTagNode(node)).toBe(true)
|
||||
});
|
||||
|
||||
test('isStringNode', () => {
|
||||
const node = {
|
||||
tag: 'test',
|
||||
content: ['123']
|
||||
};
|
||||
|
||||
expect(isStringNode(node.content[0])).toBe(true);
|
||||
});
|
||||
|
||||
test('attrValue boolean', () => {
|
||||
expect(attrValue('test', true)).toBe('test');
|
||||
});
|
||||
|
||||
test('attrValue number', () => {
|
||||
expect(attrValue('test', 123)).toBe('test="123"');
|
||||
});
|
||||
|
||||
test('attrValue string', () => {
|
||||
expect(attrValue('test', 'hello')).toBe('test="hello"');
|
||||
});
|
||||
|
||||
test('attrValue object', () => {
|
||||
const attrs = { tag: 'test' };
|
||||
|
||||
expect(attrValue('test', attrs)).toBe('test="{"tag":"test"}"');
|
||||
});
|
||||
|
||||
test('isEOL', () => {
|
||||
expect(isEOL('\n')).toBe(true)
|
||||
});
|
||||
|
||||
test('attrsToString', () => {
|
||||
expect(attrsToString({
|
||||
tag: 'test',
|
||||
foo: 'bar',
|
||||
disabled: true
|
||||
})).toBe(` tag="test" foo="bar" disabled`)
|
||||
});
|
||||
|
||||
test('attrsToString undefined', () => {
|
||||
expect(attrsToString(undefined)).toBe('')
|
||||
});
|
||||
|
||||
describe('attrsToString escape', () => {
|
||||
test(`javascript:alert("hello")`, () => {
|
||||
expect(attrsToString({
|
||||
onclick: `javascript:alert('hello')`,
|
||||
href: `javascript:alert('hello')`,
|
||||
})).toBe(` onclick="javascript%3Aalert('hello')" href="javascript%3Aalert('hello')"`)
|
||||
});
|
||||
test(`JAVASCRIPT:alert("hello")`, () => {
|
||||
expect(attrsToString({
|
||||
onclick: `JAVASCRIPT:alert('hello')`,
|
||||
href: `JAVASCRIPT:alert('hello')`,
|
||||
})).toBe(` onclick="JAVASCRIPT%3Aalert('hello')" href="JAVASCRIPT%3Aalert('hello')"`)
|
||||
});
|
||||
test(`<tag>`, () => {
|
||||
expect(attrsToString({
|
||||
onclick: `<tag>`,
|
||||
href: `<tag>`,
|
||||
})).toBe(` onclick="<tag>" href="<tag>"`)
|
||||
});
|
||||
});
|
||||
|
||||
test('getUniqAttr with unq attr', () => {
|
||||
expect(getUniqAttr({foo: true, 'http://bar.com': 'http://bar.com'})).toBe('http://bar.com')
|
||||
});
|
||||
|
||||
test('getUniqAttr without unq attr', () => {
|
||||
expect(getUniqAttr({foo: true})).toBe(null)
|
||||
})
|
||||
});
|
||||
@@ -0,0 +1,117 @@
|
||||
import {
|
||||
attrsToString,
|
||||
attrValue,
|
||||
appendToNode,
|
||||
getNodeLength,
|
||||
getUniqAttr,
|
||||
isTagNode,
|
||||
isStringNode,
|
||||
isEOL,
|
||||
TagNode,
|
||||
} from '../src';
|
||||
|
||||
describe('@bbob/plugin-helper/helpers', () => {
|
||||
test('appendToNode', () => {
|
||||
const value = 'test';
|
||||
const node = {content: []} as TagNode;
|
||||
|
||||
appendToNode(node, value);
|
||||
expect(node.content.pop()).toBe(value);
|
||||
});
|
||||
|
||||
test('getNodeLength', () => {
|
||||
const node = {
|
||||
tag: 'test',
|
||||
content: [
|
||||
'123',
|
||||
{
|
||||
tag: 'test2',
|
||||
content: ['123']
|
||||
}
|
||||
]
|
||||
} as TagNode;
|
||||
|
||||
expect(getNodeLength(node)).toBe(6)
|
||||
});
|
||||
|
||||
test('isTagNode', () => {
|
||||
const node = {
|
||||
tag: 'test',
|
||||
content: []
|
||||
} as TagNode;
|
||||
|
||||
expect(isTagNode(node)).toBe(true)
|
||||
});
|
||||
|
||||
test('isStringNode', () => {
|
||||
const node = {
|
||||
tag: 'test',
|
||||
content: ['123']
|
||||
};
|
||||
|
||||
expect(isStringNode(node.content[0])).toBe(true);
|
||||
});
|
||||
|
||||
test('attrValue boolean', () => {
|
||||
expect(attrValue('test', true)).toBe('test');
|
||||
});
|
||||
|
||||
test('attrValue number', () => {
|
||||
expect(attrValue('test', 123)).toBe('test="123"');
|
||||
});
|
||||
|
||||
test('attrValue string', () => {
|
||||
expect(attrValue('test', 'hello')).toBe('test="hello"');
|
||||
});
|
||||
|
||||
test('attrValue object', () => {
|
||||
const attrs = {tag: 'test'};
|
||||
|
||||
expect(attrValue('test', attrs)).toBe('test="{"tag":"test"}"');
|
||||
});
|
||||
|
||||
test('isEOL', () => {
|
||||
expect(isEOL('\n')).toBe(true)
|
||||
});
|
||||
|
||||
test('attrsToString', () => {
|
||||
expect(attrsToString({
|
||||
tag: 'test',
|
||||
foo: 'bar',
|
||||
disabled: true
|
||||
})).toBe(` tag="test" foo="bar" disabled`)
|
||||
});
|
||||
|
||||
test('attrsToString undefined', () => {
|
||||
expect(attrsToString(undefined)).toBe('')
|
||||
});
|
||||
|
||||
describe('attrsToString escape', () => {
|
||||
test(`javascript:alert("hello")`, () => {
|
||||
expect(attrsToString({
|
||||
onclick: `javascript:alert('hello')`,
|
||||
href: `javascript:alert('hello')`,
|
||||
})).toBe(` onclick="javascript%3Aalert('hello')" href="javascript%3Aalert('hello')"`)
|
||||
});
|
||||
test(`JAVASCRIPT:alert("hello")`, () => {
|
||||
expect(attrsToString({
|
||||
onclick: `JAVASCRIPT:alert('hello')`,
|
||||
href: `JAVASCRIPT:alert('hello')`,
|
||||
})).toBe(` onclick="JAVASCRIPT%3Aalert('hello')" href="JAVASCRIPT%3Aalert('hello')"`)
|
||||
});
|
||||
test(`<tag>`, () => {
|
||||
expect(attrsToString({
|
||||
onclick: `<tag>`,
|
||||
href: `<tag>`,
|
||||
})).toBe(` onclick="<tag>" href="<tag>"`)
|
||||
});
|
||||
});
|
||||
|
||||
test('getUniqAttr with unq attr', () => {
|
||||
expect(getUniqAttr({foo: true, 'http://bar.com': 'http://bar.com'})).toBe('http://bar.com')
|
||||
});
|
||||
|
||||
test('getUniqAttr without unq attr', () => {
|
||||
expect(getUniqAttr({foo: true})).toBe(null)
|
||||
})
|
||||
});
|
||||
Reference in New Issue
Block a user