Skip to content

Commit f057ec2

Browse files
authored
Add integration test for firebase-functions binary (#1028)
Add integration test for firebase-functions binary. The integration setup is more robust than what we had before - it builds and installs the Functions SDK package at the branch commit and try to run the produced binary that ships with the Functions SDK. We also modify the github CI/release script setting to run the integration test as part of its workflow.
1 parent 9e4ee8a commit f057ec2

File tree

21 files changed

+371
-43
lines changed

21 files changed

+371
-43
lines changed

.github/workflows/test.yaml

Lines changed: 24 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ jobs:
1616
- 10.x
1717
- 12.x
1818
- 14.x
19+
- 16.x
1920
steps:
2021
- uses: actions/checkout@v1
2122
- uses: actions/setup-node@v1
@@ -31,4 +32,26 @@ jobs:
3132
- run: npm install
3233
- run: npm run lint
3334
- run: npm run format
34-
- run: npm run build && npm run test
35+
- run: npm run test
36+
integration:
37+
runs-on: ubuntu-latest
38+
strategy:
39+
matrix:
40+
node-version:
41+
- 12.x
42+
- 14.x
43+
- 16.x
44+
steps:
45+
- uses: actions/checkout@v1
46+
- uses: actions/setup-node@v1
47+
with:
48+
node-version: ${{ matrix.node-version }}
49+
50+
- name: Cache npm
51+
uses: actions/cache@v1
52+
with:
53+
path: ~/.npm
54+
key: ${{ runner.os }}-node-${{ matrix.node-version }}-${{ hashFiles('**/package-lock.json') }}
55+
56+
- run: npm install
57+
- run: npm run test:bin

.mocharc.yaml

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,8 @@
11
exit: true
22
extension:
33
- ts
4-
file:
5-
- mocha/setup.ts
64
package: ./package.json
75
reporter: spec
86
require:
97
- 'ts-node/register'
10-
spec: spec/**/*.spec.ts
8+
- 'source-map-support/register'

package.json

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -149,7 +149,8 @@
149149
"format:fix": "prettier --write '**/*.{json,md,ts,yml,yaml}'",
150150
"lint": "tslint --config tslint.json --project tsconfig.json ",
151151
"lint:fix": "tslint --config tslint.json --fix --project tsconfig.json",
152-
"test": "mocha"
152+
"test": "mocha --file ./mocha/setup.ts spec/**/*.spec.ts ",
153+
"test:bin": "./scripts/bin-test/run.sh"
153154
},
154155
"dependencies": {
155156
"@types/cors": "^2.8.5",
@@ -180,10 +181,12 @@
180181
"mock-require": "^3.0.3",
181182
"mz": "^2.7.0",
182183
"nock": "^10.0.6",
184+
"node-fetch": "^2.6.7",
185+
"portfinder": "^1.0.28",
183186
"prettier": "^1.18.2",
184187
"semver": "^7.3.5",
185188
"sinon": "^7.3.2",
186-
"ts-node": "^8.3.0",
189+
"ts-node": "^10.4.0",
187190
"tslint": "^5.18.0",
188191
"tslint-config-prettier": "^1.18.0",
189192
"tslint-no-unused-expression-chai": "^0.1.4",

scripts/bin-test/mocha-setup.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
import * as chai from 'chai';
2+
import * as chaiAsPromised from 'chai-as-promised';
3+
4+
chai.use(chaiAsPromised);

scripts/bin-test/run.sh

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
#!/bin/bash
2+
set -ex # Immediately exit on failure
3+
4+
# Link the Functions SDK for the testing environment.
5+
npm run build
6+
npm link
7+
8+
# Link local SDK to all test sources.
9+
for f in scripts/bin-test/sources/*; do
10+
if [ -d "$f" ]; then
11+
(cd "$f" && npm link firebase-functions)
12+
fi
13+
done
14+
15+
## DEBUG
16+
ls -la scripts/bin-test/sources/commonjs/node_modules
17+
18+
mocha \
19+
--file ./scripts/bin-test/mocha-setup.ts \
20+
./scripts/bin-test/test.ts
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
const functions = require("firebase-functions");
2+
3+
exports.groupedhttp = functions.https.onRequest((req, resp) => {
4+
resp.status(200).send("PASS");
5+
});
6+
7+
exports.groupedcallable = functions.https.onCall(() => {
8+
return "PASS";
9+
});
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
const functions = require("firebase-functions");
2+
const functionsv2 = require("firebase-functions/v2");
3+
4+
exports.v1http = functions.https.onRequest((req, resp) => {
5+
resp.status(200).send("PASS");
6+
});
7+
8+
exports.v1callable = functions.https.onCall(() => {
9+
return "PASS";
10+
});
11+
12+
exports.v2http = functionsv2.https.onRequest((req, resp) => {
13+
resp.status(200).send("PASS");
14+
});
15+
16+
exports.v2callable = functionsv2.https.onCall(() => {
17+
return "PASS";
18+
});
19+
20+
exports.g1 = require("./g1");
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
{
2+
"name": "commonjs-grouped"
3+
}
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
const functions = require("firebase-functions");
2+
const functionsv2 = require("firebase-functions/v2");
3+
4+
exports.v1http = functions.https.onRequest((req, resp) => {
5+
resp.status(200).send("PASS");
6+
});
7+
8+
exports.v1callable = functions.https.onCall(() => {
9+
return "PASS";
10+
});
11+
12+
exports.v2http = functionsv2.https.onRequest((req, resp) => {
13+
resp.status(200).send("PASS");
14+
});
15+
16+
exports.v2callable = functionsv2.https.onCall(() => {
17+
return "PASS";
18+
});
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
{
2+
"name": "commonjs-main",
3+
"main": "functions.js"
4+
}
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
const functions = require("firebase-functions");
2+
const functionsv2 = require("firebase-functions/v2");
3+
4+
exports.v1http = functions.https.onRequest((req, resp) => {
5+
resp.status(200).send("PASS");
6+
});
7+
8+
exports.v1callable = functions.https.onCall(() => {
9+
return "PASS";
10+
});
11+
12+
exports.v2http = functionsv2.https.onRequest((req, resp) => {
13+
resp.status(200).send("PASS");
14+
});
15+
16+
exports.v2callable = functionsv2.https.onCall(() => {
17+
return "PASS";
18+
});
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
{
2+
"name": "commonjs"
3+
}

spec/fixtures/sources/esm-ext/index.mjs renamed to scripts/bin-test/sources/esm-ext/index.mjs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
1-
import * as functions from '../../../../lib/index.js';
2-
import * as functionsv2 from "../../../../lib/v2/index.js";
1+
import * as functions from "firebase-functions";
2+
import * as functionsv2 from "firebase-functions/v2";
33

44
export const v1http = functions.https.onRequest((req, resp) => {
55
resp.status(200).send("PASS");

spec/fixtures/sources/esm-main/functions.js renamed to scripts/bin-test/sources/esm-main/functions.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
1-
import * as functions from "../../../../lib/index.js";
2-
import * as functionsv2 from "../../../../lib/v2/index.js";
1+
import * as functions from "firebase-functions";
2+
import * as functionsv2 from "firebase-functions/v2";
33

44
export const v1http = functions.https.onRequest((req, resp) => {
55
resp.status(200).send("PASS");

spec/fixtures/sources/esm/index.js renamed to scripts/bin-test/sources/esm/index.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
1-
import * as functions from "../../../../lib/index.js";
2-
import * as functionsv2 from "../../../../lib/v2/index.js";
1+
import * as functions from "firebase-functions";
2+
import * as functionsv2 from "firebase-functions/v2";
33

44
export const v1http = functions.https.onRequest((req, resp) => {
55
resp.status(200).send("PASS");

0 commit comments

Comments
 (0)