mirror of
https://github.com/lovell/sharp.git
synced 2025-07-09 18:40:16 +02:00
Tests: ensure SVG is well-formed, detect lack of pango
This commit is contained in:
parent
0107a4de81
commit
65e61ad001
@ -246,7 +246,7 @@ describe('composite', () => {
|
|||||||
sharp(fixtures.inputJpg)
|
sharp(fixtures.inputJpg)
|
||||||
.resize(300, 300)
|
.resize(300, 300)
|
||||||
.composite([{
|
.composite([{
|
||||||
input: Buffer.from('<svg width="200" height="200"><rect x="0" y="0" width="200" height="200" rx="50" ry="50"/></svg>'),
|
input: Buffer.from('<svg xmlns="http://www.w3.org/2000/svg" width="200" height="200"><rect x="0" y="0" width="200" height="200" rx="50" ry="50"/></svg>'),
|
||||||
density: 96,
|
density: 96,
|
||||||
blend: 'dest-in',
|
blend: 'dest-in',
|
||||||
cutout: true
|
cutout: true
|
||||||
|
@ -141,21 +141,21 @@ describe('SVG input', function () {
|
|||||||
|
|
||||||
it('Fails to render SVG larger than 32767x32767', () =>
|
it('Fails to render SVG larger than 32767x32767', () =>
|
||||||
assert.rejects(
|
assert.rejects(
|
||||||
() => sharp(Buffer.from('<svg width="32768" height="1" />')).toBuffer(),
|
() => sharp(Buffer.from('<svg xmlns="http://www.w3.org/2000/svg" width="32768" height="1" />')).toBuffer(),
|
||||||
/Input SVG image exceeds 32767x32767 pixel limit/
|
/Input SVG image exceeds 32767x32767 pixel limit/
|
||||||
)
|
)
|
||||||
);
|
);
|
||||||
|
|
||||||
it('Fails to render scaled SVG larger than 32767x32767', () =>
|
it('Fails to render scaled SVG larger than 32767x32767', () =>
|
||||||
assert.rejects(
|
assert.rejects(
|
||||||
() => sharp(Buffer.from('<svg width="32767" height="1" />')).resize(32768).toBuffer(),
|
() => sharp(Buffer.from('<svg xmlns="http://www.w3.org/2000/svg" width="32767" height="1" />')).resize(32768).toBuffer(),
|
||||||
/Input SVG image will exceed 32767x32767 pixel limit when scaled/
|
/Input SVG image will exceed 32767x32767 pixel limit when scaled/
|
||||||
)
|
)
|
||||||
);
|
);
|
||||||
|
|
||||||
it('Detects SVG passed as a string', () =>
|
it('Detects SVG passed as a string', () =>
|
||||||
assert.rejects(
|
assert.rejects(
|
||||||
() => sharp('<svg></svg>').toBuffer(),
|
() => sharp('<svg xmlns="http://www.w3.org/2000/svg"></svg>').toBuffer(),
|
||||||
/Input file is missing, did you mean/
|
/Input file is missing, did you mean/
|
||||||
)
|
)
|
||||||
);
|
);
|
||||||
|
@ -11,13 +11,16 @@ const fixtures = require('../fixtures');
|
|||||||
describe('Text to image', function () {
|
describe('Text to image', function () {
|
||||||
this.retries(3);
|
this.retries(3);
|
||||||
|
|
||||||
it('text with default values', async () => {
|
it('text with default values', async function () {
|
||||||
const output = fixtures.path('output.text-default.png');
|
const output = fixtures.path('output.text-default.png');
|
||||||
const text = sharp({
|
const text = sharp({
|
||||||
text: {
|
text: {
|
||||||
text: 'Hello, world !'
|
text: 'Hello, world !'
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
if (!sharp.versions.pango) {
|
||||||
|
return this.skip();
|
||||||
|
}
|
||||||
const info = await text.png().toFile(output);
|
const info = await text.png().toFile(output);
|
||||||
assert.strictEqual('png', info.format);
|
assert.strictEqual('png', info.format);
|
||||||
assert.strictEqual(3, info.channels);
|
assert.strictEqual(3, info.channels);
|
||||||
@ -49,6 +52,9 @@ describe('Text to image', function () {
|
|||||||
height: maxHeight
|
height: maxHeight
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
if (!sharp.versions.pango) {
|
||||||
|
return this.skip();
|
||||||
|
}
|
||||||
text.toFile(output, function (err, info) {
|
text.toFile(output, function (err, info) {
|
||||||
if (err) throw err;
|
if (err) throw err;
|
||||||
assert.strictEqual('png', info.format);
|
assert.strictEqual('png', info.format);
|
||||||
@ -69,6 +75,9 @@ describe('Text to image', function () {
|
|||||||
dpi
|
dpi
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
if (!sharp.versions.pango) {
|
||||||
|
return this.skip();
|
||||||
|
}
|
||||||
text.toFile(output, function (err, info) {
|
text.toFile(output, function (err, info) {
|
||||||
if (err) throw err;
|
if (err) throw err;
|
||||||
assert.strictEqual('png', info.format);
|
assert.strictEqual('png', info.format);
|
||||||
@ -90,6 +99,9 @@ describe('Text to image', function () {
|
|||||||
dpi
|
dpi
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
if (!sharp.versions.pango) {
|
||||||
|
return this.skip();
|
||||||
|
}
|
||||||
text.toFile(output, function (err, info) {
|
text.toFile(output, function (err, info) {
|
||||||
if (err) throw err;
|
if (err) throw err;
|
||||||
assert.strictEqual('png', info.format);
|
assert.strictEqual('png', info.format);
|
||||||
@ -112,6 +124,9 @@ describe('Text to image', function () {
|
|||||||
font: 'sans 100'
|
font: 'sans 100'
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
if (!sharp.versions.pango) {
|
||||||
|
return this.skip();
|
||||||
|
}
|
||||||
text.toFile(output, function (err, info) {
|
text.toFile(output, function (err, info) {
|
||||||
if (err) throw err;
|
if (err) throw err;
|
||||||
assert.strictEqual('png', info.format);
|
assert.strictEqual('png', info.format);
|
||||||
@ -122,7 +137,7 @@ describe('Text to image', function () {
|
|||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
it('text with justify and composite', done => {
|
it('text with justify and composite', function (done) {
|
||||||
const output = fixtures.path('output.text-composite.png');
|
const output = fixtures.path('output.text-composite.png');
|
||||||
const width = 500;
|
const width = 500;
|
||||||
const dpi = 300;
|
const dpi = 300;
|
||||||
@ -153,6 +168,9 @@ describe('Text to image', function () {
|
|||||||
left: 30,
|
left: 30,
|
||||||
top: 250
|
top: 250
|
||||||
}]);
|
}]);
|
||||||
|
if (!sharp.versions.pango) {
|
||||||
|
return this.skip();
|
||||||
|
}
|
||||||
text.toFile(output, function (err, info) {
|
text.toFile(output, function (err, info) {
|
||||||
if (err) throw err;
|
if (err) throw err;
|
||||||
assert.strictEqual('png', info.format);
|
assert.strictEqual('png', info.format);
|
||||||
|
Loading…
x
Reference in New Issue
Block a user