Skip to content

Commit 328acd4

Browse files
committed
added an integration test
1 parent 74100ee commit 328acd4

File tree

1 file changed

+29
-0
lines changed

1 file changed

+29
-0
lines changed

packages/gatsby-core-utils/src/__tests__/fetch-remote-file.js

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -133,7 +133,23 @@ const server = setupServer(
133133
ctx.body(content)
134134
)
135135
}),
136+
// Should test with non-ascii word `개` (which means dog in Korean)
137+
rest.get(
138+
`http://external.com/${encodeURIComponent(`개`)}.jpg`,
139+
async (req, res, ctx) => {
140+
const { content, contentLength } = await getFileContent(
141+
path.join(__dirname, `./fixtures/dog-thumbnail.jpg`),
142+
req
143+
)
136144

145+
return res(
146+
ctx.set(`Content-Type`, `image/jpg`),
147+
ctx.set(`Content-Length`, contentLength),
148+
ctx.status(200),
149+
ctx.body(content)
150+
)
151+
}
152+
),
137153
rest.get(`http://external.com/dog`, async (req, res, ctx) => {
138154
const { content, contentLength } = await getFileContent(
139155
path.join(__dirname, `./fixtures/dog-thumbnail.jpg`),
@@ -333,6 +349,19 @@ describe(`fetch-remote-file`, () => {
333349
expect(gotStream).toBeCalledTimes(1)
334350
})
335351

352+
it(`downloads and create a jpg file for file with non-ascii filename`, async () => {
353+
const filePath = await fetchRemoteFile({
354+
url: `http://external.com/${encodeURIComponent(`개`)}.jpg`,
355+
cache,
356+
})
357+
358+
expect(path.basename(filePath)).toBe(`개.jpg`)
359+
expect(getFileSize(filePath)).resolves.toBe(
360+
await getFileSize(path.join(__dirname, `./fixtures/dog-thumbnail.jpg`))
361+
)
362+
expect(gotStream).toBeCalledTimes(1)
363+
})
364+
336365
it(`downloads and create a jpg file for unknown extension`, async () => {
337366
const filePath = await fetchRemoteFile({
338367
url: `http://external.com/dog`,

0 commit comments

Comments
 (0)