@dev-blinq/cucumber_client 1.0.1743-dev → 1.0.1745-dev
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.
|
@@ -14,6 +14,40 @@ import socketLogger, { getErrorMessage } from "../utils/socket_logger.js";
|
|
|
14
14
|
|
|
15
15
|
const STEP_KEYWORDS = new Set(["Given", "When", "Then"]);
|
|
16
16
|
|
|
17
|
+
/**
|
|
18
|
+
* @typedef {Object} StepDefinitionParseError
|
|
19
|
+
* @property {"STEP_DEFINITION_PARSE_ERROR"} code
|
|
20
|
+
* @property {string} message
|
|
21
|
+
* @property {string} filePath
|
|
22
|
+
* @property {number | null} line
|
|
23
|
+
* @property {number | null} column
|
|
24
|
+
* @property {Error} cause
|
|
25
|
+
*/
|
|
26
|
+
|
|
27
|
+
/**
|
|
28
|
+
* Create a structured parse error for step definition files.
|
|
29
|
+
* @param {string} filePath
|
|
30
|
+
* @param {unknown} error
|
|
31
|
+
* @returns {Error & StepDefinitionParseError}
|
|
32
|
+
*/
|
|
33
|
+
export function createStepDefinitionParseError(filePath, error) {
|
|
34
|
+
const err = error instanceof Error ? error : new Error(String(error));
|
|
35
|
+
const loc = /** @type {any} */ (error)?.loc || /** @type {any} */ (error)?.location;
|
|
36
|
+
const line = loc?.line ?? null;
|
|
37
|
+
const column = loc?.column ?? null;
|
|
38
|
+
const message = err.message || "Failed to parse step definition file";
|
|
39
|
+
|
|
40
|
+
const parseError = new Error(
|
|
41
|
+
`Step definition parse failed in ${filePath}${line ? `:${line}${column !== null ? `:${column}` : ""}` : ""}: ${message}`
|
|
42
|
+
);
|
|
43
|
+
/** @type {Error & StepDefinitionParseError} */ (parseError).code = "STEP_DEFINITION_PARSE_ERROR";
|
|
44
|
+
/** @type {Error & StepDefinitionParseError} */ (parseError).filePath = filePath;
|
|
45
|
+
/** @type {Error & StepDefinitionParseError} */ (parseError).line = line;
|
|
46
|
+
/** @type {Error & StepDefinitionParseError} */ (parseError).column = column;
|
|
47
|
+
/** @type {Error & StepDefinitionParseError} */ (parseError).cause = err;
|
|
48
|
+
return /** @type {Error & StepDefinitionParseError} */ (parseError);
|
|
49
|
+
}
|
|
50
|
+
|
|
17
51
|
/**
|
|
18
52
|
* Parse a step definitions file and return its AST.
|
|
19
53
|
* @param {string} filePath
|
|
@@ -21,12 +55,15 @@ const STEP_KEYWORDS = new Set(["Given", "When", "Then"]);
|
|
|
21
55
|
*/
|
|
22
56
|
export async function parse(filePath) {
|
|
23
57
|
const code = await fs.readFile(filePath, "utf-8");
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
58
|
+
try {
|
|
59
|
+
const ast = babelParse(code, {
|
|
60
|
+
sourceType: "module",
|
|
61
|
+
// plugins: ["jsx", "typescript"],
|
|
62
|
+
});
|
|
63
|
+
return ast;
|
|
64
|
+
} catch (error) {
|
|
65
|
+
throw createStepDefinitionParseError(filePath, error);
|
|
66
|
+
}
|
|
30
67
|
}
|
|
31
68
|
|
|
32
69
|
/**
|
|
@@ -41,7 +41,7 @@ async function evaluate(frame, script) {
|
|
|
41
41
|
await evaluate(childFrame, script);
|
|
42
42
|
}
|
|
43
43
|
}
|
|
44
|
-
async function findNestedFrameSelector(frame, obj
|
|
44
|
+
async function findNestedFrameSelector(frame, obj) {
|
|
45
45
|
try {
|
|
46
46
|
const parent = frame.parentFrame();
|
|
47
47
|
if (!parent)
|
|
@@ -49,10 +49,10 @@ async function findNestedFrameSelector(frame, obj = {}) {
|
|
|
49
49
|
const frameElement = await frame.frameElement();
|
|
50
50
|
if (!frameElement)
|
|
51
51
|
return;
|
|
52
|
-
const selectors = await
|
|
52
|
+
const selectors = await parent.evaluate((element) => {
|
|
53
53
|
const recorder = window.__bvt_Recorder;
|
|
54
54
|
return recorder.locatorGenerator.getElementLocators(element, { excludeText: true }).locators;
|
|
55
|
-
});
|
|
55
|
+
}, frameElement);
|
|
56
56
|
return findNestedFrameSelector(parent, { children: obj, selectors });
|
|
57
57
|
}
|
|
58
58
|
catch (e) {
|
|
@@ -773,11 +773,11 @@ export class BVTRecorder {
|
|
|
773
773
|
const contextElement = document.querySelector(`[data-blinq-context-id="${contextId}"]`);
|
|
774
774
|
const el = document.querySelector(`[data-blinq-id="${id}"]`);
|
|
775
775
|
if (!recorder || !el) {
|
|
776
|
-
return { locators: []
|
|
776
|
+
return { locators: [] };
|
|
777
777
|
}
|
|
778
778
|
if (contextElement && recorder.locatorGenerator.toContextLocators) {
|
|
779
779
|
const result = recorder.locatorGenerator.toContextLocators(el, contextElement);
|
|
780
|
-
return result ?? { locators: []
|
|
780
|
+
return result ?? { locators: [] };
|
|
781
781
|
}
|
|
782
782
|
const isRecordingText = mode === "recordingText";
|
|
783
783
|
return recorder.locatorGenerator.getElementLocators(el, {
|