Skip to content

Commit

Permalink
Merge 406503f into 227c71c
Browse files Browse the repository at this point in the history
  • Loading branch information
jeswr committed Mar 8, 2023
2 parents 227c71c + 406503f commit cec4dbd
Show file tree
Hide file tree
Showing 12 changed files with 14 additions and 16 deletions.
1 change: 1 addition & 0 deletions .eslintrc.js
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ module.exports = {
Headers: false,
Request: false,
XMLHttpRequest: false,
globalThis: false,
},
rules: {
// Default
Expand Down
3 changes: 0 additions & 3 deletions engines/query-sparql/test/QuerySparql-solid-test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@ const config = [{
}];

// Store global fetch to reset to after mock.
// eslint-disable-next-line no-undef
const globalFetch = globalThis.fetch;

// Use an increased timeout, since the CSS server takes too much setup time.
Expand Down Expand Up @@ -109,15 +108,13 @@ describe('System test: QuerySparql over Solid Pods', () => {

// Override global fetch with auth fetch
// @ts-expect-error
// eslint-disable-next-line no-undef
globalThis.fetch = jest.fn(authFetch);
});

afterAll(async() => {
await app.stop();

// Reset global fetch. This is probably redundant, as jest clears the DOM after each file.
// eslint-disable-next-line no-undef
globalThis.fetch = globalFetch;
});

Expand Down
2 changes: 1 addition & 1 deletion engines/query-sparql/test/QuerySparql-test.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
/** @jest-environment setup-polly-jest/jest-environment-node */

// Needed to undo automock from actor-http-native, cleaner workarounds do not appear to be working.
if (!global.window) {
if (!globalThis.window) {
jest.unmock('follow-redirects');
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import { ActorDereferenceHttp } from '../lib/ActorDereferenceHttp';
const streamifyString = require('streamify-string');

// TODO: Remove when targeting NodeJS 18+
global.ReadableStream = global.ReadableStream || require('web-streams-ponyfill').ReadableStream;
globalThis.ReadableStream = globalThis.ReadableStream || require('web-streams-ponyfill').ReadableStream;

describe('ActorDereferenceHttp', () => {
let bus: any;
Expand Down
4 changes: 2 additions & 2 deletions packages/actor-http-fetch/lib/ActorHttpFetch.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,9 +23,9 @@ export class ActorHttpFetch extends ActorHttp {
}

public static createUserAgent(): string {
return `Comunica/actor-http-fetch (${typeof global.navigator === 'undefined' ?
return `Comunica/actor-http-fetch (${typeof globalThis.navigator === 'undefined' ?
`Node.js ${process.version}; ${process.platform}` :
`Browser-${global.navigator.userAgent}`})`;
`Browser-${globalThis.navigator.userAgent}`})`;
}

public async test(action: IActionHttp): Promise<IMediatorTypeTime> {
Expand Down
2 changes: 1 addition & 1 deletion packages/actor-http-fetch/lib/FetchInitPreprocessor.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ export class FetchInitPreprocessor implements IFetchInitPreprocessor {
public async createAbortController(): Promise<AbortController> {
// Fallback to abort-controller for Node 14 backward compatibility
/* istanbul ignore next */
const AbortController = global.AbortController || await import('abort-controller');
const AbortController = globalThis.AbortController || await import('abort-controller');
return new AbortController();
}
}
Expand Down
2 changes: 1 addition & 1 deletion packages/actor-http-fetch/test/ActorHttpFetch-test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ describe('ActorHttpFetch', () => {
it('should create a user agent in the browser', () => {
(<any> global).navigator = { userAgent: 'Dummy' };
return expect(ActorHttpFetch.createUserAgent())
.toEqual(`Comunica/actor-http-fetch (Browser-${global.navigator.userAgent})`);
.toEqual(`Comunica/actor-http-fetch (Browser-${globalThis.navigator.userAgent})`);
});

it('should create a user agent in Node.js', () => {
Expand Down
4 changes: 2 additions & 2 deletions packages/actor-http-native/lib/ActorHttpNative.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,9 +20,9 @@ export class ActorHttpNative extends ActorHttp {
}

public static createUserAgent(): string {
return `Comunica/actor-http-native (${typeof global.navigator === 'undefined' ?
return `Comunica/actor-http-native (${typeof globalThis.navigator === 'undefined' ?
`Node.js ${process.version}; ${process.platform}` :
`Browser-${global.navigator.userAgent}`})`;
`Browser-${globalThis.navigator.userAgent}`})`;
}

public async test(action: IActionHttp): Promise<IMediatorTypeTime> {
Expand Down
2 changes: 1 addition & 1 deletion packages/actor-http-native/test/ActorHttpNative-test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ describe('ActorHttpNative', () => {
it('should create a user agent in the browser', () => {
(<any> global).navigator = { userAgent: 'Dummy' };
return expect(ActorHttpNative.createUserAgent())
.toEqual(`Comunica/actor-http-native (Browser-${global.navigator.userAgent})`);
.toEqual(`Comunica/actor-http-native (Browser-${globalThis.navigator.userAgent})`);
});

it('should create a user agent in Node.js', () => {
Expand Down
2 changes: 1 addition & 1 deletion packages/actor-init-query/lib/ActorInitQuery-browser.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import { ActorInitQueryBase } from './ActorInitQueryBase';
/* istanbul ignore next */
if (typeof process === 'undefined') {
// Polyfills process.nextTick for readable-stream
global.process = require('process'); // eslint-disable-line import/no-nodejs-modules
globalThis.process = require('process'); // eslint-disable-line import/no-nodejs-modules
}

export class ActorInitQuery extends ActorInitQueryBase {}
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ const streamifyString = require('streamify-string');
const DF = new DataFactory();

// TODO: Remove when targeting NodeJS 18+
global.ReadableStream = global.ReadableStream || require('web-streams-ponyfill').ReadableStream;
globalThis.ReadableStream = globalThis.ReadableStream || require('web-streams-ponyfill').ReadableStream;

describe('RdfSourceSparql', () => {
const context = new ActionContext({});
Expand Down
4 changes: 2 additions & 2 deletions packages/bus-http/lib/ActorHttp.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@ import type { IAction, IActorArgs, IActorOutput, IActorTest, Mediate } from '@co
import { Actor } from '@comunica/core';
import { ReadableWebToNodeStream } from 'readable-web-to-node-stream';

if (!global.ReadableStream) {
global.ReadableStream = require('web-streams-ponyfill').ReadableStream;
if (!globalThis.ReadableStream) {
globalThis.ReadableStream = require('web-streams-ponyfill').ReadableStream;
}

const isStream = require('is-stream');
Expand Down

0 comments on commit cec4dbd

Please sign in to comment.