From 328acd46e34e2749f770d18c2962bb7c4406cc7e Mon Sep 17 00:00:00 2001 From: Hyeseong Kim Date: Tue, 13 Sep 2022 15:10:07 +0900 Subject: [PATCH] added an integration test --- .../src/__tests__/fetch-remote-file.js | 29 +++++++++++++++++++ 1 file changed, 29 insertions(+) diff --git a/packages/gatsby-core-utils/src/__tests__/fetch-remote-file.js b/packages/gatsby-core-utils/src/__tests__/fetch-remote-file.js index 58f7fd1e26eae..5cbf985fcce67 100644 --- a/packages/gatsby-core-utils/src/__tests__/fetch-remote-file.js +++ b/packages/gatsby-core-utils/src/__tests__/fetch-remote-file.js @@ -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`), @@ -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`,