Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

test: fix test image timeout #262

Merged
merged 2 commits into from
Sep 20, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 12 additions & 12 deletions __test__/index.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,9 @@ import { Resvg, renderAsync } from '../index'
import { jimpToRgbaPixels } from './helper'

test('Use href to load a JPG image without alpha', async (t) => {
const imgUrl = 'https://himg.bdimg.com/sys/portrait/hotitem/wildkid/46'
const imgUrl = 'https://wd.imgix.net/image/kheDArv5csY6rvQUJDbWRscckLr1/De5peVXJZz3uSEmmVeYJ.png?w=500'
const svg = `<svg xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink">
<image href="${imgUrl}" width="300" height="300"/>
<image href="${imgUrl}" width="500" height="250"/>
</svg>`
const resvg = new Resvg(svg, {
font: {
Expand Down Expand Up @@ -87,25 +87,25 @@ test('svg to RGBA pixels Array', async (t) => {
})

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

t.is(result.getWidth(), 1200)
t.is(result.getHeight(), 623)
t.is(result.getWidth(), 800)
t.is(result.getHeight(), 1156)
})

test('fit to height', async (t) => {
const filePath = '../example/text.svg'
const filePath = '../example/bbox.svg'
const svg = await fs.readFile(join(__dirname, filePath))
const resvg = new Resvg(svg, {
background: '#eeebe6',
Expand All @@ -118,23 +118,23 @@ test('fit to height', async (t) => {
const pngBuffer = pngData.asPng()
const result = await jimp.read(pngBuffer)

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

test('Get SVG original size', async (t) => {
const filePath = '../example/text.svg'
const filePath = '../example/bbox.svg'
const svg = await fs.readFile(join(__dirname, filePath))
const resvg = new Resvg(svg, {
background: '#eeebe6',
fitTo: {
mode: 'width',
value: 1200, // The original size is not affected by the fitTo parameter
value: 600, // The original size is not affected by the fitTo parameter
},
})

t.is(resvg.width, 1324)
t.is(resvg.height, 687)
t.is(resvg.width, 180)
t.is(resvg.height, 260)
})

test('SVG size must be rounded to an integer', (t) => {
Expand Down
24 changes: 12 additions & 12 deletions __test__/wasm.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,9 @@ test.before(async () => {
})

test('Use href to load a JPG image without alpha', async (t) => {
const imgUrl = 'https://himg.bdimg.com/sys/portrait/hotitem/wildkid/46'
const imgUrl = 'https://wd.imgix.net/image/kheDArv5csY6rvQUJDbWRscckLr1/De5peVXJZz3uSEmmVeYJ.png?w=500'
const svg = `<svg xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink">
<image href="${imgUrl}" width="300" height="300"/>
<image href="${imgUrl}" width="500" height="250"/>
</svg>`
const resvg = new Resvg(svg)
const resolved = await Promise.all(
Expand Down Expand Up @@ -101,27 +101,27 @@ test('buffer input', async (t) => {
})

test('fit to width', async (t) => {
const filePath = '../example/text.svg'
const filePath = '../example/bbox.svg'
const svg = await fs.readFile(join(__dirname, filePath))
const svgString = svg.toString('utf-8')
const opts = {
background: '#eeebe6',
fitTo: {
mode: 'width',
value: 1200,
value: 800,
},
}
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(), 1200)
t.is(result.getHeight(), 623)
t.is(result.getWidth(), 800)
t.is(result.getHeight(), 1156)
})

test('fit to height', async (t) => {
const filePath = '../example/text.svg'
const filePath = '../example/bbox.svg'
const svg = await fs.readFile(join(__dirname, filePath))
const svgString = svg.toString('utf-8')
const opts = {
Expand All @@ -136,23 +136,23 @@ test('fit to height', async (t) => {
const pngBuffer = pngData.asPng()
const result = await jimp.read(Buffer.from(pngBuffer))

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

test('Get SVG original size', async (t) => {
const filePath = '../example/text.svg'
const filePath = '../example/bbox.svg'
const svg = await fs.readFile(join(__dirname, filePath))
const resvg = new Resvg(svg, {
background: '#eeebe6',
fitTo: {
mode: 'width',
value: 1200, // The original size is not affected by the fitTo parameter
value: 600, // The original size is not affected by the fitTo parameter
},
})

t.is(resvg.width, 1324)
t.is(resvg.height, 687)
t.is(resvg.width, 180)
t.is(resvg.height, 260)
})

test('SVG size must be rounded to an integer', (t) => {
Expand Down
Loading