Skip to content

Commit

Permalink
test: using simple SVG files to make testing faster
Browse files Browse the repository at this point in the history
text.svg => bbox.svg
  • Loading branch information
yisibl committed Sep 20, 2023
1 parent fd07ca5 commit 716e34e
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 20 deletions.
20 changes: 10 additions & 10 deletions __test__/index.spec.ts
Original file line number Diff line number Diff line change
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
20 changes: 10 additions & 10 deletions __test__/wasm.spec.ts
Original file line number Diff line number Diff line change
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

1 comment on commit 716e34e

@vercel
Copy link

@vercel vercel bot commented on 716e34e Sep 20, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Successfully deployed to the following URLs:

resvg-js – ./

resvg-js-git-main-yisibl.vercel.app
resvg-js-yisibl.vercel.app
resvg-js.vercel.app

Please sign in to comment.