Skip to content

Commit 414f4d6

Browse files
committed
Fix loop count test timestamp flake
1 parent 64ab0be commit 414f4d6

1 file changed

Lines changed: 11 additions & 10 deletions

File tree

‎tests/loop-count.js‎

Lines changed: 11 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ const throwsA = (fn, type, label) => {
1111
};
1212

1313
const frames = () => [new Frame(new Image(4, 4).fill(0xff0000ff), {duration: 40}), new Frame(new Image(4, 4).fill(0x00ff00ff), {duration: 60})];
14+
const metadata = {creationTime: 0};
1415
// each format: its encode method, its encoder factory, and the count the file stores when it loops forever or plays
1516
// (the GIF's NETSCAPE block counts repetitions, APNG and WebP count plays)
1617
const formats = {GIF: ['encodeGIF', 'gifEncoder'], APNG: ['encodeAPNG', 'apngEncoder'], WebP: ['encodeWebP', 'webpEncoder']};
@@ -26,8 +27,8 @@ const netscape = bytes => {
2627
if (new Animation(frames()).loopCount !== Infinity || new Animation([]).loopCount !== Infinity) panic('the default loop count should be Infinity');
2728
for (const [format, [encode, factory]] of Object.entries(formats)) {
2829
const animation = new Animation(frames());
29-
const bytes = await animation[encode]();
30-
const encoder = Animation[factory](4, 4);
30+
const bytes = await animation[encode]({metadata});
31+
const encoder = Animation[factory](4, 4, {metadata});
3132
for (const frame of frames()) await encoder.add(frame);
3233
if (!Buffer.from(await encoder.finish()).equals(Buffer.from(bytes))) panic(`${format}: the encoder's default isn't the animation's`);
3334
if (encode === 'encodeGIF' && netscape(bytes) !== 0) panic(`${format}: forever should be stored as NETSCAPE count 0, not ${netscape(bytes)}`);
@@ -39,9 +40,9 @@ const netscape = bytes => {
3940

4041
// Infinity is forever, explicitly, in every entry point
4142
for (const [format, [encode, factory]] of Object.entries(formats)) {
42-
const forever = await new Animation(frames(), {loopCount: Infinity})[encode]();
43-
if (!Buffer.from(forever).equals(Buffer.from(await new Animation(frames())[encode]()))) panic(`${format}: Infinity isn't the default`);
44-
const encoder = Animation[factory](4, 4, {loopCount: Infinity});
43+
const forever = await new Animation(frames(), {loopCount: Infinity})[encode]({metadata});
44+
if (!Buffer.from(forever).equals(Buffer.from(await new Animation(frames())[encode]({metadata})))) panic(`${format}: Infinity isn't the default`);
45+
const encoder = Animation[factory](4, 4, {loopCount: Infinity, metadata});
4546
for (const frame of frames()) await encoder.add(frame);
4647
if (!Buffer.from(await encoder.finish()).equals(Buffer.from(forever))) panic(`${format}: the encoder with Infinity`);
4748
const setter = new Animation(frames(), {loopCount: 2});
@@ -52,18 +53,18 @@ const netscape = bytes => {
5253
// finite counts: 0 plays once, n repeats n times, through the constructor, the setter and each encoder
5354
for (const count of [0, 1, 5]) {
5455
for (const [format, [encode, factory]] of Object.entries(formats)) {
55-
const bytes = await new Animation(frames(), {loopCount: count})[encode]();
56+
const bytes = await new Animation(frames(), {loopCount: count})[encode]({metadata});
5657
if (format === 'GIF' && netscape(bytes) !== (count === 0 ? null : count)) panic(`GIF: loop count ${count} stored as ${netscape(bytes)}`);
5758
const back = await Animation.decode(bytes);
5859
if (back.loopCount !== count) panic(`${format}: loop count ${count} decodes as ${back.loopCount}`);
5960

60-
const encoder = Animation[factory](4, 4, {loopCount: count});
61+
const encoder = Animation[factory](4, 4, {loopCount: count, metadata});
6162
for (const frame of frames()) await encoder.add(frame);
6263
if (!Buffer.from(await encoder.finish()).equals(Buffer.from(bytes))) panic(`${format}: encoder with loop count ${count} differs`);
6364

6465
const set = new Animation(frames());
6566
set.loopCount = count;
66-
if (set.loopCount !== count || !Buffer.from(await set[encode]()).equals(Buffer.from(bytes))) panic(`${format}: setter with loop count ${count}`);
67+
if (set.loopCount !== count || !Buffer.from(await set[encode]({metadata})).equals(Buffer.from(bytes))) panic(`${format}: setter with loop count ${count}`);
6768
}
6869
}
6970

@@ -75,11 +76,11 @@ const netscape = bytes => {
7576
const limits = {GIF: 65535, WebP: 65534, APNG: 2 ** 31 - 2};
7677
for (const [format, max] of Object.entries(limits)) {
7778
const [encode, factory] = formats[format];
78-
const bytes = await new Animation(frames(), {loopCount: max})[encode]();
79+
const bytes = await new Animation(frames(), {loopCount: max})[encode]({metadata});
7980
if (format === 'GIF' && netscape(bytes) !== max) panic(`GIF: the largest count ${max} is stored as ${netscape(bytes)}`);
8081
const back = await Animation.decode(bytes);
8182
if (back.loopCount !== max) panic(`${format}: the largest count ${max} decodes as ${back.loopCount}`);
82-
const encoder = Animation[factory](4, 4, {loopCount: max});
83+
const encoder = Animation[factory](4, 4, {loopCount: max, metadata});
8384
for (const frame of frames()) await encoder.add(frame);
8485
if (!Buffer.from(await encoder.finish()).equals(Buffer.from(bytes))) panic(`${format}: the encoder with the largest count ${max} differs`);
8586

0 commit comments

Comments
 (0)