43 lines
1.4 KiB
JavaScript
43 lines
1.4 KiB
JavaScript
const { parse } = require('./jsxParser.js');
|
|
const result1 = require('./result1.json');
|
|
|
|
const cmps = {
|
|
ExampleComponent: { x: 'examplecomponent' },
|
|
home: 'home',
|
|
ExampleWithChildren: 'examplewithchildren',
|
|
enclosed: 'enclosed',
|
|
};
|
|
|
|
// Example includes:
|
|
// - nested components
|
|
// - HTML entities
|
|
// - inline styles
|
|
// - classNames
|
|
// - attribute without a value
|
|
const str = `
|
|
<div class="homeGrid">
|
|
<text>
|
|
<div class="homeTop"></div>
|
|
<div style="background: black; text-align: right; color: white; height: 20px; font-size: 15px; width: 100px">
|
|
<ExampleComponent title="Hello world" skus=" 55-12940,102-109012"
|
|
loc="home" linktext="I AM HERE" linkurl="/hello"></ExampleComponent>
|
|
</div>
|
|
<div class="homeMiddle"><home ></home></div>
|
|
<div class="homeBottom"> </div>
|
|
<div class="homeBottom">
|
|
<ExampleWithChildren logo="/logo.svg" title="Please wait"
|
|
linktext="READ MORE" linkurl="https://google.com/" moretext="More"
|
|
content1="Let's go">
|
|
<enclosed a="b" tagged />
|
|
</ExampleWithChildren>
|
|
</div>
|
|
</div>
|
|
`;
|
|
const result = parse(str, cmps, (tag, attrs) => ({ tag, attrs }));
|
|
if (JSON.stringify(result) != JSON.stringify(result1))
|
|
{
|
|
process.stderr.write('Test failed, got:\n');
|
|
process.stderr.write(JSON.stringify(result, null, 2));
|
|
process.exit(1);
|
|
}
|