Skip to content

Commit

Permalink
Add integration test for firebase-functions binary (#1028)
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
taeold authored Feb 3, 2022
1 parent 9e4ee8a commit f057ec2
Show file tree
Hide file tree
Showing 21 changed files with 371 additions and 43 deletions.
25 changes: 24 additions & 1 deletion .github/workflows/test.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ jobs:
- 10.x
- 12.x
- 14.x
- 16.x
steps:
- uses: actions/checkout@v1
- uses: actions/setup-node@v1
Expand All @@ -31,4 +32,26 @@ jobs:
- run: npm install
- run: npm run lint
- run: npm run format
- run: npm run build && npm run test
- run: npm run test
integration:
runs-on: ubuntu-latest
strategy:
matrix:
node-version:
- 12.x
- 14.x
- 16.x
steps:
- uses: actions/checkout@v1
- uses: actions/setup-node@v1
with:
node-version: ${{ matrix.node-version }}

- name: Cache npm
uses: actions/cache@v1
with:
path: ~/.npm
key: ${{ runner.os }}-node-${{ matrix.node-version }}-${{ hashFiles('**/package-lock.json') }}

- run: npm install
- run: npm run test:bin
4 changes: 1 addition & 3 deletions .mocharc.yaml
Original file line number Diff line number Diff line change
@@ -1,10 +1,8 @@
exit: true
extension:
- ts
file:
- mocha/setup.ts
package: ./package.json
reporter: spec
require:
- 'ts-node/register'
spec: spec/**/*.spec.ts
- 'source-map-support/register'
7 changes: 5 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -149,7 +149,8 @@
"format:fix": "prettier --write '**/*.{json,md,ts,yml,yaml}'",
"lint": "tslint --config tslint.json --project tsconfig.json ",
"lint:fix": "tslint --config tslint.json --fix --project tsconfig.json",
"test": "mocha"
"test": "mocha --file ./mocha/setup.ts spec/**/*.spec.ts ",
"test:bin": "./scripts/bin-test/run.sh"
},
"dependencies": {
"@types/cors": "^2.8.5",
Expand Down Expand Up @@ -180,10 +181,12 @@
"mock-require": "^3.0.3",
"mz": "^2.7.0",
"nock": "^10.0.6",
"node-fetch": "^2.6.7",
"portfinder": "^1.0.28",
"prettier": "^1.18.2",
"semver": "^7.3.5",
"sinon": "^7.3.2",
"ts-node": "^8.3.0",
"ts-node": "^10.4.0",
"tslint": "^5.18.0",
"tslint-config-prettier": "^1.18.0",
"tslint-no-unused-expression-chai": "^0.1.4",
Expand Down
4 changes: 4 additions & 0 deletions scripts/bin-test/mocha-setup.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
import * as chai from 'chai';
import * as chaiAsPromised from 'chai-as-promised';

chai.use(chaiAsPromised);
20 changes: 20 additions & 0 deletions scripts/bin-test/run.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
#!/bin/bash
set -ex # Immediately exit on failure

# Link the Functions SDK for the testing environment.
npm run build
npm link

# Link local SDK to all test sources.
for f in scripts/bin-test/sources/*; do
if [ -d "$f" ]; then
(cd "$f" && npm link firebase-functions)
fi
done

## DEBUG
ls -la scripts/bin-test/sources/commonjs/node_modules

mocha \
--file ./scripts/bin-test/mocha-setup.ts \
./scripts/bin-test/test.ts
9 changes: 9 additions & 0 deletions scripts/bin-test/sources/commonjs-grouped/g1.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
const functions = require("firebase-functions");

exports.groupedhttp = functions.https.onRequest((req, resp) => {
resp.status(200).send("PASS");
});

exports.groupedcallable = functions.https.onCall(() => {
return "PASS";
});
20 changes: 20 additions & 0 deletions scripts/bin-test/sources/commonjs-grouped/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
const functions = require("firebase-functions");
const functionsv2 = require("firebase-functions/v2");

exports.v1http = functions.https.onRequest((req, resp) => {
resp.status(200).send("PASS");
});

exports.v1callable = functions.https.onCall(() => {
return "PASS";
});

exports.v2http = functionsv2.https.onRequest((req, resp) => {
resp.status(200).send("PASS");
});

exports.v2callable = functionsv2.https.onCall(() => {
return "PASS";
});

exports.g1 = require("./g1");
3 changes: 3 additions & 0 deletions scripts/bin-test/sources/commonjs-grouped/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{
"name": "commonjs-grouped"
}
18 changes: 18 additions & 0 deletions scripts/bin-test/sources/commonjs-main/functions.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
const functions = require("firebase-functions");
const functionsv2 = require("firebase-functions/v2");

exports.v1http = functions.https.onRequest((req, resp) => {
resp.status(200).send("PASS");
});

exports.v1callable = functions.https.onCall(() => {
return "PASS";
});

exports.v2http = functionsv2.https.onRequest((req, resp) => {
resp.status(200).send("PASS");
});

exports.v2callable = functionsv2.https.onCall(() => {
return "PASS";
});
4 changes: 4 additions & 0 deletions scripts/bin-test/sources/commonjs-main/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
{
"name": "commonjs-main",
"main": "functions.js"
}
18 changes: 18 additions & 0 deletions scripts/bin-test/sources/commonjs/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
const functions = require("firebase-functions");
const functionsv2 = require("firebase-functions/v2");

exports.v1http = functions.https.onRequest((req, resp) => {
resp.status(200).send("PASS");
});

exports.v1callable = functions.https.onCall(() => {
return "PASS";
});

exports.v2http = functionsv2.https.onRequest((req, resp) => {
resp.status(200).send("PASS");
});

exports.v2callable = functionsv2.https.onCall(() => {
return "PASS";
});
3 changes: 3 additions & 0 deletions scripts/bin-test/sources/commonjs/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{
"name": "commonjs"
}
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import * as functions from '../../../../lib/index.js';
import * as functionsv2 from "../../../../lib/v2/index.js";
import * as functions from "firebase-functions";
import * as functionsv2 from "firebase-functions/v2";

export const v1http = functions.https.onRequest((req, resp) => {
resp.status(200).send("PASS");
Expand Down
File renamed without changes.
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import * as functions from "../../../../lib/index.js";
import * as functionsv2 from "../../../../lib/v2/index.js";
import * as functions from "firebase-functions";
import * as functionsv2 from "firebase-functions/v2";

export const v1http = functions.https.onRequest((req, resp) => {
resp.status(200).send("PASS");
Expand Down
File renamed without changes.
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import * as functions from "../../../../lib/index.js";
import * as functionsv2 from "../../../../lib/v2/index.js";
import * as functions from "firebase-functions";
import * as functionsv2 from "firebase-functions/v2";

export const v1http = functions.https.onRequest((req, resp) => {
resp.status(200).send("PASS");
Expand Down
File renamed without changes.
Loading

0 comments on commit f057ec2

Please sign in to comment.