-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.test.js
41 lines (34 loc) · 1018 Bytes
/
index.test.js
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
const path = require('path')
const rollup = require('rollup')
const svgToSymbol = require('../src/index.js')
const resolve = path.resolve.bind(path, __dirname)
test('basic', async () => {
const bundle = await rollup.rollup({
input: resolve('sprite.js'),
plugins: [
svgToSymbol()
]
})
const { code } = await bundle.generate({
format: 'cjs'
})
const sprite = eval(code) // eslint-disable-line
expect(sprite).toBe('<svg><defs><symbol id="add">add</symbol><symbol id="close">close</symbol></defs></svg>')
})
test('extractId', async () => {
const bundle = await rollup.rollup({
input: resolve('sprite.js'),
plugins: [
svgToSymbol({
extractId({ name }) {
return `icon-${name}`
}
})
]
})
const { code } = await bundle.generate({
format: 'cjs'
})
const sprite = eval(code) // eslint-disable-line
expect(sprite).toBe('<svg><defs><symbol id="icon-add">add</symbol><symbol id="icon-close">close</symbol></defs></svg>')
})