-
-
Notifications
You must be signed in to change notification settings - Fork 59
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* 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
1 parent
9a20bff
commit 8cb04a0
Showing
19 changed files
with
188 additions
and
290 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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" | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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" | ||
|
@@ -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" | ||
|
@@ -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" | ||
|
@@ -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" | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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" | ||
|
@@ -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" | ||
|
@@ -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" | ||
|
@@ -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" | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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<% } %>; | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 %>!'); | ||
}); | ||
});<% } %> |
Oops, something went wrong.