mirror of
https://github.com/tenrok/BBob.git
synced 2026-05-15 11:59:37 +03:00
2d1a08ba9a
* chore: fix swc + rollup transform * chore: fix pkg-task args parsing * chore: update lerna, rollup and swc to build proper es6 files * chore: fix swc build for es targets * ci: nodes matrix to newest versions * ci: rollup to mjs, swc to json * ci: add canary publish * ci: no git tag for canary * ci: no private publish for canary * ci: remove --canary from publish-canary * fix: remove gitHead from package.json * fix: tests setup * fix: bbob plugin helper imports * fix: plugin helper build priority and circular deps * fix: add nx for parallel build * fix: npm ci * fix: code ql * fix: remove exports directive * fix: rollup build * fix: vue2 test and minify * fix: bundle size limits * feat: bundlephobia pr review * feat: bundlephobia more popular action * feat: publish branch to npm * fix: secret NPM token * fix: bundlephobia version * fix: remove bundlephobia checker * fix: npm publish in PR * chore: release 2.8.3 * chore: fix test runs on CI, removed 14.x version * fix: sync package-lock * fix: remove lock files in sub packages * fix: bundlesize > bundlesize2 * fix: update lock files * fix: lock file in vue2-example
117 lines
2.7 KiB
JavaScript
117 lines
2.7 KiB
JavaScript
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)
|
|
})
|
|
});
|