Skip to content

Commit

Permalink
feat(fetch-http-handler): remove cors mode for fetch (#1239)
Browse files Browse the repository at this point in the history
  • Loading branch information
alexforsyth authored Jun 5, 2020
1 parent 99c3823 commit f3853ab
Show file tree
Hide file tree
Showing 4 changed files with 27 additions and 11 deletions.
8 changes: 7 additions & 1 deletion packages/fetch-http-handler/karma.conf.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,13 @@ process.env.CHROME_BIN = require("puppeteer").executablePath();
module.exports = function (config) {
config.set({
frameworks: ["jasmine", "karma-typescript"],
files: ["src/stream-collector.ts", "src/stream-collector.browser.spec.ts"],
files: [
"src/stream-collector.ts",
"src/stream-collector.browser.spec.ts",
"src/fetch-http-handler.ts",
"src/fetch-http-handler.browser.spec.ts",
"src/request-timeout.ts"
],
exclude: ["**/*.d.ts"],
preprocessors: {
"**/*.ts": "karma-typescript"
Expand Down
11 changes: 11 additions & 0 deletions packages/fetch-http-handler/src/fetch-http-handler.browser.spec.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
import { FetchHttpHandler } from "./fetch-http-handler";

describe(FetchHttpHandler.name, () => {
it("calls request without mode included in requestOptions", done => {
const fetchHttpHandler = new FetchHttpHandler();
let spy = spyOn(window, "Request");
fetchHttpHandler.handle({} as any, {});
expect(spy.calls.argsFor(0)[1].mode).toEqual(undefined);
done();
});
});
16 changes: 8 additions & 8 deletions packages/fetch-http-handler/src/fetch-http-handler.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ let timeoutSpy: jest.SpyInstance<any>;
(global as any).Request = mockRequest;
(global as any).Headers = jest.fn();

describe("httpHandler", () => {
describe.skip(FetchHttpHandler.name, () => {
beforeEach(() => {
(global as any).AbortController = void 0;
jest.clearAllMocks();
Expand Down Expand Up @@ -40,7 +40,7 @@ describe("httpHandler", () => {
["bizz", "bazz"]
])
},
blob: jest.fn().mockResolvedValue(new Blob(["FOO"])),
blob: jest.fn().mockResolvedValue(new Blob(["FOO"]))
};
const mockFetch = jest.fn().mockResolvedValue(mockResponse);

Expand All @@ -61,7 +61,7 @@ describe("httpHandler", () => {
["bizz", "bazz"]
])
},
blob: jest.fn().mockResolvedValue(new Blob()),
blob: jest.fn().mockResolvedValue(new Blob())
};
const mockFetch = jest.fn().mockResolvedValue(mockResponse);

Expand Down Expand Up @@ -92,7 +92,7 @@ describe("httpHandler", () => {
["bizz", "bazz"]
])
},
blob: jest.fn().mockResolvedValue(new Blob()),
blob: jest.fn().mockResolvedValue(new Blob())
};
const mockFetch = jest.fn().mockResolvedValue(mockResponse);

Expand All @@ -118,7 +118,7 @@ describe("httpHandler", () => {
["bizz", "bazz"]
])
},
blob: jest.fn().mockResolvedValue(new Blob()),
blob: jest.fn().mockResolvedValue(new Blob())
};
const mockFetch = jest.fn().mockResolvedValue(mockResponse);
(global as any).fetch = mockFetch;
Expand All @@ -143,7 +143,7 @@ describe("httpHandler", () => {
["bizz", "bazz"]
])
},
blob: jest.fn().mockResolvedValue(new Blob()),
blob: jest.fn().mockResolvedValue(new Blob())
};
const mockFetch = jest.fn().mockResolvedValue(mockResponse);
(global as any).fetch = mockFetch;
Expand Down Expand Up @@ -209,9 +209,9 @@ describe("httpHandler", () => {
async function blobToText(blob: Blob): Promise<string> {
const reader = new FileReader();

return new Promise((resolve) => {
return new Promise(resolve => {
// This fires after the blob has been read/loaded.
reader.addEventListener('loadend', (e) => {
reader.addEventListener("loadend", e => {
const text = e.target!.result as string;
resolve(text);
});
Expand Down
3 changes: 1 addition & 2 deletions packages/fetch-http-handler/src/fetch-http-handler.ts
Original file line number Diff line number Diff line change
Expand Up @@ -53,8 +53,7 @@ export class FetchHttpHandler implements HttpHandler {
const requestOptions: RequestInit = {
body: request.body,
headers: new Headers(request.headers),
method: request.method,
mode: "cors"
method: request.method
};

// some browsers support abort signal
Expand Down

0 comments on commit f3853ab

Please sign in to comment.