Skip to content

Commit

Permalink
added an integration test
Browse files Browse the repository at this point in the history
  • Loading branch information
cometkim committed Sep 13, 2022
1 parent 74100ee commit 328acd4
Showing 1 changed file with 29 additions and 0 deletions.
29 changes: 29 additions & 0 deletions packages/gatsby-core-utils/src/__tests__/fetch-remote-file.js
Expand Up @@ -133,7 +133,23 @@ const server = setupServer(
ctx.body(content)
)
}),
// Should test with non-ascii word `개` (which means dog in Korean)
rest.get(
`http://external.com/${encodeURIComponent(`개`)}.jpg`,
async (req, res, ctx) => {
const { content, contentLength } = await getFileContent(
path.join(__dirname, `./fixtures/dog-thumbnail.jpg`),
req
)

return res(
ctx.set(`Content-Type`, `image/jpg`),
ctx.set(`Content-Length`, contentLength),
ctx.status(200),
ctx.body(content)
)
}
),
rest.get(`http://external.com/dog`, async (req, res, ctx) => {
const { content, contentLength } = await getFileContent(
path.join(__dirname, `./fixtures/dog-thumbnail.jpg`),
Expand Down Expand Up @@ -333,6 +349,19 @@ describe(`fetch-remote-file`, () => {
expect(gotStream).toBeCalledTimes(1)
})

it(`downloads and create a jpg file for file with non-ascii filename`, async () => {
const filePath = await fetchRemoteFile({
url: `http://external.com/${encodeURIComponent(`개`)}.jpg`,
cache,
})

expect(path.basename(filePath)).toBe(`개.jpg`)
expect(getFileSize(filePath)).resolves.toBe(
await getFileSize(path.join(__dirname, `./fixtures/dog-thumbnail.jpg`))
)
expect(gotStream).toBeCalledTimes(1)
})

it(`downloads and create a jpg file for unknown extension`, async () => {
const filePath = await fetchRemoteFile({
url: `http://external.com/dog`,
Expand Down

0 comments on commit 328acd4

Please sign in to comment.