Skip to content

Commit

Permalink
Avoid using globalThis
Browse files Browse the repository at this point in the history
  • Loading branch information
frederikprijck committed Aug 16, 2023
1 parent e55c2e5 commit d486dc0
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 12 deletions.
12 changes: 3 additions & 9 deletions src/lib/runtime.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import {
} from './models.js';

export * from './models.js';
export const getFormDataCls = () => globalThis.FormData;
export const getFormDataCls = () => FormData;

/**
* @private
Expand All @@ -32,7 +32,7 @@ export class BaseAPI {
}

this.middleware = configuration.middleware || [];
this.fetchApi = configuration.fetchApi || globalThis.fetch;
this.fetchApi = configuration.fetchApi || fetch;
this.parseError = configuration.parseError;
this.timeoutDuration =
typeof configuration.timeoutDuration === 'number' ? configuration.timeoutDuration : 10000;
Expand Down Expand Up @@ -85,11 +85,10 @@ export class BaseAPI {
})),
};

const Blob = globalThis.Blob;
const init: RequestInit = {
...overriddenInit,
body:
(await isFormData(overriddenInit.body)) ||
overriddenInit.body instanceof FormData ||
overriddenInit.body instanceof URLSearchParams ||
overriddenInit.body instanceof Blob
? overriddenInit.body
Expand Down Expand Up @@ -173,11 +172,6 @@ export class BaseAPI {
};
}

async function isFormData(value: unknown): Promise<boolean> {
const FormData = globalThis.FormData;
return typeof FormData !== 'undefined' && value instanceof FormData;
}

/**
* @private
*/
Expand Down
3 changes: 0 additions & 3 deletions test/management/jobs.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -175,7 +175,6 @@ describe('JobsManager', () => {
let request: nock.Scope;

beforeEach(async () => {
const Blob = globalThis.Blob;
data = {
users: new Blob([fs.readFileSync(usersFilePath)], { type: 'application/json' }),
connection_id: 'con_test',
Expand Down Expand Up @@ -386,7 +385,6 @@ describe('JobsManager', () => {
let data: PostUsersImportsData;

beforeEach(async () => {
const Blob = globalThis.Blob;
data = {
users: new Blob([fs.readFileSync(usersFilePath)], { type: 'application/json' }),
connection_id: 'con_test',
Expand Down Expand Up @@ -449,7 +447,6 @@ describe('JobsManager', () => {
})
.reply(200, {});

const Blob = globalThis.Blob;
await jobs
.importUsers({
...data,
Expand Down

0 comments on commit d486dc0

Please sign in to comment.