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

Commit

Permalink
feat(fetch): switch to cross-fetch instead of isomorphic-fetch (#101)
Browse files Browse the repository at this point in the history
  • Loading branch information
JAdshead committed Apr 21, 2020
1 parent 6e16cc9 commit 82155d5
Show file tree
Hide file tree
Showing 8 changed files with 363 additions and 227 deletions.
2 changes: 1 addition & 1 deletion __tests__/integration/helpers/wait.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
* permissions and limitations under the License.
*/

const fetch = require('isomorphic-fetch');
const fetch = require('cross-fetch');
const https = require('https');

const waitFor = (ms) => new Promise((res) => setTimeout(res, ms));
Expand Down
33 changes: 18 additions & 15 deletions __tests__/integration/one-app.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@

// Headers are under a key with a dangling underscore
/* eslint-disable no-underscore-dangle */
import fetch from 'isomorphic-fetch';
import fetch from 'cross-fetch';
import yargs, { argv } from 'yargs';

import { setUpTestRunner, tearDownTestRunner } from './helpers/testRunner';
Expand Down Expand Up @@ -78,10 +78,11 @@ describe('Tests that require Docker setup', () => {
},
}
);
const rawHeaders = response.headers.raw();
expect(response.status).toBe(200);
expect(response.headers._headers).not.toHaveProperty('access-control-allow-origin');
expect(response.headers._headers).not.toHaveProperty('access-control-expose-headers');
expect(response.headers._headers).not.toHaveProperty('access-control-allow-credentials');
expect(rawHeaders).not.toHaveProperty('access-control-allow-origin');
expect(rawHeaders).not.toHaveProperty('access-control-expose-headers');
expect(rawHeaders).not.toHaveProperty('access-control-allow-credentials');
});

test('app rejects CORS OPTIONS pre-flight requests for POST', async () => {
Expand All @@ -97,13 +98,14 @@ describe('Tests that require Docker setup', () => {

expect(response.status).toBe(200);
// preflight-only headers
expect(response.headers._headers).not.toHaveProperty('access-control-max-age');
expect(response.headers._headers).not.toHaveProperty('access-control-allow-methods');
expect(response.headers._headers).not.toHaveProperty('access-control-allow-headers');
const rawHeaders = response.headers.raw();
expect(rawHeaders).not.toHaveProperty('access-control-max-age');
expect(rawHeaders).not.toHaveProperty('access-control-allow-methods');
expect(rawHeaders).not.toHaveProperty('access-control-allow-headers');
// any respnse headers
expect(response.headers._headers).not.toHaveProperty('access-control-allow-origin');
expect(response.headers._headers).not.toHaveProperty('access-control-expose-headers');
expect(response.headers._headers).not.toHaveProperty('access-control-allow-credentials');
expect(rawHeaders).not.toHaveProperty('access-control-allow-origin');
expect(rawHeaders).not.toHaveProperty('access-control-expose-headers');
expect(rawHeaders).not.toHaveProperty('access-control-allow-credentials');
});

describe('tenant without corsOrigins set', () => {
Expand Down Expand Up @@ -133,10 +135,11 @@ describe('Tests that require Docker setup', () => {
},
}
);
const rawHeaders = response.headers.raw();
expect(response.status).toBe(200);
expect(response.headers._headers).not.toHaveProperty('access-control-allow-origin');
expect(response.headers._headers).not.toHaveProperty('access-control-expose-headers');
expect(response.headers._headers).not.toHaveProperty('access-control-allow-credentials');
expect(rawHeaders).not.toHaveProperty('access-control-allow-origin');
expect(rawHeaders).not.toHaveProperty('access-control-expose-headers');
expect(rawHeaders).not.toHaveProperty('access-control-allow-credentials');
});

afterAll(async () => {
Expand Down Expand Up @@ -877,8 +880,8 @@ describe('Tests that can run against either local Docker setup or remote One App
}
);
expect(response.status).toBe(200);
expect(response.headers._headers).toHaveProperty('access-control-allow-origin');
expect(response.headers._headers['access-control-allow-origin']).toEqual(['test.example.com']);
expect(response.headers.raw()).toHaveProperty('access-control-allow-origin');
expect(response.headers.get('access-control-allow-origin')).toEqual('test.example.com');
});

test('app renders frank-lloyd-root on a POST', async () => {
Expand Down
2 changes: 1 addition & 1 deletion __tests__/server/index.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ describe('server index', () => {
getModules: () => getModulesImplementation,
}));

jest.doMock('isomorphic-fetch');
jest.doMock('cross-fetch');

jest.doMock(
'../../src/server/utils/loadModules',
Expand Down
543 changes: 338 additions & 205 deletions package-lock.json

Large diffs are not rendered by default.

4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@
"dependencies": {
"@americanexpress/env-config-utils": "^2.0.2",
"@americanexpress/lumberjack": "^1.1.3",
"@americanexpress/one-app-bundler": "^6.3.0",
"@americanexpress/one-app-bundler": "^6.4.0",
"@americanexpress/one-app-ducks": "^4.0.0",
"@americanexpress/one-app-router": "^1.0.0",
"@americanexpress/vitruvius": "^2.0.0",
Expand All @@ -84,14 +84,14 @@
"cookie-parser": "^1.4.4",
"core-js": "^3.4.1",
"cors": "^2.8.5",
"cross-fetch": "^3.0.4",
"express": "^4.17.1",
"helmet": "^3.21.2",
"holocron": "^1.1.0",
"holocron-module-route": "^1.1.0",
"if-env": "^1.0.4",
"immutable": "^4.0.0-rc.12",
"ip": "^1.1.5",
"isomorphic-fetch": "^2.2.1",
"lean-intl": "^4.2.2",
"matcher": "^2.1.0",
"pidusage": "^2.0.17",
Expand Down

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion prod-sample/sample-modules/ssr-frank/0.0.0/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -19,4 +19,4 @@
"babel-preset-amex": "^3.1.0",
"rimraf": "^2.5.2"
}
}
}
2 changes: 1 addition & 1 deletion src/server/init.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@

import 'core-js/stable';
import 'regenerator-runtime/runtime';
import 'isomorphic-fetch';
import 'cross-fetch/polyfill';

import './polyfill/intl';
import './config/env/argv';
Expand Down

0 comments on commit 82155d5

Please sign in to comment.