[go: nahoru, domu]

Skip to content

Commit

Permalink
extensions functional test update (firebase#2181)
Browse files Browse the repository at this point in the history
* use shared testing framework for tests

* remove AndWait function

* link global module and run test file
  • Loading branch information
bkendall committed Apr 27, 2020
1 parent e8c328e commit e5c1bdb
Show file tree
Hide file tree
Showing 7 changed files with 107 additions and 308 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
package-lock.json
7 changes: 5 additions & 2 deletions scripts/extensions-emulator-tests/run.sh
Original file line number Diff line number Diff line change
@@ -1,12 +1,15 @@
#!/bin/bash

set -e # Immediately exit on failure

# Globally link the CLI for the testing framework.
npm link

cd scripts/extensions-emulator-tests/greet-the-world
npm i
cd - # Return to root so that we don't need a relative path for mocha

mocha \
--require ts-node/register \
--require source-map-support/register \
--require src/test/helpers/mocha-bootstrap.js \
scripts/extensions-emulator-tests/test.spec.ts
scripts/extensions-emulator-tests/tests.ts
275 changes: 0 additions & 275 deletions scripts/extensions-emulator-tests/test.spec.ts

This file was deleted.

62 changes: 62 additions & 0 deletions scripts/extensions-emulator-tests/tests.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
import { expect } from "chai";
import * as fs from "fs";
import * as path from "path";
import * as subprocess from "child_process";

import { FrameworkOptions, TriggerEndToEndTest } from "../integration-helpers/framework";

const EXTENSION_ROOT = path.dirname(__filename) + "/greet-the-world";

const FIREBASE_PROJECT = process.env.FBTOOLS_TARGET_PROJECT || "";
const FIREBASE_PROJECT_ZONE = "us-east1";
const TEST_CONFIG_FILE = "test-firebase.json";
const TEST_FUNCTION_NAME = "greetTheWorld";

/*
* Various delays that are needed because this test spawns
* parallel emulator subprocesses.
*/
const TEST_SETUP_TIMEOUT = 60000;
const EMULATORS_SHUTDOWN_DELAY_MS = 5000;

function readConfig(): FrameworkOptions {
const filename = path.join(EXTENSION_ROOT, "test-firebase.json");
const data = fs.readFileSync(filename, "utf8");
return JSON.parse(data);
}

describe("extension emulator", () => {
let test: TriggerEndToEndTest;

before(async function() {
this.timeout(TEST_SETUP_TIMEOUT); // eslint-disable-line no-invalid-this

expect(FIREBASE_PROJECT).to.exist.and.not.be.empty;

// TODO(joehan): Delete the --open-sesame call when extdev flag is removed.
const p = subprocess.spawnSync("firebase", ["--open-sesame", "extdev"], { cwd: __dirname });
console.log("open-sesame output:", p.stdout.toString());

test = new TriggerEndToEndTest(FIREBASE_PROJECT, EXTENSION_ROOT, readConfig());
await test.startExtEmulators([
"--test-params",
"test-params.env",
"--test-config",
TEST_CONFIG_FILE,
]);
});

after(async function() {
this.timeout(EMULATORS_SHUTDOWN_DELAY_MS); // eslint-disable-line no-invalid-this
await test.stopEmulators();
});

it("should execute an HTTP function", async function() {
this.timeout(EMULATORS_SHUTDOWN_DELAY_MS); // eslint-disable-line no-invalid-this

const res = await test.invokeHttpFunction(TEST_FUNCTION_NAME, FIREBASE_PROJECT_ZONE);

expect(res.statusCode).to.equal(200);
expect(res.body).to.equal("Hello World from greet-the-world");
});
});
File renamed without changes.
Loading

0 comments on commit e5c1bdb

Please sign in to comment.