@dvl-software/eip-cypress 0.1.0 → 0.2.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.
- package/CHANGELOG.md +9 -0
- package/README.md +46 -0
- package/dist/cli.js +532 -29
- package/dist/index.cjs +164 -35
- package/dist/index.d.cts +15 -2
- package/dist/index.d.ts +15 -2
- package/dist/index.js +162 -33
- package/package.json +4 -1
package/dist/index.cjs
CHANGED
|
@@ -29,9 +29,9 @@ __export(src_exports, {
|
|
|
29
29
|
});
|
|
30
30
|
module.exports = __toCommonJS(src_exports);
|
|
31
31
|
var import_node_crypto = require("crypto");
|
|
32
|
-
var
|
|
32
|
+
var import_node_fs2 = require("fs");
|
|
33
33
|
var import_promises = require("fs/promises");
|
|
34
|
-
var
|
|
34
|
+
var import_node_path2 = require("path");
|
|
35
35
|
var import_node_zlib = require("zlib");
|
|
36
36
|
|
|
37
37
|
// src/api.ts
|
|
@@ -75,6 +75,17 @@ var EipApi = class {
|
|
|
75
75
|
finish(runId, endedAt) {
|
|
76
76
|
return this.json("POST", `/api/v1/auto-test-results/runs/${runId}/finish`, { ended_at: endedAt });
|
|
77
77
|
}
|
|
78
|
+
/** Parallel runs: the machine's next specs; with `specs` it sends the run's spec list. */
|
|
79
|
+
next(runId, body) {
|
|
80
|
+
return this.json("POST", `/api/v1/auto-test-results/runs/${runId}/next`, body);
|
|
81
|
+
}
|
|
82
|
+
finishMachine(runId, machineId) {
|
|
83
|
+
return this.json("POST", `/api/v1/auto-test-results/runs/${runId}/machines/${machineId}/finish`);
|
|
84
|
+
}
|
|
85
|
+
/** Calls EIP again after it was unreachable (the parallel CLI keeps trying for a while before it gives up). */
|
|
86
|
+
resetReachability() {
|
|
87
|
+
this.networkFailures = 0;
|
|
88
|
+
}
|
|
78
89
|
rerunList(runNumber, projectId) {
|
|
79
90
|
const query = new URLSearchParams({ run_number: String(runNumber) });
|
|
80
91
|
if (projectId) query.set("project_id", projectId);
|
|
@@ -413,7 +424,7 @@ function planSpec(specPath, results, browser, settings) {
|
|
|
413
424
|
const recorded = byKey.get(key(test.title, retry));
|
|
414
425
|
const started = recorded?.wallClockStartedAt ? Date.parse(recorded.wallClockStartedAt) : void 0;
|
|
415
426
|
const isLast = retry === attemptStates.length - 1;
|
|
416
|
-
const error = recorded?.error ?? (isLast && test.displayError ? splitError(test.displayError) : void 0);
|
|
427
|
+
const error = recorded?.error ?? (isLast && test.displayError ? splitError(test.displayError) : void 0) ?? (cyAttempt.state === "failed" && results.error ? specError(results.error) : void 0);
|
|
417
428
|
const pass = new Redaction(settings.extra_redact_fields, settings.extra_redact_patterns);
|
|
418
429
|
const planned = {
|
|
419
430
|
state: cyAttempt.state,
|
|
@@ -466,6 +477,12 @@ function splitError(display) {
|
|
|
466
477
|
const match = /^([A-Za-z]*Error):\s*(.*)$/.exec(firstLine);
|
|
467
478
|
return match ? { name: match[1], message: match[2], stack: display } : { message: firstLine, stack: display };
|
|
468
479
|
}
|
|
480
|
+
var ANSI = /\u001b\[[0-9;]*m/g;
|
|
481
|
+
function specError(text) {
|
|
482
|
+
const plain = text.replace(ANSI, "").trim();
|
|
483
|
+
const message = plain.split(/\n\s*\n/, 1)[0]?.replace(/\s*\n\s*/g, " ") ?? plain;
|
|
484
|
+
return { message, stack: plain };
|
|
485
|
+
}
|
|
469
486
|
function attachScreenshots(tests, results, settings) {
|
|
470
487
|
for (const shot of results.screenshots ?? []) {
|
|
471
488
|
const taken = shot.takenAt ? Date.parse(shot.takenAt) : void 0;
|
|
@@ -555,9 +572,27 @@ function forEachAttempt(tests, fn) {
|
|
|
555
572
|
// src/context.ts
|
|
556
573
|
var import_node_child_process = require("child_process");
|
|
557
574
|
var TRUE = ["1", "true", "yes"];
|
|
575
|
+
function buildIdFrom(env) {
|
|
576
|
+
const own = env.EIP_CI_BUILD_ID?.trim();
|
|
577
|
+
if (own) return own;
|
|
578
|
+
if (env.GITHUB_ACTIONS === "true" && env.GITHUB_RUN_ID) return `github-${env.GITHUB_RUN_ID}-${env.GITHUB_RUN_ATTEMPT || "1"}`;
|
|
579
|
+
return void 0;
|
|
580
|
+
}
|
|
581
|
+
function positiveInt(value, max) {
|
|
582
|
+
const n = Number(value?.trim());
|
|
583
|
+
return Number.isInteger(n) && n >= 1 ? Math.min(n, max) : void 0;
|
|
584
|
+
}
|
|
558
585
|
function readOptions(env = process.env) {
|
|
559
586
|
const rerun = env.EIP_RERUN_OF?.trim().replace(/^#/, "");
|
|
560
587
|
return {
|
|
588
|
+
buildId: buildIdFrom(env)?.slice(0, 200),
|
|
589
|
+
group: env.EIP_GROUP?.trim().slice(0, 100) || void 0,
|
|
590
|
+
totalMachines: positiveInt(env.EIP_PARALLEL_TOTAL, 1e3),
|
|
591
|
+
batch: positiveInt(env.EIP_PARALLEL_BATCH, 100) ?? 1,
|
|
592
|
+
machineId: env.EIP_MACHINE_ID?.trim() || void 0,
|
|
593
|
+
parallelSeed: TRUE.includes((env.EIP_PARALLEL_SEED ?? "").toLowerCase()),
|
|
594
|
+
parallelStateFile: env.EIP_PARALLEL_STATE?.trim() || void 0,
|
|
595
|
+
parallelSpec: env.EIP_PARALLEL_SPEC?.trim() || void 0,
|
|
561
596
|
apiKey: env.EIP_API_KEY?.trim() || void 0,
|
|
562
597
|
apiUrl: env.EIP_API_URL?.trim().replace(/\/+$/, "") || void 0,
|
|
563
598
|
projectId: env.EIP_PROJECT_ID?.trim() || void 0,
|
|
@@ -610,6 +645,84 @@ function runGit(args) {
|
|
|
610
645
|
}
|
|
611
646
|
}
|
|
612
647
|
|
|
648
|
+
// src/parallel.ts
|
|
649
|
+
var import_node_fs = require("fs");
|
|
650
|
+
var import_node_os = require("os");
|
|
651
|
+
var import_node_path = require("path");
|
|
652
|
+
var import_tinyglobby = require("tinyglobby");
|
|
653
|
+
var ALWAYS_IGNORED = ["**/node_modules/**"];
|
|
654
|
+
var UNSAFE_SPEC = /(^|\/)\.\.(\/|$)|^\/|^[A-Za-z]:|["%^&|<>,\p{Cc}]/u;
|
|
655
|
+
function isShareableSpec(path) {
|
|
656
|
+
return path.length > 0 && !UNSAFE_SPEC.test(posixPath(path));
|
|
657
|
+
}
|
|
658
|
+
function list(value) {
|
|
659
|
+
if (Array.isArray(value)) return value.filter((v) => typeof v === "string" && v.length > 0);
|
|
660
|
+
return typeof value === "string" && value.length > 0 ? [value] : [];
|
|
661
|
+
}
|
|
662
|
+
function real(path) {
|
|
663
|
+
try {
|
|
664
|
+
return (0, import_node_fs.realpathSync)(path);
|
|
665
|
+
} catch {
|
|
666
|
+
return path;
|
|
667
|
+
}
|
|
668
|
+
}
|
|
669
|
+
async function findSpecs(config, userSpec, cwd = process.cwd()) {
|
|
670
|
+
const root = real(config.projectRoot ?? cwd);
|
|
671
|
+
const ignore = [...list(config.excludeSpecPattern), ...ALWAYS_IGNORED];
|
|
672
|
+
const found = userSpec ? (await (0, import_tinyglobby.glob)(userSpec.split(",").map((s) => s.trim()).filter(Boolean), { cwd: real(cwd), ignore, absolute: true })).map((p) => (0, import_node_path.relative)(root, real(p))) : await (0, import_tinyglobby.glob)(list(config.specPattern).map((p) => (0, import_node_path.isAbsolute)(p) ? posixPath((0, import_node_path.relative)(root, real(p))) : p), { cwd: root, ignore });
|
|
673
|
+
return [...new Set(found.map(posixPath))].filter((p) => !p.startsWith("../") && !(0, import_node_path.isAbsolute)(p)).sort();
|
|
674
|
+
}
|
|
675
|
+
function literal(root, spec) {
|
|
676
|
+
return escapeGlob(posixPath((0, import_node_path.resolve)(root, spec)));
|
|
677
|
+
}
|
|
678
|
+
function specPatternFor(root, specs) {
|
|
679
|
+
const safe = specs.filter(isShareableSpec);
|
|
680
|
+
return safe.length ? safe.map((s) => literal(root, s)) : [posixPath((0, import_node_path.resolve)(root, "__eip_no_spec__"))];
|
|
681
|
+
}
|
|
682
|
+
function escapeGlob(path) {
|
|
683
|
+
return path.replace(/[*?[\]{}()!+@]/g, "\\$&");
|
|
684
|
+
}
|
|
685
|
+
var CI_MARKERS = ["CI", "GITHUB_ACTIONS", "GITLAB_CI", "BUILDKITE", "JENKINS_URL", "TF_BUILD", "CIRCLECI", "TEAMCITY_VERSION"];
|
|
686
|
+
function shareableHostName(env = process.env) {
|
|
687
|
+
const ci = CI_MARKERS.some((name) => {
|
|
688
|
+
const value = env[name]?.trim().toLowerCase();
|
|
689
|
+
return !!value && value !== "false" && value !== "0";
|
|
690
|
+
});
|
|
691
|
+
return ci ? (0, import_node_os.hostname)().slice(0, 255) : void 0;
|
|
692
|
+
}
|
|
693
|
+
function parallelBlock(opts, env = process.env) {
|
|
694
|
+
return {
|
|
695
|
+
build_id: opts.buildId,
|
|
696
|
+
group: opts.group,
|
|
697
|
+
machine_id: opts.machineId,
|
|
698
|
+
host_name: shareableHostName(env),
|
|
699
|
+
total_machines: opts.totalMachines
|
|
700
|
+
};
|
|
701
|
+
}
|
|
702
|
+
function isParallel(opts) {
|
|
703
|
+
return !!opts.machineId && !!opts.buildId;
|
|
704
|
+
}
|
|
705
|
+
async function seedSpecs(api, runId, opts, config) {
|
|
706
|
+
const found = await findSpecs(config, opts.parallelSpec);
|
|
707
|
+
const specs = found.filter(isShareableSpec);
|
|
708
|
+
const left = found.filter((s) => !isShareableSpec(s));
|
|
709
|
+
if (left.length) {
|
|
710
|
+
console.log(`[EIP] ${left.length} spec file(s) can't be shared between machines because of a character in the path (" % ^ & | < > ,), and don't run with --parallel: ${left.slice(0, 5).join(", ")}${left.length > 5 ? ", \u2026" : ""}`);
|
|
711
|
+
}
|
|
712
|
+
const answer = await api.next(runId, { machine_id: opts.machineId, batch: opts.batch, specs });
|
|
713
|
+
const batch = answer.action === "run" ? answer.specs : [];
|
|
714
|
+
config.specPattern = specPatternFor(config.projectRoot ?? process.cwd(), batch);
|
|
715
|
+
writeState(opts, { specs: batch.filter(isShareableSpec) });
|
|
716
|
+
return batch;
|
|
717
|
+
}
|
|
718
|
+
function writeState(opts, state) {
|
|
719
|
+
if (!opts.parallelStateFile) return;
|
|
720
|
+
try {
|
|
721
|
+
(0, import_node_fs.writeFileSync)(opts.parallelStateFile, JSON.stringify(state));
|
|
722
|
+
} catch {
|
|
723
|
+
}
|
|
724
|
+
}
|
|
725
|
+
|
|
613
726
|
// src/index.ts
|
|
614
727
|
var LOG_PREFIX = "[EIP]";
|
|
615
728
|
var MAX_SPEC_BODY_BYTES = 7 * 1024 * 1024;
|
|
@@ -661,29 +774,47 @@ async function setupEip(on, config, options = {}) {
|
|
|
661
774
|
if (opts.rerunOf !== void 0) {
|
|
662
775
|
await applyRerun(api, opts, config, state);
|
|
663
776
|
}
|
|
777
|
+
const parallel = isParallel(opts);
|
|
778
|
+
const openBody = (details) => ({
|
|
779
|
+
client_run_id: clientRunId,
|
|
780
|
+
project_id: opts.projectId,
|
|
781
|
+
name: opts.runName,
|
|
782
|
+
framework: "cypress",
|
|
783
|
+
tool_version: details?.cypressVersion,
|
|
784
|
+
browser: details?.browser ? `${details.browser.displayName ?? details.browser.name} ${details.browser.majorVersion ?? ""}`.trim() : void 0,
|
|
785
|
+
os_name: details?.system ? `${details.system.osName} ${details.system.osVersion}` : void 0,
|
|
786
|
+
spec_count: parallel ? void 0 : details?.specs?.length,
|
|
787
|
+
started_at: (/* @__PURE__ */ new Date()).toISOString(),
|
|
788
|
+
environment: opts.environment,
|
|
789
|
+
rerun_of: opts.rerunOf,
|
|
790
|
+
ci: ciContext(),
|
|
791
|
+
git: gitContext(),
|
|
792
|
+
parallel: parallel ? parallelBlock(opts) : void 0
|
|
793
|
+
});
|
|
794
|
+
const applyOpened = (opened) => {
|
|
795
|
+
state.runId = opened.run_id;
|
|
796
|
+
state.runNumber = opened.run_number;
|
|
797
|
+
state.settings = { ...DEFAULT_SETTINGS, ...withoutNulls(opened.settings) };
|
|
798
|
+
state.storageFull = opened.storage_full;
|
|
799
|
+
};
|
|
800
|
+
if (parallel && opts.parallelSeed) {
|
|
801
|
+
try {
|
|
802
|
+
applyOpened(await api.openRun(openBody()));
|
|
803
|
+
const batch = await seedSpecs(api, state.runId, opts, config);
|
|
804
|
+
console.log(`${LOG_PREFIX} Run #${state.runNumber}: spec list sent; this machine starts with ${batch.length} spec(s).`);
|
|
805
|
+
} catch (e) {
|
|
806
|
+
writeState(opts, { specs: [], error: errorText(e) });
|
|
807
|
+
config.specPattern = [];
|
|
808
|
+
console.log(`${LOG_PREFIX} Could not send the spec list to EIP: ${errorText(e)}.`);
|
|
809
|
+
}
|
|
810
|
+
}
|
|
664
811
|
on("before:run", async (details) => {
|
|
665
812
|
await hooks.beforeRun?.(details);
|
|
666
813
|
try {
|
|
667
|
-
|
|
668
|
-
|
|
669
|
-
|
|
670
|
-
|
|
671
|
-
framework: "cypress",
|
|
672
|
-
tool_version: details.cypressVersion,
|
|
673
|
-
browser: details.browser ? `${details.browser.displayName ?? details.browser.name} ${details.browser.majorVersion ?? ""}`.trim() : void 0,
|
|
674
|
-
os_name: details.system ? `${details.system.osName} ${details.system.osVersion}` : void 0,
|
|
675
|
-
spec_count: details.specs?.length,
|
|
676
|
-
started_at: (/* @__PURE__ */ new Date()).toISOString(),
|
|
677
|
-
environment: opts.environment,
|
|
678
|
-
rerun_of: opts.rerunOf,
|
|
679
|
-
ci: ciContext(),
|
|
680
|
-
git: gitContext()
|
|
681
|
-
});
|
|
682
|
-
state.runId = opened.run_id;
|
|
683
|
-
state.runNumber = opened.run_number;
|
|
684
|
-
state.settings = { ...DEFAULT_SETTINGS, ...withoutNulls(opened.settings) };
|
|
685
|
-
state.storageFull = opened.storage_full;
|
|
686
|
-
console.log(`${LOG_PREFIX} Run #${opened.run_number} opened${opts.rerunOf ? ` (re-run of #${opts.rerunOf})` : ""}.`);
|
|
814
|
+
applyOpened(await api.openRun(openBody(details)));
|
|
815
|
+
if (!parallel) {
|
|
816
|
+
console.log(`${LOG_PREFIX} Run #${state.runNumber} opened${opts.rerunOf ? ` (re-run of #${opts.rerunOf})` : ""}.`);
|
|
817
|
+
}
|
|
687
818
|
if (state.storageFull) {
|
|
688
819
|
console.log(`${LOG_PREFIX} Storage is full: results are sent, videos, screenshots and request logs are not.`);
|
|
689
820
|
}
|
|
@@ -699,7 +830,7 @@ async function setupEip(on, config, options = {}) {
|
|
|
699
830
|
checkRerunMatches(state, spec.relative, results);
|
|
700
831
|
if (!state.runId) return;
|
|
701
832
|
const plan = planSpec(spec.relative, results, { attempts: events }, state.settings);
|
|
702
|
-
await postSpec(api, state, plan);
|
|
833
|
+
await postSpec(api, state, plan, parallel ? opts.machineId : void 0);
|
|
703
834
|
} catch (e) {
|
|
704
835
|
warn(state, `spec:${spec.relative}`, `Could not send ${spec.relative}: ${errorText(e)}`);
|
|
705
836
|
}
|
|
@@ -707,7 +838,7 @@ async function setupEip(on, config, options = {}) {
|
|
|
707
838
|
on("after:run", async (results) => {
|
|
708
839
|
try {
|
|
709
840
|
reportRerunMatches(state);
|
|
710
|
-
await finishRun(api, state);
|
|
841
|
+
if (!parallel) await finishRun(api, state);
|
|
711
842
|
} catch (e) {
|
|
712
843
|
warn(state, "finish", `Could not finish the run in EIP: ${errorText(e)}`);
|
|
713
844
|
} finally {
|
|
@@ -735,16 +866,16 @@ function registerUserHooksOnly(on, hooks) {
|
|
|
735
866
|
}
|
|
736
867
|
async function applyRerun(api, opts, config, state) {
|
|
737
868
|
try {
|
|
738
|
-
const
|
|
739
|
-
if (
|
|
869
|
+
const list2 = await api.rerunList(opts.rerunOf, opts.projectId);
|
|
870
|
+
if (list2.specs.length === 0) {
|
|
740
871
|
console.log(`${LOG_PREFIX} Run #${opts.rerunOf} has no failed or skipped tests \u2014 running everything.`);
|
|
741
872
|
return;
|
|
742
873
|
}
|
|
743
874
|
const root = config.projectRoot ?? process.cwd();
|
|
744
|
-
const specs =
|
|
745
|
-
const gone =
|
|
875
|
+
const specs = list2.specs.map((s) => ({ ...s, spec: posixPath(s.spec) })).filter((s) => !(0, import_node_path2.isAbsolute)(s.spec) && (0, import_node_fs2.existsSync)((0, import_node_path2.join)(root, s.spec)));
|
|
876
|
+
const gone = list2.specs.length - specs.length;
|
|
746
877
|
if (specs.length === 0) {
|
|
747
|
-
console.log(`${LOG_PREFIX} None of the ${
|
|
878
|
+
console.log(`${LOG_PREFIX} None of the ${list2.specs.length} spec file(s) of run #${opts.rerunOf} exists any more \u2014 running everything.`);
|
|
748
879
|
return;
|
|
749
880
|
}
|
|
750
881
|
config.specPattern = specs.map((s) => escapeGlob(s.spec));
|
|
@@ -770,16 +901,13 @@ function reportRerunMatches(state) {
|
|
|
770
901
|
if (!state.rerunTitles || state.rerunFound >= state.rerunExpected) return;
|
|
771
902
|
console.log(`${LOG_PREFIX} Re-run: only ${state.rerunFound} of ${state.rerunExpected} test(s) were found and run.`);
|
|
772
903
|
}
|
|
773
|
-
function escapeGlob(path) {
|
|
774
|
-
return path.replace(/[*?[\]{}()!+@]/g, "\\$&");
|
|
775
|
-
}
|
|
776
904
|
function setExposed(config, name, value) {
|
|
777
905
|
const cfg = config;
|
|
778
906
|
cfg.expose = { ...cfg.expose ?? {}, [name]: value };
|
|
779
907
|
const major = Number(String(cfg.version ?? "").split(".")[0]);
|
|
780
908
|
if (!(major >= 15)) cfg.env = { ...cfg.env ?? {}, [name]: value };
|
|
781
909
|
}
|
|
782
|
-
async function postSpec(api, state, plan) {
|
|
910
|
+
async function postSpec(api, state, plan, machineId) {
|
|
783
911
|
const runId = state.runId;
|
|
784
912
|
const videoId = plan.videoPath ? await uploadFile(api, state, "VIDEO", plan.videoPath) : void 0;
|
|
785
913
|
const tests = [];
|
|
@@ -817,6 +945,7 @@ async function postSpec(api, state, plan) {
|
|
|
817
945
|
ended_at: plan.ended_at,
|
|
818
946
|
duration_ms: plan.duration_ms,
|
|
819
947
|
video_upload_id: videoId,
|
|
948
|
+
machine_id: machineId,
|
|
820
949
|
tests
|
|
821
950
|
};
|
|
822
951
|
if (!fitPayload(tests, MAX_SPEC_BODY_BYTES, () => Buffer.byteLength(JSON.stringify(body)))) {
|
|
@@ -833,7 +962,7 @@ var CONTENT_TYPES = {
|
|
|
833
962
|
".jpeg": "image/jpeg"
|
|
834
963
|
};
|
|
835
964
|
async function uploadFile(api, state, kind, path) {
|
|
836
|
-
const type = CONTENT_TYPES[(0,
|
|
965
|
+
const type = CONTENT_TYPES[(0, import_node_path2.extname)(path).toLowerCase()];
|
|
837
966
|
if (!type || state.storageFull || !state.runId) return void 0;
|
|
838
967
|
let content;
|
|
839
968
|
try {
|
package/dist/index.d.cts
CHANGED
|
@@ -11,6 +11,18 @@ interface PluginOptions {
|
|
|
11
11
|
/** Allows a plain-http EIP_API_URL that isn't localhost. */
|
|
12
12
|
allowHttp: boolean;
|
|
13
13
|
disabled: boolean;
|
|
14
|
+
/** Parallel runs: containers with the same build id (and group) report into one run. */
|
|
15
|
+
buildId?: string;
|
|
16
|
+
group?: string;
|
|
17
|
+
totalMachines?: number;
|
|
18
|
+
/** Specs per Cypress start in a parallel run. */
|
|
19
|
+
batch: number;
|
|
20
|
+
/** Set by `eip-cypress run --parallel` for the Cypress processes it starts. */
|
|
21
|
+
machineId?: string;
|
|
22
|
+
parallelSeed: boolean;
|
|
23
|
+
parallelStateFile?: string;
|
|
24
|
+
/** The user's own `--spec`, which the CLI moves here so the first container can send the matching specs. */
|
|
25
|
+
parallelSpec?: string;
|
|
14
26
|
}
|
|
15
27
|
|
|
16
28
|
/** One cleaning pass; {@link count} tells how many values were removed. */
|
|
@@ -33,6 +45,9 @@ declare class Redaction {
|
|
|
33
45
|
private replace;
|
|
34
46
|
}
|
|
35
47
|
|
|
48
|
+
/** A file path as a literal glob (Cypress resolves specPattern with fast-glob). */
|
|
49
|
+
declare function escapeGlob(path: string): string;
|
|
50
|
+
|
|
36
51
|
/** Your own handlers for events the plugin uses: Cypress keeps only one handler per event, so pass them here. */
|
|
37
52
|
interface EipHooks {
|
|
38
53
|
beforeRun?: (details: Cypress.BeforeRunDetails) => unknown | Promise<unknown>;
|
|
@@ -53,8 +68,6 @@ interface SetupOptions extends Partial<PluginOptions> {
|
|
|
53
68
|
* Without a key it does nothing. It never changes the outcome of the Cypress run.
|
|
54
69
|
*/
|
|
55
70
|
declare function setupEip(on: Cypress.PluginEvents, config: Cypress.PluginConfigOptions, options?: SetupOptions): Promise<Cypress.PluginConfigOptions>;
|
|
56
|
-
/** A file path as a literal glob (Cypress resolves specPattern with fast-glob). */
|
|
57
|
-
declare function escapeGlob(path: string): string;
|
|
58
71
|
declare function hhmmss(ms: number): string;
|
|
59
72
|
|
|
60
73
|
export { type EipHooks, type PluginOptions, Redaction, type SetupOptions, escapeGlob, hhmmss, setupEip };
|
package/dist/index.d.ts
CHANGED
|
@@ -11,6 +11,18 @@ interface PluginOptions {
|
|
|
11
11
|
/** Allows a plain-http EIP_API_URL that isn't localhost. */
|
|
12
12
|
allowHttp: boolean;
|
|
13
13
|
disabled: boolean;
|
|
14
|
+
/** Parallel runs: containers with the same build id (and group) report into one run. */
|
|
15
|
+
buildId?: string;
|
|
16
|
+
group?: string;
|
|
17
|
+
totalMachines?: number;
|
|
18
|
+
/** Specs per Cypress start in a parallel run. */
|
|
19
|
+
batch: number;
|
|
20
|
+
/** Set by `eip-cypress run --parallel` for the Cypress processes it starts. */
|
|
21
|
+
machineId?: string;
|
|
22
|
+
parallelSeed: boolean;
|
|
23
|
+
parallelStateFile?: string;
|
|
24
|
+
/** The user's own `--spec`, which the CLI moves here so the first container can send the matching specs. */
|
|
25
|
+
parallelSpec?: string;
|
|
14
26
|
}
|
|
15
27
|
|
|
16
28
|
/** One cleaning pass; {@link count} tells how many values were removed. */
|
|
@@ -33,6 +45,9 @@ declare class Redaction {
|
|
|
33
45
|
private replace;
|
|
34
46
|
}
|
|
35
47
|
|
|
48
|
+
/** A file path as a literal glob (Cypress resolves specPattern with fast-glob). */
|
|
49
|
+
declare function escapeGlob(path: string): string;
|
|
50
|
+
|
|
36
51
|
/** Your own handlers for events the plugin uses: Cypress keeps only one handler per event, so pass them here. */
|
|
37
52
|
interface EipHooks {
|
|
38
53
|
beforeRun?: (details: Cypress.BeforeRunDetails) => unknown | Promise<unknown>;
|
|
@@ -53,8 +68,6 @@ interface SetupOptions extends Partial<PluginOptions> {
|
|
|
53
68
|
* Without a key it does nothing. It never changes the outcome of the Cypress run.
|
|
54
69
|
*/
|
|
55
70
|
declare function setupEip(on: Cypress.PluginEvents, config: Cypress.PluginConfigOptions, options?: SetupOptions): Promise<Cypress.PluginConfigOptions>;
|
|
56
|
-
/** A file path as a literal glob (Cypress resolves specPattern with fast-glob). */
|
|
57
|
-
declare function escapeGlob(path: string): string;
|
|
58
71
|
declare function hhmmss(ms: number): string;
|
|
59
72
|
|
|
60
73
|
export { type EipHooks, type PluginOptions, Redaction, type SetupOptions, escapeGlob, hhmmss, setupEip };
|
package/dist/index.js
CHANGED
|
@@ -7,7 +7,7 @@ import {
|
|
|
7
7
|
import { randomUUID } from "crypto";
|
|
8
8
|
import { existsSync } from "fs";
|
|
9
9
|
import { readFile } from "fs/promises";
|
|
10
|
-
import { extname, isAbsolute, join } from "path";
|
|
10
|
+
import { extname, isAbsolute as isAbsolute2, join } from "path";
|
|
11
11
|
import { gzipSync } from "zlib";
|
|
12
12
|
|
|
13
13
|
// src/api.ts
|
|
@@ -51,6 +51,17 @@ var EipApi = class {
|
|
|
51
51
|
finish(runId, endedAt) {
|
|
52
52
|
return this.json("POST", `/api/v1/auto-test-results/runs/${runId}/finish`, { ended_at: endedAt });
|
|
53
53
|
}
|
|
54
|
+
/** Parallel runs: the machine's next specs; with `specs` it sends the run's spec list. */
|
|
55
|
+
next(runId, body) {
|
|
56
|
+
return this.json("POST", `/api/v1/auto-test-results/runs/${runId}/next`, body);
|
|
57
|
+
}
|
|
58
|
+
finishMachine(runId, machineId) {
|
|
59
|
+
return this.json("POST", `/api/v1/auto-test-results/runs/${runId}/machines/${machineId}/finish`);
|
|
60
|
+
}
|
|
61
|
+
/** Calls EIP again after it was unreachable (the parallel CLI keeps trying for a while before it gives up). */
|
|
62
|
+
resetReachability() {
|
|
63
|
+
this.networkFailures = 0;
|
|
64
|
+
}
|
|
54
65
|
rerunList(runNumber, projectId) {
|
|
55
66
|
const query = new URLSearchParams({ run_number: String(runNumber) });
|
|
56
67
|
if (projectId) query.set("project_id", projectId);
|
|
@@ -161,7 +172,7 @@ function planSpec(specPath, results, browser, settings) {
|
|
|
161
172
|
const recorded = byKey.get(key(test.title, retry));
|
|
162
173
|
const started = recorded?.wallClockStartedAt ? Date.parse(recorded.wallClockStartedAt) : void 0;
|
|
163
174
|
const isLast = retry === attemptStates.length - 1;
|
|
164
|
-
const error = recorded?.error ?? (isLast && test.displayError ? splitError(test.displayError) : void 0);
|
|
175
|
+
const error = recorded?.error ?? (isLast && test.displayError ? splitError(test.displayError) : void 0) ?? (cyAttempt.state === "failed" && results.error ? specError(results.error) : void 0);
|
|
165
176
|
const pass = new Redaction(settings.extra_redact_fields, settings.extra_redact_patterns);
|
|
166
177
|
const planned = {
|
|
167
178
|
state: cyAttempt.state,
|
|
@@ -214,6 +225,12 @@ function splitError(display) {
|
|
|
214
225
|
const match = /^([A-Za-z]*Error):\s*(.*)$/.exec(firstLine);
|
|
215
226
|
return match ? { name: match[1], message: match[2], stack: display } : { message: firstLine, stack: display };
|
|
216
227
|
}
|
|
228
|
+
var ANSI = /\u001b\[[0-9;]*m/g;
|
|
229
|
+
function specError(text) {
|
|
230
|
+
const plain = text.replace(ANSI, "").trim();
|
|
231
|
+
const message = plain.split(/\n\s*\n/, 1)[0]?.replace(/\s*\n\s*/g, " ") ?? plain;
|
|
232
|
+
return { message, stack: plain };
|
|
233
|
+
}
|
|
217
234
|
function attachScreenshots(tests, results, settings) {
|
|
218
235
|
for (const shot of results.screenshots ?? []) {
|
|
219
236
|
const taken = shot.takenAt ? Date.parse(shot.takenAt) : void 0;
|
|
@@ -303,9 +320,27 @@ function forEachAttempt(tests, fn) {
|
|
|
303
320
|
// src/context.ts
|
|
304
321
|
import { execFileSync } from "child_process";
|
|
305
322
|
var TRUE = ["1", "true", "yes"];
|
|
323
|
+
function buildIdFrom(env) {
|
|
324
|
+
const own = env.EIP_CI_BUILD_ID?.trim();
|
|
325
|
+
if (own) return own;
|
|
326
|
+
if (env.GITHUB_ACTIONS === "true" && env.GITHUB_RUN_ID) return `github-${env.GITHUB_RUN_ID}-${env.GITHUB_RUN_ATTEMPT || "1"}`;
|
|
327
|
+
return void 0;
|
|
328
|
+
}
|
|
329
|
+
function positiveInt(value, max) {
|
|
330
|
+
const n = Number(value?.trim());
|
|
331
|
+
return Number.isInteger(n) && n >= 1 ? Math.min(n, max) : void 0;
|
|
332
|
+
}
|
|
306
333
|
function readOptions(env = process.env) {
|
|
307
334
|
const rerun = env.EIP_RERUN_OF?.trim().replace(/^#/, "");
|
|
308
335
|
return {
|
|
336
|
+
buildId: buildIdFrom(env)?.slice(0, 200),
|
|
337
|
+
group: env.EIP_GROUP?.trim().slice(0, 100) || void 0,
|
|
338
|
+
totalMachines: positiveInt(env.EIP_PARALLEL_TOTAL, 1e3),
|
|
339
|
+
batch: positiveInt(env.EIP_PARALLEL_BATCH, 100) ?? 1,
|
|
340
|
+
machineId: env.EIP_MACHINE_ID?.trim() || void 0,
|
|
341
|
+
parallelSeed: TRUE.includes((env.EIP_PARALLEL_SEED ?? "").toLowerCase()),
|
|
342
|
+
parallelStateFile: env.EIP_PARALLEL_STATE?.trim() || void 0,
|
|
343
|
+
parallelSpec: env.EIP_PARALLEL_SPEC?.trim() || void 0,
|
|
309
344
|
apiKey: env.EIP_API_KEY?.trim() || void 0,
|
|
310
345
|
apiUrl: env.EIP_API_URL?.trim().replace(/\/+$/, "") || void 0,
|
|
311
346
|
projectId: env.EIP_PROJECT_ID?.trim() || void 0,
|
|
@@ -358,6 +393,84 @@ function runGit(args) {
|
|
|
358
393
|
}
|
|
359
394
|
}
|
|
360
395
|
|
|
396
|
+
// src/parallel.ts
|
|
397
|
+
import { realpathSync, writeFileSync } from "fs";
|
|
398
|
+
import { hostname } from "os";
|
|
399
|
+
import { isAbsolute, relative, resolve } from "path";
|
|
400
|
+
import { glob } from "tinyglobby";
|
|
401
|
+
var ALWAYS_IGNORED = ["**/node_modules/**"];
|
|
402
|
+
var UNSAFE_SPEC = /(^|\/)\.\.(\/|$)|^\/|^[A-Za-z]:|["%^&|<>,\p{Cc}]/u;
|
|
403
|
+
function isShareableSpec(path) {
|
|
404
|
+
return path.length > 0 && !UNSAFE_SPEC.test(posixPath(path));
|
|
405
|
+
}
|
|
406
|
+
function list(value) {
|
|
407
|
+
if (Array.isArray(value)) return value.filter((v) => typeof v === "string" && v.length > 0);
|
|
408
|
+
return typeof value === "string" && value.length > 0 ? [value] : [];
|
|
409
|
+
}
|
|
410
|
+
function real(path) {
|
|
411
|
+
try {
|
|
412
|
+
return realpathSync(path);
|
|
413
|
+
} catch {
|
|
414
|
+
return path;
|
|
415
|
+
}
|
|
416
|
+
}
|
|
417
|
+
async function findSpecs(config, userSpec, cwd = process.cwd()) {
|
|
418
|
+
const root = real(config.projectRoot ?? cwd);
|
|
419
|
+
const ignore = [...list(config.excludeSpecPattern), ...ALWAYS_IGNORED];
|
|
420
|
+
const found = userSpec ? (await glob(userSpec.split(",").map((s) => s.trim()).filter(Boolean), { cwd: real(cwd), ignore, absolute: true })).map((p) => relative(root, real(p))) : await glob(list(config.specPattern).map((p) => isAbsolute(p) ? posixPath(relative(root, real(p))) : p), { cwd: root, ignore });
|
|
421
|
+
return [...new Set(found.map(posixPath))].filter((p) => !p.startsWith("../") && !isAbsolute(p)).sort();
|
|
422
|
+
}
|
|
423
|
+
function literal(root, spec) {
|
|
424
|
+
return escapeGlob(posixPath(resolve(root, spec)));
|
|
425
|
+
}
|
|
426
|
+
function specPatternFor(root, specs) {
|
|
427
|
+
const safe = specs.filter(isShareableSpec);
|
|
428
|
+
return safe.length ? safe.map((s) => literal(root, s)) : [posixPath(resolve(root, "__eip_no_spec__"))];
|
|
429
|
+
}
|
|
430
|
+
function escapeGlob(path) {
|
|
431
|
+
return path.replace(/[*?[\]{}()!+@]/g, "\\$&");
|
|
432
|
+
}
|
|
433
|
+
var CI_MARKERS = ["CI", "GITHUB_ACTIONS", "GITLAB_CI", "BUILDKITE", "JENKINS_URL", "TF_BUILD", "CIRCLECI", "TEAMCITY_VERSION"];
|
|
434
|
+
function shareableHostName(env = process.env) {
|
|
435
|
+
const ci = CI_MARKERS.some((name) => {
|
|
436
|
+
const value = env[name]?.trim().toLowerCase();
|
|
437
|
+
return !!value && value !== "false" && value !== "0";
|
|
438
|
+
});
|
|
439
|
+
return ci ? hostname().slice(0, 255) : void 0;
|
|
440
|
+
}
|
|
441
|
+
function parallelBlock(opts, env = process.env) {
|
|
442
|
+
return {
|
|
443
|
+
build_id: opts.buildId,
|
|
444
|
+
group: opts.group,
|
|
445
|
+
machine_id: opts.machineId,
|
|
446
|
+
host_name: shareableHostName(env),
|
|
447
|
+
total_machines: opts.totalMachines
|
|
448
|
+
};
|
|
449
|
+
}
|
|
450
|
+
function isParallel(opts) {
|
|
451
|
+
return !!opts.machineId && !!opts.buildId;
|
|
452
|
+
}
|
|
453
|
+
async function seedSpecs(api, runId, opts, config) {
|
|
454
|
+
const found = await findSpecs(config, opts.parallelSpec);
|
|
455
|
+
const specs = found.filter(isShareableSpec);
|
|
456
|
+
const left = found.filter((s) => !isShareableSpec(s));
|
|
457
|
+
if (left.length) {
|
|
458
|
+
console.log(`[EIP] ${left.length} spec file(s) can't be shared between machines because of a character in the path (" % ^ & | < > ,), and don't run with --parallel: ${left.slice(0, 5).join(", ")}${left.length > 5 ? ", \u2026" : ""}`);
|
|
459
|
+
}
|
|
460
|
+
const answer = await api.next(runId, { machine_id: opts.machineId, batch: opts.batch, specs });
|
|
461
|
+
const batch = answer.action === "run" ? answer.specs : [];
|
|
462
|
+
config.specPattern = specPatternFor(config.projectRoot ?? process.cwd(), batch);
|
|
463
|
+
writeState(opts, { specs: batch.filter(isShareableSpec) });
|
|
464
|
+
return batch;
|
|
465
|
+
}
|
|
466
|
+
function writeState(opts, state) {
|
|
467
|
+
if (!opts.parallelStateFile) return;
|
|
468
|
+
try {
|
|
469
|
+
writeFileSync(opts.parallelStateFile, JSON.stringify(state));
|
|
470
|
+
} catch {
|
|
471
|
+
}
|
|
472
|
+
}
|
|
473
|
+
|
|
361
474
|
// src/index.ts
|
|
362
475
|
var LOG_PREFIX = "[EIP]";
|
|
363
476
|
var MAX_SPEC_BODY_BYTES = 7 * 1024 * 1024;
|
|
@@ -409,29 +522,47 @@ async function setupEip(on, config, options = {}) {
|
|
|
409
522
|
if (opts.rerunOf !== void 0) {
|
|
410
523
|
await applyRerun(api, opts, config, state);
|
|
411
524
|
}
|
|
525
|
+
const parallel = isParallel(opts);
|
|
526
|
+
const openBody = (details) => ({
|
|
527
|
+
client_run_id: clientRunId,
|
|
528
|
+
project_id: opts.projectId,
|
|
529
|
+
name: opts.runName,
|
|
530
|
+
framework: "cypress",
|
|
531
|
+
tool_version: details?.cypressVersion,
|
|
532
|
+
browser: details?.browser ? `${details.browser.displayName ?? details.browser.name} ${details.browser.majorVersion ?? ""}`.trim() : void 0,
|
|
533
|
+
os_name: details?.system ? `${details.system.osName} ${details.system.osVersion}` : void 0,
|
|
534
|
+
spec_count: parallel ? void 0 : details?.specs?.length,
|
|
535
|
+
started_at: (/* @__PURE__ */ new Date()).toISOString(),
|
|
536
|
+
environment: opts.environment,
|
|
537
|
+
rerun_of: opts.rerunOf,
|
|
538
|
+
ci: ciContext(),
|
|
539
|
+
git: gitContext(),
|
|
540
|
+
parallel: parallel ? parallelBlock(opts) : void 0
|
|
541
|
+
});
|
|
542
|
+
const applyOpened = (opened) => {
|
|
543
|
+
state.runId = opened.run_id;
|
|
544
|
+
state.runNumber = opened.run_number;
|
|
545
|
+
state.settings = { ...DEFAULT_SETTINGS, ...withoutNulls(opened.settings) };
|
|
546
|
+
state.storageFull = opened.storage_full;
|
|
547
|
+
};
|
|
548
|
+
if (parallel && opts.parallelSeed) {
|
|
549
|
+
try {
|
|
550
|
+
applyOpened(await api.openRun(openBody()));
|
|
551
|
+
const batch = await seedSpecs(api, state.runId, opts, config);
|
|
552
|
+
console.log(`${LOG_PREFIX} Run #${state.runNumber}: spec list sent; this machine starts with ${batch.length} spec(s).`);
|
|
553
|
+
} catch (e) {
|
|
554
|
+
writeState(opts, { specs: [], error: errorText(e) });
|
|
555
|
+
config.specPattern = [];
|
|
556
|
+
console.log(`${LOG_PREFIX} Could not send the spec list to EIP: ${errorText(e)}.`);
|
|
557
|
+
}
|
|
558
|
+
}
|
|
412
559
|
on("before:run", async (details) => {
|
|
413
560
|
await hooks.beforeRun?.(details);
|
|
414
561
|
try {
|
|
415
|
-
|
|
416
|
-
|
|
417
|
-
|
|
418
|
-
|
|
419
|
-
framework: "cypress",
|
|
420
|
-
tool_version: details.cypressVersion,
|
|
421
|
-
browser: details.browser ? `${details.browser.displayName ?? details.browser.name} ${details.browser.majorVersion ?? ""}`.trim() : void 0,
|
|
422
|
-
os_name: details.system ? `${details.system.osName} ${details.system.osVersion}` : void 0,
|
|
423
|
-
spec_count: details.specs?.length,
|
|
424
|
-
started_at: (/* @__PURE__ */ new Date()).toISOString(),
|
|
425
|
-
environment: opts.environment,
|
|
426
|
-
rerun_of: opts.rerunOf,
|
|
427
|
-
ci: ciContext(),
|
|
428
|
-
git: gitContext()
|
|
429
|
-
});
|
|
430
|
-
state.runId = opened.run_id;
|
|
431
|
-
state.runNumber = opened.run_number;
|
|
432
|
-
state.settings = { ...DEFAULT_SETTINGS, ...withoutNulls(opened.settings) };
|
|
433
|
-
state.storageFull = opened.storage_full;
|
|
434
|
-
console.log(`${LOG_PREFIX} Run #${opened.run_number} opened${opts.rerunOf ? ` (re-run of #${opts.rerunOf})` : ""}.`);
|
|
562
|
+
applyOpened(await api.openRun(openBody(details)));
|
|
563
|
+
if (!parallel) {
|
|
564
|
+
console.log(`${LOG_PREFIX} Run #${state.runNumber} opened${opts.rerunOf ? ` (re-run of #${opts.rerunOf})` : ""}.`);
|
|
565
|
+
}
|
|
435
566
|
if (state.storageFull) {
|
|
436
567
|
console.log(`${LOG_PREFIX} Storage is full: results are sent, videos, screenshots and request logs are not.`);
|
|
437
568
|
}
|
|
@@ -447,7 +578,7 @@ async function setupEip(on, config, options = {}) {
|
|
|
447
578
|
checkRerunMatches(state, spec.relative, results);
|
|
448
579
|
if (!state.runId) return;
|
|
449
580
|
const plan = planSpec(spec.relative, results, { attempts: events }, state.settings);
|
|
450
|
-
await postSpec(api, state, plan);
|
|
581
|
+
await postSpec(api, state, plan, parallel ? opts.machineId : void 0);
|
|
451
582
|
} catch (e) {
|
|
452
583
|
warn(state, `spec:${spec.relative}`, `Could not send ${spec.relative}: ${errorText(e)}`);
|
|
453
584
|
}
|
|
@@ -455,7 +586,7 @@ async function setupEip(on, config, options = {}) {
|
|
|
455
586
|
on("after:run", async (results) => {
|
|
456
587
|
try {
|
|
457
588
|
reportRerunMatches(state);
|
|
458
|
-
await finishRun(api, state);
|
|
589
|
+
if (!parallel) await finishRun(api, state);
|
|
459
590
|
} catch (e) {
|
|
460
591
|
warn(state, "finish", `Could not finish the run in EIP: ${errorText(e)}`);
|
|
461
592
|
} finally {
|
|
@@ -483,16 +614,16 @@ function registerUserHooksOnly(on, hooks) {
|
|
|
483
614
|
}
|
|
484
615
|
async function applyRerun(api, opts, config, state) {
|
|
485
616
|
try {
|
|
486
|
-
const
|
|
487
|
-
if (
|
|
617
|
+
const list2 = await api.rerunList(opts.rerunOf, opts.projectId);
|
|
618
|
+
if (list2.specs.length === 0) {
|
|
488
619
|
console.log(`${LOG_PREFIX} Run #${opts.rerunOf} has no failed or skipped tests \u2014 running everything.`);
|
|
489
620
|
return;
|
|
490
621
|
}
|
|
491
622
|
const root = config.projectRoot ?? process.cwd();
|
|
492
|
-
const specs =
|
|
493
|
-
const gone =
|
|
623
|
+
const specs = list2.specs.map((s) => ({ ...s, spec: posixPath(s.spec) })).filter((s) => !isAbsolute2(s.spec) && existsSync(join(root, s.spec)));
|
|
624
|
+
const gone = list2.specs.length - specs.length;
|
|
494
625
|
if (specs.length === 0) {
|
|
495
|
-
console.log(`${LOG_PREFIX} None of the ${
|
|
626
|
+
console.log(`${LOG_PREFIX} None of the ${list2.specs.length} spec file(s) of run #${opts.rerunOf} exists any more \u2014 running everything.`);
|
|
496
627
|
return;
|
|
497
628
|
}
|
|
498
629
|
config.specPattern = specs.map((s) => escapeGlob(s.spec));
|
|
@@ -518,16 +649,13 @@ function reportRerunMatches(state) {
|
|
|
518
649
|
if (!state.rerunTitles || state.rerunFound >= state.rerunExpected) return;
|
|
519
650
|
console.log(`${LOG_PREFIX} Re-run: only ${state.rerunFound} of ${state.rerunExpected} test(s) were found and run.`);
|
|
520
651
|
}
|
|
521
|
-
function escapeGlob(path) {
|
|
522
|
-
return path.replace(/[*?[\]{}()!+@]/g, "\\$&");
|
|
523
|
-
}
|
|
524
652
|
function setExposed(config, name, value) {
|
|
525
653
|
const cfg = config;
|
|
526
654
|
cfg.expose = { ...cfg.expose ?? {}, [name]: value };
|
|
527
655
|
const major = Number(String(cfg.version ?? "").split(".")[0]);
|
|
528
656
|
if (!(major >= 15)) cfg.env = { ...cfg.env ?? {}, [name]: value };
|
|
529
657
|
}
|
|
530
|
-
async function postSpec(api, state, plan) {
|
|
658
|
+
async function postSpec(api, state, plan, machineId) {
|
|
531
659
|
const runId = state.runId;
|
|
532
660
|
const videoId = plan.videoPath ? await uploadFile(api, state, "VIDEO", plan.videoPath) : void 0;
|
|
533
661
|
const tests = [];
|
|
@@ -565,6 +693,7 @@ async function postSpec(api, state, plan) {
|
|
|
565
693
|
ended_at: plan.ended_at,
|
|
566
694
|
duration_ms: plan.duration_ms,
|
|
567
695
|
video_upload_id: videoId,
|
|
696
|
+
machine_id: machineId,
|
|
568
697
|
tests
|
|
569
698
|
};
|
|
570
699
|
if (!fitPayload(tests, MAX_SPEC_BODY_BYTES, () => Buffer.byteLength(JSON.stringify(body)))) {
|