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
38 changes: 26 additions & 12 deletions src/checkValidTargetFilters.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,47 +22,61 @@

describe("checkValidTargetFilters", () => {
it("should resolve", async () => {
const options = Object.assign(SAMPLE_OPTIONS, {
const options = {
...SAMPLE_OPTIONS,
only: "functions",
});
};
await expect(checkValidTargetFilters(options)).to.be.fulfilled;
});

it("should resolve if there are no 'only' targets specified", async () => {
const options = Object.assign(SAMPLE_OPTIONS, {
only: null,
});
const options = {
...SAMPLE_OPTIONS,
only: null as any,

Check warning on line 35 in src/checkValidTargetFilters.spec.ts

View workflow job for this annotation

GitHub Actions / lint (20)

Unexpected any. Specify a different type

Check warning on line 35 in src/checkValidTargetFilters.spec.ts

View workflow job for this annotation

GitHub Actions / lint (20)

Unsafe assignment of an `any` value
};
await expect(checkValidTargetFilters(options)).to.be.fulfilled;
});

it("should error if an only option and except option have been provided", async () => {
const options = Object.assign(SAMPLE_OPTIONS, {
const options = {
...SAMPLE_OPTIONS,
only: "functions",
except: "hosting",
});
};
await expect(checkValidTargetFilters(options)).to.be.rejectedWith(
"Cannot specify both --only and --except",
);
});

UNFILTERABLE_TARGETS.forEach((target) => {
it(`should error if non-filter-type target (${target}) has filters`, async () => {
const options = Object.assign(SAMPLE_OPTIONS, {
const options = {
...SAMPLE_OPTIONS,
only: `${target}:filter`,
except: null,
});
};
await expect(checkValidTargetFilters(options)).to.be.rejectedWith(
/Filters specified with colons \(e.g. --only functions:func1,functions:func2\) are only supported for .*/,
);
});
});

it("should error if the same target is specified with and without a filter", async () => {
const options = Object.assign(SAMPLE_OPTIONS, {
const options = {
...SAMPLE_OPTIONS,
only: "functions,functions:filter",
});
};
await expect(checkValidTargetFilters(options)).to.be.rejectedWith(
'Cannot specify "--only functions" and "--only functions:<filter>" at the same time',
);
});

it("should error if a target filter is missing product prefix", async () => {
const options = {
...SAMPLE_OPTIONS,
only: "functions:func1,func2",
};
await expect(checkValidTargetFilters(options)).to.be.rejectedWith(
/"func2" is not a valid deploy target/,
);
});
});
14 changes: 14 additions & 0 deletions src/checkValidTargetFilters.ts
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,20 @@ export async function checkValidTargetFilters(options: Options): Promise<void> {
),
);
}

for (const target of only) {
const baseTarget = target.split(":")[0];
if (!VALID_DEPLOY_TARGETS.includes(baseTarget)) {
return reject(
new FirebaseError(
`"${baseTarget}" is not a valid deploy target. Valid target prefixes are: ${VALID_DEPLOY_TARGETS.join(
", ",
)}`,
),
);
}
}
Comment thread
joehan marked this conversation as resolved.

return resolve();
});
}
Loading