-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathconfig.spec.ts
77 lines (71 loc) · 2.04 KB
/
config.spec.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
import test from 'ava'
import { transform, Config, State } from '..'
const svgBaseCode = `
<svg width="88px" height="88px" xmlns="http://www.w3.org/2000/svg" viewBox="0 0 88 88">
<g fill="none" fill-rule="evenodd" stroke="#063855" stroke-linecap="square" stroke-width="2">
<path d="M51 37 37 51M51 51 37 37"/>
</g>
</svg>
`
test('without config and state', async t => {
const result = await transform(svgBaseCode)
t.snapshot(result)
})
const configs: (Config & { state?: Partial<State> })[] = [
{ dimensions: false },
{ expandProps: false },
{ expandProps: 'start' },
{ icon: true },
{ icon: 24 },
{ icon: '2em' },
{ native: true },
{ native: true, icon: true },
{ native: true, expandProps: false },
{ native: true, ref: true },
{ ref: true },
{ svgProps: { a: 'b', b: '{props.b}' } },
{ replaceAttrValues: { none: 'black' } },
{ replaceAttrValues: { none: '{black}' } },
// { svgo: false },
// { prettier: false },
// {
// template: (_, { tpl }) =>
// tpl`const noop = () => null; export default noop;`,
// },
{ titleProp: true },
{ descProp: true },
{ memo: true },
{
namedExport: 'Component',
state: { caller: { previousExport: 'export default "logo.svg";' } },
},
{ exportType: 'named' },
{ jsxRuntime: 'automatic' },
{ jsxRuntime: 'classic-preact' },
{ jsxRuntimeImport: { source: 'hyperapp-jsx-pragma', defaultSpecifier: 'h' } }
]
configs.forEach(async c => {
test(`accepts options ${JSON.stringify(c)}`, async t => {
const { state, ...config } = c
const result = await transform(svgBaseCode, config, state)
t.snapshot(result)
})
})
test('titleProp: without title added', async t => {
const svg = `
<svg width="0" height="0" style="position:absolute">
<path d="M0 0h24v24H0z" fill="none" />
</svg>
`
const result = await transform(svg, { titleProp: true })
t.snapshot(result)
})
test('descProp: without desc added', async t => {
const svg = `
<svg width="0" height="0" style="position:absolute">
<path d="M0 0h24v24H0z" fill="none" />
</svg>
`
const result = await transform(svg, { descProp: true })
t.snapshot(result)
})