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

Commit 7083586

Browse files
committed
Don't exit with missing suite ID when plugin is disabled
1 parent 82c8892 commit 7083586

File tree

6 files changed

+32
-11
lines changed

6 files changed

+32
-11
lines changed

packages/cypress-plugin/src/plugin.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ import {
1919
normalizeTestName,
2020
toPosix,
2121
UnflakableConfig,
22+
UnflakableConfigEnabled,
2223
} from "@unflakable/plugins-common";
2324
import { printWarning, require, userAgent } from "./utils";
2425
import { configureMochaReporter } from "./reporter-config";
@@ -505,7 +506,8 @@ ${
505506
end_time: new Date(results.endedTestsAt).toISOString(),
506507
test_runs: testRuns,
507508
},
508-
testSuiteId: this.unflakableConfig.testSuiteId,
509+
testSuiteId: (this.unflakableConfig as UnflakableConfigEnabled)
510+
.testSuiteId,
509511
apiKey: this.apiKey,
510512
baseUrl: this.unflakableConfig.apiBaseUrl,
511513
clientDescription: userAgentStr,

packages/jest-plugin/src/reporter.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,7 @@ import {
4444
loadGitRepo,
4545
toPosix,
4646
UnflakableConfig,
47+
UnflakableConfigEnabled,
4748
} from "@unflakable/plugins-common";
4849

4950
const debug = _debug("unflakable:reporter");
@@ -414,7 +415,8 @@ export default class UnflakableReporter extends BaseReporter {
414415
aggregatedResults: AggregatedResult,
415416
unflakableConfig: UnflakableConfig
416417
): Promise<void> {
417-
const testSuiteId = unflakableConfig.testSuiteId;
418+
const testSuiteId = (unflakableConfig as UnflakableConfigEnabled)
419+
.testSuiteId;
418420

419421
const git = unflakableConfig.gitAutoDetect ? await loadGitRepo() : null;
420422
const repoRoot = git !== null ? await getRepoRoot(git) : this.rootDir;

packages/plugins-common/src/config.ts

Lines changed: 23 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -9,19 +9,30 @@ const debug = _debug("unflakable:plugins-common:config");
99

1010
export type QuarantineMode = "no_quarantine" | "skip_tests" | "ignore_failures";
1111

12-
export type UnflakableConfig = {
12+
type UnflakableConfigInner = {
1313
apiBaseUrl: string | undefined;
14-
enabled: boolean;
1514
failureRetries: number;
1615
gitAutoDetect: boolean;
1716
quarantineMode: QuarantineMode;
18-
testSuiteId: string;
1917
uploadResults: boolean;
2018
};
2119

22-
type UnflakableConfigFile = Omit<UnflakableConfig, "testSuiteId"> & {
20+
export type UnflakableConfigEnabled = {
21+
enabled: true;
22+
testSuiteId: string;
23+
} & UnflakableConfigInner;
24+
25+
export type UnflakableConfig =
26+
| UnflakableConfigEnabled
27+
| ({
28+
enabled: false;
29+
testSuiteId: string | undefined;
30+
} & UnflakableConfigInner);
31+
32+
type UnflakableConfigFile = {
33+
enabled: boolean;
2334
testSuiteId: string | undefined;
24-
};
35+
} & UnflakableConfigInner;
2536

2637
const defaultConfig: UnflakableConfigFile = {
2738
apiBaseUrl: undefined,
@@ -196,12 +207,17 @@ const mergeConfigWithEnv = (
196207
config.testSuiteId.length > 0
197208
) {
198209
debug(`Using suite ID \`${config.testSuiteId}\` from config file`);
199-
return config as UnflakableConfig;
200-
} else {
210+
return config.enabled
211+
? // TypeScript has trouble inferring that these types are correct otherwise.
212+
{ ...config, enabled: true, testSuiteId: config.testSuiteId }
213+
: { ...config, enabled: false };
214+
} else if (config.enabled) {
201215
throw new Error(
202216
`Unflakable test suite ID not found in config file or ${suiteIdOverride.name} environment ` +
203217
"variable"
204218
);
219+
} else {
220+
return { ...config, enabled: false };
205221
}
206222
};
207223

packages/plugins-common/src/index.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ import path from "path";
55
export {
66
QuarantineMode,
77
UnflakableConfig,
8+
UnflakableConfigEnabled,
89
loadApiKey,
910
loadConfig,
1011
loadConfigSync,

packages/test-common/src/config.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ import {
99
import type { cosmiconfig, cosmiconfigSync, Options } from "cosmiconfig";
1010
import { default as expect } from "expect";
1111

12-
const debug = _debug("unflakable:integration-common:config");
12+
const debug = _debug("unflakable:test-common:config");
1313

1414
const throwUnimplemented = (): never => {
1515
throw new Error("unimplemented");

packages/test-common/src/git.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ import { setSimpleGitFactory } from "@unflakable/plugins-common";
55
import { SimpleGit, TaskOptions, Response as GitResponse } from "simple-git";
66
import deepEqual from "deep-equal";
77

8-
const debug = _debug("unflakable:integration-common:git");
8+
const debug = _debug("unflakable:test-common:git");
99

1010
export type SimpleGitMockRef = {
1111
sha: string;

0 commit comments

Comments
 (0)