-
Notifications
You must be signed in to change notification settings - Fork 928
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add integration test for discovering functions from a project reposit…
…ory.
- Loading branch information
Showing
18 changed files
with
215 additions
and
0 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
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
26 changes: 26 additions & 0 deletions
26
scripts/functions-discover-tests/fixtures/codebases/firebase.json
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 |
---|---|---|
@@ -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" | ||
] | ||
} | ||
] | ||
} |
6 changes: 6 additions & 0 deletions
6
scripts/functions-discover-tests/fixtures/codebases/install.sh
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 |
---|---|---|
@@ -0,0 +1,6 @@ | ||
#!/bin/bash | ||
set -euxo pipefail # bash strict mode | ||
IFS=$'\n\t' | ||
|
||
(cd v1 && npm i) | ||
(cd v2 && npm i) |
5 changes: 5 additions & 0 deletions
5
scripts/functions-discover-tests/fixtures/codebases/v1/index.js
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 |
---|---|---|
@@ -0,0 +1,5 @@ | ||
const functions = require("firebase-functions"); | ||
|
||
exports.hellov1 = functions.https.onRequest((request, response) => { | ||
response.send("Hello from Firebase!"); | ||
}); |
9 changes: 9 additions & 0 deletions
9
scripts/functions-discover-tests/fixtures/codebases/v1/package.json
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 |
---|---|---|
@@ -0,0 +1,9 @@ | ||
{ | ||
"name": "codebase-v1", | ||
"dependencies": { | ||
"firebase-functions": "^4.0.0" | ||
}, | ||
"engines": { | ||
"node": "16" | ||
} | ||
} |
5 changes: 5 additions & 0 deletions
5
scripts/functions-discover-tests/fixtures/codebases/v2/index.js
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 |
---|---|---|
@@ -0,0 +1,5 @@ | ||
import { onRequest } from "firebase-functions/v2/https"; | ||
|
||
export const hellov2 = onRequest((request, response) => { | ||
response.send("Hello from Firebase!"); | ||
}); |
10 changes: 10 additions & 0 deletions
10
scripts/functions-discover-tests/fixtures/codebases/v2/package.json
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 |
---|---|---|
@@ -0,0 +1,10 @@ | ||
{ | ||
"name": "codebase-v2", | ||
"type": "module", | ||
"dependencies": { | ||
"firebase-functions": "^4.0.0" | ||
}, | ||
"engines": { | ||
"node": "16" | ||
} | ||
} |
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 |
---|---|---|
@@ -0,0 +1 @@ | ||
{} |
11 changes: 11 additions & 0 deletions
11
scripts/functions-discover-tests/fixtures/esm/functions/index.js
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 |
---|---|---|
@@ -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!"); | ||
}); |
10 changes: 10 additions & 0 deletions
10
scripts/functions-discover-tests/fixtures/esm/functions/package.json
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 |
---|---|---|
@@ -0,0 +1,10 @@ | ||
{ | ||
"name": "esm", | ||
"type": "module", | ||
"dependencies": { | ||
"firebase-functions": "^4.0.0" | ||
}, | ||
"engines": { | ||
"node": "16" | ||
} | ||
} |
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 |
---|---|---|
@@ -0,0 +1,5 @@ | ||
#!/bin/bash | ||
set -euxo pipefail # bash strict mode | ||
IFS=$'\n\t' | ||
|
||
cd functions && npm i |
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 |
---|---|---|
@@ -0,0 +1 @@ | ||
{} |
10 changes: 10 additions & 0 deletions
10
scripts/functions-discover-tests/fixtures/simple/functions/index.js
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 |
---|---|---|
@@ -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!"); | ||
}); |
9 changes: 9 additions & 0 deletions
9
scripts/functions-discover-tests/fixtures/simple/functions/package.json
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 |
---|---|---|
@@ -0,0 +1,9 @@ | ||
{ | ||
"name": "simple", | ||
"dependencies": { | ||
"firebase-functions": "^4.0.0" | ||
}, | ||
"engines": { | ||
"node": "16" | ||
} | ||
} |
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 |
---|---|---|
@@ -0,0 +1,5 @@ | ||
#!/bin/bash | ||
set -euxo pipefail # bash strict mode | ||
IFS=$'\n\t' | ||
|
||
cd functions && npm i |
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 |
---|---|---|
@@ -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 |
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 |
---|---|---|
@@ -0,0 +1,87 @@ | ||
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 || "danielylee-test-6"; | ||
|
||
interface Testcase { | ||
name: string; | ||
projectDir: string; | ||
expects: { | ||
codebase: string; | ||
endpoints: string[]; | ||
}[]; | ||
} | ||
|
||
describe("Function discovery test", function (this) { | ||
this.timeout(1000_000); | ||
|
||
before(async () => { | ||
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[] = [ | ||
{ | ||
name: "simple", | ||
projectDir: "simple", | ||
expects: [ | ||
{ | ||
codebase: "default", | ||
endpoints: ["hellov1", "hellov2"], | ||
}, | ||
], | ||
}, | ||
{ | ||
name: "esm", | ||
projectDir: "esm", | ||
expects: [ | ||
{ | ||
codebase: "default", | ||
endpoints: ["hellov1", "hellov2"], | ||
}, | ||
], | ||
}, | ||
{ | ||
name: "codebases", | ||
projectDir: "codebases", | ||
expects: [ | ||
{ | ||
codebase: "v1", | ||
endpoints: ["hellov1"], | ||
}, | ||
{ | ||
codebase: "v2", | ||
endpoints: ["hellov2"], | ||
}, | ||
], | ||
}, | ||
]; | ||
|
||
for (const tc of testCases) { | ||
it(`discovers functions in a ${tc.name} project`, async () => { | ||
const cli = new CLIProcess("default", path.join(FIXTURES, tc.projectDir)); | ||
|
||
let output: any; | ||
await cli.start("functions:discover", FIREBASE_PROJECT, ["--json"], (data: any) => { | ||
output = JSON.parse(data); | ||
return true; | ||
}); | ||
expect(output.status).to.equal("success"); | ||
for (const e of tc.expects) { | ||
const endpoints = output.result?.[e.codebase]?.endpoints; | ||
expect(endpoints).to.be.an("object").that.is.not.empty; | ||
expect(Object.keys(endpoints)).to.have.length(e.endpoints.length); | ||
expect(Object.keys(endpoints)).to.include.members(e.endpoints); | ||
} | ||
|
||
await cli.stop(); | ||
}); | ||
} | ||
}); |