Skip to content

Commit 58ce112

Browse files
authored
Add a manifest file next to each test fixture. (#7332)
1 parent 1191a6c commit 58ce112

File tree

34 files changed

+200
-146
lines changed

34 files changed

+200
-146
lines changed

.prettierignore

+3
Original file line numberDiff line numberDiff line change
@@ -6,3 +6,6 @@
66
/scripts/webframeworks-deploy-tests/angular/**
77
/scripts/webframeworks-deploy-tests/nextjs/**
88
/src/frameworks/docs/**
9+
10+
# Intentionally invalid YAML file:
11+
/src/test/fixtures/extension-yamls/invalid/extension.yaml

scripts/emulator-tests/unzipEmulators.spec.ts

+23-16
Original file line numberDiff line numberDiff line change
@@ -4,35 +4,42 @@ import * as path from "path";
44
import { unzip } from "../../src/unzip";
55
import { DownloadDetails } from "../../src/emulator/downloadableEmulators";
66
import { Client } from "../../src/apiv2";
7-
const fixturesDir = path.resolve(__dirname, "dev");
8-
9-
const ZIP_FIXTURES_PATH = path.join(fixturesDir, "zip-files");
10-
const ZIP_TEMPORARY_PATH = path.join(ZIP_FIXTURES_PATH, "temp");
7+
import { tmpdir } from "os";
118

129
describe("unzipEmulators", () => {
10+
let tempDir: string;
11+
12+
before(async () => {
13+
tempDir = await fs.promises.mkdtemp(path.join(tmpdir(), "firebasetest-"));
14+
});
15+
16+
after(async () => {
17+
await fs.promises.rmdir(tempDir, { recursive: true });
18+
});
19+
1320
it("should unzip a ui emulator zip file", async () => {
1421
const [uiVersion, uiRemoteUrl] = [
1522
DownloadDetails.ui.version,
1623
DownloadDetails.ui.opts.remoteUrl,
1724
];
1825

19-
const uiZipPath = path.join(ZIP_TEMPORARY_PATH, `ui-v${uiVersion}.zip`);
26+
const uiZipPath = path.join(tempDir, `ui-v${uiVersion}.zip`);
2027

21-
await fs.promises.mkdir(ZIP_TEMPORARY_PATH, { recursive: true });
28+
await fs.promises.mkdir(tempDir, { recursive: true });
2229
if (!(await fs.promises.access(uiZipPath).catch(() => false))) {
2330
await downloadFile(uiRemoteUrl, uiZipPath);
2431
}
2532

26-
await unzip(uiZipPath, path.join(ZIP_TEMPORARY_PATH, "ui"));
33+
await unzip(uiZipPath, path.join(tempDir, "ui"));
2734

28-
const files = await fs.promises.readdir(ZIP_TEMPORARY_PATH);
35+
const files = await fs.promises.readdir(tempDir);
2936
expect(files).to.include("ui");
3037

31-
const uiFiles = await fs.promises.readdir(path.join(ZIP_TEMPORARY_PATH, "ui"));
38+
const uiFiles = await fs.promises.readdir(path.join(tempDir, "ui"));
3239
expect(uiFiles).to.include("client");
3340
expect(uiFiles).to.include("server");
3441

35-
const serverFiles = await fs.promises.readdir(path.join(ZIP_TEMPORARY_PATH, "ui", "server"));
42+
const serverFiles = await fs.promises.readdir(path.join(tempDir, "ui", "server"));
3643
expect(serverFiles).to.include("server.mjs");
3744
}).timeout(10000);
3845

@@ -42,28 +49,28 @@ describe("unzipEmulators", () => {
4249
DownloadDetails.pubsub.opts.remoteUrl,
4350
];
4451

45-
const pubsubZipPath = path.join(ZIP_TEMPORARY_PATH, `pubsub-emulator-v${pubsubVersion}.zip`);
52+
const pubsubZipPath = path.join(tempDir, `pubsub-emulator-v${pubsubVersion}.zip`);
4653

4754
if (!(await fs.promises.access(pubsubZipPath).catch(() => false))) {
4855
await downloadFile(pubsubRemoteUrl, pubsubZipPath);
4956
}
5057

51-
await unzip(pubsubZipPath, path.join(ZIP_TEMPORARY_PATH, "pubsub"));
58+
await unzip(pubsubZipPath, path.join(tempDir, "pubsub"));
5259

53-
const files = await fs.promises.readdir(ZIP_TEMPORARY_PATH);
60+
const files = await fs.promises.readdir(tempDir);
5461
expect(files).to.include("pubsub");
5562

56-
const pubsubFiles = await fs.promises.readdir(path.join(ZIP_TEMPORARY_PATH, "pubsub"));
63+
const pubsubFiles = await fs.promises.readdir(path.join(tempDir, "pubsub"));
5764
expect(pubsubFiles).to.include("pubsub-emulator");
5865

5966
const pubsubEmulatorFiles = await fs.promises.readdir(
60-
path.join(ZIP_TEMPORARY_PATH, "pubsub", "pubsub-emulator"),
67+
path.join(tempDir, "pubsub", "pubsub-emulator"),
6168
);
6269
expect(pubsubEmulatorFiles).to.include("bin");
6370
expect(pubsubEmulatorFiles).to.include("lib");
6471

6572
const binFiles = await fs.promises.readdir(
66-
path.join(ZIP_TEMPORARY_PATH, "pubsub", "pubsub-emulator", "bin"),
73+
path.join(tempDir, "pubsub", "pubsub-emulator", "bin"),
6774
);
6875
expect(binFiles).to.include("cloud-pubsub-emulator");
6976
}).timeout(10000);

src/archiveDirectory.spec.ts

+3-4
Original file line numberDiff line numberDiff line change
@@ -3,13 +3,12 @@ import { expect } from "chai";
33
import { FirebaseError } from "./error";
44

55
import { archiveDirectory } from "./archiveDirectory";
6-
7-
const SOME_FIXTURE_DIRECTORY = resolve(__dirname, "./test/fixtures/config-imports");
6+
import { FIXTURE_DIR } from "./test/fixtures/config-imports";
87

98
describe("archiveDirectory", () => {
109
it("should archive happy little directories", async () => {
11-
const result = await archiveDirectory(SOME_FIXTURE_DIRECTORY, {});
12-
expect(result.source).to.equal(SOME_FIXTURE_DIRECTORY);
10+
const result = await archiveDirectory(FIXTURE_DIR, {});
11+
expect(result.source).to.equal(FIXTURE_DIR);
1312
expect(result.size).to.be.greaterThan(0);
1413
});
1514

src/config.spec.ts

+10-10
Original file line numberDiff line numberDiff line change
@@ -2,17 +2,17 @@ import { expect } from "chai";
22
import * as path from "path";
33

44
import { Config } from "./config";
5-
6-
function fixtureDir(name: string): string {
7-
return path.resolve(__dirname, "./test/fixtures/" + name);
8-
}
5+
import { FIREBASE_JSON_PATH as VALID_CONFIG_PATH } from "./test/fixtures/valid-config";
6+
import { FIXTURE_DIR as SIMPLE_CONFIG_DIR } from "./test/fixtures/config-imports";
7+
import { FIXTURE_DIR as DUP_TOP_LEVEL_CONFIG_DIR } from "./test/fixtures/dup-top-level";
98

109
describe("Config", () => {
1110
describe("#load", () => {
1211
it("should load a cjson file when configPath is specified", () => {
12+
const cwd = __dirname;
1313
const config = Config.load({
14-
cwd: __dirname,
15-
configPath: "./test/fixtures/valid-config/firebase.json",
14+
cwd,
15+
configPath: path.relative(cwd, VALID_CONFIG_PATH),
1616
});
1717
expect(config).to.not.be.null;
1818
if (config) {
@@ -23,19 +23,19 @@ describe("Config", () => {
2323

2424
describe("#parseFile", () => {
2525
it("should load a cjson file", () => {
26-
const config = new Config({}, { cwd: fixtureDir("config-imports") });
26+
const config = new Config({}, { cwd: SIMPLE_CONFIG_DIR });
2727
expect(config.parseFile("hosting", "hosting.json").public).to.equal(".");
2828
});
2929

3030
it("should error out for an unknown file", () => {
31-
const config = new Config({}, { cwd: fixtureDir("config-imports") });
31+
const config = new Config({}, { cwd: SIMPLE_CONFIG_DIR });
3232
expect(() => {
3333
config.parseFile("hosting", "i-dont-exist.json");
3434
}).to.throw("Imported file i-dont-exist.json does not exist");
3535
});
3636

3737
it("should error out for an unrecognized extension", () => {
38-
const config = new Config({}, { cwd: fixtureDir("config-imports") });
38+
const config = new Config({}, { cwd: SIMPLE_CONFIG_DIR });
3939
expect(() => {
4040
config.parseFile("hosting", "unsupported.txt");
4141
}).to.throw("unsupported.txt is not of a supported config file type");
@@ -49,7 +49,7 @@ describe("Config", () => {
4949
});
5050

5151
it("should prevent top-level key duplication", () => {
52-
const config = new Config({ rules: "rules.json" }, { cwd: fixtureDir("dup-top-level") });
52+
const config = new Config({ rules: "rules.json" }, { cwd: DUP_TOP_LEVEL_CONFIG_DIR });
5353
expect(config.materialize("rules")).to.deep.equal({ ".read": true });
5454
});
5555
});

src/extensions/emulator/specHelper.spec.ts

+4-3
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,11 @@
11
import { expect } from "chai";
2-
import * as path from "path";
32

43
import * as specHelper from "./specHelper";
54
import { Resource } from "../types";
65
import { FirebaseError } from "../../error";
76
import { Runtime } from "../../deploy/functions/runtimes/supported";
7+
import { FIXTURE_DIR as MINIMAL_EXT_DIR } from "../../test/fixtures/extension-yamls/minimal";
8+
import { FIXTURE_DIR as HELLO_WORLD_EXT_DIR } from "../../test/fixtures/extension-yamls/hello-world";
89

910
const testResource: Resource = {
1011
name: "test-resource",
@@ -25,7 +26,7 @@ describe("readExtensionYaml", () => {
2526
}[] = [
2627
{
2728
desc: "should read a minimal extension.yaml",
28-
directory: path.resolve(__dirname, "../../test/fixtures/extension-yamls/minimal"),
29+
directory: MINIMAL_EXT_DIR,
2930
expected: {
3031
apis: [],
3132
contributors: [],
@@ -46,7 +47,7 @@ describe("readExtensionYaml", () => {
4647
},
4748
{
4849
desc: "should read a hello-world extension.yaml",
49-
directory: path.resolve(__dirname, "../../test/fixtures/extension-yamls/hello-world"),
50+
directory: HELLO_WORLD_EXT_DIR,
5051
expected: {
5152
apis: [],
5253
billingRequired: true,

src/extensions/localHelper.spec.ts

+4-16
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,13 @@
11
import { expect } from "chai";
22
import * as fs from "fs-extra";
33
import * as yaml from "yaml";
4-
import { resolve } from "path";
54
import * as sinon from "sinon";
65

76
import * as localHelper from "./localHelper";
87
import { FirebaseError } from "../error";
9-
10-
const EXT_FIXTURE_DIRECTORY = resolve(__dirname, "../test/fixtures/sample-ext");
11-
const EXT_PREINSTALL_FIXTURE_DIRECTORY = resolve(
12-
__dirname,
13-
"../test/fixtures/sample-ext-preinstall",
14-
);
8+
import { FIXTURE_DIR as EXT_FIXTURE_DIRECTORY } from "../test/fixtures/extension-yamls/sample-ext";
9+
import { FIXTURE_DIR as EXT_PREINSTALL_FIXTURE_DIRECTORY } from "../test/fixtures/extension-yamls/sample-ext-preinstall";
10+
import { FIXTURE_DIR as INVALID_EXT_DIRECTORY } from "../test/fixtures/extension-yamls/invalid";
1511

1612
describe("localHelper", () => {
1713
const sandbox = sinon.createSandbox();
@@ -36,16 +32,8 @@ describe("localHelper", () => {
3632
});
3733

3834
describe("with an invalid YAML file", () => {
39-
beforeEach(() => {
40-
sandbox.stub(fs, "readFileSync").returns(`name: foo\nunknownkey\nother: value`);
41-
});
42-
43-
afterEach(() => {
44-
sandbox.restore();
45-
});
46-
4735
it("should return a rejected promise with a useful error if extension.yaml is invalid", async () => {
48-
await expect(localHelper.getLocalExtensionSpec(EXT_FIXTURE_DIRECTORY)).to.be.rejectedWith(
36+
await expect(localHelper.getLocalExtensionSpec(INVALID_EXT_DIRECTORY)).to.be.rejectedWith(
4937
FirebaseError,
5038
/YAML Error.+Implicit keys need to be on a single line.+line 2.+/,
5139
);

src/hosting/config.spec.ts

+3-3
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,12 @@
11
import { expect } from "chai";
2-
import * as path from "path";
32
import { FirebaseError } from "../error";
43
import { HostingConfig, HostingMultiple, HostingSingle } from "../firebaseConfig";
54

65
import * as config from "./config";
76
import { HostingOptions } from "./options";
87
import { cloneDeep } from "../utils";
98
import { setEnabled } from "../experiments";
9+
import { FIREBASE_JSON_PATH, FIXTURE_DIR } from "../test/fixtures/simplehosting";
1010

1111
function options(
1212
hostingConfig: HostingConfig,
@@ -25,8 +25,8 @@ function options(
2525
return targetsToSites?.[name] || [];
2626
},
2727
},
28-
cwd: path.resolve(__dirname, "../test/fixtures/simplehosting"),
29-
configPath: path.resolve(__dirname, "../test/fixtures/simplehosting/firebase.json"),
28+
cwd: FIXTURE_DIR,
29+
configPath: FIREBASE_JSON_PATH,
3030
...base,
3131
};
3232
}

src/listFiles.spec.ts

+5-3
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,13 @@
11
import { expect } from "chai";
2-
import { resolve } from "path";
32

43
import { listFiles } from "./listFiles";
4+
import { FIXTURE_DIR } from "./test/fixtures/ignores";
55

66
describe("listFiles", () => {
77
// for details, see the file structure and firebase.json in test/fixtures/ignores
88
it("should ignore firebase-debug.log, specified ignores, and nothing else", () => {
9-
const fileNames = listFiles(resolve(__dirname, "./test/fixtures/ignores"), [
9+
const fileNames = listFiles(FIXTURE_DIR, [
10+
"index.ts",
1011
"**/.*",
1112
"firebase.json",
1213
"ignored.txt",
@@ -16,9 +17,10 @@ describe("listFiles", () => {
1617
});
1718

1819
it("should allow us to not specify additional ignores", () => {
19-
const fileNames = listFiles(resolve(__dirname, "./test/fixtures/ignores"));
20+
const fileNames = listFiles(FIXTURE_DIR);
2021
expect(fileNames.sort()).to.have.members([
2122
".hiddenfile",
23+
"index.ts",
2224
"firebase.json",
2325
"ignored.txt",
2426
"ignored/deeper/index.txt",

src/profileReport.spec.ts

+3-6
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,16 @@
11
import { expect } from "chai";
22

3-
import * as path from "path";
43
import * as stream from "stream";
54
import { extractReadableIndex, formatNumber, ProfileReport } from "./profileReport";
5+
import { SAMPLE_INPUT_PATH, SAMPLE_OUTPUT_PATH } from "./test/fixtures/profiler-data";
66

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

11-
const fixturesDir = path.resolve(__dirname, "./test/fixtures");
12-
1311
function newReport() {
14-
const input = path.resolve(fixturesDir, "profiler-data/sample.json");
1512
const throwAwayStream = new stream.PassThrough();
16-
return new ProfileReport(input, throwAwayStream, {
13+
return new ProfileReport(SAMPLE_INPUT_PATH, throwAwayStream, {
1714
format: "JSON",
1815
isFile: false,
1916
collapse: true,
@@ -24,7 +21,7 @@ function newReport() {
2421
describe("profilerReport", () => {
2522
it("should correctly generate a report", () => {
2623
const report = newReport();
27-
const output = require(path.resolve(fixturesDir, "profiler-data/sample-output.json"));
24+
const output = require(SAMPLE_OUTPUT_PATH);
2825
return expect(report.generate()).to.eventually.deep.equal(output);
2926
});
3027

src/rc.spec.ts

+5-5
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,14 @@
11
import { expect } from "chai";
22
import * as path from "path";
33
import { RC, loadRC, RCData } from "./rc";
4-
5-
const fixturesDir = path.resolve(__dirname, "./test/fixtures");
4+
import { CONFLICT_RC_DIR, FIREBASE_JSON_PATH, INVALID_RC_DIR } from "./test/fixtures/fbrc";
65

76
const EMPTY_DATA: RCData = { projects: {}, targets: {}, etags: {}, dataconnectEmulatorConfig: {} };
87

98
describe("RC", () => {
109
describe(".load", () => {
1110
it("should load from nearest project directory", () => {
12-
const result = loadRC({ cwd: path.resolve(fixturesDir, "fbrc/conflict") });
11+
const result = loadRC({ cwd: CONFLICT_RC_DIR });
1312
expect(result.projects.default).to.eq("top");
1413
});
1514

@@ -19,12 +18,13 @@ describe("RC", () => {
1918
});
2019

2120
it("should not throw up on invalid json", () => {
22-
const result = loadRC({ cwd: path.resolve(fixturesDir, "fbrc/invalid") });
21+
const result = loadRC({ cwd: INVALID_RC_DIR });
2322
return expect(result.data).to.deep.eq(EMPTY_DATA);
2423
});
2524

2625
it("should load from the right directory when --config is specified", () => {
27-
const result = loadRC({ cwd: __dirname, configPath: "./test/fixtures/fbrc/firebase.json" });
26+
const cwd = __dirname;
27+
const result = loadRC({ cwd, configPath: path.relative(cwd, FIREBASE_JSON_PATH) });
2828
expect(result.projects.default).to.eq("top");
2929
});
3030
});

src/rulesDeploy.spec.ts

+4-7
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
import { expect } from "chai";
2-
import * as path from "path";
32
import * as sinon from "sinon";
43

54
import { FirebaseError } from "./error";
@@ -12,18 +11,17 @@ import { Config } from "./config";
1211
import * as gcp from "./gcp";
1312

1413
import { RulesDeploy, RulesetServiceType } from "./rulesDeploy";
14+
import { FIXTURE_DIR, FIXTURE_FIRESTORE_RULES_PATH } from "./test/fixtures/rulesDeploy";
15+
import { FIXTURE_DIR as CROSS_SERVICE_FIXTURE_DIR } from "./test/fixtures/rulesDeployCrossService";
1516

1617
describe("RulesDeploy", () => {
17-
const FIXTURE_DIR = path.resolve(__dirname, "test/fixtures/rulesDeploy");
1818
const BASE_OPTIONS: { cwd: string; project: string; config: any } = {
1919
cwd: FIXTURE_DIR,
2020
project: "test-project",
2121
config: null,
2222
};
2323
BASE_OPTIONS.config = Config.load(BASE_OPTIONS, false);
24-
const FIRESTORE_RULES_CONTENT = readFileSync(
25-
path.resolve(FIXTURE_DIR, "firestore.rules"),
26-
).toString();
24+
const FIRESTORE_RULES_CONTENT = readFileSync(FIXTURE_FIRESTORE_RULES_PATH).toString();
2725

2826
describe("addFile", () => {
2927
it("should successfully add a file that exists", () => {
@@ -340,9 +338,8 @@ describe("RulesDeploy", () => {
340338
});
341339

342340
describe("with cross-service rules", () => {
343-
const FIXTURE_DIR = path.resolve(__dirname, "test/fixtures/rulesDeployCrossService");
344341
const CROSS_SERVICE_OPTIONS: { cwd: string; project: string; config: any } = {
345-
cwd: FIXTURE_DIR,
342+
cwd: CROSS_SERVICE_FIXTURE_DIR,
346343
project: "test-project",
347344
config: null,
348345
};

0 commit comments

Comments
 (0)