Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions firebase-vscode/src/test/runTest.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import * as path from "path";
import * as os from "os";

import { runTests } from "@vscode/test-electron";

Expand All @@ -13,9 +14,11 @@ async function main() {
const extensionTestsPath = path.resolve(__dirname, "./suite/index");

// Download VS Code, unzip it and run the integration test
const tmpUserData = path.join(os.tmpdir(), `vsc-ud-${Math.random().toString(36).substring(2, 7)}`);
await runTests({
extensionDevelopmentPath,
extensionTestsPath,
launchArgs: ["--user-data-dir", tmpUserData],
});
} catch (err) {
console.error("Failed to run tests");
Expand Down
27 changes: 20 additions & 7 deletions firebase-vscode/src/test/suite/execution-error-handling.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,11 @@ import * as gif from "../../../../src/gemini/fdcExperience";
import { dataConnectConfigs } from "../../data-connect/config";
import { ResultValue } from "../../result";
import { registerExecution } from "../../data-connect/execution/execution";
import { requireAuthWrapper } from "../../cli";
import * as auth from "../../../../src/auth";
import * as nock from "nock";
import nock from "../../../../src/test/helpers/nock";
import { setAccessToken } from "../../../../src/apiv2";
import { googleOrigin } from "../../../../src/api";
import { configstore } from "../../../../src/configstore";

firebaseSuite(
Expand All @@ -18,16 +20,24 @@ firebaseSuite(
let showInformationMessageStub: any;
let authStub: any;
let executionDisposable: vscode.Disposable;
let originalFirebaseToken: string | undefined;

setup(() => {
setup(async () => {
nock.cleanAll();
showErrorMessageStub = stub(vscode.window, "showErrorMessage");
showInformationMessageStub = stub(
vscode.window,
"showInformationMessage",
);
authStub = stub(auth, "getAccessToken").resolves({
access_token: "an_access_token",
});
originalFirebaseToken = process.env.FIREBASE_TOKEN;
process.env.FIREBASE_TOKEN = "mock_refresh_token";

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

Modifying process.env.FIREBASE_TOKEN directly without restoring its original value can cause side effects or failures in other tests running in the same process (especially in CI environments where a real token might be set). Consider saving the original value and restoring it in teardown.

      (globalThis as any).originalFirebaseToken = process.env.FIREBASE_TOKEN;
      process.env.FIREBASE_TOKEN = "mock_refresh_token";

nock(googleOrigin())
.post("/oauth2/v3/token")
.reply(200, {
access_token: "an_access_token",
expires_in: 3600,
});
await requireAuthWrapper(false);
setAccessToken("an_access_token");

stub(vscode.window, "withProgress").callsFake(async (options, task) => {
Expand Down Expand Up @@ -72,11 +82,14 @@ firebaseSuite(
analyticsLogger,
emulatorsController,
);

nock.cleanAll();
});

teardown(() => {
if (originalFirebaseToken === undefined) {
delete process.env.FIREBASE_TOKEN;
} else {
process.env.FIREBASE_TOKEN = originalFirebaseToken;
}
executionDisposable.dispose();
restore();
nock.cleanAll();
Expand Down
1 change: 0 additions & 1 deletion scripts/hosting-tests/rewrites-tests/tests.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@
import * as firebase from "../../../src";
import { execSync } from "child_process";
import { command as functionsDelete } from "../../../src/commands/functions-delete";
import fetch, { Request } from "node-fetch";
import { FirebaseError } from "../../../src/error";

tmp.setGracefulCleanup();
Expand Down Expand Up @@ -161,7 +160,7 @@
join(tempDirInfo.tempDir.name, ".", "functions"),
);

await client.deploy({

Check warning on line 163 in scripts/hosting-tests/rewrites-tests/tests.ts

View workflow job for this annotation

GitHub Actions / lint (24)

Unsafe call of an `any` typed value

Check warning on line 163 in scripts/hosting-tests/rewrites-tests/tests.ts

View workflow job for this annotation

GitHub Actions / lint (24)

Unsafe member access .deploy on an `any` value
project: process.env.FBTOOLS_TARGET_PROJECT,
cwd: tempDirInfo.tempDir.name,
only: "hosting,functions",
Expand All @@ -169,12 +168,12 @@
});

const staticResponse = await fetch(
`https://${process.env.FBTOOLS_CLIENT_INTEGRATION_SITE}.web.app/index.html`,

Check warning on line 171 in scripts/hosting-tests/rewrites-tests/tests.ts

View workflow job for this annotation

GitHub Actions / lint (24)

Invalid type "string | undefined" of template literal expression
);
expect(await staticResponse.text()).to.contain("Rabbit");

const functionsRequest = new Request(
`https://${process.env.FBTOOLS_CLIENT_INTEGRATION_SITE}.web.app/helloWorld`,

Check warning on line 176 in scripts/hosting-tests/rewrites-tests/tests.ts

View workflow job for this annotation

GitHub Actions / lint (24)

Invalid type "string | undefined" of template literal expression
);

const functionsResponse = await fetch(functionsRequest);
Expand Down Expand Up @@ -206,7 +205,7 @@
join(tempDirInfo.tempDir.name, ".", "functions"),
);

await client.deploy({

Check warning on line 208 in scripts/hosting-tests/rewrites-tests/tests.ts

View workflow job for this annotation

GitHub Actions / lint (24)

Unsafe call of an `any` typed value

Check warning on line 208 in scripts/hosting-tests/rewrites-tests/tests.ts

View workflow job for this annotation

GitHub Actions / lint (24)

Unsafe member access .deploy on an `any` value
project: process.env.FBTOOLS_TARGET_PROJECT,
cwd: tempDirInfo.tempDir.name,
only: "hosting,functions",
Expand All @@ -214,12 +213,12 @@
});

const staticResponse = await fetch(
`https://${process.env.FBTOOLS_CLIENT_INTEGRATION_SITE}.web.app/index.html`,

Check warning on line 216 in scripts/hosting-tests/rewrites-tests/tests.ts

View workflow job for this annotation

GitHub Actions / lint (24)

Invalid type "string | undefined" of template literal expression
);
expect(await staticResponse.text()).to.contain("Rabbit");

const functionsRequest = new Request(
`https://${process.env.FBTOOLS_CLIENT_INTEGRATION_SITE}.web.app/helloWorld`,

Check warning on line 221 in scripts/hosting-tests/rewrites-tests/tests.ts

View workflow job for this annotation

GitHub Actions / lint (24)

Invalid type "string | undefined" of template literal expression
);

const functionsResponse = await fetch(functionsRequest);
Expand Down Expand Up @@ -251,7 +250,7 @@
["europe-west1"],
);

await client.deploy({

Check warning on line 253 in scripts/hosting-tests/rewrites-tests/tests.ts

View workflow job for this annotation

GitHub Actions / lint (24)

Unsafe call of an `any` typed value

Check warning on line 253 in scripts/hosting-tests/rewrites-tests/tests.ts

View workflow job for this annotation

GitHub Actions / lint (24)

Unsafe member access .deploy on an `any` value
project: process.env.FBTOOLS_TARGET_PROJECT,
cwd: tempDirInfo.tempDir.name,
only: "hosting,functions",
Expand Down
2 changes: 1 addition & 1 deletion scripts/hosting-tests/run.sh
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ echo "${DATE}" > "public/${TARGET_FILE}"
echo "Initialized temp directory."

echo "Testing local serve..."
firebase serve --only hosting --project "${FBTOOLS_TARGET_PROJECT}" --port "${PORT}" &
firebase serve --only hosting --project "${FBTOOLS_TARGET_PROJECT}" --port "${PORT}" --debug &
PID="$!"
sleep 5
VALUE="$(curl localhost:${PORT}/${TARGET_FILE})"
Expand Down
2 changes: 0 additions & 2 deletions scripts/integration-helpers/framework.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
import fetch, { Response } from "node-fetch";

import { CLIProcess } from "./cli";
import { Emulators } from "../../src/emulator/types";

Expand Down
1 change: 0 additions & 1 deletion scripts/storage-emulator-integration/utils.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import * as fs from "fs";
import * as path from "path";
import fetch from "node-fetch";
import * as crypto from "crypto";
import * as os from "os";
import { FrameworkOptions } from "../integration-helpers/framework";
Expand Down
Loading