Skip to content

Commit 4bdab6f

Browse files
committed
Removed node-fetch from rules-unit-testing
1 parent a377fb2 commit 4bdab6f

File tree

8 files changed

+5
-14
lines changed

8 files changed

+5
-14
lines changed

packages/rules-unit-testing/package.json

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -53,9 +53,5 @@
5353
"typings": "dist/index.d.ts",
5454
"bugs": {
5555
"url": "https://github.com/firebase/firebase-js-sdk/issues"
56-
},
57-
"dependencies": {
58-
"node-fetch": "2.6.7",
59-
"@types/node-fetch": "2.6.4"
6056
}
6157
}

packages/rules-unit-testing/src/impl/discovery.ts

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,6 @@
1616
*/
1717

1818
import { EmulatorConfig, HostAndPort } from '../public_types';
19-
import nodeFetch from 'node-fetch';
2019
import { makeUrl, fixHostname } from './url';
2120

2221
/**
@@ -27,9 +26,9 @@ import { makeUrl, fixHostname } from './url';
2726
*/
2827
export async function discoverEmulators(
2928
hub: HostAndPort,
30-
fetch: typeof nodeFetch = nodeFetch
29+
fetchImpl: typeof fetch = fetch
3130
): Promise<DiscoveredEmulators> {
32-
const res = await fetch(makeUrl(hub, '/emulators'));
31+
const res = await fetchImpl(makeUrl(hub, '/emulators'));
3332
if (!res.ok) {
3433
throw new Error(
3534
`HTTP Error ${res.status} when attempting to reach Emulator Hub at ${res.url}, are you sure it is running?`

packages/rules-unit-testing/src/impl/rules.ts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,6 @@
1717

1818
import { HostAndPort } from '../public_types';
1919
import { makeUrl } from './url';
20-
import fetch from 'node-fetch';
2120

2221
/**
2322
* @private

packages/rules-unit-testing/src/impl/test_environment.ts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,6 @@
1515
* limitations under the License.
1616
*/
1717

18-
import fetch from 'node-fetch';
1918
import firebase from 'firebase/compat/app';
2019
import 'firebase/compat/firestore';
2120
import 'firebase/compat/database';

packages/rules-unit-testing/src/util.ts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,6 @@ import {
2121
} from './impl/discovery';
2222
import { fixHostname, makeUrl } from './impl/url';
2323
import { HostAndPort } from './public_types';
24-
import fetch from 'node-fetch';
2524

2625
/**
2726
* Run a setup function with background Cloud Functions triggers disabled. This can be used to

packages/rules-unit-testing/test/impl/discovery.test.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,7 @@ describe('discoverEmulators()', () => {
7171
// Connect to port:0. Should always fail (although error codes may differ among OSes).
7272
await expect(
7373
discoverEmulators({ host: '127.0.0.1', port: 0 })
74-
).to.be.rejectedWith(/EADDRNOTAVAIL|ECONNREFUSED/);
74+
).to.be.rejectedWith(/EADDRNOTAVAIL|ECONNREFUSED|fetch failed/);
7575
});
7676

7777
it('throws if response status is not 2xx', async () => {

packages/rules-unit-testing/test/util.test.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -165,7 +165,7 @@ describe('assertFails()', () => {
165165

166166
describe('withFunctionTriggersDisabled()', () => {
167167
it('disabling function triggers does not throw, returns value', async function () {
168-
const fetchSpy = sinon.spy(require('node-fetch'), 'default');
168+
const fetchSpy = sinon.spy(globalThis, 'fetch');
169169

170170
const res = await withFunctionTriggersDisabled(() => {
171171
return Promise.resolve(1234);
@@ -176,7 +176,7 @@ describe('withFunctionTriggersDisabled()', () => {
176176
});
177177

178178
it('disabling function triggers always re-enables, event when the function throws', async function () {
179-
const fetchSpy = sinon.spy(require('node-fetch'), 'default');
179+
const fetchSpy = sinon.spy(globalThis, 'fetch');
180180

181181
const res = withFunctionTriggersDisabled(() => {
182182
throw new Error('I throw!');

scripts/emulator-testing/emulators/emulator.ts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,6 @@ import { ChildProcess } from 'child_process';
2121
import * as fs from 'fs';
2222
import * as os from 'os';
2323
import * as path from 'path';
24-
import fetch from 'node-fetch';
2524
// @ts-ignore
2625
import * as tmp from 'tmp';
2726

0 commit comments

Comments
 (0)