Skip to content

Commit 388ddf7

Browse files
committed
test: updated scale tests
1 parent eeb1ccb commit 388ddf7

File tree

1 file changed

+92
-0
lines changed

1 file changed

+92
-0
lines changed

src/plugins/scale.test.ts

Lines changed: 92 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -75,3 +75,95 @@ test('applies scale with a mix of exact and relative dimensions', async () => {
7575
failureThreshold: 10,
7676
});
7777
});
78+
79+
test('does not apply scale when dimensions are missing', async () => {
80+
const imagecache = new ImageCache([
81+
{
82+
presetName: 'scale',
83+
actions: [
84+
{
85+
action: 'scale',
86+
config: {},
87+
},
88+
],
89+
},
90+
]);
91+
92+
const image = await imagecache.render('./examples/in.png', 'scale');
93+
const imageBuffer = await image.toBuffer();
94+
expect(imageBuffer).toMatchImageSnapshot({
95+
failureThresholdType: 'percent',
96+
failureThreshold: 1,
97+
});
98+
});
99+
100+
test('does not scale when upscale is false and final dimensions are bigger', async () => {
101+
const imagecache = new ImageCache([
102+
{
103+
presetName: 'scale',
104+
actions: [
105+
{
106+
action: 'scale',
107+
config: {
108+
width: 20000,
109+
height: 10000,
110+
upscale: false,
111+
},
112+
},
113+
],
114+
},
115+
]);
116+
117+
const image = await imagecache.render('./examples/in.png', 'scale');
118+
const imageBuffer = await image.toBuffer();
119+
expect(imageBuffer).toMatchImageSnapshot({
120+
failureThresholdType: 'percent',
121+
failureThreshold: 1,
122+
});
123+
});
124+
125+
test('applies scale when width is missing', async () => {
126+
const imagecache = new ImageCache([
127+
{
128+
presetName: 'scale',
129+
actions: [
130+
{
131+
action: 'scale',
132+
config: {
133+
height: 100,
134+
},
135+
},
136+
],
137+
},
138+
]);
139+
140+
const image = await imagecache.render('./examples/in.png', 'scale');
141+
const imageBuffer = await image.toBuffer();
142+
expect(imageBuffer).toMatchImageSnapshot({
143+
failureThresholdType: 'percent',
144+
failureThreshold: 10,
145+
});
146+
});
147+
148+
test('applies scale when height is missing', async () => {
149+
const imagecache = new ImageCache([
150+
{
151+
presetName: 'scale',
152+
actions: [
153+
{
154+
action: 'scale',
155+
config: {
156+
width: 200,
157+
},
158+
},
159+
],
160+
},
161+
]);
162+
163+
const image = await imagecache.render('./examples/in.png', 'scale');
164+
const imageBuffer = await image.toBuffer();
165+
expect(imageBuffer).toMatchImageSnapshot({
166+
failureThresholdType: 'percent',
167+
failureThreshold: 10,
168+
});
169+
});

0 commit comments

Comments
 (0)