@mobilewright/inspector 0.0.69 → 0.0.71
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/package.json +3 -3
- package/public/js/codegen-source.js +30 -0
- package/public/js/codegen.js +1 -8
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@mobilewright/inspector",
|
|
3
|
-
"version": "0.0.
|
|
3
|
+
"version": "0.0.71",
|
|
4
4
|
"description": "Browser-based element inspector for Mobilewright",
|
|
5
5
|
"homepage": "https://mobilewright.dev",
|
|
6
6
|
"license": "Apache-2.0",
|
|
@@ -31,8 +31,8 @@
|
|
|
31
31
|
"public"
|
|
32
32
|
],
|
|
33
33
|
"dependencies": {
|
|
34
|
-
"@mobilewright/core": "^0.0.
|
|
35
|
-
"@mobilewright/protocol": "^0.0.
|
|
34
|
+
"@mobilewright/core": "^0.0.71",
|
|
35
|
+
"@mobilewright/protocol": "^0.0.71",
|
|
36
36
|
"express": "^5.2.1",
|
|
37
37
|
"open": "^10.2.0"
|
|
38
38
|
},
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
// Pure source-editing helpers for codegen. No DOM access, so tests can import this module.
|
|
2
|
+
|
|
3
|
+
// Inserts a recorded line before the line that closes the generated body.
|
|
4
|
+
// That line is the first one consisting only of bodyEnd: recorded steps are indented in a test
|
|
5
|
+
// and never equal `await device.close();` in a library script, so a step such as
|
|
6
|
+
// `await device.setGeolocation({ ... });`, or code added after the test, cannot be mistaken for it.
|
|
7
|
+
// If the user edited that line away, fall back to the last occurrence, then to appending.
|
|
8
|
+
export function insertBeforeBodyEnd(source, bodyEnd, line) {
|
|
9
|
+
const end = bodyEndLineStart(source, bodyEnd) ?? lastIndexOrNull(source, bodyEnd)
|
|
10
|
+
if (end === null) {
|
|
11
|
+
return source + line + '\n'
|
|
12
|
+
}
|
|
13
|
+
return source.slice(0, end) + line + '\n' + source.slice(end)
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
function bodyEndLineStart(source, bodyEnd) {
|
|
17
|
+
let lineStart = 0
|
|
18
|
+
for (const sourceLine of source.split('\n')) {
|
|
19
|
+
if (sourceLine.trimEnd() === bodyEnd) {
|
|
20
|
+
return lineStart
|
|
21
|
+
}
|
|
22
|
+
lineStart += sourceLine.length + 1
|
|
23
|
+
}
|
|
24
|
+
return null
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
function lastIndexOrNull(source, bodyEnd) {
|
|
28
|
+
const index = source.lastIndexOf(bodyEnd)
|
|
29
|
+
return index === -1 ? null : index
|
|
30
|
+
}
|
package/public/js/codegen.js
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import { DetailPane, Inspector, ScreenshotPane, applyTheme, escQ, locatorCode, makeResizable } from './app.js'
|
|
2
2
|
import { ViewTreePane } from './view-tree.js'
|
|
3
|
+
import { insertBeforeBodyEnd } from './codegen-source.js'
|
|
3
4
|
|
|
4
5
|
// What the generated code runs under: the @mobilewright/test runner, or a plain script using the library.
|
|
5
6
|
// Recorded lines are the same for both, since each exposes `device` and `screen`; only the wrapper differs.
|
|
@@ -103,14 +104,6 @@ function centerOf({ x, y, width, height }) {
|
|
|
103
104
|
return { x: Math.round(x + width / 2), y: Math.round(y + height / 2) }
|
|
104
105
|
}
|
|
105
106
|
|
|
106
|
-
function insertBeforeBodyEnd(source, bodyEnd, line) {
|
|
107
|
-
const end = source.lastIndexOf(bodyEnd)
|
|
108
|
-
if (end === -1) {
|
|
109
|
-
return source + line + '\n'
|
|
110
|
-
}
|
|
111
|
-
return source.slice(0, end) + line + '\n' + source.slice(end)
|
|
112
|
-
}
|
|
113
|
-
|
|
114
107
|
class Recorder {
|
|
115
108
|
#editor = document.getElementById('code-editor')
|
|
116
109
|
#recordBtn = document.getElementById('record-btn')
|