@alwaysmeticulous/cli 2.16.0 → 2.17.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (38) hide show
  1. package/dist/api/test-run.api.d.ts +2 -1
  2. package/dist/commands/bootstrap/bootstrap.command.d.ts +1 -1
  3. package/dist/commands/bootstrap/bootstrap.command.js +2 -2
  4. package/dist/commands/create-test/create-test.command.d.ts +1 -1
  5. package/dist/commands/create-test/create-test.command.js +2 -2
  6. package/dist/commands/debug-replay/debug-replay.command.d.ts +1 -1
  7. package/dist/commands/debug-replay/debug-replay.command.js +2 -2
  8. package/dist/commands/download-replay/download-replay.command.d.ts +1 -1
  9. package/dist/commands/download-replay/download-replay.command.js +2 -2
  10. package/dist/commands/download-session/download-session.command.d.ts +1 -1
  11. package/dist/commands/download-session/download-session.command.js +2 -2
  12. package/dist/commands/record/record.command.d.ts +1 -1
  13. package/dist/commands/record/record.command.js +2 -2
  14. package/dist/commands/replay/replay.command.d.ts +1 -1
  15. package/dist/commands/replay/replay.command.js +2 -2
  16. package/dist/commands/run-all-tests/run-all-tests.command.d.ts +4 -2
  17. package/dist/commands/run-all-tests/run-all-tests.command.js +22 -120
  18. package/dist/commands/screenshot-diff/screenshot-diff.command.d.ts +1 -1
  19. package/dist/commands/screenshot-diff/screenshot-diff.command.js +3 -3
  20. package/dist/commands/serve/serve.command.d.ts +1 -1
  21. package/dist/commands/serve/serve.command.js +2 -2
  22. package/dist/commands/show-project/show-project.command.d.ts +1 -1
  23. package/dist/commands/show-project/show-project.command.js +2 -2
  24. package/dist/commands/update-tests/update-tests.command.d.ts +1 -1
  25. package/dist/commands/update-tests/update-tests.command.js +2 -2
  26. package/dist/index.d.ts +12 -11
  27. package/dist/index.js +14 -12
  28. package/dist/main.js +12 -12
  29. package/dist/parallel-tests/parallel-tests.handler.d.ts +2 -0
  30. package/dist/parallel-tests/parallel-tests.handler.js +10 -1
  31. package/dist/parallel-tests/run-all-tests.d.ts +46 -0
  32. package/dist/parallel-tests/run-all-tests.js +169 -0
  33. package/dist/parallel-tests/run-all-tests.types.d.ts +5 -0
  34. package/dist/parallel-tests/run-all-tests.types.js +2 -0
  35. package/dist/tsconfig.tsbuildinfo +1 -1
  36. package/dist/utils/github-summary.utils.d.ts +1 -2
  37. package/dist/utils/github-summary.utils.js +1 -3
  38. package/package.json +2 -2
@@ -3,6 +3,7 @@ import { AxiosInstance } from "axios";
3
3
  import { TestRun } from "../api/test-run.api";
4
4
  import { ScreenshotAssertionsEnabledOptions } from "../command-utils/common-types";
5
5
  import { MeticulousCliConfig, TestCaseResult } from "../config/config.types";
6
+ import { TestRunProgress } from "./run-all-tests.types";
6
7
  export interface RunAllTestsInParallelOptions {
7
8
  config: MeticulousCliConfig;
8
9
  client: AxiosInstance;
@@ -21,6 +22,7 @@ export interface RunAllTestsInParallelOptions {
21
22
  deflake: boolean;
22
23
  cachedTestRunResults: TestCaseResult[];
23
24
  replayEventsDependencies: ReplayEventsDependencies;
25
+ onTestFinished?: (progress: TestRunProgress) => void;
24
26
  }
25
27
  /** Handler for running Meticulous tests in parallel using child processes */
26
28
  export declare const runAllTestsInParallel: (options: RunAllTestsInParallelOptions) => Promise<TestCaseResult[]>;
@@ -13,7 +13,7 @@ const test_run_api_1 = require("../api/test-run.api");
13
13
  const config_utils_1 = require("../utils/config.utils");
14
14
  const run_all_tests_utils_1 = require("../utils/run-all-tests.utils");
15
15
  /** Handler for running Meticulous tests in parallel using child processes */
16
- const runAllTestsInParallel = async ({ config, client, testRun, apiToken, commitSha, baseCommitSha, appUrl, useAssetsSnapshottedInBaseSimulation, executionOptions, screenshottingOptions, parallelTasks, deflake, cachedTestRunResults, replayEventsDependencies, }) => {
16
+ const runAllTestsInParallel = async ({ config, client, testRun, apiToken, commitSha, baseCommitSha, appUrl, useAssetsSnapshottedInBaseSimulation, executionOptions, screenshottingOptions, parallelTasks, deflake, cachedTestRunResults, replayEventsDependencies, onTestFinished, }) => {
17
17
  const logger = loglevel_1.default.getLogger(common_1.METICULOUS_LOGGER_NAME);
18
18
  const results = [...cachedTestRunResults];
19
19
  const queue = await (0, run_all_tests_utils_1.getTestsToRun)({
@@ -22,6 +22,11 @@ const runAllTestsInParallel = async ({ config, client, testRun, apiToken, commit
22
22
  cachedTestRunResults,
23
23
  baseCommitSha,
24
24
  });
25
+ const progress = {
26
+ runningTestCases: queue.length,
27
+ failedTestCases: 0,
28
+ passedTestCases: 0,
29
+ };
25
30
  const allTasksDone = (0, common_1.defer)();
26
31
  let inProgress = 0;
27
32
  const maxTasks = parallelTasks !== null && parallelTasks !== void 0 ? parallelTasks : Math.max((0, os_1.cpus)().length, 1);
@@ -92,6 +97,10 @@ const runAllTestsInParallel = async ({ config, client, testRun, apiToken, commit
92
97
  .then(async (result) => {
93
98
  --inProgress;
94
99
  results.push(result);
100
+ progress.failedTestCases += result.result === "fail" ? 1 : 0;
101
+ progress.passedTestCases += result.result === "pass" ? 1 : 0;
102
+ --progress.runningTestCases;
103
+ onTestFinished === null || onTestFinished === void 0 ? void 0 : onTestFinished(progress);
95
104
  (0, test_run_api_1.putTestRunResults)({
96
105
  client,
97
106
  testRunId: testRun.id,
@@ -0,0 +1,46 @@
1
+ import { ReplayExecutionOptions } from "@alwaysmeticulous/common";
2
+ import { TestRunStatus } from "../api/test-run.api";
3
+ import { ScreenshotAssertionsEnabledOptions } from "../command-utils/common-types";
4
+ import { TestCaseResult } from "../config/config.types";
5
+ import { TestRunProgress } from "./run-all-tests.types";
6
+ export interface Options {
7
+ testsFile: string | null;
8
+ executionOptions: ReplayExecutionOptions;
9
+ screenshottingOptions: ScreenshotAssertionsEnabledOptions;
10
+ apiToken: string | null;
11
+ commitSha: string | null;
12
+ /**
13
+ * The base commit to compare test results against for test cases that don't have a baseReplayId specified.
14
+ */
15
+ baseCommitSha: string | null;
16
+ appUrl: string | null;
17
+ useAssetsSnapshottedInBaseSimulation: boolean;
18
+ /**
19
+ * If null runs in parralel with a sensible number of parrelel tasks for the given machine.
20
+ *
21
+ * Set to 1 to disable parralelism.
22
+ */
23
+ parallelTasks: number | null;
24
+ deflake: boolean;
25
+ useCache: boolean;
26
+ githubSummary: boolean;
27
+ onTestRunCreated?: (testRun: TestRun & {
28
+ status: "Running";
29
+ }) => void;
30
+ onTestFinished?: (testRun: TestRun & {
31
+ status: "Running";
32
+ }) => void;
33
+ }
34
+ export interface RunAllTestsResult {
35
+ testRun: TestRun & {
36
+ status: "Success" | "Failure";
37
+ };
38
+ testCaseResults: TestCaseResult[];
39
+ }
40
+ export interface TestRun {
41
+ id: string;
42
+ url: string;
43
+ status: TestRunStatus;
44
+ progress: TestRunProgress;
45
+ }
46
+ export declare const runAllTests: ({ testsFile, apiToken, commitSha: commitSha_, baseCommitSha, appUrl, useAssetsSnapshottedInBaseSimulation, executionOptions, screenshottingOptions, parallelTasks, deflake, useCache, githubSummary, onTestRunCreated, onTestFinished, }: Options) => Promise<RunAllTestsResult>;
@@ -0,0 +1,169 @@
1
+ "use strict";
2
+ var __importDefault = (this && this.__importDefault) || function (mod) {
3
+ return (mod && mod.__esModule) ? mod : { "default": mod };
4
+ };
5
+ Object.defineProperty(exports, "__esModule", { value: true });
6
+ exports.runAllTests = void 0;
7
+ const common_1 = require("@alwaysmeticulous/common");
8
+ const loglevel_1 = __importDefault(require("loglevel"));
9
+ const client_1 = require("../api/client");
10
+ const test_run_api_1 = require("../api/test-run.api");
11
+ const config_1 = require("../config/config");
12
+ const deflake_tests_handler_1 = require("../deflake-tests/deflake-tests.handler");
13
+ const replay_assets_1 = require("../local-data/replay-assets");
14
+ const parallel_tests_handler_1 = require("../parallel-tests/parallel-tests.handler");
15
+ const commit_sha_utils_1 = require("../utils/commit-sha.utils");
16
+ const config_utils_1 = require("../utils/config.utils");
17
+ const github_summary_utils_1 = require("../utils/github-summary.utils");
18
+ const run_all_tests_utils_1 = require("../utils/run-all-tests.utils");
19
+ const version_utils_1 = require("../utils/version.utils");
20
+ const runAllTests = async ({ testsFile, apiToken, commitSha: commitSha_, baseCommitSha, appUrl, useAssetsSnapshottedInBaseSimulation, executionOptions, screenshottingOptions, parallelTasks, deflake, useCache, githubSummary, onTestRunCreated, onTestFinished, }) => {
21
+ if (appUrl != null && useAssetsSnapshottedInBaseSimulation) {
22
+ throw new Error("Arguments useAssetsSnapshottedInBaseSimulation and appUrl are mutually exclusive");
23
+ }
24
+ const logger = loglevel_1.default.getLogger(common_1.METICULOUS_LOGGER_NAME);
25
+ const client = (0, client_1.createClient)({ apiToken });
26
+ const config = await (0, config_1.readConfig)(testsFile || undefined);
27
+ const testCases = config.testCases || [];
28
+ if (!testCases.length) {
29
+ throw new Error("Error! No test case defined");
30
+ }
31
+ const commitSha = (await (0, commit_sha_utils_1.getCommitSha)(commitSha_)) || "unknown";
32
+ const meticulousSha = await (0, version_utils_1.getMeticulousVersion)();
33
+ const cachedTestRunResults = useCache
34
+ ? await (0, test_run_api_1.getCachedTestRunResults)({ client, commitSha })
35
+ : [];
36
+ const replayEventsDependencies = await (0, replay_assets_1.loadReplayEventsDependencies)();
37
+ const testRun = await (0, test_run_api_1.createTestRun)({
38
+ client,
39
+ commitSha,
40
+ meticulousSha,
41
+ configData: config,
42
+ });
43
+ const testRunUrl = (0, test_run_api_1.getTestRunUrl)(testRun);
44
+ onTestRunCreated === null || onTestRunCreated === void 0 ? void 0 : onTestRunCreated({
45
+ id: testRun.id,
46
+ url: testRunUrl,
47
+ status: "Running",
48
+ progress: {
49
+ failedTestCases: 0,
50
+ passedTestCases: 0,
51
+ runningTestCases: testCases.length,
52
+ },
53
+ });
54
+ logger.info("");
55
+ logger.info(`Test run URL: ${testRunUrl}`);
56
+ logger.info("");
57
+ const getResults = async () => {
58
+ if (parallelTasks == null || parallelTasks > 1) {
59
+ const results = await (0, parallel_tests_handler_1.runAllTestsInParallel)({
60
+ config,
61
+ client,
62
+ testRun,
63
+ executionOptions,
64
+ screenshottingOptions,
65
+ apiToken,
66
+ commitSha,
67
+ appUrl,
68
+ useAssetsSnapshottedInBaseSimulation,
69
+ parallelTasks,
70
+ deflake,
71
+ cachedTestRunResults,
72
+ replayEventsDependencies,
73
+ baseCommitSha,
74
+ onTestFinished: (progress) => {
75
+ onTestFinished === null || onTestFinished === void 0 ? void 0 : onTestFinished({
76
+ id: testRun.id,
77
+ url: testRunUrl,
78
+ status: "Running",
79
+ progress,
80
+ });
81
+ },
82
+ });
83
+ return results;
84
+ }
85
+ const results = [...cachedTestRunResults];
86
+ const testsToRun = await (0, run_all_tests_utils_1.getTestsToRun)({
87
+ testCases,
88
+ cachedTestRunResults,
89
+ client,
90
+ baseCommitSha: baseCommitSha !== null && baseCommitSha !== void 0 ? baseCommitSha : null,
91
+ });
92
+ const progress = {
93
+ runningTestCases: testRun.length,
94
+ failedTestCases: 0,
95
+ passedTestCases: 0,
96
+ };
97
+ for (const testCase of testsToRun) {
98
+ const result = await (0, deflake_tests_handler_1.deflakeReplayCommandHandler)({
99
+ replayTarget: (0, config_utils_1.getReplayTargetForTestCase)({
100
+ useAssetsSnapshottedInBaseSimulation,
101
+ appUrl,
102
+ testCase,
103
+ }),
104
+ executionOptions,
105
+ screenshottingOptions,
106
+ testCase,
107
+ apiToken,
108
+ commitSha,
109
+ deflake,
110
+ generatedBy: { type: "testRun", runId: testRun.id },
111
+ testRunId: testRun.id,
112
+ replayEventsDependencies,
113
+ });
114
+ results.push(result);
115
+ progress.failedTestCases += result.result === "fail" ? 1 : 0;
116
+ progress.passedTestCases += result.result === "pass" ? 1 : 0;
117
+ --progress.runningTestCases;
118
+ onTestFinished === null || onTestFinished === void 0 ? void 0 : onTestFinished({
119
+ id: testRun.id,
120
+ url: testRunUrl,
121
+ status: "Running",
122
+ progress,
123
+ });
124
+ await (0, test_run_api_1.putTestRunResults)({
125
+ client,
126
+ testRunId: testRun.id,
127
+ status: "Running",
128
+ resultData: { results },
129
+ });
130
+ }
131
+ return (0, run_all_tests_utils_1.sortResults)({ results, testCases });
132
+ };
133
+ const results = await getResults();
134
+ const runAllFailure = results.find(({ result }) => result === "fail");
135
+ const overallStatus = runAllFailure ? "Failure" : "Success";
136
+ await (0, test_run_api_1.putTestRunResults)({
137
+ client,
138
+ testRunId: testRun.id,
139
+ status: overallStatus,
140
+ resultData: { results },
141
+ });
142
+ logger.info("");
143
+ logger.info("Results");
144
+ logger.info("=======");
145
+ logger.info(`URL: ${testRunUrl}`);
146
+ logger.info("=======");
147
+ results.forEach(({ title, result }) => {
148
+ logger.info(`${title} => ${result}`);
149
+ });
150
+ if (githubSummary) {
151
+ await (0, github_summary_utils_1.writeGitHubSummary)({ testRunUrl, results });
152
+ }
153
+ return {
154
+ testRun: {
155
+ url: testRunUrl,
156
+ id: testRun.id,
157
+ status: overallStatus,
158
+ progress: {
159
+ passedTestCases: results.filter(({ result }) => result === "pass")
160
+ .length,
161
+ failedTestCases: results.filter(({ result }) => result === "fail")
162
+ .length,
163
+ runningTestCases: 0,
164
+ },
165
+ },
166
+ testCaseResults: results,
167
+ };
168
+ };
169
+ exports.runAllTests = runAllTests;
@@ -0,0 +1,5 @@
1
+ export interface TestRunProgress {
2
+ failedTestCases: number;
3
+ passedTestCases: number;
4
+ runningTestCases: number;
5
+ }
@@ -0,0 +1,2 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });