-
Notifications
You must be signed in to change notification settings - Fork 7
/
Copy pathtest.js
37 lines (31 loc) · 3.12 KB
/
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
import test from 'ava'
const fs = require('fs')
const outlineStroke = require('./')
const src = `
<svg xmlns="http://www.w3.org/2000/svg" width="506.3" height="506.3" viewBox="0 0 506.3 506.3"><g fill="none" stroke="#202020" stroke-width="16.333" stroke-miterlimit="10"><path d="M122.5 122.5h375.7v375.7H122.5z"/><path d="M122.5 383.8H8.2V8.2h375.6v114.3M310.3 204.2v212.3M416.5 310.3H204.2"/></g></svg>`
const expected = `<svg xmlns="http://www.w3.org/2000/svg" width="506" height="506" viewBox="0 0 506 506" version="1.1">
<path d="M 0 196 L 0 392 57 392 L 114 392 114 449 L 114 506 309.835 506 L 505.671 506 506.335 419.750 C 506.700 372.313, 506.890 258.350, 506.758 166.500 C 506.625 74.650, 506.397 25.263, 506.250 56.750 L 505.984 114 448.992 114 L 392 114 392 57 L 392 0 196 0 L 0 0 0 196 M 0.490 196.500 C 0.490 304.300, 0.607 348.252, 0.750 294.170 C 0.893 240.089, 0.893 151.889, 0.750 98.170 C 0.607 44.452, 0.490 88.700, 0.490 196.500 M 16.667 16.667 C 16.300 17.033, 16 97.808, 16 196.167 L 16 375 65 375 L 114 375 114 244.500 L 114 114 244.500 114 L 375 114 375 65 L 375 16 196.167 16 C 97.808 16, 17.033 16.300, 16.667 16.667 M 131 310.500 L 131 490 310.500 490 L 490 490 490 310.500 L 490 131 310.500 131 L 131 131 131 310.500 M 302 253 L 302 302 253 302 L 204 302 204 310 L 204 318 253 318 L 302 318 302 367 L 302 416 310 416 L 318 416 318 367 L 318 318 367 318 L 416 318 416 310 L 416 302 367 302 L 318 302 318 253 L 318 204 310 204 L 302 204 302 253" stroke="none" fill="black" fill-rule="evenodd"/>
</svg>`
const expectedWithParams = `<svg xmlns="http://www.w3.org/2000/svg" width="506" height="506" viewBox="0 0 506 506" version="1.1">
<rect x="0" y="0" width="100%" height="100%" fill="#a1a5a5" />
<path d="M 0 196 L 0 392 57 392 L 114 392 114 449 L 114 506 309.835 506 L 505.671 506 506.335 419.750 C 506.700 372.313, 506.890 258.350, 506.758 166.500 C 506.625 74.650, 506.397 25.263, 506.250 56.750 L 505.984 114 448.992 114 L 392 114 392 57 L 392 0 196 0 L 0 0 0 196 M 0.490 196.500 C 0.490 304.300, 0.607 348.252, 0.750 294.170 C 0.893 240.089, 0.893 151.889, 0.750 98.170 C 0.607 44.452, 0.490 88.700, 0.490 196.500 M 16.667 16.667 C 16.300 17.033, 16 97.808, 16 196.167 L 16 375 65 375 L 114 375 114 244.500 L 114 114 244.500 114 L 375 114 375 65 L 375 16 196.167 16 C 97.808 16, 17.033 16.300, 16.667 16.667 M 131 310.500 L 131 490 310.500 490 L 490 490 490 310.500 L 490 131 310.500 131 L 131 131 131 310.500 M 302 253 L 302 302 253 302 L 204 302 204 310 L 204 318 253 318 L 302 318 302 367 L 302 416 310 416 L 318 416 318 367 L 318 318 367 318 L 416 318 416 310 L 416 302 367 302 L 318 302 318 253 L 318 204 310 204 L 302 204 302 253" stroke="none" fill="#bada55" fill-rule="evenodd"/>
</svg>`
test('Converts from string', async (t) => {
const res = await outlineStroke(src)
t.is(res, expected)
})
test.cb('Converts from Buffer', (t) => {
fs.readFile('./src.svg', (err, data) => {
outlineStroke(data).then((res) => {
t.is(res, expected)
t.end()
})
})
})
test('Apply params (color)', async (t) => {
const res = await outlineStroke(src, {
color: '#bada55',
background: '#a1a5a5',
})
t.is(res, expectedWithParams)
})