Skip to content
This repository was archived by the owner on Sep 1, 2024. It is now read-only.

Commit b5b8b78

Browse files
committed
Fix --test-suite-id precedence
1 parent 606e56d commit b5b8b78

File tree

3 files changed

+33
-8
lines changed

3 files changed

+33
-8
lines changed

packages/cypress-plugin/src/main.ts

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -263,7 +263,7 @@ const main = async (): Promise<void> => {
263263
? path.resolve(process.cwd(), runOptions.project)
264264
: process.cwd();
265265

266-
const unflakableConfig = await loadConfig(projectRoot);
266+
const unflakableConfig = await loadConfig(projectRoot, args["test-suite-id"]);
267267
debug(`Unflakable plugin is ${unflakableConfig.enabled ? "en" : "dis"}abled`);
268268

269269
if (unflakableConfig.enabled) {
@@ -285,9 +285,6 @@ const main = async (): Promise<void> => {
285285
"quarantine-mode"
286286
] as QuarantineMode;
287287
}
288-
if (args["test-suite-id"] !== undefined) {
289-
unflakableConfig.testSuiteId = args["test-suite-id"];
290-
}
291288
if (args["upload-results"] !== undefined) {
292289
unflakableConfig.uploadResults = args["upload-results"];
293290
}

packages/cypress-plugin/test/integration/src/config.test.ts

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,20 @@ integrationTestSuite(() => {
3737
));
3838

3939
it("set test suite ID via CLI", (done) =>
40+
integrationTest(
41+
{
42+
params: {
43+
cliArgs: ["--test-suite-id", "MOCK_SUITE_ID_CLI"],
44+
envVars: {
45+
UNFLAKABLE_SUITE_ID: undefined,
46+
},
47+
expectedSuiteId: "MOCK_SUITE_ID_CLI",
48+
},
49+
},
50+
done
51+
));
52+
53+
it("set test suite ID via CLI override", (done) =>
4054
integrationTest(
4155
{
4256
params: {

packages/plugins-common/src/config.ts

Lines changed: 18 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -141,7 +141,10 @@ const apiBaseUrlOverride = new EnvVar("UNFLAKABLE_API_BASE_URL");
141141
const apiKey = new EnvVar("UNFLAKABLE_API_KEY");
142142
const enabledOverride = new EnvVar("UNFLAKABLE_ENABLED");
143143

144-
const mergeConfigWithEnv = (config: UnflakableConfigFile): UnflakableConfig => {
144+
const mergeConfigWithEnv = (
145+
config: UnflakableConfigFile,
146+
cliTestSuiteId?: string
147+
): UnflakableConfig => {
145148
if (enabledOverride.value !== undefined) {
146149
const enabled = !["false", "0"].includes(enabledOverride.value);
147150
debug(
@@ -177,7 +180,13 @@ const mergeConfigWithEnv = (config: UnflakableConfigFile): UnflakableConfig => {
177180
config.uploadResults = uploadResults;
178181
}
179182

180-
if (suiteIdOverride.value !== undefined && suiteIdOverride.value.length > 0) {
183+
if (cliTestSuiteId !== undefined) {
184+
debug(`Using suite ID \`${cliTestSuiteId}\` from CLI`);
185+
return { ...config, testSuiteId: cliTestSuiteId };
186+
} else if (
187+
suiteIdOverride.value !== undefined &&
188+
suiteIdOverride.value.length > 0
189+
) {
181190
debug(
182191
`Using suite ID \`${suiteIdOverride.value}\` from environment variable ${suiteIdOverride.name}`
183192
);
@@ -236,8 +245,13 @@ const loadConfigFile = async (
236245
}
237246
};
238247

239-
export const loadConfig = (searchFrom: string): Promise<UnflakableConfig> =>
240-
loadConfigFile(searchFrom).then(mergeConfigWithEnv);
248+
export const loadConfig = (
249+
searchFrom: string,
250+
testSuiteId?: string
251+
): Promise<UnflakableConfig> =>
252+
loadConfigFile(searchFrom).then((config) =>
253+
mergeConfigWithEnv(config, testSuiteId)
254+
);
241255

242256
const loadConfigFileSync = (searchFrom: string): UnflakableConfigFile => {
243257
const configExplorer = cosmiconfigSync("unflakable", {

0 commit comments

Comments
 (0)