Skip to content

Commit

Permalink
v7.2.0 (#277)
Browse files Browse the repository at this point in the history
* fix(function): replace usage of test over it in jest tests
* fix(function): use "should" prefix in test names
* build(deps-dev): bump lint-staged from 10.2.11 to 10.3.0 (#271) - @dependabot
* build(deps): bump yeoman-generator from 4.11.0 to 4.12.0 (#272) - @dependabot
* build(deps-dev): bump @babel/cli from 7.10.5 to 7.11.6 (#270) - @dependabot
* build(deps-dev): bump @babel/register from 7.10.5 to 7.11.5 (#273) - @dependabot
* build(deps): bump http-proxy in /examples/redux-firestore (#274) - @dependabot
* build(deps): bump node-fetch in /examples/react-firebase-redux/functions - @dependabot
* build(deps): bump http-proxy in /examples/react-firebase-redux (#275) - @dependabot
  • Loading branch information
prescottprue authored Sep 13, 2020
1 parent 9a20bff commit 8cb04a0
Show file tree
Hide file tree
Showing 19 changed files with 188 additions and 290 deletions.
13 changes: 4 additions & 9 deletions examples/react-firebase-redux/functions/yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -3060,15 +3060,10 @@ [email protected]:
resolved "https://registry.yarnpkg.com/negotiator/-/negotiator-0.6.2.tgz#feacf7ccf525a77ae9634436a64883ffeca346fb"
integrity sha512-hZXc7K2e+PgeI1eDBe/10Ard4ekbfrrqG8Ep+8Jmf4JID2bNg7NvCPOZN+kfF574pFQI7mum2AUqDidoKqcTOw==

node-fetch@^2.2.0:
version "2.3.0"
resolved "https://registry.yarnpkg.com/node-fetch/-/node-fetch-2.3.0.tgz#1a1d940bbfb916a1d3e0219f037e89e71f8c5fa5"
integrity sha512-MOd8pV3fxENbryESLgVIeaGKrdl+uaYhCSSVkjeOb/31/njTpcis5aWfdqgNlHIrKOLRbMnfPINPOML2CIFeXA==

node-fetch@^2.3.0, node-fetch@^2.6.0:
version "2.6.0"
resolved "https://registry.yarnpkg.com/node-fetch/-/node-fetch-2.6.0.tgz#e633456386d4aa55863f676a7ab0daa8fdecb0fd"
integrity sha512-8dG4H5ujfvFiqDmVu9fQ5bOHUC15JMjMY/Zumv26oOvvVJjM67KF8koCWIabKQ1GJIa9r2mMZscBq/TbdOcmNA==
node-fetch@^2.2.0, node-fetch@^2.3.0, node-fetch@^2.6.0:
version "2.6.1"
resolved "https://registry.yarnpkg.com/node-fetch/-/node-fetch-2.6.1.tgz#045bd323631f76ed2e2b55573394416b639a0052"
integrity sha512-V4aYg89jEoVRxRb2fJdAg8FHvI7cEyYdVAh94HH0UIK8oJxUfkjlDQN9RbMx+bEjP7+ggMiFRprSti032Oipxw==

node-forge@^0.9.0, node-forge@^0.9.1:
version "0.9.1"
Expand Down
31 changes: 11 additions & 20 deletions examples/react-firebase-redux/yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -5906,13 +5906,6 @@ [email protected]:
dependencies:
ms "^2.1.1"

debug@=3.1.0:
version "3.1.0"
resolved "https://registry.yarnpkg.com/debug/-/debug-3.1.0.tgz#5bb5a0672628b64149566ba16819e61518c67261"
integrity sha512-OX8XqP7/1a9cqkxYw2yXss15f26NKWBpDXQd0/uK/KPqdQhxbPa994hnzjcE2VqQpDslf55723cKPUOGSmMY3g==
dependencies:
ms "2.0.0"

debug@^3.0.0, debug@^3.1.0, debug@^3.1.1, debug@^3.2.5:
version "3.2.6"
resolved "https://registry.yarnpkg.com/debug/-/debug-3.2.6.tgz#e83d17de16d8a7efb7717edbe5fb10135eee629b"
Expand Down Expand Up @@ -7126,10 +7119,10 @@ [email protected]:
resolved "https://registry.yarnpkg.com/eventemitter2/-/eventemitter2-6.4.2.tgz#f31f8b99d45245f0edbc5b00797830ff3b388970"
integrity sha512-r/Pwupa5RIzxIHbEKCkNXqpEQIIT4uQDxmP4G/Lug/NokVUWj0joz/WzWl3OxRpC5kDrH/WdiUJoR+IrwvXJEw==

eventemitter3@^3.0.0:
version "3.1.0"
resolved "https://registry.yarnpkg.com/eventemitter3/-/eventemitter3-3.1.0.tgz#090b4d6cdbd645ed10bf750d4b5407942d7ba163"
integrity sha512-ivIvhpq/Y0uSjcHDcOIccjmYjGLcP09MFGE7ysAwkAvkXfpZlC985pH2/ui64DKazbTW/4kN3yqozUxlXzI6cA==
eventemitter3@^4.0.0:
version "4.0.7"
resolved "https://registry.yarnpkg.com/eventemitter3/-/eventemitter3-4.0.7.tgz#2de9b68f6528d5644ef5c59526a1b4a07306169f"
integrity sha512-8guHBZCwKnFhYdHr2ysuRWErTwhoN2X8XELRlrRwpmfeY2jjuUN4taQMsULKUVo1K4DvZl+0pgfyoysHxvmvEw==

events@^3.0.0:
version "3.0.0"
Expand Down Expand Up @@ -7762,11 +7755,9 @@ flush-write-stream@^1.0.0:
readable-stream "^2.0.4"

follow-redirects@^1.0.0:
version "1.5.9"
resolved "https://registry.yarnpkg.com/follow-redirects/-/follow-redirects-1.5.9.tgz#c9ed9d748b814a39535716e531b9196a845d89c6"
integrity sha512-Bh65EZI/RU8nx0wbYF9shkFZlqLP+6WT/5FnA3cE/djNSuKNHJEinGGZgu/cQEkeeb2GdFOgenAmn8qaqYke2w==
dependencies:
debug "=3.1.0"
version "1.13.0"
resolved "https://registry.yarnpkg.com/follow-redirects/-/follow-redirects-1.13.0.tgz#b42e8d93a2a7eea5ed88633676d6597bc8e384db"
integrity sha512-aq6gF1BEKje4a9i9+5jimNFIpq4Q1WiwBToeRK5NvZBd/TRsmW8BsJfOEGkr76TbOyPVD3OVDN910EcUNtRYEA==

for-in@^0.1.3:
version "0.1.8"
Expand Down Expand Up @@ -8781,11 +8772,11 @@ [email protected]:
micromatch "^3.1.10"

http-proxy@^1.17.0:
version "1.17.0"
resolved "https://registry.yarnpkg.com/http-proxy/-/http-proxy-1.17.0.tgz#7ad38494658f84605e2f6db4436df410f4e5be9a"
integrity sha512-Taqn+3nNvYRfJ3bGvKfBSRwy1v6eePlm3oc/aWVxZp57DQr5Eq3xhKJi7Z4hZpS8PC3H4qI+Yly5EmFacGuA/g==
version "1.18.1"
resolved "https://registry.yarnpkg.com/http-proxy/-/http-proxy-1.18.1.tgz#401541f0534884bbf95260334e72f88ee3976549"
integrity sha512-7mz/721AbnJwIVbnaSv1Cz3Am0ZLT/UBwkC92VlxhXv/k/BBQfM2fXElQNC27BVGr0uwUpplYPQM9LnaBMR5NQ==
dependencies:
eventemitter3 "^3.0.0"
eventemitter3 "^4.0.0"
follow-redirects "^1.0.0"
requires-port "^1.0.0"

Expand Down
31 changes: 11 additions & 20 deletions examples/redux-firestore/yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -5858,13 +5858,6 @@ [email protected]:
dependencies:
ms "^2.1.1"

debug@=3.1.0:
version "3.1.0"
resolved "https://registry.yarnpkg.com/debug/-/debug-3.1.0.tgz#5bb5a0672628b64149566ba16819e61518c67261"
integrity sha512-OX8XqP7/1a9cqkxYw2yXss15f26NKWBpDXQd0/uK/KPqdQhxbPa994hnzjcE2VqQpDslf55723cKPUOGSmMY3g==
dependencies:
ms "2.0.0"

debug@^3.0.0, debug@^3.1.0, debug@^3.1.1, debug@^3.2.5:
version "3.2.6"
resolved "https://registry.yarnpkg.com/debug/-/debug-3.2.6.tgz#e83d17de16d8a7efb7717edbe5fb10135eee629b"
Expand Down Expand Up @@ -7107,10 +7100,10 @@ [email protected]:
resolved "https://registry.yarnpkg.com/eventemitter2/-/eventemitter2-6.4.2.tgz#f31f8b99d45245f0edbc5b00797830ff3b388970"
integrity sha512-r/Pwupa5RIzxIHbEKCkNXqpEQIIT4uQDxmP4G/Lug/NokVUWj0joz/WzWl3OxRpC5kDrH/WdiUJoR+IrwvXJEw==

eventemitter3@^3.0.0:
version "3.1.0"
resolved "https://registry.yarnpkg.com/eventemitter3/-/eventemitter3-3.1.0.tgz#090b4d6cdbd645ed10bf750d4b5407942d7ba163"
integrity sha512-ivIvhpq/Y0uSjcHDcOIccjmYjGLcP09MFGE7ysAwkAvkXfpZlC985pH2/ui64DKazbTW/4kN3yqozUxlXzI6cA==
eventemitter3@^4.0.0:
version "4.0.7"
resolved "https://registry.yarnpkg.com/eventemitter3/-/eventemitter3-4.0.7.tgz#2de9b68f6528d5644ef5c59526a1b4a07306169f"
integrity sha512-8guHBZCwKnFhYdHr2ysuRWErTwhoN2X8XELRlrRwpmfeY2jjuUN4taQMsULKUVo1K4DvZl+0pgfyoysHxvmvEw==

events@^3.0.0:
version "3.0.0"
Expand Down Expand Up @@ -7743,11 +7736,9 @@ flush-write-stream@^1.0.0:
readable-stream "^2.0.4"

follow-redirects@^1.0.0:
version "1.5.10"
resolved "https://registry.yarnpkg.com/follow-redirects/-/follow-redirects-1.5.10.tgz#7b7a9f9aea2fdff36786a94ff643ed07f4ff5e2a"
integrity sha512-0V5l4Cizzvqt5D44aTXbFZz+FtyXV1vrDN6qrelxtfYQKW0KO0W2T/hkE8xvGa/540LkZlkaUjO4ailYTFtHVQ==
dependencies:
debug "=3.1.0"
version "1.13.0"
resolved "https://registry.yarnpkg.com/follow-redirects/-/follow-redirects-1.13.0.tgz#b42e8d93a2a7eea5ed88633676d6597bc8e384db"
integrity sha512-aq6gF1BEKje4a9i9+5jimNFIpq4Q1WiwBToeRK5NvZBd/TRsmW8BsJfOEGkr76TbOyPVD3OVDN910EcUNtRYEA==

for-in@^0.1.3:
version "0.1.8"
Expand Down Expand Up @@ -8762,11 +8753,11 @@ [email protected]:
micromatch "^3.1.10"

http-proxy@^1.17.0:
version "1.17.0"
resolved "https://registry.yarnpkg.com/http-proxy/-/http-proxy-1.17.0.tgz#7ad38494658f84605e2f6db4436df410f4e5be9a"
integrity sha512-Taqn+3nNvYRfJ3bGvKfBSRwy1v6eePlm3oc/aWVxZp57DQr5Eq3xhKJi7Z4hZpS8PC3H4qI+Yly5EmFacGuA/g==
version "1.18.1"
resolved "https://registry.yarnpkg.com/http-proxy/-/http-proxy-1.18.1.tgz#401541f0534884bbf95260334e72f88ee3976549"
integrity sha512-7mz/721AbnJwIVbnaSv1Cz3Am0ZLT/UBwkC92VlxhXv/k/BBQfM2fXElQNC27BVGr0uwUpplYPQM9LnaBMR5NQ==
dependencies:
eventemitter3 "^3.0.0"
eventemitter3 "^4.0.0"
follow-redirects "^1.0.0"
requires-port "^1.0.0"

Expand Down
2 changes: 1 addition & 1 deletion generators/app/templates/_package.json
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@
"babel-eslint": "^10.1.0",
"cross-env": "^7.0.2",<% if (includeUiTests) { %>
"cypress": "^4.12.1",
"cypress-firebase": "^1.4.3",<% } %>
"cypress-firebase": "^1.4.4",<% } %>
"eslint": "^7.7.0",
"eslint-config-prettier": "^6.11.0",
"eslint-config-standard": "^14.1.1",
Expand Down
16 changes: 10 additions & 6 deletions generators/function/templates/_authFunction.js
Original file line number Diff line number Diff line change
@@ -1,14 +1,18 @@
import * as functions from 'firebase-functions'<% if (airbnbLinting) { %>;<% } %>
// import * as admin from 'firebase-admin'<% if (airbnbLinting) { %>;<% } %>
import * as functions from 'firebase-functions'<% if (airbnbLinting) { %>;<% } %><% if (usingTypescript) { %>
import * as admin from 'firebase-admin'<% if (airbnbLinting) { %>;<% } %><% } %>

/**
* @param {firebase.auth.UserRecord} user - User associated with auth event
* @param {functions.EventContext} context - Function event context
* @returns {Promise} Resolves after handling even
* @param <% if (!usingTypescript) { %>{firebase.auth.UserRecord} <% } %>user - User associated with auth event
* @param <% if (!usingTypescript) { %>{functions.EventContext} <% } %>context - Function event context
* @returns <% if (!usingTypescript) { %>{Promise} <% } %>Resolves after handling even
*/
function <%= camelName %>Event(user, context) {
function <%= camelName %>Event(<% if (!usingTypescript) { %>user, context)<% } %><% if (usingTypescript) { %>
user: admin.auth.UserRecord,
context: functions.EventContext
): Promise<null><% } %> {
const { timestamp } = context<% if (airbnbLinting) { %>;<% } %>
console.log('Auth <%= eventType %> event', { user, timestamp })<% if (airbnbLinting) { %>;<% } %>
return null
}

/**
Expand Down
7 changes: 3 additions & 4 deletions generators/function/templates/_authTest-airbnb.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,8 @@ describe('<%= camelName %> Auth Cloud Function (Auth:<%= eventType %>)', () => {
functionsTest.cleanup();
});

<% if (jestTesting) { %>test<% } else { %>it<% } %>('handles event', async () => {
await <%= camelName %>({});
// TODO: Switch this to a real assertion which confirms functionality
expect(null).<% if (jestTesting) { %>toEqual(null)<% } else { %>to.be.null<% } %>;
it('should handle event', async () => {
const results = await <%= camelName %>({});
expect(results).<% if (jestTesting) { %>toBeNull()<% } else { %>to.be.null<% } %>;
});
});
7 changes: 3 additions & 4 deletions generators/function/templates/_authTest.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,8 @@ describe('<%= camelName %> Auth Cloud Function (Auth:<%= eventType %>)', () => {
functionsTest.cleanup()
})

<% if (jestTesting) { %>test<% } else { %>it<% } %>('handles event', async () => {
await <%= camelName %>({})
// TODO: Switch this to a real assertion which confirms functionality
expect(null).<% if (jestTesting) { %>toEqual(null)<% } else { %>to.be.null<% } %>
it('should handle event', async () => {
const results = await <%= camelName %>({})
expect(results).<% if (jestTesting) { %>toBeNull()<% } else { %>to.be.null<% } %>
})
})
47 changes: 16 additions & 31 deletions generators/function/templates/_firestoreTest-airbnb.js
Original file line number Diff line number Diff line change
@@ -1,53 +1,38 @@
import * as firebaseTesting from '@firebase/testing'
import <%= eventType %>Original from './index';

const adminApp = firebaseTesting.initializeAdminApp({
projectId: process.env.GCLOUD_PROJECT,
databaseName: process.env.GCLOUD_PROJECT,
});
import * as firebaseTesting from '@firebase/testing';
import <%= camelName %>Original from './index';

const eventPath = '<%= camelName %>';

const <%= camelName %> = functionsTest.wrap(<%= camelName %>Unwrapped);
const <%= camelName %> = functionsTest.wrap(<%= camelName %>Original);

describe('<%= camelName %> Firestore Cloud Function (<%= eventType %>)', () => {
beforeEach(async () => {
// Clean database before each test
await firebaseTesting.clearFirestoreData({
projectId: process.env.GCLOUD_PROJECT,
});
});

after(async () => {
after<% if (jestTesting) { %>All<% } %>(async () => {
// Restoring stubs to the original methods
functionsTest.cleanup()
// Cleanup all apps (keeps active listeners from preventing JS from exiting)
await Promise.all(firebaseTesting.apps().map((app) => app.delete()));
});

it('handles event', async () => {
it('should handle event', async () => {
const eventData = { some: 'value' }<% if (eventType === 'onWrite') { %>
const beforeData = { another: 'thing' }
const beforeData = { another: 'thing' };
// Build create change event
const beforeSnap = functionsTest.firestore.makeDocumentSnapshot(beforeData, 'document/path');
const afterSnap = functionsTest.firestore.makeDocumentSnapshot(
eventData,
eventPath
)
const changeEvent = { before: beforeSnap, after: afterSnap }
);
const changeEvent = { before: beforeSnap, after: afterSnap };
const fakeContext = {
params: {},
}
await <%= camelName %>({ after: snap }, fakeContext)<% } else { %>
};
const results = await <%= camelName %>({ after: snap }, fakeContext);<% } else { %>
// Build onCreate
const snap = functionsTest.firestore.makeDocumentSnapshot(eventData, eventPath)
const snap = functionsTest.firestore.makeDocumentSnapshot(eventData, eventPath);
const fakeContext = {
params: {},
}
await <%= camelName %>(snap, fakeContext)<% } %>
// TODO: Uncomment and make an assertion
// const result = await adminApp.firestore().doc('some/path').get()
// expect(result).toEqual()
// const fakeEvent = functionsTest.firestore.makeDocumentSnapshot({foo: 'bar'}, 'document/path');
})
})
};
const results = await <%= camelName %>(snap, fakeContext)<% } %>;
expect(results).<% if (jestTesting) { %>toBeNull()<% } else { %>to.be.null<% } %>;
});
});
19 changes: 6 additions & 13 deletions generators/function/templates/_firestoreTest.js
Original file line number Diff line number Diff line change
@@ -1,11 +1,6 @@
import * as firebaseTesting from '@firebase/testing'
import <%= camelName %>Original from './index'

const adminApp = firebaseTesting.initializeAdminApp({
projectId: process.env.GCLOUD_PROJECT,
databaseName: process.env.GCLOUD_PROJECT,
})

const eventPath = '<%= camelName %>'

const <%= camelName %> = functionsTest.wrap(<%= camelName %>Original)
Expand All @@ -18,18 +13,18 @@ describe('<%= camelName %> Firestore Cloud Function (<%= eventType %>)', () => {
})
})

after(async () => {
after<% if (jestTesting) { %>All<% } %>(async () => {
// Restoring stubs to the original methods
functionsTest.cleanup()
// Cleanup all apps (keeps active listeners from preventing JS from exiting)
await Promise.all(firebaseTesting.apps().map((app) => app.delete()))
})

<% if (jestTesting) { %>test<% } else { %>it<% } %>('handles event', async () => {
it('should handle event', async () => {
const eventData = { some: 'value' }<% if (eventType === 'onWrite') { %>
const beforeData = { another: 'thing' }
// Build create change event
const beforeSnap = functionsTest.firestore.makeDocumentSnapshot(beforeData, 'document/path');
const beforeSnap = functionsTest.firestore.makeDocumentSnapshot(beforeData, 'document/path')
const afterSnap = functionsTest.firestore.makeDocumentSnapshot(
eventData,
eventPath
Expand All @@ -38,15 +33,13 @@ describe('<%= camelName %> Firestore Cloud Function (<%= eventType %>)', () => {
const fakeContext = {
params: {},
}
await <%= camelName %>({ after: snap }, fakeContext)<% } else { %>
const results = await <%= camelName %>({ after: snap }, fakeContext)<% } else { %>
// Build onCreate
const snap = functionsTest.firestore.makeDocumentSnapshot(eventData, eventPath)
const fakeContext = {
params: {},
}
await <%= camelName %>(snap, fakeContext)<% } %>
// TODO: Switch this to a real assertion which confirms functionality
const result = await adminApp.firestore().doc('some/path').get()
expect(result).<% if (jestTesting) { %>toEqual(null)<% } else { %>to.be.null<% } %>``
const results = await <%= camelName %>(snap, fakeContext)<% } %>
expect(results).<% if (jestTesting) { %>toBeNull()<% } else { %>to.be.null<% } %>
})
})
30 changes: 13 additions & 17 deletions generators/function/templates/_httpsTest-airbnb.js
Original file line number Diff line number Diff line change
@@ -1,30 +1,26 @@
import <%= name %> from './index';
<% if (eventType !== 'onCall') { %>import <%= name %> from './index';<% } %><% if (eventType === 'onCall') { %>
import <%= camelName %>Unwrapped from './index';

const <%= camelName %> = functionsTest.wrap(<%= camelName %>Unwrapped);<% } %>

<% if (eventType === 'onCall') { %>describe('<%= camelName %> HTTPS Callable Cloud Function', () => {
<% if (jestTesting) { %>test<% } else { %>it<% } %>('responds with hello message when sent an empty request', async () => {
it('should respond with hello message when sent an empty request', async () => {
const data = {};
const context = {};
// Invoke request handler with fake data + context objects
const response = await <%= name %>(data, context);
// Confirm no error is thrown
expect(err).to.not.exist;
// Confirm response contains message
expect(response).to.have.property('message', 'Hello World');
})
expect(response).<% if (jestTesting) { %>toHaveProperty<% } else { %>to.have.property<% } %>('message', 'Hello from <%= name %>!');
});
});<% } %><% if (eventType !== 'onCall') { %>describe('<%= camelName %> HTTPS Cloud Function', () => {
<% if (jestTesting) { %>test<% } else { %>it<% } %>('responds with hello message when sent an empty request', done => {
it('should response with hello message when sent an empty request', async () => {
// Create fake request and response objects, with a mock functionality
const req = {};
// Parameters of request can also be stubbed
// const req = { query: { text: 'input' } }
// A fake response object, with a stubbed end function which asserts that
// it is called with a hello message
const res = {
end: (msg) => {
expect(msg).to.equal('Hello from <%= name %>!');
done();
},
}
end: <% if (jestTesting) { %>jest.fn()<% } else { %>sinon.stub()<% } %>,
};
// Invoke https function with fake request + response objects
<%= camelName %>(req, res);
await <%= camelName %>(req, res);
expect(res.end).<% if (jestTesting) { %>toHaveBeenCalledWith<% } else { %>to.have.been.calledWith<% } %>('Hello from <%= name %>!');
});
});<% } %>
Loading

0 comments on commit 8cb04a0

Please sign in to comment.