[go: nahoru, domu]

Skip to content

Commit

Permalink
Move src/test/*.spec.ts tests (#7318)
Browse files Browse the repository at this point in the history
  • Loading branch information
yuchenshi committed Jun 14, 2024
1 parent f0e9276 commit ea0954e
Show file tree
Hide file tree
Showing 38 changed files with 104 additions and 103 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import * as nock from "nock";
import * as os from "os";
import * as sinon from "sinon";

import { validateOptions, serialExportUsers } from "../accountExporter";
import { validateOptions, serialExportUsers } from "./accountExporter";

describe("accountExporter", () => {
describe("validateOptions", () => {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
import * as nock from "nock";
import { expect } from "chai";

import { googleOrigin } from "../api";
import { googleOrigin } from "./api";

import * as accountImporter from "../accountImporter";
import * as accountImporter from "./accountImporter";

describe("accountImporter", () => {
before(() => {
Expand Down
10 changes: 5 additions & 5 deletions src/test/api.spec.ts → src/api.spec.ts
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
import { expect } from "chai";

import * as utils from "../utils";
import * as utils from "./utils";

describe("api", () => {
beforeEach(() => {
// The api module resolves env var statically so we need to
// do lazy imports and clear the import each time.
delete require.cache[require.resolve("../api")];
delete require.cache[require.resolve("./api")];
});

afterEach(() => {
Expand All @@ -18,21 +18,21 @@ describe("api", () => {
});

after(() => {
delete require.cache[require.resolve("../api")];
delete require.cache[require.resolve("./api")];
});

it("should override with FIRESTORE_URL", () => {
process.env.FIRESTORE_URL = "http://foobar.com";

const api = require("../api");
const api = require("./api");
expect(api.firestoreOrigin()).to.eq("http://foobar.com");
});

it("should prefer FIRESTORE_EMULATOR_HOST to FIRESTORE_URL", () => {
process.env.FIRESTORE_EMULATOR_HOST = "localhost:8080";
process.env.FIRESTORE_URL = "http://foobar.com";

const api = require("../api");
const api = require("./api");
expect(api.firestoreOriginOrEmulator()).to.eq("http://localhost:8080");
});
});
10 changes: 5 additions & 5 deletions src/test/apiv2.spec.ts → src/apiv2.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,20 +4,20 @@ import * as nock from "nock";
import AbortController from "abort-controller";
const proxySetup = require("proxy");

import { Client } from "../apiv2";
import { FirebaseError } from "../error";
import { streamToString, stringToStream } from "../utils";
import { Client } from "./apiv2";
import { FirebaseError } from "./error";
import { streamToString, stringToStream } from "./utils";

describe("apiv2", () => {
beforeEach(() => {
// The api module has package variables that we don't want sticking around.
delete require.cache[require.resolve("../apiv2")];
delete require.cache[require.resolve("./apiv2")];

nock.cleanAll();
});

after(() => {
delete require.cache[require.resolve("../apiv2")];
delete require.cache[require.resolve("./apiv2")];
});

describe("request", () => {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
import { resolve } from "path";
import { expect } from "chai";
import { FirebaseError } from "../error";
import { FirebaseError } from "./error";

import { archiveDirectory } from "../archiveDirectory";
import { archiveDirectory } from "./archiveDirectory";

const SOME_FIXTURE_DIRECTORY = resolve(__dirname, "./fixtures/config-imports");
const SOME_FIXTURE_DIRECTORY = resolve(__dirname, "./test/fixtures/config-imports");

describe("archiveDirectory", () => {
it("should archive happy little directories", async () => {
Expand Down
6 changes: 3 additions & 3 deletions src/test/auth.spec.ts → src/auth.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,9 @@ import {
getGlobalDefaultAccount,
getProjectDefaultAccount,
selectAccount,
} from "../auth";
import { configstore } from "../configstore";
import { Account } from "../types/auth";
} from "./auth";
import { configstore } from "./configstore";
import { Account } from "./types/auth";

describe("auth", () => {
const sandbox: sinon.SinonSandbox = sinon.createSandbox();
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import { expect } from "chai";
import { configstore } from "../configstore";
import { configstore } from "./configstore";
import * as sinon from "sinon";

import { checkMinRequiredVersion } from "../checkMinRequiredVersion";
import { checkMinRequiredVersion } from "./checkMinRequiredVersion";
import Sinon from "sinon";

describe("checkMinRequiredVersion", () => {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
import { expect } from "chai";

import { Options } from "../options";
import { RC } from "../rc";
import { Options } from "./options";
import { RC } from "./rc";

import { checkValidTargetFilters } from "../checkValidTargetFilters";
import { checkValidTargetFilters } from "./checkValidTargetFilters";

const SAMPLE_OPTIONS: Options = {
cwd: "/",
Expand Down
4 changes: 2 additions & 2 deletions src/test/command.spec.ts → src/command.spec.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import { expect } from "chai";
import * as nock from "nock";

import { Command, validateProjectId } from "../command";
import { FirebaseError } from "../error";
import { Command, validateProjectId } from "./command";
import { FirebaseError } from "./error";

describe("Command", () => {
let command: Command;
Expand Down
6 changes: 3 additions & 3 deletions src/test/config.spec.ts → src/config.spec.ts
Original file line number Diff line number Diff line change
@@ -1,18 +1,18 @@
import { expect } from "chai";
import * as path from "path";

import { Config } from "../config";
import { Config } from "./config";

function fixtureDir(name: string): string {
return path.resolve(__dirname, "./fixtures/" + name);
return path.resolve(__dirname, "./test/fixtures/" + name);
}

describe("Config", () => {
describe("#load", () => {
it("should load a cjson file when configPath is specified", () => {
const config = Config.load({
cwd: __dirname,
configPath: "./fixtures/valid-config/firebase.json",
configPath: "./test/fixtures/valid-config/firebase.json",
});
expect(config).to.not.be.null;
if (config) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,11 @@ import * as fs from "fs";
import * as path from "path";
import * as os from "os";

import * as api from "../api";
import { configstore } from "../configstore";
import * as defaultCredentials from "../defaultCredentials";
import { getGlobalDefaultAccount } from "../auth";
import { Account } from "../types/auth";
import * as api from "./api";
import { configstore } from "./configstore";
import * as defaultCredentials from "./defaultCredentials";
import { getGlobalDefaultAccount } from "./auth";
import { Account } from "./types/auth";

describe("defaultCredentials", () => {
const sandbox: sinon.SinonSandbox = sinon.createSandbox();
Expand Down
4 changes: 2 additions & 2 deletions src/test/downloadUtils.spec.ts → src/downloadUtils.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@ import { readFileSync } from "fs-extra";
import * as nock from "nock";
import { gunzipSync, gzipSync } from "zlib";

import { downloadToTmp } from "../downloadUtils";
import { FirebaseError } from "../error";
import { downloadToTmp } from "./downloadUtils";
import { FirebaseError } from "./error";

describe("downloadToTmp", () => {
it("should download a file", async () => {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { expect } from "chai";
import * as nock from "nock";

import { check, ensure, POLL_SETTINGS } from "../ensureApiEnabled";
import { check, ensure, POLL_SETTINGS } from "./ensureApiEnabled";

const FAKE_PROJECT_ID = "my_project";
const FAKE_API = "myapi.googleapis.com";
Expand Down
2 changes: 1 addition & 1 deletion src/test/error.spec.ts → src/error.spec.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { expect } from "chai";
import { FirebaseError } from "../error";
import { FirebaseError } from "./error";

describe("error", () => {
describe("FirebaseError", () => {
Expand Down
2 changes: 1 addition & 1 deletion src/test/experiments.spec.ts → src/experiments.spec.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { expect } from "chai";
import { enableExperimentsFromCliEnvVariable, isEnabled, setEnabled } from "../experiments";
import { enableExperimentsFromCliEnvVariable, isEnabled, setEnabled } from "./experiments";

describe("experiments", () => {
let originalCLIState = process.env.FIREBASE_CLI_EXPERIMENTS;
Expand Down
8 changes: 4 additions & 4 deletions src/test/fetchWebSetup.spec.ts → src/fetchWebSetup.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,10 @@ import { expect } from "chai";
import * as nock from "nock";
import * as sinon from "sinon";

import { configstore } from "../configstore";
import { fetchWebSetup, getCachedWebSetup } from "../fetchWebSetup";
import { firebaseApiOrigin } from "../api";
import { FirebaseError } from "../error";
import { configstore } from "./configstore";
import { fetchWebSetup, getCachedWebSetup } from "./fetchWebSetup";
import { firebaseApiOrigin } from "./api";
import { FirebaseError } from "./error";

describe("fetchWebSetup module", () => {
before(() => {
Expand Down
6 changes: 3 additions & 3 deletions src/test/filterTargets.spec.ts → src/filterTargets.spec.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { expect } from "chai";
import { filterTargets } from "../filterTargets";
import { Options } from "../options";
import { RC } from "../rc";
import { filterTargets } from "./filterTargets";
import { Options } from "./options";
import { RC } from "./rc";

const SAMPLE_OPTIONS: Options = {
cwd: "/",
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { expect } from "chai";
import { getValidator } from "../firebaseConfigValidate";
import { FirebaseConfig } from "../firebaseConfig";
import { getValidator } from "./firebaseConfigValidate";
import { FirebaseConfig } from "./firebaseConfig";

describe("firebaseConfigValidate", () => {
it("should accept a basic, valid config", () => {
Expand Down
2 changes: 1 addition & 1 deletion src/test/fsAsync.spec.ts → src/fsAsync.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import * as os from "os";
import * as path from "path";
import { sync as rimraf } from "rimraf";

import * as fsAsync from "../fsAsync";
import * as fsAsync from "./fsAsync";

// These tests work on the following directory structure:
// <basedir>
Expand Down
2 changes: 1 addition & 1 deletion src/test/fsutils.spec.ts → src/fsutils.spec.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { expect } from "chai";

import * as fsutils from "../fsutils";
import * as fsutils from "./fsutils";

describe("fsutils", () => {
describe("fileExistsSync", () => {
Expand Down
4 changes: 2 additions & 2 deletions src/test/functional.spec.ts → src/functional.spec.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import { expect } from "chai";
import { flatten } from "lodash";
import { SameType } from "../metaprogramming";
import { SameType } from "./metaprogramming";

import * as f from "../functional";
import * as f from "./functional";

describe("functional", () => {
describe("flatten", () => {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { expect } from "chai";

import * as functionsConfig from "../functionsConfig";
import * as functionsConfig from "./functionsConfig";

describe("config.parseSetArgs", () => {
it("should throw if a reserved namespace is used", () => {
Expand Down
5 changes: 3 additions & 2 deletions src/hosting/config.spec.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { expect } from "chai";
import * as path from "path";
import { FirebaseError } from "../error";
import { HostingConfig, HostingMultiple, HostingSingle } from "../firebaseConfig";

Expand All @@ -24,8 +25,8 @@ function options(
return targetsToSites?.[name] || [];
},
},
cwd: __dirname + "/../fixtures/simplehosting",
configPath: __dirname + "/../fixtures/simplehosting/firebase.json",
cwd: path.resolve(__dirname, "../test/fixtures/simplehosting"),
configPath: path.resolve(__dirname, "../test/fixtures/simplehosting/firebase.json"),
...base,
};
}
Expand Down
6 changes: 3 additions & 3 deletions src/test/listFiles.spec.ts → src/listFiles.spec.ts
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
import { expect } from "chai";
import { resolve } from "path";

import { listFiles } from "../listFiles";
import { listFiles } from "./listFiles";

describe("listFiles", () => {
// for details, see the file structure and firebase.json in test/fixtures/ignores
it("should ignore firebase-debug.log, specified ignores, and nothing else", () => {
const fileNames = listFiles(resolve(__dirname, "./fixtures/ignores"), [
const fileNames = listFiles(resolve(__dirname, "./test/fixtures/ignores"), [
"**/.*",
"firebase.json",
"ignored.txt",
Expand All @@ -16,7 +16,7 @@ describe("listFiles", () => {
});

it("should allow us to not specify additional ignores", () => {
const fileNames = listFiles(resolve(__dirname, "./fixtures/ignores"));
const fileNames = listFiles(resolve(__dirname, "./test/fixtures/ignores"));
expect(fileNames.sort()).to.have.members([
".hiddenfile",
"firebase.json",
Expand Down
6 changes: 3 additions & 3 deletions src/test/localFunction.spec.ts → src/localFunction.spec.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import { expect } from "chai";

import LocalFunction from "../localFunction";
import { EmulatedTriggerDefinition } from "../emulator/functionsEmulatorShared";
import { FunctionsEmulatorShell } from "../emulator/functionsEmulatorShell";
import LocalFunction from "./localFunction";
import { EmulatedTriggerDefinition } from "./emulator/functionsEmulatorShared";
import { FunctionsEmulatorShell } from "./emulator/functionsEmulatorShell";

const EMULATED_TRIGGER: EmulatedTriggerDefinition = {
id: "fn",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import {
DeepOmit,
RequireKeys,
DeepExtract,
} from "../metaprogramming";
} from "./metaprogramming";

describe("metaprogramming", () => {
it("can calcluate recursive keys", () => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,9 @@ import { expect } from "chai";
import * as nock from "nock";
import * as sinon from "sinon";

import { FirebaseError } from "../error";
import { OperationPollerOptions, pollOperation } from "../operation-poller";
import TimeoutError from "../throttler/errors/timeout-error";
import { FirebaseError } from "./error";
import { OperationPollerOptions, pollOperation } from "./operation-poller";
import TimeoutError from "./throttler/errors/timeout-error";

const TEST_ORIGIN = "https://firebasedummy.googleapis.com.com";
const VERSION = "v1";
Expand Down
4 changes: 2 additions & 2 deletions src/test/profileReport.spec.ts → src/profileReport.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,13 @@ import { expect } from "chai";

import * as path from "path";
import * as stream from "stream";
import { extractReadableIndex, formatNumber, ProfileReport } from "../profileReport";
import { extractReadableIndex, formatNumber, ProfileReport } from "./profileReport";

function combinerFunc(obj1: any, obj2: any): any {
return { count: obj1.count + obj2.count };
}

const fixturesDir = path.resolve(__dirname, "./fixtures");
const fixturesDir = path.resolve(__dirname, "./test/fixtures");

function newReport() {
const input = path.resolve(fixturesDir, "profiler-data/sample.json");
Expand Down
6 changes: 3 additions & 3 deletions src/test/projectUtils.spec.ts → src/projectUtils.spec.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
import { expect } from "chai";
import * as sinon from "sinon";

import { needProjectNumber, needProjectId, getAliases, getProjectId } from "../projectUtils";
import * as projects from "../management/projects";
import { RC } from "../rc";
import { needProjectNumber, needProjectId, getAliases, getProjectId } from "./projectUtils";
import * as projects from "./management/projects";
import { RC } from "./rc";

describe("getProjectId", () => {
it("should prefer projectId, falling back to project", () => {
Expand Down
Loading

0 comments on commit ea0954e

Please sign in to comment.