Skip to content

Commit 3f9b4b0

Browse files
committed
Run npm run format.
1 parent bff17b7 commit 3f9b4b0

34 files changed

+1217
-1444
lines changed
Lines changed: 49 additions & 79 deletions
Original file line numberDiff line numberDiff line change
@@ -1,37 +1,33 @@
1-
import { PubSub } from '@google-cloud/pubsub';
2-
import { GoogleAuth } from 'google-auth-library';
3-
import { Request, Response } from 'express';
4-
import * as admin from 'firebase-admin';
5-
import * as functions from 'firebase-functions';
6-
import * as fs from 'fs';
7-
import fetch from 'node-fetch';
1+
import { PubSub } from "@google-cloud/pubsub";
2+
import { GoogleAuth } from "google-auth-library";
3+
import { Request, Response } from "express";
4+
import * as admin from "firebase-admin";
5+
import * as functions from "firebase-functions";
6+
import * as fs from "fs";
7+
import fetch from "node-fetch";
88

9-
import * as v1 from './v1';
10-
import * as v2 from './v2';
9+
import * as v1 from "./v1";
10+
import * as v2 from "./v2";
1111
const getNumTests = (m: object): number => {
12-
return Object.keys(m).filter((k) =>
13-
({}.hasOwnProperty.call(m[k], '__endpoint'))
14-
).length;
12+
return Object.keys(m).filter((k) => ({}.hasOwnProperty.call(m[k], "__endpoint"))).length;
1513
};
1614
const numTests = getNumTests(v1) + getNumTests(v2);
1715
export { v1, v2 };
1816

19-
import { REGION } from './region';
20-
import * as testLab from './v1/testLab-utils';
17+
import { REGION } from "./region";
18+
import * as testLab from "./v1/testLab-utils";
2119

2220
const firebaseConfig = JSON.parse(process.env.FIREBASE_CONFIG);
2321
admin.initializeApp();
2422

2523
async function callHttpsTrigger(name: string, data: any) {
2624
const url = `https://${REGION}-${firebaseConfig.projectId}.cloudfunctions.net/${name}`;
27-
const client = await new GoogleAuth().getIdTokenClient(
28-
'32555940559.apps.googleusercontent.com'
29-
);
25+
const client = await new GoogleAuth().getIdTokenClient("32555940559.apps.googleusercontent.com");
3026
const resp = await client.request({
3127
url,
32-
method: 'POST',
28+
method: "POST",
3329
headers: {
34-
'Content-Type': 'application/json',
30+
"Content-Type": "application/json",
3531
},
3632
body: JSON.stringify({ data }),
3733
});
@@ -40,11 +36,7 @@ async function callHttpsTrigger(name: string, data: any) {
4036
}
4137
}
4238

43-
async function callV2HttpsTrigger(
44-
name: string,
45-
data: any,
46-
accessToken: string
47-
) {
39+
async function callV2HttpsTrigger(name: string, data: any, accessToken: string) {
4840
const getFnResp = await fetch(
4941
`https://cloudfunctions.googleapis.com/v2beta/projects/${firebaseConfig.projectId}/locations/${REGION}/functions/${name}`,
5042
{
@@ -62,14 +54,12 @@ async function callV2HttpsTrigger(
6254
throw new Error(`Cannot call v2 https trigger ${name} - no uri found`);
6355
}
6456

65-
const client = await new GoogleAuth().getIdTokenClient(
66-
'32555940559.apps.googleusercontent.com'
67-
);
57+
const client = await new GoogleAuth().getIdTokenClient("32555940559.apps.googleusercontent.com");
6858
const invokeFnREsp = await client.request({
6959
url: uri,
70-
method: 'POST',
60+
method: "POST",
7161
headers: {
72-
'Content-Type': 'application/json',
62+
"Content-Type": "application/json",
7363
},
7464
body: JSON.stringify({ data }),
7565
});
@@ -78,17 +68,13 @@ async function callV2HttpsTrigger(
7868
}
7969
}
8070

81-
async function callScheduleTrigger(
82-
functionName: string,
83-
region: string,
84-
accessToken: string
85-
) {
71+
async function callScheduleTrigger(functionName: string, region: string, accessToken: string) {
8672
const response = await fetch(
8773
`https://cloudscheduler.googleapis.com/v1/projects/${firebaseConfig.projectId}/locations/us-central1/jobs/firebase-schedule-${functionName}-${region}:run`,
8874
{
89-
method: 'POST',
75+
method: "POST",
9076
headers: {
91-
'Content-Type': 'application/json',
77+
"Content-Type": "application/json",
9278
Authorization: `Bearer ${accessToken}`,
9379
},
9480
}
@@ -101,19 +87,16 @@ async function callScheduleTrigger(
10187
return;
10288
}
10389

104-
async function updateRemoteConfig(
105-
testId: string,
106-
accessToken: string
107-
): Promise<void> {
90+
async function updateRemoteConfig(testId: string, accessToken: string): Promise<void> {
10891
const resp = await fetch(
10992
`https://firebaseremoteconfig.googleapis.com/v1/projects/${firebaseConfig.projectId}/remoteConfig`,
11093
{
111-
method: 'PUT',
94+
method: "PUT",
11295
headers: {
11396
Authorization: `Bearer ${accessToken}`,
114-
'Content-Type': 'application/json; UTF-8',
115-
'Accept-Encoding': 'gzip',
116-
'If-Match': '*',
97+
"Content-Type": "application/json; UTF-8",
98+
"Accept-Encoding": "gzip",
99+
"If-Match": "*",
117100
},
118101
body: JSON.stringify({ version: { description: testId } }),
119102
}
@@ -126,88 +109,78 @@ async function updateRemoteConfig(
126109
function v1Tests(testId: string, accessToken: string): Array<Promise<unknown>> {
127110
return [
128111
// A database write to trigger the Firebase Realtime Database tests.
129-
admin.database().ref(`dbTests/${testId}/start`).set({ '.sv': 'timestamp' }),
112+
admin.database().ref(`dbTests/${testId}/start`).set({ ".sv": "timestamp" }),
130113
// A Pub/Sub publish to trigger the Cloud Pub/Sub tests.
131-
new PubSub()
132-
.topic('pubsubTests')
133-
.publish(Buffer.from(JSON.stringify({ testId }))),
114+
new PubSub().topic("pubsubTests").publish(Buffer.from(JSON.stringify({ testId }))),
134115
// A user creation to trigger the Firebase Auth user creation tests.
135116
admin
136117
.auth()
137118
.createUser({
138119
email: `${testId}@fake.com`,
139-
password: 'secret',
120+
password: "secret",
140121
displayName: `${testId}`,
141122
})
142123
.then((userRecord) => {
143124
// A user deletion to trigger the Firebase Auth user deletion tests.
144125
admin.auth().deleteUser(userRecord.uid);
145126
}),
146127
// A firestore write to trigger the Cloud Firestore tests.
147-
admin.firestore().collection('tests').doc(testId).set({ test: testId }),
128+
admin.firestore().collection("tests").doc(testId).set({ test: testId }),
148129
// Invoke a callable HTTPS trigger.
149-
callHttpsTrigger('v1-callableTests', { foo: 'bar', testId }),
130+
callHttpsTrigger("v1-callableTests", { foo: "bar", testId }),
150131
// A Remote Config update to trigger the Remote Config tests.
151132
updateRemoteConfig(testId, accessToken),
152133
// A storage upload to trigger the Storage tests
153134
admin
154135
.storage()
155136
.bucket()
156-
.upload('/tmp/' + testId + '.txt'),
137+
.upload("/tmp/" + testId + ".txt"),
157138
testLab.startTestRun(firebaseConfig.projectId, testId, accessToken),
158139
// Invoke the schedule for our scheduled function to fire
159-
callScheduleTrigger('v1-schedule', 'us-central1', accessToken),
140+
callScheduleTrigger("v1-schedule", "us-central1", accessToken),
160141
];
161142
}
162143

163144
function v2Tests(testId: string, accessToken: string): Array<Promise<void>> {
164145
return [
165146
// Invoke a callable HTTPS trigger.
166-
callV2HttpsTrigger('v2-callabletests', { foo: 'bar', testId }, accessToken),
147+
callV2HttpsTrigger("v2-callabletests", { foo: "bar", testId }, accessToken),
167148
];
168149
}
169150

170151
export const integrationTests: any = functions
171152
.region(REGION)
172153
.runWith({
173154
timeoutSeconds: 540,
174-
invoker: 'private',
155+
invoker: "private",
175156
})
176157
.https.onRequest(async (req: Request, resp: Response) => {
177158
const testId = admin.database().ref().push().key;
178159
admin.database().ref(`testRuns/${testId}/timestamp`).set(Date.now());
179160
const testIdRef = admin.database().ref(`testRuns/${testId}`);
180-
functions.logger.info('testId is: ', testId);
181-
fs.writeFile('/tmp/' + testId + '.txt', 'test', () => {});
161+
functions.logger.info("testId is: ", testId);
162+
fs.writeFile("/tmp/" + testId + ".txt", "test", () => {});
182163
try {
183-
const accessToken = await admin.credential
184-
.applicationDefault()
185-
.getAccessToken();
164+
const accessToken = await admin.credential.applicationDefault().getAccessToken();
186165
await Promise.all([
187166
...v1Tests(testId, accessToken.access_token),
188167
...v2Tests(testId, accessToken.access_token),
189168
]);
190169
// On test completion, check that all tests pass and reply "PASS", or provide further details.
191-
functions.logger.info('Waiting for all tests to report they pass...');
170+
functions.logger.info("Waiting for all tests to report they pass...");
192171
await new Promise<void>((resolve, reject) => {
193-
setTimeout(() => reject(new Error('Timeout')), 5 * 60 * 1000);
172+
setTimeout(() => reject(new Error("Timeout")), 5 * 60 * 1000);
194173
let testsExecuted = 0;
195-
testIdRef.on('child_added', (snapshot) => {
196-
if (snapshot.key === 'timestamp') {
174+
testIdRef.on("child_added", (snapshot) => {
175+
if (snapshot.key === "timestamp") {
197176
return;
198177
}
199178
testsExecuted += 1;
200179
if (!snapshot.val().passed) {
201-
reject(
202-
new Error(
203-
`test ${snapshot.key} failed; see database for details.`
204-
)
205-
);
180+
reject(new Error(`test ${snapshot.key} failed; see database for details.`));
206181
return;
207182
}
208-
functions.logger.info(
209-
`${snapshot.key} passed (${testsExecuted} of ${numTests})`
210-
);
183+
functions.logger.info(`${snapshot.key} passed (${testsExecuted} of ${numTests})`);
211184
if (testsExecuted < numTests) {
212185
// Not all tests have completed. Wait longer.
213186
return;
@@ -216,17 +189,14 @@ export const integrationTests: any = functions
216189
resolve();
217190
});
218191
});
219-
functions.logger.info('All tests pass!');
220-
resp.status(200).send('PASS \n');
192+
functions.logger.info("All tests pass!");
193+
resp.status(200).send("PASS \n");
221194
} catch (err) {
222195
functions.logger.info(`Some tests failed: ${err}`, err);
223196
resp
224197
.status(500)
225-
.send(
226-
`FAIL - details at ${functions.firebaseConfig()
227-
.databaseURL!}/testRuns/${testId}`
228-
);
198+
.send(`FAIL - details at ${functions.firebaseConfig().databaseURL}/testRuns/${testId}`);
229199
} finally {
230-
testIdRef.off('child_added');
200+
testIdRef.off("child_added");
231201
}
232202
});
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,2 @@
11
// TODO: Add back support for selecting region for integration test once params is ready.
2-
export const REGION = 'us-central1';
2+
export const REGION = "us-central1";

integration_test/functions/src/testing.ts

Lines changed: 6 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
1-
import * as firebase from 'firebase-admin';
2-
import * as functions from 'firebase-functions';
1+
import * as firebase from "firebase-admin";
2+
import * as functions from "firebase-functions";
33

44
export type TestCase<T> = (data: T, context?: functions.EventContext) => any;
55
export interface TestCaseMap<T> {
@@ -31,7 +31,7 @@ export class TestSuite<T> {
3131
.then(
3232
(result) => {
3333
functions.logger.info(
34-
`${result ? 'Passed' : 'Failed with successful op'}: ${testName}`
34+
`${result ? "Passed" : "Failed with successful op"}: ${testName}`
3535
);
3636
return { name: testName, passed: !!result };
3737
},
@@ -49,10 +49,7 @@ export class TestSuite<T> {
4949
const passed = sum === running.length;
5050
functions.logger.info(summary);
5151
const result = { passed, summary, tests: results };
52-
return firebase
53-
.database()
54-
.ref(`testRuns/${testId}/${this.name}`)
55-
.set(result);
52+
return firebase.database().ref(`testRuns/${testId}/${this.name}`).set(result);
5653
});
5754
}
5855
}
@@ -73,10 +70,7 @@ export function evaluate(value: boolean, errMsg: string) {
7370
}
7471

7572
export function expectEq(left: any, right: any) {
76-
return evaluate(
77-
left == right,
78-
JSON.stringify(left) + ' does not equal ' + JSON.stringify(right)
79-
);
73+
return evaluate(left == right, JSON.stringify(left) + " does not equal " + JSON.stringify(right));
8074
}
8175

8276
function deepEq(left: any, right: any) {
@@ -128,7 +122,7 @@ export function expectReject<EventType>(f: (e: EventType) => Promise<void>) {
128122
}
129123

130124
if (!rejected) {
131-
throw new Error('Test should have returned a rejected promise');
125+
throw new Error("Test should have returned a rejected promise");
132126
}
133127
};
134128
}

mocha/setup.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
1-
import * as chai from 'chai';
2-
import * as chaiAsPromised from 'chai-as-promised';
3-
import * as nock from 'nock';
1+
import * as chai from "chai";
2+
import * as chaiAsPromised from "chai-as-promised";
3+
import * as nock from "nock";
44

55
chai.use(chaiAsPromised);
66

scripts/bin-test/mocha-setup.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import * as chai from 'chai';
2-
import * as chaiAsPromised from 'chai-as-promised';
1+
import * as chai from "chai";
2+
import * as chaiAsPromised from "chai-as-promised";
33

44
chai.use(chaiAsPromised);

0 commit comments

Comments
 (0)