testit-adapter-cypress 3.7.5
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/README.md +240 -0
- package/dist/browser/commandLog.d.ts +10 -0
- package/dist/browser/commandLog.js +213 -0
- package/dist/browser/events/cypress.d.ts +2 -0
- package/dist/browser/events/cypress.js +38 -0
- package/dist/browser/events/index.d.ts +2 -0
- package/dist/browser/events/index.js +15 -0
- package/dist/browser/events/mocha.d.ts +3 -0
- package/dist/browser/events/mocha.js +80 -0
- package/dist/browser/index.d.ts +1 -0
- package/dist/browser/index.js +14 -0
- package/dist/browser/lifecycle.d.ts +21 -0
- package/dist/browser/lifecycle.js +227 -0
- package/dist/browser/patching.d.ts +5 -0
- package/dist/browser/patching.js +117 -0
- package/dist/browser/runtime.d.ts +31 -0
- package/dist/browser/runtime.js +284 -0
- package/dist/browser/serialize.d.ts +3 -0
- package/dist/browser/serialize.js +57 -0
- package/dist/browser/state.d.ts +28 -0
- package/dist/browser/state.js +80 -0
- package/dist/browser/steps.d.ts +14 -0
- package/dist/browser/steps.js +114 -0
- package/dist/browser/testplan.d.ts +2 -0
- package/dist/browser/testplan.js +55 -0
- package/dist/browser/types.d.ts +35 -0
- package/dist/browser/types.js +30 -0
- package/dist/browser/utils.d.ts +65 -0
- package/dist/browser/utils.js +187 -0
- package/dist/converter.d.ts +43 -0
- package/dist/converter.js +84 -0
- package/dist/index.d.ts +2 -0
- package/dist/index.js +6 -0
- package/dist/models/index.d.ts +0 -0
- package/dist/models/index.js +1 -0
- package/dist/models/status.d.ts +5 -0
- package/dist/models/status.js +9 -0
- package/dist/models/types.d.ts +280 -0
- package/dist/models/types.js +2 -0
- package/dist/node-utils.d.ts +15 -0
- package/dist/node-utils.js +93 -0
- package/dist/reporter.d.ts +24 -0
- package/dist/reporter.js +382 -0
- package/dist/utils.d.ts +17 -0
- package/dist/utils.js +34 -0
- package/package.json +50 -0
|
@@ -0,0 +1,227 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.completeSpecAsync = exports.flushRuntimeMessages = exports.throwAfterSpecCompletion = exports.completeSpecOnAfterHookFailure = exports.completeSpecIfNoAfterHookLeft = exports.reportScreenshot = exports.reportTestEnd = exports.reportTestSkip = exports.completeHookErrorReporting = exports.reportTestOrHookFail = exports.reportTestPass = exports.reportStepStop = exports.reportStepStart = exports.reportTestStart = exports.reportHookEnd = exports.reportHookStart = exports.reportSuiteEnd = exports.reportSuiteStart = exports.reportRunStart = void 0;
|
|
4
|
+
const types_js_1 = require("./types.js");
|
|
5
|
+
const runtime_js_1 = require("./runtime.js");
|
|
6
|
+
const state_js_1 = require("./state.js");
|
|
7
|
+
const steps_js_1 = require("./steps.js");
|
|
8
|
+
const utils_js_1 = require("./utils.js");
|
|
9
|
+
const status_js_1 = require("../models/status.js");
|
|
10
|
+
const reportRunStart = () => {
|
|
11
|
+
(0, state_js_1.enqueueRuntimeMessage)({
|
|
12
|
+
type: "cypress_run_start",
|
|
13
|
+
data: {},
|
|
14
|
+
});
|
|
15
|
+
};
|
|
16
|
+
exports.reportRunStart = reportRunStart;
|
|
17
|
+
const reportSuiteStart = (suite) => {
|
|
18
|
+
(0, state_js_1.enqueueRuntimeMessage)({
|
|
19
|
+
type: "cypress_suite_start",
|
|
20
|
+
data: {
|
|
21
|
+
id: suite.id,
|
|
22
|
+
name: suite.title,
|
|
23
|
+
root: suite.root,
|
|
24
|
+
start: Date.now(),
|
|
25
|
+
},
|
|
26
|
+
});
|
|
27
|
+
};
|
|
28
|
+
exports.reportSuiteStart = reportSuiteStart;
|
|
29
|
+
const reportSuiteEnd = (suite) => {
|
|
30
|
+
(0, state_js_1.enqueueRuntimeMessage)({
|
|
31
|
+
type: "cypress_suite_end",
|
|
32
|
+
data: {
|
|
33
|
+
root: suite.root,
|
|
34
|
+
stop: Date.now(),
|
|
35
|
+
},
|
|
36
|
+
});
|
|
37
|
+
};
|
|
38
|
+
exports.reportSuiteEnd = reportSuiteEnd;
|
|
39
|
+
const reportHookStart = (hook, start) => {
|
|
40
|
+
(0, state_js_1.enqueueRuntimeMessage)({
|
|
41
|
+
type: "cypress_hook_start",
|
|
42
|
+
data: {
|
|
43
|
+
name: hook.title,
|
|
44
|
+
scopeType: hook.hookName.includes("each") ? "each" : "all",
|
|
45
|
+
position: hook.hookName.includes("before") ? "before" : "after",
|
|
46
|
+
start: start ?? Date.now(),
|
|
47
|
+
},
|
|
48
|
+
});
|
|
49
|
+
};
|
|
50
|
+
exports.reportHookStart = reportHookStart;
|
|
51
|
+
const reportHookEnd = (hook) => {
|
|
52
|
+
(0, steps_js_1.finalizeSteps)();
|
|
53
|
+
(0, state_js_1.enqueueRuntimeMessage)({
|
|
54
|
+
type: "cypress_hook_end",
|
|
55
|
+
data: {
|
|
56
|
+
duration: hook.duration ?? 0,
|
|
57
|
+
},
|
|
58
|
+
});
|
|
59
|
+
};
|
|
60
|
+
exports.reportHookEnd = reportHookEnd;
|
|
61
|
+
const reportTestStart = (test) => {
|
|
62
|
+
(0, state_js_1.setCurrentTest)(test);
|
|
63
|
+
(0, state_js_1.enqueueRuntimeMessage)({
|
|
64
|
+
type: "cypress_test_start",
|
|
65
|
+
data: (0, utils_js_1.getTestStartData)(test),
|
|
66
|
+
});
|
|
67
|
+
(0, utils_js_1.markTestAsReported)(test);
|
|
68
|
+
};
|
|
69
|
+
exports.reportTestStart = reportTestStart;
|
|
70
|
+
const reportStepStart = (id, name) => {
|
|
71
|
+
(0, state_js_1.enqueueRuntimeMessage)({
|
|
72
|
+
type: "cypress_step_start",
|
|
73
|
+
data: {
|
|
74
|
+
id,
|
|
75
|
+
name,
|
|
76
|
+
start: Date.now(),
|
|
77
|
+
},
|
|
78
|
+
});
|
|
79
|
+
};
|
|
80
|
+
exports.reportStepStart = reportStepStart;
|
|
81
|
+
const reportStepStop = (step, status, statusDetails) => {
|
|
82
|
+
(0, state_js_1.enqueueRuntimeMessage)({
|
|
83
|
+
type: "cypress_step_stop",
|
|
84
|
+
data: (0, utils_js_1.getStepStopData)(step, status, statusDetails),
|
|
85
|
+
});
|
|
86
|
+
};
|
|
87
|
+
exports.reportStepStop = reportStepStop;
|
|
88
|
+
const reportTestPass = () => {
|
|
89
|
+
(0, state_js_1.enqueueRuntimeMessage)({
|
|
90
|
+
type: "cypress_test_pass",
|
|
91
|
+
data: {},
|
|
92
|
+
});
|
|
93
|
+
};
|
|
94
|
+
exports.reportTestPass = reportTestPass;
|
|
95
|
+
const reportTestOrHookFail = (err) => {
|
|
96
|
+
const status = status_js_1.Status.FAILED;
|
|
97
|
+
const statusDetails = (0, utils_js_1.getMessageAndTraceFromError)(err);
|
|
98
|
+
(0, steps_js_1.stopAllSteps)(status, statusDetails);
|
|
99
|
+
(0, state_js_1.enqueueRuntimeMessage)({
|
|
100
|
+
type: "cypress_fail",
|
|
101
|
+
data: {
|
|
102
|
+
status,
|
|
103
|
+
statusDetails,
|
|
104
|
+
},
|
|
105
|
+
});
|
|
106
|
+
};
|
|
107
|
+
exports.reportTestOrHookFail = reportTestOrHookFail;
|
|
108
|
+
const completeHookErrorReporting = (hook, err) => {
|
|
109
|
+
const isEachHook = hook.hookName.includes("each");
|
|
110
|
+
const suite = hook.parent;
|
|
111
|
+
const testFailData = (0, utils_js_1.getStatusDataOfTestSkippedByHookError)(hook.title, isEachHook, err, suite);
|
|
112
|
+
// Cypress doens't emit 'hook end' if the hook has failed.
|
|
113
|
+
(0, exports.reportHookEnd)(hook);
|
|
114
|
+
// Cypress doens't emit 'test end' if the hook has failed.
|
|
115
|
+
// We must report the test's end manualy in case of a 'before each' hook.
|
|
116
|
+
reportCurrentTestIfAny();
|
|
117
|
+
// Cypress skips the remaining tests in the suite of a failed hook.
|
|
118
|
+
// We should include them to the report manually.
|
|
119
|
+
reportRemainingTests(suite, testFailData);
|
|
120
|
+
};
|
|
121
|
+
exports.completeHookErrorReporting = completeHookErrorReporting;
|
|
122
|
+
const reportTestSkip = (test) => {
|
|
123
|
+
if ((0, utils_js_1.isTestReported)(test)) {
|
|
124
|
+
(0, steps_js_1.stopAllSteps)(status_js_1.Status.SKIPPED, {
|
|
125
|
+
message: "The test was skipped before the command was completed",
|
|
126
|
+
});
|
|
127
|
+
}
|
|
128
|
+
else {
|
|
129
|
+
(0, exports.reportTestStart)(test);
|
|
130
|
+
}
|
|
131
|
+
(0, state_js_1.enqueueRuntimeMessage)({
|
|
132
|
+
type: "cypress_test_skip",
|
|
133
|
+
data: (0, utils_js_1.getTestSkipData)(),
|
|
134
|
+
});
|
|
135
|
+
};
|
|
136
|
+
exports.reportTestSkip = reportTestSkip;
|
|
137
|
+
const reportTestEnd = (test) => {
|
|
138
|
+
(0, steps_js_1.finalizeSteps)();
|
|
139
|
+
(0, state_js_1.enqueueRuntimeMessage)({
|
|
140
|
+
type: "cypress_test_end",
|
|
141
|
+
data: {
|
|
142
|
+
duration: test.duration ?? 0,
|
|
143
|
+
retries: test._retries ?? 0,
|
|
144
|
+
},
|
|
145
|
+
});
|
|
146
|
+
(0, state_js_1.dropCurrentTest)();
|
|
147
|
+
};
|
|
148
|
+
exports.reportTestEnd = reportTestEnd;
|
|
149
|
+
const reportScreenshot = (path, name) => {
|
|
150
|
+
(0, state_js_1.enqueueRuntimeMessage)({
|
|
151
|
+
type: "attachment_path",
|
|
152
|
+
data: { path, name, contentType: types_js_1.ContentType.PNG },
|
|
153
|
+
});
|
|
154
|
+
};
|
|
155
|
+
exports.reportScreenshot = reportScreenshot;
|
|
156
|
+
const completeSpecIfNoAfterHookLeft = (context) => {
|
|
157
|
+
if ((0, utils_js_1.isLastRootAfterHook)(context)) {
|
|
158
|
+
const hook = context.test;
|
|
159
|
+
if (!(0, utils_js_1.isTmsHook)(hook)) {
|
|
160
|
+
(0, exports.reportHookEnd)(hook);
|
|
161
|
+
}
|
|
162
|
+
return (0, exports.completeSpecAsync)();
|
|
163
|
+
}
|
|
164
|
+
};
|
|
165
|
+
exports.completeSpecIfNoAfterHookLeft = completeSpecIfNoAfterHookLeft;
|
|
166
|
+
const completeSpecOnAfterHookFailure = (context, hookError) => {
|
|
167
|
+
try {
|
|
168
|
+
(0, exports.reportTestOrHookFail)(hookError);
|
|
169
|
+
(0, exports.completeHookErrorReporting)(context.test, hookError);
|
|
170
|
+
// cy.task's then doesn't have onrejected, that's why we don't log async errors here.
|
|
171
|
+
return (0, exports.completeSpecAsync)();
|
|
172
|
+
}
|
|
173
|
+
catch (e) {
|
|
174
|
+
logTmsRootAfterError(context, e);
|
|
175
|
+
}
|
|
176
|
+
};
|
|
177
|
+
exports.completeSpecOnAfterHookFailure = completeSpecOnAfterHookFailure;
|
|
178
|
+
const throwAfterSpecCompletion = (context, err) => {
|
|
179
|
+
const chain = (0, exports.completeSpecOnAfterHookFailure)(context, err)?.then(() => {
|
|
180
|
+
throw err;
|
|
181
|
+
});
|
|
182
|
+
if (!chain) {
|
|
183
|
+
throw err;
|
|
184
|
+
}
|
|
185
|
+
};
|
|
186
|
+
exports.throwAfterSpecCompletion = throwAfterSpecCompletion;
|
|
187
|
+
const flushRuntimeMessages = () => (0, runtime_js_1.getTestRuntime)().flushTmsMessagesToTask("reportTmsCypressSpecMessages");
|
|
188
|
+
exports.flushRuntimeMessages = flushRuntimeMessages;
|
|
189
|
+
const completeSpecAsync = () => (0, runtime_js_1.getTestRuntime)().flushTmsMessagesToTaskAsync("reportFinalTmsCypressSpecMessages");
|
|
190
|
+
exports.completeSpecAsync = completeSpecAsync;
|
|
191
|
+
const reportCurrentTestIfAny = () => {
|
|
192
|
+
const currentTest = (0, state_js_1.getCurrentTest)();
|
|
193
|
+
if (currentTest) {
|
|
194
|
+
(0, exports.reportTestEnd)(currentTest);
|
|
195
|
+
(0, utils_js_1.markTestAsReported)(currentTest);
|
|
196
|
+
}
|
|
197
|
+
};
|
|
198
|
+
const reportRemainingTests = (suite, testFailData) => {
|
|
199
|
+
for (const test of (0, utils_js_1.iterateTests)(suite)) {
|
|
200
|
+
// Some tests in the suite might've been already reported (e.g. current test got test_end above).
|
|
201
|
+
if (!(0, utils_js_1.isTestReported)(test)) {
|
|
202
|
+
reportTestsSkippedByHookError(test, test.pending ? { ...(0, utils_js_1.getTestSkipData)(), status: status_js_1.Status.SKIPPED } : testFailData);
|
|
203
|
+
}
|
|
204
|
+
}
|
|
205
|
+
};
|
|
206
|
+
const reportTestsSkippedByHookError = (test, testFailData) => {
|
|
207
|
+
(0, state_js_1.enqueueRuntimeMessage)({
|
|
208
|
+
type: "cypress_skipped_test",
|
|
209
|
+
data: {
|
|
210
|
+
...(0, utils_js_1.getTestStartData)(test),
|
|
211
|
+
...testFailData,
|
|
212
|
+
...(0, utils_js_1.getTestStopData)(test),
|
|
213
|
+
suites: (0, utils_js_1.getSuitePath)(test).map((s) => s.id),
|
|
214
|
+
},
|
|
215
|
+
});
|
|
216
|
+
(0, utils_js_1.markTestAsReported)(test);
|
|
217
|
+
};
|
|
218
|
+
const logTmsRootAfterError = (context, err) => {
|
|
219
|
+
// We play safe and swallow errors here to keep the original 'after all' error.
|
|
220
|
+
try {
|
|
221
|
+
// eslint-disable-next-line no-console
|
|
222
|
+
console.error(`Unexpected error when reporting the failure of ${context.test?.title ?? "'after all'"}`);
|
|
223
|
+
// eslint-disable-next-line no-console
|
|
224
|
+
console.error(err);
|
|
225
|
+
}
|
|
226
|
+
catch { }
|
|
227
|
+
};
|
|
@@ -0,0 +1,117 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.enableScopeLevelAfterHookReporting = void 0;
|
|
4
|
+
const lifecycle_js_1 = require("./lifecycle.js");
|
|
5
|
+
const utils_js_1 = require("./utils.js");
|
|
6
|
+
/**
|
|
7
|
+
* Patches the `after` function, to inject reporting of spec-level
|
|
8
|
+
* `after` hooks defined by the user.
|
|
9
|
+
*/
|
|
10
|
+
const enableScopeLevelAfterHookReporting = () => {
|
|
11
|
+
const suiteDepthCounter = createSuiteDepthCounterState();
|
|
12
|
+
patchDescribe(suiteDepthCounter);
|
|
13
|
+
patchAfter(suiteDepthCounter);
|
|
14
|
+
};
|
|
15
|
+
exports.enableScopeLevelAfterHookReporting = enableScopeLevelAfterHookReporting;
|
|
16
|
+
const createSuiteDepthCounterState = () => {
|
|
17
|
+
let suiteDepth = 0;
|
|
18
|
+
return {
|
|
19
|
+
getSuiteDepth: () => suiteDepth,
|
|
20
|
+
incrementSuiteDepth: () => {
|
|
21
|
+
suiteDepth++;
|
|
22
|
+
},
|
|
23
|
+
decrementSuiteDepth: () => {
|
|
24
|
+
suiteDepth--;
|
|
25
|
+
},
|
|
26
|
+
};
|
|
27
|
+
};
|
|
28
|
+
const patchDescribe = ({ incrementSuiteDepth, decrementSuiteDepth }) => {
|
|
29
|
+
const patchDescribeFn = (target) => (title, configOrFn, fn) => {
|
|
30
|
+
incrementSuiteDepth();
|
|
31
|
+
try {
|
|
32
|
+
return forwardDescribeCall(target, title, configOrFn, fn);
|
|
33
|
+
}
|
|
34
|
+
finally {
|
|
35
|
+
decrementSuiteDepth();
|
|
36
|
+
}
|
|
37
|
+
};
|
|
38
|
+
const originalDescribeFn = globalThis.describe;
|
|
39
|
+
const patchedDescribe = patchDescribeFn(originalDescribeFn);
|
|
40
|
+
patchedDescribe.only = patchDescribeFn(originalDescribeFn.only);
|
|
41
|
+
patchedDescribe.skip = patchDescribeFn(originalDescribeFn.skip);
|
|
42
|
+
globalThis.describe = patchedDescribe;
|
|
43
|
+
};
|
|
44
|
+
const patchAfter = ({ getSuiteDepth }) => {
|
|
45
|
+
const originalAfter = globalThis.after;
|
|
46
|
+
const patchedAfter = (nameOrFn, fn) => {
|
|
47
|
+
return typeof nameOrFn === "string"
|
|
48
|
+
? originalAfter(nameOrFn, wrapRootAfterFn(getSuiteDepth, fn))
|
|
49
|
+
: originalAfter(wrapRootAfterFn(getSuiteDepth, nameOrFn));
|
|
50
|
+
};
|
|
51
|
+
globalThis.after = patchedAfter;
|
|
52
|
+
};
|
|
53
|
+
const forwardDescribeCall = (target, ...args) => {
|
|
54
|
+
const [title, configOrFn, fn] = args;
|
|
55
|
+
if (typeof fn === "undefined" && typeof configOrFn === "undefined") {
|
|
56
|
+
return target(title);
|
|
57
|
+
}
|
|
58
|
+
else if (typeof configOrFn === "function") {
|
|
59
|
+
return target(title, configOrFn);
|
|
60
|
+
}
|
|
61
|
+
else {
|
|
62
|
+
return target(title, configOrFn, fn);
|
|
63
|
+
}
|
|
64
|
+
};
|
|
65
|
+
const wrapRootAfterFn = (getSuiteDepth, fn) => {
|
|
66
|
+
if (getSuiteDepth() === 0 && fn) {
|
|
67
|
+
const wrappedFn = fn.length ? wrapAfterFnWithCallback(fn) : wrapAfterFnWithoutArgs(fn);
|
|
68
|
+
Object.defineProperty(wrappedFn, "name", { value: fn.name });
|
|
69
|
+
return wrappedFn;
|
|
70
|
+
}
|
|
71
|
+
return fn;
|
|
72
|
+
};
|
|
73
|
+
const wrapAfterFnWithCallback = (fn) => {
|
|
74
|
+
return function (done) {
|
|
75
|
+
const wrappedDone = (hookError) => {
|
|
76
|
+
if (hookError) {
|
|
77
|
+
if (!(0, lifecycle_js_1.completeSpecOnAfterHookFailure)(this, hookError)?.then(() => done(hookError))) {
|
|
78
|
+
done(hookError);
|
|
79
|
+
}
|
|
80
|
+
return;
|
|
81
|
+
}
|
|
82
|
+
try {
|
|
83
|
+
if ((0, lifecycle_js_1.completeSpecIfNoAfterHookLeft)(this)?.then(() => done())) {
|
|
84
|
+
return;
|
|
85
|
+
}
|
|
86
|
+
}
|
|
87
|
+
catch (e) {
|
|
88
|
+
done(e);
|
|
89
|
+
return;
|
|
90
|
+
}
|
|
91
|
+
done();
|
|
92
|
+
};
|
|
93
|
+
return fn.bind(this)(wrappedDone);
|
|
94
|
+
};
|
|
95
|
+
};
|
|
96
|
+
const wrapAfterFnWithoutArgs = (fn) => {
|
|
97
|
+
return function () {
|
|
98
|
+
let result;
|
|
99
|
+
let syncError;
|
|
100
|
+
try {
|
|
101
|
+
result = fn.bind(this)();
|
|
102
|
+
}
|
|
103
|
+
catch (e) {
|
|
104
|
+
syncError = e;
|
|
105
|
+
}
|
|
106
|
+
if (syncError) {
|
|
107
|
+
(0, lifecycle_js_1.throwAfterSpecCompletion)(this, syncError);
|
|
108
|
+
}
|
|
109
|
+
else if ((0, utils_js_1.isPromise)(result)) {
|
|
110
|
+
return result.then(() => (0, lifecycle_js_1.completeSpecIfNoAfterHookLeft)(this), (asyncError) => (0, lifecycle_js_1.throwAfterSpecCompletion)(this, asyncError));
|
|
111
|
+
}
|
|
112
|
+
else {
|
|
113
|
+
(0, lifecycle_js_1.completeSpecIfNoAfterHookLeft)(this);
|
|
114
|
+
return result;
|
|
115
|
+
}
|
|
116
|
+
};
|
|
117
|
+
};
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
import { Label, Link, Status } from "testit-js-commons";
|
|
2
|
+
import type { AttachmentOptions, TestRuntime } from "./types.js";
|
|
3
|
+
import type { StatusDetails } from "../models/types.js";
|
|
4
|
+
export declare const initTestRuntime: () => void;
|
|
5
|
+
export declare const getTestRuntime: () => TmsCypressTestRuntime;
|
|
6
|
+
declare class TmsCypressTestRuntime implements TestRuntime {
|
|
7
|
+
#private;
|
|
8
|
+
constructor();
|
|
9
|
+
addLabels(...labels: Label[]): PromiseLike<void>;
|
|
10
|
+
addTags(...tags: string[]): PromiseLike<void>;
|
|
11
|
+
addLinks(...links: Link[]): PromiseLike<void>;
|
|
12
|
+
addWorkItemIds(...workItemIds: string[]): PromiseLike<void>;
|
|
13
|
+
addParameter(name: string, value: string): PromiseLike<void>;
|
|
14
|
+
addDescription(markdown: string): PromiseLike<void>;
|
|
15
|
+
addTitle(markdown: string): PromiseLike<void>;
|
|
16
|
+
addDisplayName(name: string): PromiseLike<void>;
|
|
17
|
+
addNameSpace(name: string): PromiseLike<void>;
|
|
18
|
+
addClassName(name: string): PromiseLike<void>;
|
|
19
|
+
addAttachments(name: string, content: Buffer | string, options: AttachmentOptions): PromiseLike<void>;
|
|
20
|
+
addAttachmentsFromPath(name: string, path: string, options: Omit<AttachmentOptions, "encoding">): PromiseLike<void>;
|
|
21
|
+
addGlobalAttachments(name: string, content: Buffer | string, options: AttachmentOptions): PromiseLike<void>;
|
|
22
|
+
addGlobalAttachmentsFromPath(name: string, path: string, options: Omit<AttachmentOptions, "encoding">): PromiseLike<void>;
|
|
23
|
+
addMessage(details: StatusDetails): PromiseLike<void>;
|
|
24
|
+
logStep(name: string, status?: Status, error?: Error): PromiseLike<void>;
|
|
25
|
+
step<T = void>(name: string, body: () => T | PromiseLike<T>): Cypress.ThenReturn<T, T>;
|
|
26
|
+
stepDisplayName(name: string): PromiseLike<void>;
|
|
27
|
+
stepParameter(name: string, value: string): PromiseLike<void>;
|
|
28
|
+
flushTmsMessagesToTask(taskName: string): void;
|
|
29
|
+
flushTmsMessagesToTaskAsync(taskName: string): Cypress.Chainable<unknown> | undefined;
|
|
30
|
+
}
|
|
31
|
+
export {};
|
|
@@ -0,0 +1,284 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __classPrivateFieldGet = (this && this.__classPrivateFieldGet) || function (receiver, state, kind, f) {
|
|
3
|
+
if (kind === "a" && !f) throw new TypeError("Private accessor was defined without a getter");
|
|
4
|
+
if (typeof state === "function" ? receiver !== state || !f : !state.has(receiver)) throw new TypeError("Cannot read private member from an object whose class did not declare it");
|
|
5
|
+
return kind === "m" ? f : kind === "a" ? f.call(receiver) : f ? f.value : state.get(receiver);
|
|
6
|
+
};
|
|
7
|
+
var _TmsCypressTestRuntime_instances, _TmsCypressTestRuntime_resetMessages, _TmsCypressTestRuntime_enqueueMessageAsync, _TmsCypressTestRuntime_dequeueAllMessages, _TmsCypressTestRuntime_buildAttachmentContent, _TmsCypressTestRuntime_normalizeAttachmentContent, _TmsCypressTestRuntime_isSerializedBuffer, _TmsCypressTestRuntime_isInOriginContext;
|
|
8
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
9
|
+
exports.getTestRuntime = exports.initTestRuntime = void 0;
|
|
10
|
+
const testit_js_commons_1 = require("testit-js-commons");
|
|
11
|
+
const state_js_1 = require("./state.js");
|
|
12
|
+
const steps_js_1 = require("./steps.js");
|
|
13
|
+
const utils_js_1 = require("./utils.js");
|
|
14
|
+
const initTestRuntime = () => (0, utils_js_1.setGlobalTestRuntime)(new TmsCypressTestRuntime());
|
|
15
|
+
exports.initTestRuntime = initTestRuntime;
|
|
16
|
+
const getTestRuntime = () => (0, utils_js_1.getGlobalTestRuntime)();
|
|
17
|
+
exports.getTestRuntime = getTestRuntime;
|
|
18
|
+
class TmsCypressTestRuntime {
|
|
19
|
+
constructor() {
|
|
20
|
+
_TmsCypressTestRuntime_instances.add(this);
|
|
21
|
+
__classPrivateFieldGet(this, _TmsCypressTestRuntime_instances, "m", _TmsCypressTestRuntime_resetMessages).call(this);
|
|
22
|
+
}
|
|
23
|
+
addLabels(...labels) {
|
|
24
|
+
return __classPrivateFieldGet(this, _TmsCypressTestRuntime_instances, "m", _TmsCypressTestRuntime_enqueueMessageAsync).call(this, {
|
|
25
|
+
type: "metadata",
|
|
26
|
+
data: {
|
|
27
|
+
labels,
|
|
28
|
+
},
|
|
29
|
+
});
|
|
30
|
+
}
|
|
31
|
+
addTags(...tags) {
|
|
32
|
+
return __classPrivateFieldGet(this, _TmsCypressTestRuntime_instances, "m", _TmsCypressTestRuntime_enqueueMessageAsync).call(this, {
|
|
33
|
+
type: "metadata",
|
|
34
|
+
data: {
|
|
35
|
+
tags,
|
|
36
|
+
},
|
|
37
|
+
});
|
|
38
|
+
}
|
|
39
|
+
addLinks(...links) {
|
|
40
|
+
return __classPrivateFieldGet(this, _TmsCypressTestRuntime_instances, "m", _TmsCypressTestRuntime_enqueueMessageAsync).call(this, {
|
|
41
|
+
type: "metadata",
|
|
42
|
+
data: {
|
|
43
|
+
links,
|
|
44
|
+
},
|
|
45
|
+
});
|
|
46
|
+
}
|
|
47
|
+
addWorkItemIds(...workItemIds) {
|
|
48
|
+
return __classPrivateFieldGet(this, _TmsCypressTestRuntime_instances, "m", _TmsCypressTestRuntime_enqueueMessageAsync).call(this, {
|
|
49
|
+
type: "metadata",
|
|
50
|
+
data: {
|
|
51
|
+
workItemIds,
|
|
52
|
+
},
|
|
53
|
+
});
|
|
54
|
+
}
|
|
55
|
+
addParameter(name, value) {
|
|
56
|
+
return __classPrivateFieldGet(this, _TmsCypressTestRuntime_instances, "m", _TmsCypressTestRuntime_enqueueMessageAsync).call(this, {
|
|
57
|
+
type: "metadata",
|
|
58
|
+
data: {
|
|
59
|
+
parameters: [
|
|
60
|
+
{
|
|
61
|
+
name,
|
|
62
|
+
value
|
|
63
|
+
},
|
|
64
|
+
],
|
|
65
|
+
},
|
|
66
|
+
});
|
|
67
|
+
}
|
|
68
|
+
addDescription(markdown) {
|
|
69
|
+
return __classPrivateFieldGet(this, _TmsCypressTestRuntime_instances, "m", _TmsCypressTestRuntime_enqueueMessageAsync).call(this, {
|
|
70
|
+
type: "metadata",
|
|
71
|
+
data: {
|
|
72
|
+
description: markdown,
|
|
73
|
+
},
|
|
74
|
+
});
|
|
75
|
+
}
|
|
76
|
+
addTitle(markdown) {
|
|
77
|
+
return __classPrivateFieldGet(this, _TmsCypressTestRuntime_instances, "m", _TmsCypressTestRuntime_enqueueMessageAsync).call(this, {
|
|
78
|
+
type: "metadata",
|
|
79
|
+
data: {
|
|
80
|
+
title: markdown,
|
|
81
|
+
},
|
|
82
|
+
});
|
|
83
|
+
}
|
|
84
|
+
addDisplayName(name) {
|
|
85
|
+
return __classPrivateFieldGet(this, _TmsCypressTestRuntime_instances, "m", _TmsCypressTestRuntime_enqueueMessageAsync).call(this, {
|
|
86
|
+
type: "metadata",
|
|
87
|
+
data: {
|
|
88
|
+
displayName: name,
|
|
89
|
+
},
|
|
90
|
+
});
|
|
91
|
+
}
|
|
92
|
+
addNameSpace(name) {
|
|
93
|
+
return __classPrivateFieldGet(this, _TmsCypressTestRuntime_instances, "m", _TmsCypressTestRuntime_enqueueMessageAsync).call(this, {
|
|
94
|
+
type: "metadata",
|
|
95
|
+
data: {
|
|
96
|
+
namespace: name,
|
|
97
|
+
},
|
|
98
|
+
});
|
|
99
|
+
}
|
|
100
|
+
addClassName(name) {
|
|
101
|
+
return __classPrivateFieldGet(this, _TmsCypressTestRuntime_instances, "m", _TmsCypressTestRuntime_enqueueMessageAsync).call(this, {
|
|
102
|
+
type: "metadata",
|
|
103
|
+
data: {
|
|
104
|
+
classname: name,
|
|
105
|
+
},
|
|
106
|
+
});
|
|
107
|
+
}
|
|
108
|
+
addAttachments(name, content, options) {
|
|
109
|
+
const [attachmentContent, actualEncoding] = __classPrivateFieldGet(this, _TmsCypressTestRuntime_instances, "m", _TmsCypressTestRuntime_buildAttachmentContent).call(this, content);
|
|
110
|
+
return __classPrivateFieldGet(this, _TmsCypressTestRuntime_instances, "m", _TmsCypressTestRuntime_enqueueMessageAsync).call(this, {
|
|
111
|
+
type: "attachment_content",
|
|
112
|
+
data: {
|
|
113
|
+
name,
|
|
114
|
+
content: attachmentContent,
|
|
115
|
+
encoding: actualEncoding,
|
|
116
|
+
contentType: options.contentType,
|
|
117
|
+
fileExtension: options.fileExtension,
|
|
118
|
+
},
|
|
119
|
+
});
|
|
120
|
+
}
|
|
121
|
+
addAttachmentsFromPath(name, path, options) {
|
|
122
|
+
return __classPrivateFieldGet(this, _TmsCypressTestRuntime_instances, "m", _TmsCypressTestRuntime_enqueueMessageAsync).call(this, {
|
|
123
|
+
type: "attachment_path",
|
|
124
|
+
data: {
|
|
125
|
+
name,
|
|
126
|
+
path,
|
|
127
|
+
contentType: options.contentType,
|
|
128
|
+
fileExtension: options.fileExtension,
|
|
129
|
+
},
|
|
130
|
+
});
|
|
131
|
+
}
|
|
132
|
+
addGlobalAttachments(name, content, options) {
|
|
133
|
+
const [attachmentContent, actualEncoding] = __classPrivateFieldGet(this, _TmsCypressTestRuntime_instances, "m", _TmsCypressTestRuntime_buildAttachmentContent).call(this, content);
|
|
134
|
+
return __classPrivateFieldGet(this, _TmsCypressTestRuntime_instances, "m", _TmsCypressTestRuntime_enqueueMessageAsync).call(this, {
|
|
135
|
+
type: "global_attachment_content",
|
|
136
|
+
data: {
|
|
137
|
+
name,
|
|
138
|
+
content: attachmentContent,
|
|
139
|
+
encoding: actualEncoding,
|
|
140
|
+
contentType: options.contentType,
|
|
141
|
+
fileExtension: options.fileExtension,
|
|
142
|
+
},
|
|
143
|
+
});
|
|
144
|
+
}
|
|
145
|
+
addGlobalAttachmentsFromPath(name, path, options) {
|
|
146
|
+
return __classPrivateFieldGet(this, _TmsCypressTestRuntime_instances, "m", _TmsCypressTestRuntime_enqueueMessageAsync).call(this, {
|
|
147
|
+
type: "global_attachment_path",
|
|
148
|
+
data: {
|
|
149
|
+
name,
|
|
150
|
+
path,
|
|
151
|
+
contentType: options.contentType,
|
|
152
|
+
fileExtension: options.fileExtension,
|
|
153
|
+
},
|
|
154
|
+
});
|
|
155
|
+
}
|
|
156
|
+
addMessage(details) {
|
|
157
|
+
return __classPrivateFieldGet(this, _TmsCypressTestRuntime_instances, "m", _TmsCypressTestRuntime_enqueueMessageAsync).call(this, {
|
|
158
|
+
type: "global_error",
|
|
159
|
+
data: details,
|
|
160
|
+
});
|
|
161
|
+
}
|
|
162
|
+
logStep(name, status = testit_js_commons_1.Status.PASSED, error) {
|
|
163
|
+
if (__classPrivateFieldGet(this, _TmsCypressTestRuntime_instances, "m", _TmsCypressTestRuntime_isInOriginContext).call(this)) {
|
|
164
|
+
(0, steps_js_1.startTmsApiStep)(name);
|
|
165
|
+
(0, steps_js_1.stopCurrentTmsApiStep)(status, error ? (0, utils_js_1.getMessageAndTraceFromError)(error) : undefined);
|
|
166
|
+
return Cypress.Promise.resolve();
|
|
167
|
+
}
|
|
168
|
+
return cy
|
|
169
|
+
.wrap(steps_js_1.TMS_STEP_CMD_SUBJECT, { log: false })
|
|
170
|
+
.then(() => {
|
|
171
|
+
(0, steps_js_1.startTmsApiStep)(name);
|
|
172
|
+
return Cypress.Promise.resolve();
|
|
173
|
+
})
|
|
174
|
+
.then(() => {
|
|
175
|
+
(0, steps_js_1.stopCurrentTmsApiStep)(status, error ? (0, utils_js_1.getMessageAndTraceFromError)(error) : undefined);
|
|
176
|
+
return Cypress.Promise.resolve();
|
|
177
|
+
});
|
|
178
|
+
}
|
|
179
|
+
step(name, body) {
|
|
180
|
+
return cy
|
|
181
|
+
.wrap(steps_js_1.TMS_STEP_CMD_SUBJECT, { log: false })
|
|
182
|
+
.then(() => {
|
|
183
|
+
(0, steps_js_1.startTmsApiStep)(name);
|
|
184
|
+
return Cypress.Promise.resolve(body());
|
|
185
|
+
})
|
|
186
|
+
.then((result) => {
|
|
187
|
+
(0, steps_js_1.stopCurrentTmsApiStep)();
|
|
188
|
+
return result;
|
|
189
|
+
});
|
|
190
|
+
}
|
|
191
|
+
stepDisplayName(name) {
|
|
192
|
+
return __classPrivateFieldGet(this, _TmsCypressTestRuntime_instances, "m", _TmsCypressTestRuntime_enqueueMessageAsync).call(this, {
|
|
193
|
+
type: "step_metadata",
|
|
194
|
+
data: {
|
|
195
|
+
name,
|
|
196
|
+
},
|
|
197
|
+
});
|
|
198
|
+
}
|
|
199
|
+
stepParameter(name, value) {
|
|
200
|
+
return __classPrivateFieldGet(this, _TmsCypressTestRuntime_instances, "m", _TmsCypressTestRuntime_enqueueMessageAsync).call(this, {
|
|
201
|
+
type: "step_metadata",
|
|
202
|
+
data: {
|
|
203
|
+
parameters: [{ name, value }],
|
|
204
|
+
},
|
|
205
|
+
});
|
|
206
|
+
}
|
|
207
|
+
flushTmsMessagesToTask(taskName) {
|
|
208
|
+
const messages = __classPrivateFieldGet(this, _TmsCypressTestRuntime_instances, "m", _TmsCypressTestRuntime_dequeueAllMessages).call(this);
|
|
209
|
+
if (messages.length) {
|
|
210
|
+
cy.task(taskName, { absolutePath: Cypress.spec.absolute, messages }, { log: false });
|
|
211
|
+
}
|
|
212
|
+
}
|
|
213
|
+
flushTmsMessagesToTaskAsync(taskName) {
|
|
214
|
+
const messages = __classPrivateFieldGet(this, _TmsCypressTestRuntime_instances, "m", _TmsCypressTestRuntime_dequeueAllMessages).call(this);
|
|
215
|
+
if (messages.length) {
|
|
216
|
+
const args = {
|
|
217
|
+
absolutePath: Cypress.spec.absolute,
|
|
218
|
+
messages,
|
|
219
|
+
isInteractive: Cypress.config("isInteractive"),
|
|
220
|
+
};
|
|
221
|
+
return cy.task(taskName, args, { log: false });
|
|
222
|
+
}
|
|
223
|
+
}
|
|
224
|
+
}
|
|
225
|
+
_TmsCypressTestRuntime_instances = new WeakSet(), _TmsCypressTestRuntime_resetMessages = function _TmsCypressTestRuntime_resetMessages() {
|
|
226
|
+
(0, state_js_1.setRuntimeMessages)([]);
|
|
227
|
+
}, _TmsCypressTestRuntime_enqueueMessageAsync = function _TmsCypressTestRuntime_enqueueMessageAsync(message) {
|
|
228
|
+
(0, state_js_1.enqueueRuntimeMessage)(message);
|
|
229
|
+
return Cypress.Promise.resolve();
|
|
230
|
+
}, _TmsCypressTestRuntime_dequeueAllMessages = function _TmsCypressTestRuntime_dequeueAllMessages() {
|
|
231
|
+
const messages = (0, state_js_1.getRuntimeMessages)();
|
|
232
|
+
__classPrivateFieldGet(this, _TmsCypressTestRuntime_instances, "m", _TmsCypressTestRuntime_resetMessages).call(this);
|
|
233
|
+
return messages;
|
|
234
|
+
}, _TmsCypressTestRuntime_buildAttachmentContent = function _TmsCypressTestRuntime_buildAttachmentContent(content) {
|
|
235
|
+
const rawContent = __classPrivateFieldGet(this, _TmsCypressTestRuntime_instances, "m", _TmsCypressTestRuntime_normalizeAttachmentContent).call(this, content);
|
|
236
|
+
const encoding = typeof rawContent === "string" ? "utf8" : "base64";
|
|
237
|
+
return [(0, utils_js_1.uint8ArrayToBase64)(rawContent), encoding];
|
|
238
|
+
}, _TmsCypressTestRuntime_normalizeAttachmentContent = function _TmsCypressTestRuntime_normalizeAttachmentContent(content) {
|
|
239
|
+
if (typeof content === "string") {
|
|
240
|
+
return content;
|
|
241
|
+
}
|
|
242
|
+
if (__classPrivateFieldGet(this, _TmsCypressTestRuntime_instances, "m", _TmsCypressTestRuntime_isSerializedBuffer).call(this, content)) {
|
|
243
|
+
return new Uint8Array(content.data);
|
|
244
|
+
}
|
|
245
|
+
return content;
|
|
246
|
+
}, _TmsCypressTestRuntime_isSerializedBuffer = function _TmsCypressTestRuntime_isSerializedBuffer(content) {
|
|
247
|
+
if (!content || typeof content !== "object") {
|
|
248
|
+
return false;
|
|
249
|
+
}
|
|
250
|
+
const candidate = content;
|
|
251
|
+
return candidate.type === "Buffer" && Array.isArray(candidate.data);
|
|
252
|
+
}, _TmsCypressTestRuntime_isInOriginContext = function _TmsCypressTestRuntime_isInOriginContext() {
|
|
253
|
+
try {
|
|
254
|
+
const hasOriginContext = !!window.cypressOriginContext;
|
|
255
|
+
const hasOriginWindow = !!window.cypressOriginWindow;
|
|
256
|
+
if (hasOriginContext || hasOriginWindow) {
|
|
257
|
+
return true;
|
|
258
|
+
}
|
|
259
|
+
const baseUrl = Cypress.config("baseUrl");
|
|
260
|
+
const currentOrigin = window.location.origin;
|
|
261
|
+
if (baseUrl && currentOrigin !== baseUrl) {
|
|
262
|
+
return true;
|
|
263
|
+
}
|
|
264
|
+
const cypressInstance = window.Cypress;
|
|
265
|
+
if (cypressInstance && cypressInstance.state && cypressInstance.state("origin")) {
|
|
266
|
+
return true;
|
|
267
|
+
}
|
|
268
|
+
try {
|
|
269
|
+
const cyExists = typeof cy !== "undefined";
|
|
270
|
+
const cyTaskExists = typeof cy.task !== "undefined";
|
|
271
|
+
// In cy.origin context, cy.task may not be available or may throw
|
|
272
|
+
if (!cyExists || !cyTaskExists) {
|
|
273
|
+
return true;
|
|
274
|
+
}
|
|
275
|
+
}
|
|
276
|
+
catch (error) {
|
|
277
|
+
return true;
|
|
278
|
+
}
|
|
279
|
+
return false;
|
|
280
|
+
}
|
|
281
|
+
catch (error) {
|
|
282
|
+
return true;
|
|
283
|
+
}
|
|
284
|
+
};
|