Skip to content

Commit

Permalink
Add test for nested template literals
Browse files Browse the repository at this point in the history
Initially I thought this package wouldn't work for nested template
literals (which ChromeDevTools used). I wanted to do TDD and add
the test first (since there was no test for it yet) and I discovered
this use case is already covered. That's because the `template.tag`
for MemberExpressions already includes the whole line, and thus
it matches on `lihtml.html`, which indeed includes `html`.

So let's add the test to make sure this use case remains covers,
but no actual code changes are required 🎉
  • Loading branch information
TimvdLippe committed May 25, 2021
1 parent c40abd4 commit d7ab08e
Showing 1 changed file with 23 additions and 0 deletions.
23 changes: 23 additions & 0 deletions test/minifyHTMLLiterals.spec.ts
Expand Up @@ -214,6 +214,21 @@ describe('minifyHTMLLiterals()', () => {
}
`;

const NESTED_TEMPLATE_SOURCE = `
function nested() {
return LitHtml.html\`<div id="container">
<span>Some content here</span>
</div>
\`;
}
`;

const NESTED_TEMPLATE_SOURCE_MIN = `
function nested() {
return LitHtml.html\`<div id="container"><span>Some content here</span></div>\`;
}
`;

it('should minify "html" and "css" tagged templates', () => {
const result = minifyHTMLLiterals(SOURCE, { fileName: 'test.js' });
expect(result).to.be.an('object');
Expand All @@ -232,6 +247,14 @@ describe('minifyHTMLLiterals()', () => {
expect(result!.code).to.equal(COMMENT_SOURCE_MIN);
});

it('should minify html tagged with a member expression ending in html', () => {
const result = minifyHTMLLiterals(NESTED_TEMPLATE_SOURCE, {
fileName: 'test.js'
});
expect(result).to.be.an('object');
expect(result!.code).to.equal(NESTED_TEMPLATE_SOURCE_MIN);
});

it('should minify multiline svg elements', () => {
const result = minifyHTMLLiterals(SVG_MULTILINE_SOURCE, {
fileName: 'test.js'
Expand Down

0 comments on commit d7ab08e

Please sign in to comment.