Skip to content

Commit b5b5e91

Browse files
committed
test: add StringLiteral and TemplateElement case
1 parent cef0dc1 commit b5b5e91

File tree

3 files changed

+42
-1
lines changed

3 files changed

+42
-1
lines changed

packages/unplugin-tailwindcss-mangle/package.json

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,9 @@
5757
"tailwindcss",
5858
"utilities",
5959
"mangle",
60-
"class"
60+
"class",
61+
"obfuscator",
62+
"obfuscation"
6163
],
6264
"author": "SonOfMagic <[email protected]>",
6365
"license": "MIT",
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
// Jest Snapshot v1, https://goo.gl/fbAQLP
2+
3+
exports[`js handler common StringLiteral 1`] = `"element.innerHTML = "<div class=\\"tw-a tw-b\\">count is counter</div>";"`;
4+
5+
exports[`js handler common TemplateElement 1`] = `
6+
"const counter = 0;
7+
element.innerHTML = \`<div class="tw-a tw-b">count is \${counter}</div>\`;"
8+
`;
Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
import { jsHandler } from '../src/js/index'
2+
import ClassGenerator from '../src/classGenerator'
3+
describe('js handler', () => {
4+
it('common StringLiteral', () => {
5+
const classGenerator = new ClassGenerator()
6+
const runtimeSet = new Set<string>()
7+
runtimeSet.add('dark:bg-zinc-800/30')
8+
runtimeSet.add('lg:dark:bg-zinc-800/30')
9+
// eslint-disable-next-line no-template-curly-in-string
10+
const testCase = 'element.innerHTML = \'<div class="dark:bg-zinc-800/30 lg:dark:bg-zinc-800/30">count is counter</div>\''
11+
const code = jsHandler(testCase, {
12+
classGenerator,
13+
runtimeSet
14+
}).code
15+
expect(code).toMatchSnapshot()
16+
})
17+
18+
it('common TemplateElement', () => {
19+
const classGenerator = new ClassGenerator()
20+
const runtimeSet = new Set<string>()
21+
runtimeSet.add('dark:bg-zinc-800/30')
22+
runtimeSet.add('lg:dark:bg-zinc-800/30')
23+
// eslint-disable-next-line no-template-curly-in-string
24+
const testCase = 'const counter = 0;element.innerHTML = `<div class="dark:bg-zinc-800/30 lg:dark:bg-zinc-800/30">count is ${counter}</div>`'
25+
const code = jsHandler(testCase, {
26+
classGenerator,
27+
runtimeSet
28+
}).code
29+
expect(code).toMatchSnapshot()
30+
})
31+
})

0 commit comments

Comments
 (0)