Skip to content
This repository has been archived by the owner on May 15, 2024. It is now read-only.

Commit

Permalink
fix(module-files): return correct status
Browse files Browse the repository at this point in the history
  • Loading branch information
JAdshead authored and 10xLaCroixDrinker committed Nov 30, 2021
1 parent 2d9064f commit 9a7712d
Show file tree
Hide file tree
Showing 4 changed files with 464 additions and 261 deletions.
43 changes: 39 additions & 4 deletions __tests__/index.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -546,13 +546,19 @@ describe('one-app-dev-cdn', () => {
[
'https://example.com/module-map.json',
{
agent: expect.any(ProxyAgent),
agent: {
http: expect.any(ProxyAgent),
https: expect.any(ProxyAgent),
},
},
],
[
'https://example.com//cdn/module-b/1.0.0/module-b.node.js',
{
agent: expect.any(ProxyAgent),
agent: {
http: expect.any(ProxyAgent),
https: expect.any(ProxyAgent),
},
headers: {
connection: 'keep-alive',
},
Expand Down Expand Up @@ -584,7 +590,10 @@ describe('one-app-dev-cdn', () => {
[
'https://example.com/module-map.json',
{
agent: expect.any(ProxyAgent),
agent: {
http: expect.any(ProxyAgent),
https: expect.any(ProxyAgent),
},
},
],
]
Expand Down Expand Up @@ -617,7 +626,10 @@ describe('one-app-dev-cdn', () => {
[
'https://example.com/module-map.json',
{
agent: expect.any(ProxyAgent),
agent: {
http: expect.any(ProxyAgent),
https: expect.any(ProxyAgent),
},
},
],
]);
Expand All @@ -626,6 +638,29 @@ describe('one-app-dev-cdn', () => {
.get('/cdn/module-b/1.0.0/module-b.node.js?key="123');
expect(moduleResponse.status).toBe(500);
});

it('returns a correct status code from proxy request', async () => {
expect.assertions(1);

const fcdn = setupTest({
useLocalModules: false,
appPort: 3000,
remoteModuleMapUrl: 'https://example.com/module-map.json',
});

got.mockReturnJsonOnce(defaultRemoteMap);
const gotError = new Error('Network error!');
gotError.code = 'ERR_NON_2XX_3XX_RESPONSE';
gotError.response = { statusCode: 501 };

await supertest(fcdn)
.get('/module-map.json');

got.mockReturnFileOnce(gotError);
const moduleResponse = await supertest(fcdn)
.get('/cdn/module-b/1.0.0/some-langpack.json');
expect(moduleResponse.status).toBe(501);
});
});

describe('production', () => {
Expand Down
Loading

0 comments on commit 9a7712d

Please sign in to comment.