Skip to content

Commit b41fcde

Browse files
authored
Update remaining test targets to use undici (#7761)
Some of our build/test targets from ddb-upgrade-node-fetch still required a migration from node-fetch to undici.
1 parent 3febc4c commit b41fcde

File tree

8 files changed

+16
-18
lines changed

8 files changed

+16
-18
lines changed

integration/messaging/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515
"express": "4.18.2",
1616
"geckodriver": "2.0.4",
1717
"mocha": "9.2.2",
18-
"node-fetch": "2.6.7",
18+
"undici": "5.26.5",
1919
"selenium-assistant": "6.1.1"
2020
}
2121
}

integration/messaging/test/utils/sendMessage.js

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

18-
const fetch = require('node-fetch');
18+
const undici = require('undici');
1919
const FCM_SEND_ENDPOINT = 'https://fcm.googleapis.com/fcm/send';
2020
// Rotatable fcm server key. It's generally a bad idea to expose server keys. The reason is to
2121
// simplify testing process (no need to implement server side decryption of git secret). The
@@ -28,7 +28,7 @@ module.exports = async payload => {
2828
'Requesting to send an FCM message with payload: ' + JSON.stringify(payload)
2929
);
3030

31-
const response = await fetch(FCM_SEND_ENDPOINT, {
31+
const response = await undici.fetch(FCM_SEND_ENDPOINT, {
3232
method: 'POST',
3333
body: JSON.stringify(payload),
3434
headers: {

packages/rules-unit-testing/package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,7 @@
5454
"url": "https://github.com/firebase/firebase-js-sdk/issues"
5555
},
5656
"dependencies": {
57+
"undici": "5.26.5",
5758
"node-fetch": "2.6.7",
5859
"@types/node-fetch": "2.6.4"
5960
}

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

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@
1717

1818
import { HostAndPort } from '../public_types';
1919
import { makeUrl } from './url';
20-
import fetch from 'node-fetch';
20+
import { fetch as undiciFetch } from 'undici';
2121

2222
/**
2323
* @private
@@ -29,7 +29,7 @@ export async function loadDatabaseRules(
2929
): Promise<void> {
3030
const url = makeUrl(hostAndPort, '/.settings/rules.json');
3131
url.searchParams.append('ns', databaseName);
32-
const resp = await fetch(url, {
32+
const resp = await undiciFetch(url, {
3333
method: 'PUT',
3434
headers: { Authorization: 'Bearer owner' },
3535
body: rules
@@ -48,7 +48,7 @@ export async function loadFirestoreRules(
4848
projectId: string,
4949
rules: string
5050
): Promise<void> {
51-
const resp = await fetch(
51+
const resp = await undiciFetch(
5252
makeUrl(hostAndPort, `/emulator/v1/projects/${projectId}:securityRules`),
5353
{
5454
method: 'PUT',
@@ -72,7 +72,7 @@ export async function loadStorageRules(
7272
hostAndPort: HostAndPort,
7373
rules: string
7474
): Promise<void> {
75-
const resp = await fetch(makeUrl(hostAndPort, '/internal/setRules'), {
75+
const resp = await undiciFetch(makeUrl(hostAndPort, '/internal/setRules'), {
7676
method: 'PUT',
7777
headers: {
7878
'Content-Type': 'application/json'

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

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

18-
import fetch from 'node-fetch';
18+
import { fetch as undiciFetch } from 'undici';
1919
import firebase from 'firebase/compat/app';
2020
import 'firebase/compat/firestore';
2121
import 'firebase/compat/database';
@@ -106,7 +106,7 @@ export class RulesTestEnvironmentImpl implements RulesTestEnvironment {
106106
this.checkNotDestroyed();
107107
assertEmulatorRunning(this.emulators, 'firestore');
108108

109-
const resp = await fetch(
109+
const resp = await undiciFetch(
110110
makeUrl(
111111
this.emulators.firestore,
112112
`/emulator/v1/projects/${this.projectId}/databases/(default)/documents`

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

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ import {
2121
} from './impl/discovery';
2222
import { fixHostname, makeUrl } from './impl/url';
2323
import { HostAndPort } from './public_types';
24-
import fetch from 'node-fetch';
24+
import { fetch as undiciFetch } from 'undici';
2525

2626
/**
2727
* Run a setup function with background Cloud Functions triggers disabled. This can be used to
@@ -79,7 +79,7 @@ export async function withFunctionTriggersDisabled<TResult>(
7979
hub.host = fixHostname(hub.host);
8080
makeUrl(hub, '/functions/disableBackgroundTriggers');
8181
// Disable background triggers
82-
const disableRes = await fetch(
82+
const disableRes = await undiciFetch(
8383
makeUrl(hub, '/functions/disableBackgroundTriggers'),
8484
{
8585
method: 'PUT'
@@ -98,7 +98,7 @@ export async function withFunctionTriggersDisabled<TResult>(
9898
result = await maybeFn();
9999
} finally {
100100
// Re-enable background triggers
101-
const enableRes = await fetch(
101+
const enableRes = await undiciFetch(
102102
makeUrl(hub, '/functions/enableBackgroundTriggers'),
103103
{
104104
method: 'PUT'

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(require('undici'), '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(require('undici'), 'fetch');
180180

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

packages/storage/src/implementation/type.ts

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

18-
import { isNode } from '@firebase/util';
1918
import { invalidArgument } from './error';
2019

2120
export function isJustDef<T>(p: T | null | undefined): p is T | null {
@@ -40,9 +39,7 @@ export function isNativeBlob(p: unknown): p is Blob {
4039
}
4140

4241
export function isNativeBlobDefined(): boolean {
43-
// Note: The `isNode()` check can be removed when `node-fetch` adds native Blob support
44-
// PR: https://github.com/node-fetch/node-fetch/pull/1664
45-
return typeof Blob !== 'undefined' && !isNode();
42+
return typeof Blob !== 'undefined';
4643
}
4744

4845
export function validateNumber(

0 commit comments

Comments
 (0)