forked from elrumordelaluz/scale-that-svg
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtest.mjs
35 lines (33 loc) · 1.19 KB
/
test.mjs
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
import fs from 'fs'
import { promisify } from 'util'
import test from 'ava'
import { parse as svgson } from 'svgson'
const readFileAsync = promisify(fs.readFile)
import { scale as scaleThatSvg } from './dist/scale-that-svg.cjs.js'
test('Scale that SVG!', async (t) => {
const scale = 0.5
const input = await readFileAsync('./test.svg')
const expected = await readFileAsync('./scaled.svg')
const scaled = await scaleThatSvg(input, { scale })
const _input = await svgson(input.toString())
const _scaled = await svgson(scaled)
t.is(
Number(_scaled.attributes.viewBox.split(' ')[2]),
_input.attributes.viewBox.split(' ')[2] * scale
)
t.is(
Number(_scaled.attributes.viewBox.split(' ')[3]),
_input.attributes.viewBox.split(' ')[3] * scale
)
t.is(scaled, expected.toString())
})
test('works when no viewBox present', async (t) => {
const scale = 0.5
const input = await readFileAsync('./test-novb.svg')
const expected = await readFileAsync('./scaled.svg')
const scaled = await scaleThatSvg(input, { scale })
const _scaled = await svgson(scaled)
const _expected = await svgson(expected.toString())
delete _expected.attributes.viewBox
t.deepEqual(_scaled, _expected)
})