Skip to content

Commit

Permalink
Add integration test for discovering functions from a project reposit…
Browse files Browse the repository at this point in the history
…ory.
  • Loading branch information
taeold committed Dec 1, 2022
1 parent 4f7f273 commit 51ddf7e
Show file tree
Hide file tree
Showing 18 changed files with 130 additions and 7 deletions.
2 changes: 2 additions & 0 deletions .github/workflows/node-test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,7 @@ jobs:
- npm run test:emulator
- npm run test:extensions-emulator
- npm run test:frameworks
- npm run test:functions-discover
- npm run test:hosting
# - npm run test:hosting-rewrites # Long-running test that might conflict across test runs. Run this manually.
- npm run test:import-export
Expand Down Expand Up @@ -143,6 +144,7 @@ jobs:
- npm run test:emulator
# - npm run test:import-export # Fails becuase port 4000 is taken after first run - hub not shhutting down?
# - npm run test:extensions-emulator # Fails due to cannot find module sharp (not waiting for npm install?)
- npm run test:functions-discover
- npm run test:triggers-end-to-end
- npm run test:triggers-end-to-end:inspect
- npm run test:storage-deploy
Expand Down
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@
"test:extensions-emulator": "bash ./scripts/extensions-emulator-tests/run.sh",
"test:frameworks": "bash ./scripts/frameworks-tests/run.sh",
"test:functions-deploy": "bash ./scripts/functions-deploy-tests/run.sh",
"test:functions-discover": "bash ./scripts/functions-discover-tests/run.sh",
"test:hosting": "bash ./scripts/hosting-tests/run.sh",
"test:hosting-rewrites": "bash ./scripts/hosting-tests/rewrites-tests/run.sh",
"test:import-export": "bash ./scripts/emulator-import-export-tests/run.sh",
Expand Down
26 changes: 26 additions & 0 deletions scripts/functions-discover-tests/fixtures/codebases/firebase.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
{
"functions": [
{
"source": "v1",
"codebase": "v1",
"runtime": "nodejs16",
"ignore": [
"node_modules",
".git",
"firebase-debug.log",
"firebase-debug.*.log"
]
},
{
"source": "v2",
"codebase": "v2",
"runtime": "nodejs16",
"ignore": [
"node_modules",
".git",
"firebase-debug.log",
"firebase-debug.*.log"
]
}
]
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
#!/bin/bash
set -euxo pipefail # bash strict mode
IFS=$'\n\t'

(cd v1 && npm i)
(cd v2 && npm i)
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
const functions = require("firebase-functions");

exports.hellov1 = functions.https.onRequest((request, response) => {
response.send("Hello from Firebase!");
});
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
{
"name": "codebase-v1",
"dependencies": {
"firebase-functions": "^4.0.0"
},
"engines": {
"node": "16"
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
import { onRequest } from "firebase-functions/v2/https";

export const hellov2 = onRequest((request, response) => {
response.send("Hello from Firebase!");
});
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
{
"name": "codebase-v2",
"type": "module",
"dependencies": {
"firebase-functions": "^4.0.0"
},
"engines": {
"node": "16"
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
{}
11 changes: 11 additions & 0 deletions scripts/functions-discover-tests/fixtures/esm/functions/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
import * as functions from "firebase-functions";
import { onRequest } from "firebase-functions/v2/https";

export const hellov1 = functions.https.onRequest((request, response) => {
functions.logger.info("Hello logs!", { structuredData: true });
response.send("Hello from Firebase!");
});

export const hellov2 = onRequest((request, response) => {
response.send("Hello from Firebase!");
});
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
{
"name": "esm",
"type": "module",
"dependencies": {
"firebase-functions": "^4.0.0"
},
"engines": {
"node": "16"
}
}
5 changes: 5 additions & 0 deletions scripts/functions-discover-tests/fixtures/esm/install.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
#!/bin/bash
set -euxo pipefail # bash strict mode
IFS=$'\n\t'

cd functions && npm i
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
{}
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
const functions = require("firebase-functions");
const { onRequest } = require("firebase-functions/v2/https");

exports.hellov1 = functions.https.onRequest((request, response) => {
response.send("Hello from Firebase!");
});

exports.hellov2 = onRequest((request, response) => {
response.send("Hello from Firebase!");
});
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
{
"name": "simple",
"dependencies": {
"firebase-functions": "^4.0.0"
},
"engines": {
"node": "16"
}
}
5 changes: 5 additions & 0 deletions scripts/functions-discover-tests/fixtures/simple/install.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
#!/bin/bash
set -euxo pipefail # bash strict mode
IFS=$'\n\t'

cd functions && npm i
12 changes: 12 additions & 0 deletions scripts/functions-discover-tests/run.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
#!/bin/bash
set -euxo pipefail # bash strict mode
IFS=$'\n\t'

# Globally link the CLI for the testing framework
./scripts/npm-link.sh

for dir in ./scripts/functions-discover-tests/fixtures/*; do
(cd $dir && ./install.sh)
done

mocha scripts/functions-discover-tests/tests.ts
9 changes: 2 additions & 7 deletions scripts/functions-discover-tests/tests.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,9 @@ import * as path from "path";

import { expect } from "chai";
import { CLIProcess } from "../integration-helpers/cli";
import { requireAuth } from "../../src/requireAuth";

const FIXTURES = path.join(__dirname, "fixtures");
const FIREBASE_PROJECT = process.env.FBTOOLS_TARGET_PROJECT || "";
const FIREBASE_PROJECT = "demo-project";

interface Testcase {
name: string;
Expand All @@ -19,12 +18,8 @@ interface Testcase {
describe("Function discovery test", function (this) {
this.timeout(1000_000);

before(async () => {
before(() => {
expect(FIREBASE_PROJECT).to.exist.and.not.be.empty;
if (process.env.CI) {
// In CI, get auth credentials from environment variable.
await requireAuth({});
}
});

const testCases: Testcase[] = [
Expand Down

0 comments on commit 51ddf7e

Please sign in to comment.