Skip to content

Commit

Permalink
test: add fitTo height test case
Browse files Browse the repository at this point in the history
  • Loading branch information
yisibl committed Sep 18, 2023
1 parent 093b839 commit 244bf74
Show file tree
Hide file tree
Showing 2 changed files with 38 additions and 0 deletions.
18 changes: 18 additions & 0 deletions __test__/index.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -104,6 +104,24 @@ test('fit to width', async (t) => {
t.is(result.getHeight(), 623)
})

test('fit to height', async (t) => {
const filePath = '../example/text.svg'
const svg = await fs.readFile(join(__dirname, filePath))
const resvg = new Resvg(svg, {
background: '#eeebe6',
fitTo: {
mode: 'height',
value: 520,
},
})
const pngData = resvg.render()
const pngBuffer = pngData.asPng()
const result = await jimp.read(pngBuffer)

t.is(result.getWidth(), 1003)
t.is(result.getHeight(), 520)
})

test('Get SVG original size', async (t) => {
const filePath = '../example/text.svg'
const svg = await fs.readFile(join(__dirname, filePath))
Expand Down
20 changes: 20 additions & 0 deletions __test__/wasm.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -120,6 +120,26 @@ test('fit to width', async (t) => {
t.is(result.getHeight(), 623)
})

test('fit to height', async (t) => {
const filePath = '../example/text.svg'
const svg = await fs.readFile(join(__dirname, filePath))
const svgString = svg.toString('utf-8')
const opts = {
background: '#eeebe6',
fitTo: {
mode: 'height',
value: 520,
},
}
const resvg = new Resvg(svgString, opts)
const pngData = resvg.render()
const pngBuffer = pngData.asPng()
const result = await jimp.read(Buffer.from(pngBuffer))

t.is(result.getWidth(), 1003)
t.is(result.getHeight(), 520)
})

test('Get SVG original size', async (t) => {
const filePath = '../example/text.svg'
const svg = await fs.readFile(join(__dirname, filePath))
Expand Down

0 comments on commit 244bf74

Please sign in to comment.