From cf6af6858610e143019acb586dc57f57bc8aa2f6 Mon Sep 17 00:00:00 2001 From: Nikhil Thorat Date: Tue, 3 Sep 2019 12:44:14 -0400 Subject: [PATCH 1/2] Remove the systemFetch export from platform_node --- tfjs-core/src/platforms/platform_node.ts | 14 +++++++++++++- tfjs-core/src/platforms/platform_node_test.ts | 8 +++----- 2 files changed, 16 insertions(+), 6 deletions(-) diff --git a/tfjs-core/src/platforms/platform_node.ts b/tfjs-core/src/platforms/platform_node.ts index 95e2ad35252..351a4410d3f 100644 --- a/tfjs-core/src/platforms/platform_node.ts +++ b/tfjs-core/src/platforms/platform_node.ts @@ -24,7 +24,19 @@ export const getNodeFetch = { importFetch: () => require('node-fetch') }; -export let systemFetch: (url: string, init?: RequestInit) => Promise; +let systemFetch: FetchFn; +// These getters and setters are for testing so we don't export a mutable +// variable. +export function resetSystemFetch() { + systemFetch = null; +} +type FetchFn = (url: string, init?: RequestInit) => Promise; +export function setSystemFetch(fetchFn: FetchFn) { + systemFetch = fetchFn; +} +export function getSystemFetch(): FetchFn { + return systemFetch; +} export class PlatformNode implements Platform { private textEncoder: TextEncoder; diff --git a/tfjs-core/src/platforms/platform_node_test.ts b/tfjs-core/src/platforms/platform_node_test.ts index 81052733e2e..a58d11f5306 100644 --- a/tfjs-core/src/platforms/platform_node_test.ts +++ b/tfjs-core/src/platforms/platform_node_test.ts @@ -42,11 +42,10 @@ describeWithFlags('PlatformNode', NODE_ENVS, () => { const platform = new PlatformNode(); - const savedFetch = platform_node.systemFetch; + const savedFetch = platform_node.getSystemFetch(); // Null out the system fetch so we force it to require node-fetch. - // @ts-ignore - platform_node.systemFetch = null; + platform_node.resetSystemFetch(); const testFetch = {fetch: (url: string, init: RequestInit) => {}}; @@ -63,8 +62,7 @@ describeWithFlags('PlatformNode', NODE_ENVS, () => { expect(platform_node.getNodeFetch.importFetch).toHaveBeenCalled(); expect(testFetch.fetch).toHaveBeenCalledWith('test/url', {method: 'GET'}); - // @ts-ignore - platform_node.systemFetch = savedFetch; + platform_node.setSystemFetch(savedFetch); ENV.global.fetch = globalFetch; }); From 6fc9a2a80fb8b5827b8326dd6ebe508770e7d323 Mon Sep 17 00:00:00 2001 From: Nikhil Thorat Date: Tue, 3 Sep 2019 12:52:29 -0400 Subject: [PATCH 2/2] save --- tfjs-core/src/platforms/platform_node.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tfjs-core/src/platforms/platform_node.ts b/tfjs-core/src/platforms/platform_node.ts index 351a4410d3f..b32f8dc40ca 100644 --- a/tfjs-core/src/platforms/platform_node.ts +++ b/tfjs-core/src/platforms/platform_node.ts @@ -24,13 +24,13 @@ export const getNodeFetch = { importFetch: () => require('node-fetch') }; +type FetchFn = (url: string, init?: RequestInit) => Promise; let systemFetch: FetchFn; // These getters and setters are for testing so we don't export a mutable // variable. export function resetSystemFetch() { systemFetch = null; } -type FetchFn = (url: string, init?: RequestInit) => Promise; export function setSystemFetch(fetchFn: FetchFn) { systemFetch = fetchFn; }