-
Notifications
You must be signed in to change notification settings - Fork 10.3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
14 changed files
with
689 additions
and
38 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,88 @@ | ||
import { | ||
generateImageData, | ||
IGatsbyImageHelperArgs, | ||
IImage, | ||
} from "../image-utils" | ||
|
||
const args: IGatsbyImageHelperArgs = { | ||
pluginName: `gatsby-plugin-fake`, | ||
filename: `afile.jpg`, | ||
generateImageSource: jest.fn(), | ||
width: 400, | ||
sourceMetadata: { | ||
width: 800, | ||
height: 600, | ||
format: `jpg`, | ||
}, | ||
reporter: { | ||
warn: jest.fn(), | ||
}, | ||
} | ||
|
||
describe(`the image data helper`, () => { | ||
beforeEach(() => { | ||
jest.resetAllMocks() | ||
}) | ||
it(`throws if there's not a valid generateURL function`, () => { | ||
const generateImageSource = `this should be a function` | ||
|
||
expect(() => | ||
generateImageData(({ | ||
...args, | ||
generateImageSource, | ||
} as any) as IGatsbyImageHelperArgs) | ||
).toThrow() | ||
}) | ||
|
||
it(`calls the generateImageSource function`, () => { | ||
generateImageData(args) | ||
expect(args.generateImageSource).toHaveBeenCalledWith( | ||
`afile.jpg`, | ||
800, | ||
600, | ||
`jpg`, | ||
undefined, | ||
undefined | ||
) | ||
}) | ||
|
||
it(`returns URLs as generated`, () => { | ||
const generateImageSource = ( | ||
file: string, | ||
width: number, | ||
height: number, | ||
format | ||
): IImage => { | ||
return { | ||
src: `https://example.com/${file}?width=${width}&height=${height}`, | ||
width, | ||
height, | ||
format, | ||
} | ||
} | ||
const data = generateImageData({ ...args, generateImageSource }) | ||
expect(data).toMatchInlineSnapshot(` | ||
Object { | ||
"height": undefined, | ||
"images": Object { | ||
"fallback": Object { | ||
"sizes": "400px", | ||
"src": "https://example.com/afile.jpg?width=400&height=300", | ||
"srcSet": "https://example.com/afile.jpg?width=400&height=300 400w, | ||
https://example.com/afile.jpg?width=800&height=600 800w", | ||
}, | ||
"sources": Array [ | ||
Object { | ||
"sizes": "400px", | ||
"srcSet": "https://example.com/afile.jpg?width=400&height=300 400w, | ||
https://example.com/afile.jpg?width=800&height=600 800w", | ||
"type": "image/webp", | ||
}, | ||
], | ||
}, | ||
"layout": "fixed", | ||
"width": 400, | ||
} | ||
`) | ||
}) | ||
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
4 changes: 2 additions & 2 deletions
4
packages/gatsby-plugin-image/src/components/static-image.server.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,11 +1,11 @@ | ||
export {}; | ||
export {} | ||
|
||
declare global { | ||
declare var SERVER: boolean; | ||
declare var SERVER: boolean | ||
|
||
namespace NodeJS { | ||
interface Global { | ||
GATSBY___IMAGE: boolean; | ||
GATSBY___IMAGE: boolean | undefined | ||
} | ||
} | ||
} |
Oops, something went wrong.