Skip to content

Commit

Permalink
fix(image): use seeded picsum (#1968)
Browse files Browse the repository at this point in the history
  • Loading branch information
Shinigami92 authored Mar 30, 2023
1 parent 063ba6e commit b5bfca4
Show file tree
Hide file tree
Showing 3 changed files with 35 additions and 35 deletions.
18 changes: 9 additions & 9 deletions src/modules/image/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -199,12 +199,12 @@ export class ImageModule {
* @param options.blur Whether the image should be blurred. Defaults to `false`.
*
* @example
* faker.image.urlPicsumPhotos() // 'https://picsum.photos/id/241/640/480'
* faker.image.urlPicsumPhotos({ width: 128 }) // 'https://picsum.photos/id/241/128/480'
* faker.image.urlPicsumPhotos({ height: 128 }) // 'https://picsum.photos/id/241/640/128'
* faker.image.urlPicsumPhotos({ grayscale: true }) // 'https://picsum.photos/id/241/640/480?grayscale'
* faker.image.urlPicsumPhotos({ blur: 4 }) // 'https://picsum.photos/id/241/640/480?blur=4'
* faker.image.urlPicsumPhotos({ blur: 4, grayscale: true }) // 'https://picsum.photos/id/241/640/480?grayscale&blur=4'
* faker.image.urlPicsumPhotos() // 'https://picsum.photos/seed/NWbJM2B/640/480'
* faker.image.urlPicsumPhotos({ width: 128 }) // 'https://picsum.photos/seed/NWbJM2B/128/480'
* faker.image.urlPicsumPhotos({ height: 128 }) // 'https://picsum.photos/seed/NWbJM2B/640/128'
* faker.image.urlPicsumPhotos({ grayscale: true }) // 'https://picsum.photos/seed/NWbJM2B/640/480?grayscale'
* faker.image.urlPicsumPhotos({ blur: 4 }) // 'https://picsum.photos/seed/NWbJM2B/640/480?blur=4'
* faker.image.urlPicsumPhotos({ blur: 4, grayscale: true }) // 'https://picsum.photos/seed/NWbJM2B/640/480?grayscale&blur=4'
*
* @since 8.0.0
*/
Expand Down Expand Up @@ -238,9 +238,9 @@ export class ImageModule {
): string {
const { width = 640, height = 480, grayscale = false, blur } = options;

let url = `https://picsum.photos/id/${this.faker.number.int(
1000
)}/${width}/${height}`;
let url = `https://picsum.photos/seed/${this.faker.string.alphanumeric({
length: { min: 5, max: 10 },
})}/${width}/${height}`;

const hasValidGrayscale = grayscale === true;
const hasValidBlur = typeof blur === 'number' && blur >= 1 && blur <= 10;
Expand Down
50 changes: 25 additions & 25 deletions test/__snapshots__/image.spec.ts.snap
Original file line number Diff line number Diff line change
Expand Up @@ -26,19 +26,19 @@ exports[`image > 42 > urlLoremFlickr > with width 1`] = `"https://loremflickr.co

exports[`image > 42 > urlLoremFlickr > with width and height 1`] = `"https://loremflickr.com/128/128?lock=3373557438480384"`;

exports[`image > 42 > urlPicsumPhotos > noArgs 1`] = `"https://picsum.photos/id/374/640/480"`;
exports[`image > 42 > urlPicsumPhotos > noArgs 1`] = `"https://picsum.photos/seed/NWbJMBB/640/480"`;

exports[`image > 42 > urlPicsumPhotos > with all options 1`] = `"https://picsum.photos/id/374/128/128?grayscale&blur=4"`;
exports[`image > 42 > urlPicsumPhotos > with all options 1`] = `"https://picsum.photos/seed/NWbJMBB/128/128?grayscale&blur=4"`;

exports[`image > 42 > urlPicsumPhotos > with blur 1`] = `"https://picsum.photos/id/374/640/480?blur=6"`;
exports[`image > 42 > urlPicsumPhotos > with blur 1`] = `"https://picsum.photos/seed/NWbJMBB/640/480?blur=6"`;

exports[`image > 42 > urlPicsumPhotos > with blur and grayscale 1`] = `"https://picsum.photos/id/374/640/480?grayscale&blur=3"`;
exports[`image > 42 > urlPicsumPhotos > with blur and grayscale 1`] = `"https://picsum.photos/seed/NWbJMBB/640/480?grayscale&blur=3"`;

exports[`image > 42 > urlPicsumPhotos > with height 1`] = `"https://picsum.photos/id/374/640/128"`;
exports[`image > 42 > urlPicsumPhotos > with height 1`] = `"https://picsum.photos/seed/NWbJMBB/640/128"`;

exports[`image > 42 > urlPicsumPhotos > with width 1`] = `"https://picsum.photos/id/374/128/480"`;
exports[`image > 42 > urlPicsumPhotos > with width 1`] = `"https://picsum.photos/seed/NWbJMBB/128/480"`;

exports[`image > 42 > urlPicsumPhotos > with width and height 1`] = `"https://picsum.photos/id/374/128/128"`;
exports[`image > 42 > urlPicsumPhotos > with width and height 1`] = `"https://picsum.photos/seed/NWbJMBB/128/128"`;

exports[`image > 42 > urlPlaceholder > noArgs 1`] = `"https://via.placeholder.com/1498x3186/e4abdd/39321a.webp?text=veniam%20unde%20fugit"`;

Expand Down Expand Up @@ -66,13 +66,13 @@ exports[`image > 1211 > avatarGitHub 1`] = `"https://avatars.githubusercontent.c

exports[`image > 1211 > avatarLegacy 1`] = `"https://cloudflare-ipfs.com/ipfs/Qmd3W5DuhgHirLHGVixi6V76LhCkZUz6pnFt5AJBiyvHye/avatar/1160.jpg"`;

exports[`image > 1211 > url > noArgs 1`] = `"https://picsum.photos/id/459/640/480"`;
exports[`image > 1211 > url > noArgs 1`] = `"https://picsum.photos/seed/TMd8Z2F/640/480"`;

exports[`image > 1211 > url > with height 1`] = `"https://picsum.photos/id/459/640/128"`;
exports[`image > 1211 > url > with height 1`] = `"https://picsum.photos/seed/TMd8Z2F/640/128"`;

exports[`image > 1211 > url > with width 1`] = `"https://picsum.photos/id/459/128/480"`;
exports[`image > 1211 > url > with width 1`] = `"https://picsum.photos/seed/TMd8Z2F/128/480"`;

exports[`image > 1211 > url > with width and height 1`] = `"https://picsum.photos/id/459/128/128"`;
exports[`image > 1211 > url > with width and height 1`] = `"https://picsum.photos/seed/TMd8Z2F/128/128"`;

exports[`image > 1211 > urlLoremFlickr > noArgs 1`] = `"https://loremflickr.com/640/480?lock=8363366036799488"`;

Expand All @@ -86,19 +86,19 @@ exports[`image > 1211 > urlLoremFlickr > with width 1`] = `"https://loremflickr.

exports[`image > 1211 > urlLoremFlickr > with width and height 1`] = `"https://loremflickr.com/128/128?lock=8363366036799488"`;

exports[`image > 1211 > urlPicsumPhotos > noArgs 1`] = `"https://picsum.photos/id/929/640/480"`;
exports[`image > 1211 > urlPicsumPhotos > noArgs 1`] = `"https://picsum.photos/seed/sTMd8Z2F9G/640/480"`;

exports[`image > 1211 > urlPicsumPhotos > with all options 1`] = `"https://picsum.photos/id/929/128/128?grayscale&blur=4"`;
exports[`image > 1211 > urlPicsumPhotos > with all options 1`] = `"https://picsum.photos/seed/sTMd8Z2F9G/128/128?grayscale&blur=4"`;

exports[`image > 1211 > urlPicsumPhotos > with blur 1`] = `"https://picsum.photos/id/929/640/480?blur=6"`;
exports[`image > 1211 > urlPicsumPhotos > with blur 1`] = `"https://picsum.photos/seed/sTMd8Z2F9G/640/480?blur=6"`;

exports[`image > 1211 > urlPicsumPhotos > with blur and grayscale 1`] = `"https://picsum.photos/id/929/640/480?grayscale&blur=3"`;
exports[`image > 1211 > urlPicsumPhotos > with blur and grayscale 1`] = `"https://picsum.photos/seed/sTMd8Z2F9G/640/480?grayscale&blur=3"`;

exports[`image > 1211 > urlPicsumPhotos > with height 1`] = `"https://picsum.photos/id/929/640/128"`;
exports[`image > 1211 > urlPicsumPhotos > with height 1`] = `"https://picsum.photos/seed/sTMd8Z2F9G/640/128"`;

exports[`image > 1211 > urlPicsumPhotos > with width 1`] = `"https://picsum.photos/id/929/128/480"`;
exports[`image > 1211 > urlPicsumPhotos > with width 1`] = `"https://picsum.photos/seed/sTMd8Z2F9G/128/480"`;

exports[`image > 1211 > urlPicsumPhotos > with width and height 1`] = `"https://picsum.photos/id/929/128/128"`;
exports[`image > 1211 > urlPicsumPhotos > with width and height 1`] = `"https://picsum.photos/seed/sTMd8Z2F9G/128/128"`;

exports[`image > 1211 > urlPlaceholder > noArgs 1`] = `"https://via.placeholder.com/3714x1836/db42f0/e3f4a9.jpeg?text=consequuntur%20quidem%20nobis"`;

Expand Down Expand Up @@ -146,19 +146,19 @@ exports[`image > 1337 > urlLoremFlickr > with width 1`] = `"https://loremflickr.

exports[`image > 1337 > urlLoremFlickr > with width and height 1`] = `"https://loremflickr.com/128/128?lock=2360108468142080"`;

exports[`image > 1337 > urlPicsumPhotos > noArgs 1`] = `"https://picsum.photos/id/262/640/480"`;
exports[`image > 1337 > urlPicsumPhotos > noArgs 1`] = `"https://picsum.photos/seed/y9dhxs/640/480"`;

exports[`image > 1337 > urlPicsumPhotos > with all options 1`] = `"https://picsum.photos/id/262/128/128?grayscale&blur=4"`;
exports[`image > 1337 > urlPicsumPhotos > with all options 1`] = `"https://picsum.photos/seed/y9dhxs/128/128?grayscale&blur=4"`;

exports[`image > 1337 > urlPicsumPhotos > with blur 1`] = `"https://picsum.photos/id/262/640/480?blur=6"`;
exports[`image > 1337 > urlPicsumPhotos > with blur 1`] = `"https://picsum.photos/seed/y9dhxs/640/480?blur=6"`;

exports[`image > 1337 > urlPicsumPhotos > with blur and grayscale 1`] = `"https://picsum.photos/id/262/640/480?grayscale&blur=3"`;
exports[`image > 1337 > urlPicsumPhotos > with blur and grayscale 1`] = `"https://picsum.photos/seed/y9dhxs/640/480?grayscale&blur=3"`;

exports[`image > 1337 > urlPicsumPhotos > with height 1`] = `"https://picsum.photos/id/262/640/128"`;
exports[`image > 1337 > urlPicsumPhotos > with height 1`] = `"https://picsum.photos/seed/y9dhxs/640/128"`;

exports[`image > 1337 > urlPicsumPhotos > with width 1`] = `"https://picsum.photos/id/262/128/480"`;
exports[`image > 1337 > urlPicsumPhotos > with width 1`] = `"https://picsum.photos/seed/y9dhxs/128/480"`;

exports[`image > 1337 > urlPicsumPhotos > with width and height 1`] = `"https://picsum.photos/id/262/128/128"`;
exports[`image > 1337 > urlPicsumPhotos > with width and height 1`] = `"https://picsum.photos/seed/y9dhxs/128/128"`;

exports[`image > 1337 > urlPlaceholder > noArgs 1`] = `"https://via.placeholder.com/1048x2242/346ba0/75bd57.webp?text=tempora%20tempore%20aliquam"`;

Expand Down
2 changes: 1 addition & 1 deletion test/image.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -455,7 +455,7 @@ describe('image', () => {

expect(imageUrl).toBeTypeOf('string');
expect(imageUrl).toMatch(
/^https\:\/\/picsum\.photos\/id\/\d+\/\d+\/\d+$/
/^https\:\/\/picsum\.photos\/seed\/[0-9a-zA-Z]+\/\d+\/\d+$/
);
});
});
Expand Down

0 comments on commit b5bfca4

Please sign in to comment.