Skip to content

Commit 3febc4c

Browse files
committed
revert undici changes in tests
1 parent a95a38d commit 3febc4c

File tree

10 files changed

+44
-26
lines changed

10 files changed

+44
-26
lines changed

integration/messaging/package.json

+1-1
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-
"undici": "5.26.5",
18+
"node-fetch": "2.6.7",
1919
"selenium-assistant": "6.1.1"
2020
}
2121
}

integration/messaging/test/utils/sendMessage.js

+2-2
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515
* limitations under the License.
1616
*/
1717

18-
const undiciFetch = require('undici');
18+
const fetch = require('node-fetch');
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 undiciFetch(FCM_SEND_ENDPOINT, {
31+
const response = await fetch(FCM_SEND_ENDPOINT, {
3232
method: 'POST',
3333
body: JSON.stringify(payload),
3434
headers: {

packages/rules-unit-testing/package.json

+2-1
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"
57+
"node-fetch": "2.6.7",
58+
"@types/node-fetch": "2.6.4"
5859
}
5960
}

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

+3-3
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616
*/
1717

1818
import { EmulatorConfig, HostAndPort } from '../public_types';
19-
import { fetch as undiciFetch } from 'undici';
19+
import nodeFetch from 'node-fetch';
2020
import { makeUrl, fixHostname } from './url';
2121

2222
/**
@@ -27,9 +27,9 @@ import { makeUrl, fixHostname } from './url';
2727
*/
2828
export async function discoverEmulators(
2929
hub: HostAndPort,
30-
fetch: typeof undiciFetch = undiciFetch
30+
fetch: typeof nodeFetch = nodeFetch
3131
): Promise<DiscoveredEmulators> {
32-
const res = await undiciFetch(makeUrl(hub, '/emulators'));
32+
const res = await fetch(makeUrl(hub, '/emulators'));
3333
if (!res.ok) {
3434
throw new Error(
3535
`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

+4-4
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 as undiciFetch } from 'undici';
20+
import fetch from 'node-fetch';
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 undiciFetch(url, {
32+
const resp = await fetch(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 undiciFetch(
51+
const resp = await fetch(
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 undiciFetch(makeUrl(hostAndPort, '/internal/setRules'), {
75+
const resp = await fetch(makeUrl(hostAndPort, '/internal/setRules'), {
7676
method: 'PUT',
7777
headers: {
7878
'Content-Type': 'application/json'

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

+2-2
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515
* limitations under the License.
1616
*/
1717

18-
import { fetch as undiciFetch } from 'undici';
18+
import fetch from 'node-fetch';
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 undiciFetch(
109+
const resp = await fetch(
110110
makeUrl(
111111
this.emulators.firestore,
112112
`/emulator/v1/projects/${this.projectId}/databases/(default)/documents`

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

+2-2
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 as undiciFetch } from 'undici';
24+
import fetch from 'node-fetch';
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 undiciFetch(
82+
const disableRes = await fetch(
8383
makeUrl(hub, '/functions/disableBackgroundTriggers'),
8484
{
8585
method: 'PUT'

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

+2-2
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('undici'), 'default');
168+
const fetchSpy = sinon.spy(require('node-fetch'), 'default');
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('undici'), 'default');
179+
const fetchSpy = sinon.spy(require('node-fetch'), 'default');
180180

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

scripts/emulator-testing/emulators/emulator.ts

+2-2
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ 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 as undiciFetch } from 'undici';
24+
import fetch from 'node-fetch';
2525
// @ts-ignore
2626
import * as tmp from 'tmp';
2727

@@ -57,7 +57,7 @@ export abstract class Emulator {
5757
const writeStream: fs.WriteStream = fs.createWriteStream(filepath);
5858

5959
console.log(`Downloading emulator from [${this.binaryUrl}] ...`);
60-
undiciFetch(this.binaryUrl).then(resp => {
60+
fetch(this.binaryUrl).then(resp => {
6161
resp.body
6262
.pipe(writeStream)
6363
.on('finish', () => {

yarn.lock

+24-7
Original file line numberDiff line numberDiff line change
@@ -3471,6 +3471,14 @@
34713471
dependencies:
34723472
"@types/node" "*"
34733473

3474+
3475+
version "2.6.4"
3476+
resolved "https://registry.npmjs.org/@types/node-fetch/-/node-fetch-2.6.4.tgz#1bc3a26de814f6bf466b25aeb1473fa1afe6a660"
3477+
integrity sha512-1ZX9fcN4Rvkvgv4E6PAY5WXUFWFcRWxZa3EW83UjycOB9ljJCedb2CupIP4RZMEwF/M3eTcCihbBRgwtGbg5Rg==
3478+
dependencies:
3479+
"@types/node" "*"
3480+
form-data "^3.0.0"
3481+
34743482
"@types/node@*", "@types/node@>=10.0.0", "@types/node@>=12.12.47", "@types/node@>=13.7.0":
34753483
version "16.9.6"
34763484
resolved "https://registry.npmjs.org/@types/node/-/node-16.9.6.tgz#040a64d7faf9e5d9e940357125f0963012e66f04"
@@ -8187,6 +8195,15 @@ form-data@^2.5.0:
81878195
combined-stream "^1.0.6"
81888196
mime-types "^2.1.12"
81898197

8198+
form-data@^3.0.0:
8199+
version "3.0.1"
8200+
resolved "https://registry.npmjs.org/form-data/-/form-data-3.0.1.tgz#ebd53791b78356a99af9a300d4282c4d5eb9755f"
8201+
integrity sha512-RHkBKtLWUVwd7SqRIvCZMEvAMoGUp0XU+seQiZejj0COz3RI3hWP4sCv3gZWWLjJTd7rGwcsF5eKZGii0r/hbg==
8202+
dependencies:
8203+
asynckit "^0.4.0"
8204+
combined-stream "^1.0.8"
8205+
mime-types "^2.1.12"
8206+
81908207
form-data@^4.0.0:
81918208
version "4.0.0"
81928209
resolved "https://registry.npmjs.org/form-data/-/form-data-4.0.0.tgz#93919daeaf361ee529584b9b31664dc12c9fa452"
@@ -12471,20 +12488,20 @@ node-emoji@^1.11.0:
1247112488
dependencies:
1247212489
lodash "^4.17.21"
1247312490

12491+
[email protected], node-fetch@^2.6.7:
12492+
version "2.6.7"
12493+
resolved "https://registry.npmjs.org/node-fetch/-/node-fetch-2.6.7.tgz#24de9fba827e3b4ae44dc8b20256a379160052ad"
12494+
integrity sha512-ZjMPFEfVx5j+y2yF35Kzx5sF7kDzxuDj6ziH4FFbOp87zKDZNx8yExJIb05OGF4Nlt9IHFIMBkRl41VdvcNdbQ==
12495+
dependencies:
12496+
whatwg-url "^5.0.0"
12497+
1247412498
node-fetch@^2.5.0, node-fetch@^2.6.1:
1247512499
version "2.6.5"
1247612500
resolved "https://registry.npmjs.org/node-fetch/-/node-fetch-2.6.5.tgz#42735537d7f080a7e5f78b6c549b7146be1742fd"
1247712501
integrity sha512-mmlIVHJEu5rnIxgEgez6b9GgWXbkZj5YZ7fx+2r94a2E+Uirsp6HsPTPlomfdHtpt/B0cdKviwkoaM6pyvUOpQ==
1247812502
dependencies:
1247912503
whatwg-url "^5.0.0"
1248012504

12481-
node-fetch@^2.6.7:
12482-
version "2.6.7"
12483-
resolved "https://registry.npmjs.org/node-fetch/-/node-fetch-2.6.7.tgz#24de9fba827e3b4ae44dc8b20256a379160052ad"
12484-
integrity sha512-ZjMPFEfVx5j+y2yF35Kzx5sF7kDzxuDj6ziH4FFbOp87zKDZNx8yExJIb05OGF4Nlt9IHFIMBkRl41VdvcNdbQ==
12485-
dependencies:
12486-
whatwg-url "^5.0.0"
12487-
1248812505
node-forge@^0.10.0:
1248912506
version "0.10.0"
1249012507
resolved "https://registry.npmjs.org/node-forge/-/node-forge-0.10.0.tgz#32dea2afb3e9926f02ee5ce8794902691a676bf3"

0 commit comments

Comments
 (0)