@elastic/synthetics 1.24.2 → 1.24.4
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/dist/formatter/codegen.d.ts +69 -0
- package/dist/formatter/codegen.d.ts.map +1 -0
- package/dist/formatter/codegen.js +210 -0
- package/dist/formatter/codegen.js.map +1 -0
- package/dist/formatter/javascript.d.ts +6 -6
- package/dist/formatter/javascript.d.ts.map +1 -1
- package/dist/formatter/javascript.js +7 -7
- package/dist/formatter/javascript.js.map +1 -1
- package/package.json +7 -7
- package/src/formatter/codegen.ts +299 -0
- package/src/formatter/javascript.ts +1 -4
|
@@ -0,0 +1,69 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* MIT License
|
|
3
|
+
*
|
|
4
|
+
* Copyright (c) 2020-present, Elastic NV
|
|
5
|
+
*
|
|
6
|
+
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
7
|
+
* of this software and associated documentation files (the "Software"), to deal
|
|
8
|
+
* in the Software without restriction, including without limitation the rights
|
|
9
|
+
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
10
|
+
* copies of the Software, and to permit persons to whom the Software is
|
|
11
|
+
* furnished to do so, subject to the following conditions:
|
|
12
|
+
*
|
|
13
|
+
* The above copyright notice and this permission notice shall be included in
|
|
14
|
+
* all copies or substantial portions of the Software.
|
|
15
|
+
*
|
|
16
|
+
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
17
|
+
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
18
|
+
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
19
|
+
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
20
|
+
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
21
|
+
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
|
22
|
+
* THE SOFTWARE.
|
|
23
|
+
*
|
|
24
|
+
*/
|
|
25
|
+
export type CodegenAction = {
|
|
26
|
+
name: string;
|
|
27
|
+
selector?: string;
|
|
28
|
+
url?: string;
|
|
29
|
+
key?: string;
|
|
30
|
+
text?: string;
|
|
31
|
+
value?: string;
|
|
32
|
+
files?: string[];
|
|
33
|
+
options?: string[];
|
|
34
|
+
modifiers?: number;
|
|
35
|
+
button?: 'left' | 'middle' | 'right';
|
|
36
|
+
clickCount?: number;
|
|
37
|
+
position?: {
|
|
38
|
+
x: number;
|
|
39
|
+
y: number;
|
|
40
|
+
};
|
|
41
|
+
substring?: boolean;
|
|
42
|
+
checked?: boolean;
|
|
43
|
+
ariaSnapshot?: string;
|
|
44
|
+
};
|
|
45
|
+
export type CodegenActionInContext = {
|
|
46
|
+
action: CodegenAction;
|
|
47
|
+
frame: {
|
|
48
|
+
pageAlias: string;
|
|
49
|
+
framePath: string[];
|
|
50
|
+
};
|
|
51
|
+
};
|
|
52
|
+
export declare function quoteMultiline(text: string, indent?: string): string;
|
|
53
|
+
export declare class JavaScriptLanguageGenerator {
|
|
54
|
+
protected _isTest: boolean;
|
|
55
|
+
constructor(isTest: boolean);
|
|
56
|
+
protected _asLocator(selector: string): string;
|
|
57
|
+
protected _generateActionCall(subject: string, actionInContext: CodegenActionInContext): string;
|
|
58
|
+
}
|
|
59
|
+
export declare class JavaScriptFormatter {
|
|
60
|
+
private _baseIndent;
|
|
61
|
+
private _baseOffset;
|
|
62
|
+
private _lines;
|
|
63
|
+
constructor(offset?: number);
|
|
64
|
+
prepend(text: string): void;
|
|
65
|
+
add(text: string): void;
|
|
66
|
+
newLine(): void;
|
|
67
|
+
format(): string;
|
|
68
|
+
}
|
|
69
|
+
//# sourceMappingURL=codegen.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"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sBAAsB,GACtC,MAAM;CA8FV;AAED,qBAAa,mBAAmB;IAC9B,OAAO,CAAC,WAAW,CAAS;IAC5B,OAAO,CAAC,WAAW,CAAS;IAC5B,OAAO,CAAC,MAAM,CAAgB;gBAElB,MAAM,SAAI;IAKtB,OAAO,CAAC,IAAI,EAAE,MAAM;IAOpB,GAAG,CAAC,IAAI,EAAE,MAAM;IAOhB,OAAO;IAIP,MAAM,IAAI,MAAM;CAuBjB"}
|
|
@@ -0,0 +1,210 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/**
|
|
3
|
+
* MIT License
|
|
4
|
+
*
|
|
5
|
+
* Copyright (c) 2020-present, Elastic NV
|
|
6
|
+
*
|
|
7
|
+
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
8
|
+
* of this software and associated documentation files (the "Software"), to deal
|
|
9
|
+
* in the Software without restriction, including without limitation the rights
|
|
10
|
+
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
11
|
+
* copies of the Software, and to permit persons to whom the Software is
|
|
12
|
+
* furnished to do so, subject to the following conditions:
|
|
13
|
+
*
|
|
14
|
+
* The above copyright notice and this permission notice shall be included in
|
|
15
|
+
* all copies or substantial portions of the Software.
|
|
16
|
+
*
|
|
17
|
+
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
18
|
+
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
19
|
+
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
20
|
+
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
21
|
+
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
22
|
+
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
|
23
|
+
* THE SOFTWARE.
|
|
24
|
+
*
|
|
25
|
+
*/
|
|
26
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
27
|
+
exports.JavaScriptFormatter = exports.JavaScriptLanguageGenerator = exports.quoteMultiline = void 0;
|
|
28
|
+
/**
|
|
29
|
+
* Adapted from playwright-core's `server/codegen/javascript.ts` and
|
|
30
|
+
* `server/codegen/language.ts` (Apache-2.0, (c) Microsoft Corporation).
|
|
31
|
+
*
|
|
32
|
+
* Playwright >= 1.61 bundles its server code into `coreBundle.js` and no
|
|
33
|
+
* longer ships the codegen classes as importable modules, so the previous
|
|
34
|
+
* `playwright-core/lib/server/codegen/javascript` deep import no longer
|
|
35
|
+
* resolves. We only need the slice of the generator that
|
|
36
|
+
* `SyntheticsGenerator` extends (`_asLocator` + `_generateActionCall`) plus
|
|
37
|
+
* `JavaScriptFormatter`; the heavy locator/serialization helpers are still
|
|
38
|
+
* reachable through the bundle's exported `iso` namespace, so we reuse those
|
|
39
|
+
* directly instead of vendoring them too.
|
|
40
|
+
*/
|
|
41
|
+
/* eslint-disable @typescript-eslint/no-var-requires */
|
|
42
|
+
const { iso } = require('playwright-core/lib/coreBundle');
|
|
43
|
+
/* eslint-enable @typescript-eslint/no-var-requires */
|
|
44
|
+
const { asLocator, escapeWithQuotes, formatObject } = iso;
|
|
45
|
+
function toKeyboardModifiers(modifiers = 0) {
|
|
46
|
+
const result = [];
|
|
47
|
+
if (modifiers & 1)
|
|
48
|
+
result.push('Alt');
|
|
49
|
+
if (modifiers & 2)
|
|
50
|
+
result.push('ControlOrMeta');
|
|
51
|
+
if (modifiers & 4)
|
|
52
|
+
result.push('ControlOrMeta');
|
|
53
|
+
if (modifiers & 8)
|
|
54
|
+
result.push('Shift');
|
|
55
|
+
return result;
|
|
56
|
+
}
|
|
57
|
+
function toClickOptionsForSourceCode(action) {
|
|
58
|
+
const modifiers = toKeyboardModifiers(action.modifiers);
|
|
59
|
+
const options = {};
|
|
60
|
+
if (action.button && action.button !== 'left')
|
|
61
|
+
options.button = action.button;
|
|
62
|
+
if (modifiers.length)
|
|
63
|
+
options.modifiers = modifiers;
|
|
64
|
+
// Do not render clickCount === 2 for dblclick.
|
|
65
|
+
if (action.clickCount && action.clickCount > 2)
|
|
66
|
+
options.clickCount = action.clickCount;
|
|
67
|
+
if (action.position)
|
|
68
|
+
options.position = action.position;
|
|
69
|
+
return options;
|
|
70
|
+
}
|
|
71
|
+
function formatOptions(value, hasArguments) {
|
|
72
|
+
const keys = Object.keys(value).filter(key => value[key] !== undefined);
|
|
73
|
+
if (!keys.length)
|
|
74
|
+
return '';
|
|
75
|
+
return (hasArguments ? ', ' : '') + formatObject(value);
|
|
76
|
+
}
|
|
77
|
+
function quote(text = '') {
|
|
78
|
+
return escapeWithQuotes(text, "'");
|
|
79
|
+
}
|
|
80
|
+
function quoteMultiline(text, indent = ' ') {
|
|
81
|
+
const escape = (t) => t.replace(/\\/g, '\\\\').replace(/`/g, '\\`').replace(/\$\{/g, '\\${');
|
|
82
|
+
const lines = text.split('\n');
|
|
83
|
+
if (lines.length === 1)
|
|
84
|
+
return '`' + escape(text) + '`';
|
|
85
|
+
return ('`\n' +
|
|
86
|
+
lines
|
|
87
|
+
.map(line => indent + escape(line).replace(/\${/g, '\\${'))
|
|
88
|
+
.join('\n') +
|
|
89
|
+
`\n${indent}\``);
|
|
90
|
+
}
|
|
91
|
+
exports.quoteMultiline = quoteMultiline;
|
|
92
|
+
class JavaScriptLanguageGenerator {
|
|
93
|
+
_isTest;
|
|
94
|
+
constructor(isTest) {
|
|
95
|
+
this._isTest = isTest;
|
|
96
|
+
}
|
|
97
|
+
_asLocator(selector) {
|
|
98
|
+
return asLocator('javascript', selector);
|
|
99
|
+
}
|
|
100
|
+
_generateActionCall(subject, actionInContext) {
|
|
101
|
+
const action = actionInContext.action;
|
|
102
|
+
switch (action.name) {
|
|
103
|
+
case 'openPage':
|
|
104
|
+
throw Error('Not reached');
|
|
105
|
+
case 'closePage':
|
|
106
|
+
return `await ${subject}.close();`;
|
|
107
|
+
case 'click': {
|
|
108
|
+
let method = 'click';
|
|
109
|
+
if (action.clickCount === 2)
|
|
110
|
+
method = 'dblclick';
|
|
111
|
+
const options = toClickOptionsForSourceCode(action);
|
|
112
|
+
const optionsString = formatOptions(options, false);
|
|
113
|
+
return `await ${subject}.${this._asLocator(action.selector)}.${method}(${optionsString});`;
|
|
114
|
+
}
|
|
115
|
+
case 'hover':
|
|
116
|
+
return `await ${subject}.${this._asLocator(action.selector)}.hover(${formatOptions({ position: action.position }, false)});`;
|
|
117
|
+
case 'check':
|
|
118
|
+
return `await ${subject}.${this._asLocator(action.selector)}.check();`;
|
|
119
|
+
case 'uncheck':
|
|
120
|
+
return `await ${subject}.${this._asLocator(action.selector)}.uncheck();`;
|
|
121
|
+
case 'fill':
|
|
122
|
+
return `await ${subject}.${this._asLocator(action.selector)}.fill(${quote(action.text)});`;
|
|
123
|
+
case 'setInputFiles': {
|
|
124
|
+
const files = action.files ?? [];
|
|
125
|
+
return `await ${subject}.${this._asLocator(action.selector)}.setInputFiles(${formatObject(files.length === 1 ? files[0] : files)});`;
|
|
126
|
+
}
|
|
127
|
+
case 'press': {
|
|
128
|
+
const modifiers = toKeyboardModifiers(action.modifiers);
|
|
129
|
+
const shortcut = [...modifiers, action.key].join('+');
|
|
130
|
+
return `await ${subject}.${this._asLocator(action.selector)}.press(${quote(shortcut)});`;
|
|
131
|
+
}
|
|
132
|
+
case 'navigate':
|
|
133
|
+
return `await ${subject}.goto(${quote(action.url)});`;
|
|
134
|
+
case 'select': {
|
|
135
|
+
const opts = action.options ?? [];
|
|
136
|
+
return `await ${subject}.${this._asLocator(action.selector)}.selectOption(${formatObject(opts.length === 1 ? opts[0] : opts)});`;
|
|
137
|
+
}
|
|
138
|
+
case 'assertText':
|
|
139
|
+
return `${this._isTest ? '' : '// '}await expect(${subject}.${this._asLocator(action.selector)}).${action.substring ? 'toContainText' : 'toHaveText'}(${quote(action.text)});`;
|
|
140
|
+
case 'assertChecked':
|
|
141
|
+
return `${this._isTest ? '' : '// '}await expect(${subject}.${this._asLocator(action.selector)})${action.checked ? '' : '.not'}.toBeChecked();`;
|
|
142
|
+
case 'assertVisible':
|
|
143
|
+
return `${this._isTest ? '' : '// '}await expect(${subject}.${this._asLocator(action.selector)}).toBeVisible();`;
|
|
144
|
+
case 'assertValue': {
|
|
145
|
+
const assertion = action.value
|
|
146
|
+
? `toHaveValue(${quote(action.value)})`
|
|
147
|
+
: `toBeEmpty()`;
|
|
148
|
+
return `${this._isTest ? '' : '// '}await expect(${subject}.${this._asLocator(action.selector)}).${assertion};`;
|
|
149
|
+
}
|
|
150
|
+
case 'assertSnapshot': {
|
|
151
|
+
const commentIfNeeded = this._isTest ? '' : '// ';
|
|
152
|
+
return `${commentIfNeeded}await expect(${subject}.${this._asLocator(action.selector)}).toMatchAriaSnapshot(${quoteMultiline(action.ariaSnapshot ?? '', `${commentIfNeeded} `)});`;
|
|
153
|
+
}
|
|
154
|
+
default:
|
|
155
|
+
return '';
|
|
156
|
+
}
|
|
157
|
+
}
|
|
158
|
+
}
|
|
159
|
+
exports.JavaScriptLanguageGenerator = JavaScriptLanguageGenerator;
|
|
160
|
+
class JavaScriptFormatter {
|
|
161
|
+
_baseIndent;
|
|
162
|
+
_baseOffset;
|
|
163
|
+
_lines = [];
|
|
164
|
+
constructor(offset = 0) {
|
|
165
|
+
this._baseIndent = ' '.repeat(2);
|
|
166
|
+
this._baseOffset = ' '.repeat(offset);
|
|
167
|
+
}
|
|
168
|
+
prepend(text) {
|
|
169
|
+
const trim = isMultilineString(text)
|
|
170
|
+
? (line) => line
|
|
171
|
+
: (line) => line.trim();
|
|
172
|
+
this._lines = text.trim().split('\n').map(trim).concat(this._lines);
|
|
173
|
+
}
|
|
174
|
+
add(text) {
|
|
175
|
+
const trim = isMultilineString(text)
|
|
176
|
+
? (line) => line
|
|
177
|
+
: (line) => line.trim();
|
|
178
|
+
this._lines.push(...text.trim().split('\n').map(trim));
|
|
179
|
+
}
|
|
180
|
+
newLine() {
|
|
181
|
+
this._lines.push('');
|
|
182
|
+
}
|
|
183
|
+
format() {
|
|
184
|
+
let spaces = '';
|
|
185
|
+
let previousLine = '';
|
|
186
|
+
return this._lines
|
|
187
|
+
.map((line) => {
|
|
188
|
+
if (line === '')
|
|
189
|
+
return line;
|
|
190
|
+
if (line.startsWith('}') || line.startsWith(']'))
|
|
191
|
+
spaces = spaces.substring(this._baseIndent.length);
|
|
192
|
+
const extraSpaces = /^(for|while|if|try).*\(.*\)$/.test(previousLine)
|
|
193
|
+
? this._baseIndent
|
|
194
|
+
: '';
|
|
195
|
+
previousLine = line;
|
|
196
|
+
const callCarryOver = line.startsWith('.set');
|
|
197
|
+
line =
|
|
198
|
+
spaces + extraSpaces + (callCarryOver ? this._baseIndent : '') + line;
|
|
199
|
+
if (line.endsWith('{') || line.endsWith('['))
|
|
200
|
+
spaces += this._baseIndent;
|
|
201
|
+
return this._baseOffset + line;
|
|
202
|
+
})
|
|
203
|
+
.join('\n');
|
|
204
|
+
}
|
|
205
|
+
}
|
|
206
|
+
exports.JavaScriptFormatter = JavaScriptFormatter;
|
|
207
|
+
function isMultilineString(text) {
|
|
208
|
+
return text.match(/`[\S\s]*`/)?.[0].includes('\n');
|
|
209
|
+
}
|
|
210
|
+
//# sourceMappingURL=codegen.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"codegen.js","sourceRoot":"","sources":["../../src/formatter/codegen.ts"],"names":[],"mappings":";AAAA;;;;;;;;;;;;;;;;;;;;;;;GAuBG;;;AAEH;;;;;;;;;;;;GAYG;AAEH,uDAAuD;AACvD,MAAM,EAAE,GAAG,EAAE,GAAG,OAAO,CAAC,gCAAgC,CAMvD,CAAC;AACF,sDAAsD;AAEtD,MAAM,EAAE,SAAS,EAAE,gBAAgB,EAAE,YAAY,EAAE,GAAG,GAAG,CAAC;AAuC1D,SAAS,mBAAmB,CAAC,SAAS,GAAG,CAAC;IACxC,MAAM,MAAM,GAA4B,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UAAU,CAAC,GAAG,CAAC,IAAI,IAAI,CAAC,UAAU,CAAC,GAAG,CAAC;gBAC9C,MAAM,GAAG,MAAM,CAAC,SAAS,CAAC,IAAI,CAAC,WAAW,CAAC,MAAM,CAAC,CAAC;YAErD,MAAM,WAAW,GAAG,8BAA8B,CAAC,IAAI,CAAC,YAAY,CAAC;gBACnE,CAAC,CAAC,IAAI,CAAC,WAAW;gBAClB,CAAC,CAAC,EAAE,CAAC;YACP,YAAY,GAAG,IAAI,CAAC;YAEpB,MAAM,aAAa,GAAG,IAAI,CAAC,UAAU,CAAC,MAAM,CAAC,CAAC;YAC9C,IAAI;gBACF,MAAM,GAAG,WAAW,GAAG,CAAC,aAAa,CAAC,CAAC,CAAC,IAAI,CAAC,WAAW,CAAC,CAAC,CAAC,EAAE,CAAC,GAAG,IAAI,CAAC;YACxE,IAAI,IAAI,CAAC,QAAQ,CAAC,GAAG,CAAC,IAAI,IAAI,CAAC,QAAQ,CAAC,GAAG,CAAC;gBAC1C,MAAM,IAAI,IAAI,CAAC,WAAW,CAAC;YAC7B,OAAO,IAAI,CAAC,WAAW,GAAG,IAAI,CAAC;QACjC,CAAC,CAAC;aACD,IAAI,CAAC,IAAI,CAAC,CAAC;IAChB,CAAC;CACF;AAnDD,kDAmDC;AAED,SAAS,iBAAiB,CAAC,IAAY;IACrC,OAAO,IAAI,CAAC,KAAK,CAAC,WAAW,CAAC,EAAE,CAAC,CAAC,CAAC,CAAC,QAAQ,CAAC,IAAI,CAAC,CAAC;AACrD,CAAC"}
|
|
@@ -22,7 +22,7 @@
|
|
|
22
22
|
* THE SOFTWARE.
|
|
23
23
|
*
|
|
24
24
|
*/
|
|
25
|
-
import { JavaScriptLanguageGenerator } from '
|
|
25
|
+
import { JavaScriptLanguageGenerator } from './codegen';
|
|
26
26
|
export type Step = {
|
|
27
27
|
actions: ActionInContext[];
|
|
28
28
|
name?: string;
|
|
@@ -86,11 +86,11 @@ export declare class SyntheticsGenerator extends JavaScriptLanguageGenerator {
|
|
|
86
86
|
* @param actionInContext The action to create code for.
|
|
87
87
|
* @returns the strings generated for the action.
|
|
88
88
|
*/
|
|
89
|
-
generateAction(actionInContext: ActionInContext):
|
|
89
|
+
generateAction(actionInContext: ActionInContext): string;
|
|
90
90
|
isNewStep(actioninContext: ActionInContext): boolean;
|
|
91
|
-
generateStepStart(name: string):
|
|
92
|
-
generateStepEnd():
|
|
93
|
-
generateHeader():
|
|
91
|
+
generateStepStart(name: string): string;
|
|
92
|
+
generateStepEnd(): string;
|
|
93
|
+
generateHeader(): string;
|
|
94
94
|
generateFooter(): string;
|
|
95
95
|
/**
|
|
96
96
|
* Generates JavaScript code from a custom set of steps and nested actions.
|
|
@@ -101,7 +101,7 @@ export declare class SyntheticsGenerator extends JavaScriptLanguageGenerator {
|
|
|
101
101
|
* @returns a list of the code strings outputted by the generator
|
|
102
102
|
*/
|
|
103
103
|
generateFromSteps(steps: Steps): string;
|
|
104
|
-
generateHoistedVars():
|
|
104
|
+
generateHoistedVars(): string;
|
|
105
105
|
isVarHoisted(varName: string): boolean;
|
|
106
106
|
getDefaultOffset(): 0 | 2;
|
|
107
107
|
/**
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"javascript.d.ts","sourceRoot":"","sources":["../../src/formatter/javascript.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;GAuBG;AAEH,OAAO,
|
|
1
|
+
{"version":3,"file":"javascript.d.ts","sourceRoot":"","sources":["../../src/formatter/javascript.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;GAuBG;AAEH,OAAO,EAAE,2BAA2B,EAAuB,MAAM,WAAW,CAAC;AAE7E,MAAM,MAAM,IAAI,GAAG;IACjB,OAAO,EAAE,eAAe,EAAE,CAAC;IAC3B,IAAI,CAAC,EAAE,MAAM,CAAC;CACf,CAAC;AACF,MAAM,MAAM,KAAK,GAAG,IAAI,EAAE,CAAC;AAG3B,MAAM,MAAM,gBAAgB,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CAAC,EAAE,MAAM,CAAC;IACvB,WAAW,CAAC,EAAE,MAAM,CAAC;CACtB,CAAC;AAsCF,wBAAgB,KAAK,CAAC,IAAI,EAAE,MAAM,EAAE,IAAI,SAAM,GAAG,MAAM,CAStD;AAED;;;;GAIG;AACH,wBAAgB,WAAW,CAAC,MAAM,EAAE,MAAM,UAgCzC;AAED,qBAAa,mBAAoB,SAAQ,2BAA2B;IAKtD,OAAO,CAAC,SAAS;IAJ7B,OAAO,CAAC,eAAe,CAAC,CAAkB;IAC1C,OAAO,CAAC,UAAU,CAAU;IAC5B,OAAO,CAAC,WAAW,CAAW;gBAEV,SAAS,EAAE,OAAO;IAOtC;;;;OAIG;IACH,cAAc,CAAC,eAAe,EAAE,eAAe;IA4D/C,SAAS,CAAC,eAAe,EAAE,eAAe;IAa1C,iBAAiB,CAAC,IAAI,EAAE,MAAM;IAO9B,eAAe;IAUf,cAAc;IASd,cAAc;IAId;;;;;;;OAOG;IACH,iBAAiB,CAAC,KAAK,EAAE,KAAK,GAAG,MAAM;IA8BvC,mBAAmB;IAQnB,YAAY,CAAC,OAAO,EAAE,MAAM;IAI5B,gBAAgB;IAIhB;;;;OAIG;IACH,eAAe,CAAC,KAAK,EAAE,KAAK,GAAG,MAAM,EAAE;CAYxC"}
|
|
@@ -25,7 +25,7 @@
|
|
|
25
25
|
*/
|
|
26
26
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
27
27
|
exports.SyntheticsGenerator = exports.actionTitle = exports.quote = void 0;
|
|
28
|
-
const
|
|
28
|
+
const codegen_1 = require("./codegen");
|
|
29
29
|
function toAssertCall(pageAlias, action) {
|
|
30
30
|
const { command, selector, value } = action;
|
|
31
31
|
switch (command) {
|
|
@@ -115,7 +115,7 @@ function actionTitle(action) {
|
|
|
115
115
|
}
|
|
116
116
|
}
|
|
117
117
|
exports.actionTitle = actionTitle;
|
|
118
|
-
class SyntheticsGenerator extends
|
|
118
|
+
class SyntheticsGenerator extends codegen_1.JavaScriptLanguageGenerator {
|
|
119
119
|
isProject;
|
|
120
120
|
previousContext;
|
|
121
121
|
insideStep;
|
|
@@ -145,7 +145,7 @@ class SyntheticsGenerator extends javascript_1.JavaScriptLanguageGenerator {
|
|
|
145
145
|
}
|
|
146
146
|
const stepIndent = this.insideStep ? 2 : 0;
|
|
147
147
|
const offset = this.isProject ? 2 + stepIndent : 0 + stepIndent;
|
|
148
|
-
const formatter = new
|
|
148
|
+
const formatter = new codegen_1.JavaScriptFormatter(offset);
|
|
149
149
|
const locators = actionInContext.frame.framePath.map(selector => `.${super._asLocator(selector)}.contentFrame()`);
|
|
150
150
|
const subject = `${pageAlias}${locators.join('')}`;
|
|
151
151
|
const signals = toSignalMap(action);
|
|
@@ -187,7 +187,7 @@ class SyntheticsGenerator extends javascript_1.JavaScriptLanguageGenerator {
|
|
|
187
187
|
}
|
|
188
188
|
generateStepStart(name) {
|
|
189
189
|
this.insideStep = true;
|
|
190
|
-
const formatter = new
|
|
190
|
+
const formatter = new codegen_1.JavaScriptFormatter(this.getDefaultOffset());
|
|
191
191
|
formatter.add(`step(${quote(name)}, async () => {`);
|
|
192
192
|
return formatter.format();
|
|
193
193
|
}
|
|
@@ -196,12 +196,12 @@ class SyntheticsGenerator extends javascript_1.JavaScriptLanguageGenerator {
|
|
|
196
196
|
return '';
|
|
197
197
|
}
|
|
198
198
|
this.insideStep = false;
|
|
199
|
-
const formatter = new
|
|
199
|
+
const formatter = new codegen_1.JavaScriptFormatter(this.getDefaultOffset());
|
|
200
200
|
formatter.add(`});`);
|
|
201
201
|
return formatter.format();
|
|
202
202
|
}
|
|
203
203
|
generateHeader() {
|
|
204
|
-
const formatter = new
|
|
204
|
+
const formatter = new codegen_1.JavaScriptFormatter(0);
|
|
205
205
|
formatter.add(`
|
|
206
206
|
const { journey, step, expect } = require('@elastic/synthetics');
|
|
207
207
|
|
|
@@ -246,7 +246,7 @@ class SyntheticsGenerator extends javascript_1.JavaScriptLanguageGenerator {
|
|
|
246
246
|
return text.filter(s => !!s).join('\n');
|
|
247
247
|
}
|
|
248
248
|
generateHoistedVars() {
|
|
249
|
-
const formatter = new
|
|
249
|
+
const formatter = new codegen_1.JavaScriptFormatter(this.getDefaultOffset());
|
|
250
250
|
for (const varName of this.varsToHoist) {
|
|
251
251
|
formatter.add(`let ${varName};`);
|
|
252
252
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"javascript.js","sourceRoot":"","sources":["../../src/formatter/javascript.ts"],"names":[],"mappings":";AAAA;;;;;;;;;;;;;;;;;;;;;;;GAuBG;;;AAEH,
|
|
1
|
+
{"version":3,"file":"javascript.js","sourceRoot":"","sources":["../../src/formatter/javascript.ts"],"names":[],"mappings":";AAAA;;;;;;;;;;;;;;;;;;;;;;;GAuBG;;;AAEH,uCAA6E;AAqD7E,SAAS,YAAY,CAAC,SAAiB,EAAE,MAAc;IACrD,MAAM,EAAE,OAAO,EAAE,QAAQ,EAAE,KAAK,EAAE,GAAG,MAAM,CAAC;IAC5C,QAAQ,OAAO,EAAE;QACf,KAAK,aAAa,CAAC;QACnB,KAAK,WAAW;YACd,OAAO,gBAAgB,SAAS,IAAI,OAAO,IAAI,KAAK,CAClD,QAAQ,IAAI,EAAE,CACf,cAAc,KAAK,CAAC,KAAK,IAAI,EAAE,CAAC,IAAI,CAAC;QACxC,KAAK,WAAW,CAAC;QACjB,KAAK,UAAU,CAAC;QAChB,KAAK,WAAW,CAAC;QACjB,KAAK,YAAY,CAAC;QAClB,KAAK,WAAW,CAAC;QACjB,KAAK,YAAY;YACf,OAAO,gBAAgB,SAAS,IAAI,OAAO,IAAI,KAAK,CAClD,QAAQ,IAAI,EAAE,CACf,kBAAkB,CAAC;KACvB;AACH,CAAC;AAED,SAAS,WAAW,CAAC,MAAc;IACjC,IAAI,KAAyB,CAAC;IAC9B,IAAI,QAA4B,CAAC;IACjC,IAAI,MAA0B,CAAC;IAC/B,KAAK,MAAM,MAAM,IAAI,MAAM,CAAC,OAAO,EAAE;QACnC,IAAI,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AAC,OAAO,OAAO,GAAG,CAAC,CAAC;SAClC;QACD,OAAO,SAAS,CAAC,MAAM,EAAE,CAAC;IAC5B,CAAC;IAED,YAAY,CAAC,OAAe;QAC1B,OAAO,IAAI,CAAC,WAAW,CAAC,OAAO,CAAC,OAAO,CAAC,IAAI,CAAC,CAAC;IAChD,CAAC;IAED,gBAAgB;QACd,OAAO,IAAI,CAAC,SAAS,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC;IAChC,CAAC;IAED;;;;OAIG;IACH,eAAe,CAAC,KAAY;QAC1B,MAAM,QAAQ,GAAG,IAAI,GAAG,EAAU,CAAC;QACnC,KAAK,MAAM,IAAI,IAAI,KAAK,EAAE;YACxB,KAAK,MAAM,aAAa,IAAI,IAAI,CAAC,OAAO,EAAE;gBACxC,aAAa,CAAC,MAAM,CAAC,OAAO;qBACzB,MAAM,CAAC,CAAC,EAAE,IAAI,EAAE,UAAU,EAAE,EAAE,EAAE,CAAC,IAAI,KAAK,OAAO,IAAI,UAAU,CAAC;qBAChE,OAAO,CAAC,CAAC,EAAE,UAAU,EAAE,EAAE,EAAE,CAAC,QAAQ,CAAC,GAAG,CAAC,UAAoB,CAAC,CAAC,CAAC;gBACnE,QAAQ,CAAC,GAAG,CAAC,aAAa,CAAC,KAAK,CAAC,SAAS,CAAC,CAAC;aAC7C;SACF;QACD,OAAO,KAAK,CAAC,IAAI,CAAC,QAAQ,CAAC,CAAC,MAAM,CAAC,KAAK,CAAC,EAAE,CAAC,KAAK,KAAK,MAAM,CAAC,CAAC;IAChE,CAAC;CACF;AA/LD,kDA+LC"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@elastic/synthetics",
|
|
3
|
-
"version": "1.24.
|
|
3
|
+
"version": "1.24.4",
|
|
4
4
|
"description": "Elastic synthetic monitoring agent",
|
|
5
5
|
"main": "dist/index.js",
|
|
6
6
|
"types": "dist/index.d.ts",
|
|
@@ -61,16 +61,16 @@
|
|
|
61
61
|
"micromatch": "^4.0.8",
|
|
62
62
|
"otpauth": "^9.3.2",
|
|
63
63
|
"pirates": "^4.0.5",
|
|
64
|
-
"playwright": "=1.
|
|
65
|
-
"playwright-chromium": "=1.
|
|
66
|
-
"playwright-core": "=1.
|
|
64
|
+
"playwright": "=1.61.1",
|
|
65
|
+
"playwright-chromium": "=1.61.1",
|
|
66
|
+
"playwright-core": "=1.61.1",
|
|
67
67
|
"semver": "^7.5.4",
|
|
68
68
|
"sharp": "^0.34.2",
|
|
69
69
|
"snakecase-keys": "^4.0.1",
|
|
70
70
|
"sonic-boom": "^3.3.0",
|
|
71
71
|
"source-map-support": "^0.5.21",
|
|
72
72
|
"stack-utils": "^2.0.6",
|
|
73
|
-
"undici": "^7.
|
|
73
|
+
"undici": "^7.28.0",
|
|
74
74
|
"unzip-stream": "^0.3.4",
|
|
75
75
|
"yaml": "^2.8.3"
|
|
76
76
|
},
|
|
@@ -98,11 +98,11 @@
|
|
|
98
98
|
"typescript": "^5.1.6"
|
|
99
99
|
},
|
|
100
100
|
"overrides": {
|
|
101
|
-
"follow-redirects": "^1.
|
|
101
|
+
"follow-redirects": "^1.16.0",
|
|
102
102
|
"cross-spawn": "^7.0.5",
|
|
103
103
|
"brace-expansion@1": "^1.1.13",
|
|
104
104
|
"brace-expansion@2": "^2.0.3",
|
|
105
|
-
"brace-expansion@5": "^5.0.
|
|
105
|
+
"brace-expansion@5": "^5.0.7",
|
|
106
106
|
"archiver": {
|
|
107
107
|
"archiver-utils": {
|
|
108
108
|
"lodash": "^4.18.0"
|
|
@@ -0,0 +1,299 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* MIT License
|
|
3
|
+
*
|
|
4
|
+
* Copyright (c) 2020-present, Elastic NV
|
|
5
|
+
*
|
|
6
|
+
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
7
|
+
* of this software and associated documentation files (the "Software"), to deal
|
|
8
|
+
* in the Software without restriction, including without limitation the rights
|
|
9
|
+
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
10
|
+
* copies of the Software, and to permit persons to whom the Software is
|
|
11
|
+
* furnished to do so, subject to the following conditions:
|
|
12
|
+
*
|
|
13
|
+
* The above copyright notice and this permission notice shall be included in
|
|
14
|
+
* all copies or substantial portions of the Software.
|
|
15
|
+
*
|
|
16
|
+
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
17
|
+
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
18
|
+
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
19
|
+
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
20
|
+
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
21
|
+
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
|
22
|
+
* THE SOFTWARE.
|
|
23
|
+
*
|
|
24
|
+
*/
|
|
25
|
+
|
|
26
|
+
/**
|
|
27
|
+
* Adapted from playwright-core's `server/codegen/javascript.ts` and
|
|
28
|
+
* `server/codegen/language.ts` (Apache-2.0, (c) Microsoft Corporation).
|
|
29
|
+
*
|
|
30
|
+
* Playwright >= 1.61 bundles its server code into `coreBundle.js` and no
|
|
31
|
+
* longer ships the codegen classes as importable modules, so the previous
|
|
32
|
+
* `playwright-core/lib/server/codegen/javascript` deep import no longer
|
|
33
|
+
* resolves. We only need the slice of the generator that
|
|
34
|
+
* `SyntheticsGenerator` extends (`_asLocator` + `_generateActionCall`) plus
|
|
35
|
+
* `JavaScriptFormatter`; the heavy locator/serialization helpers are still
|
|
36
|
+
* reachable through the bundle's exported `iso` namespace, so we reuse those
|
|
37
|
+
* directly instead of vendoring them too.
|
|
38
|
+
*/
|
|
39
|
+
|
|
40
|
+
/* eslint-disable @typescript-eslint/no-var-requires */
|
|
41
|
+
const { iso } = require('playwright-core/lib/coreBundle') as {
|
|
42
|
+
iso: {
|
|
43
|
+
asLocator(language: string, selector: string): string;
|
|
44
|
+
escapeWithQuotes(text: string, char?: string): string;
|
|
45
|
+
formatObject(value: any, indent?: string): string;
|
|
46
|
+
};
|
|
47
|
+
};
|
|
48
|
+
/* eslint-enable @typescript-eslint/no-var-requires */
|
|
49
|
+
|
|
50
|
+
const { asLocator, escapeWithQuotes, formatObject } = iso;
|
|
51
|
+
|
|
52
|
+
type SmartKeyboardModifier =
|
|
53
|
+
| 'Alt'
|
|
54
|
+
| 'Control'
|
|
55
|
+
| 'ControlOrMeta'
|
|
56
|
+
| 'Meta'
|
|
57
|
+
| 'Shift';
|
|
58
|
+
|
|
59
|
+
type MouseClickOptions = {
|
|
60
|
+
button?: 'left' | 'middle' | 'right';
|
|
61
|
+
modifiers?: SmartKeyboardModifier[];
|
|
62
|
+
clickCount?: number;
|
|
63
|
+
position?: { x: number; y: number };
|
|
64
|
+
};
|
|
65
|
+
|
|
66
|
+
export type CodegenAction = {
|
|
67
|
+
name: string;
|
|
68
|
+
selector?: string;
|
|
69
|
+
url?: string;
|
|
70
|
+
key?: string;
|
|
71
|
+
text?: string;
|
|
72
|
+
value?: string;
|
|
73
|
+
files?: string[];
|
|
74
|
+
options?: string[];
|
|
75
|
+
modifiers?: number;
|
|
76
|
+
button?: 'left' | 'middle' | 'right';
|
|
77
|
+
clickCount?: number;
|
|
78
|
+
position?: { x: number; y: number };
|
|
79
|
+
substring?: boolean;
|
|
80
|
+
checked?: boolean;
|
|
81
|
+
ariaSnapshot?: string;
|
|
82
|
+
};
|
|
83
|
+
|
|
84
|
+
export type CodegenActionInContext = {
|
|
85
|
+
action: CodegenAction;
|
|
86
|
+
frame: { pageAlias: string; framePath: string[] };
|
|
87
|
+
};
|
|
88
|
+
|
|
89
|
+
function toKeyboardModifiers(modifiers = 0): SmartKeyboardModifier[] {
|
|
90
|
+
const result: SmartKeyboardModifier[] = [];
|
|
91
|
+
if (modifiers & 1) result.push('Alt');
|
|
92
|
+
if (modifiers & 2) result.push('ControlOrMeta');
|
|
93
|
+
if (modifiers & 4) result.push('ControlOrMeta');
|
|
94
|
+
if (modifiers & 8) result.push('Shift');
|
|
95
|
+
return result;
|
|
96
|
+
}
|
|
97
|
+
|
|
98
|
+
function toClickOptionsForSourceCode(action: CodegenAction): MouseClickOptions {
|
|
99
|
+
const modifiers = toKeyboardModifiers(action.modifiers);
|
|
100
|
+
const options: MouseClickOptions = {};
|
|
101
|
+
if (action.button && action.button !== 'left') options.button = action.button;
|
|
102
|
+
if (modifiers.length) options.modifiers = modifiers;
|
|
103
|
+
// Do not render clickCount === 2 for dblclick.
|
|
104
|
+
if (action.clickCount && action.clickCount > 2)
|
|
105
|
+
options.clickCount = action.clickCount;
|
|
106
|
+
if (action.position) options.position = action.position;
|
|
107
|
+
return options;
|
|
108
|
+
}
|
|
109
|
+
|
|
110
|
+
function formatOptions(value: any, hasArguments: boolean): string {
|
|
111
|
+
const keys = Object.keys(value).filter(key => value[key] !== undefined);
|
|
112
|
+
if (!keys.length) return '';
|
|
113
|
+
return (hasArguments ? ', ' : '') + formatObject(value);
|
|
114
|
+
}
|
|
115
|
+
|
|
116
|
+
function quote(text = ''): string {
|
|
117
|
+
return escapeWithQuotes(text, "'");
|
|
118
|
+
}
|
|
119
|
+
|
|
120
|
+
export function quoteMultiline(text: string, indent = ' ') {
|
|
121
|
+
const escape = (t: string) =>
|
|
122
|
+
t.replace(/\\/g, '\\\\').replace(/`/g, '\\`').replace(/\$\{/g, '\\${');
|
|
123
|
+
const lines = text.split('\n');
|
|
124
|
+
if (lines.length === 1) return '`' + escape(text) + '`';
|
|
125
|
+
return (
|
|
126
|
+
'`\n' +
|
|
127
|
+
lines
|
|
128
|
+
.map(line => indent + escape(line).replace(/\${/g, '\\${'))
|
|
129
|
+
.join('\n') +
|
|
130
|
+
`\n${indent}\``
|
|
131
|
+
);
|
|
132
|
+
}
|
|
133
|
+
|
|
134
|
+
export class JavaScriptLanguageGenerator {
|
|
135
|
+
protected _isTest: boolean;
|
|
136
|
+
|
|
137
|
+
constructor(isTest: boolean) {
|
|
138
|
+
this._isTest = isTest;
|
|
139
|
+
}
|
|
140
|
+
|
|
141
|
+
protected _asLocator(selector: string) {
|
|
142
|
+
return asLocator('javascript', selector);
|
|
143
|
+
}
|
|
144
|
+
|
|
145
|
+
protected _generateActionCall(
|
|
146
|
+
subject: string,
|
|
147
|
+
actionInContext: CodegenActionInContext
|
|
148
|
+
): string {
|
|
149
|
+
const action = actionInContext.action;
|
|
150
|
+
switch (action.name) {
|
|
151
|
+
case 'openPage':
|
|
152
|
+
throw Error('Not reached');
|
|
153
|
+
case 'closePage':
|
|
154
|
+
return `await ${subject}.close();`;
|
|
155
|
+
case 'click': {
|
|
156
|
+
let method = 'click';
|
|
157
|
+
if (action.clickCount === 2) method = 'dblclick';
|
|
158
|
+
const options = toClickOptionsForSourceCode(action);
|
|
159
|
+
const optionsString = formatOptions(options, false);
|
|
160
|
+
return `await ${subject}.${this._asLocator(
|
|
161
|
+
action.selector
|
|
162
|
+
)}.${method}(${optionsString});`;
|
|
163
|
+
}
|
|
164
|
+
case 'hover':
|
|
165
|
+
return `await ${subject}.${this._asLocator(
|
|
166
|
+
action.selector
|
|
167
|
+
)}.hover(${formatOptions({ position: action.position }, false)});`;
|
|
168
|
+
case 'check':
|
|
169
|
+
return `await ${subject}.${this._asLocator(action.selector)}.check();`;
|
|
170
|
+
case 'uncheck':
|
|
171
|
+
return `await ${subject}.${this._asLocator(
|
|
172
|
+
action.selector
|
|
173
|
+
)}.uncheck();`;
|
|
174
|
+
case 'fill':
|
|
175
|
+
return `await ${subject}.${this._asLocator(
|
|
176
|
+
action.selector
|
|
177
|
+
)}.fill(${quote(action.text)});`;
|
|
178
|
+
case 'setInputFiles': {
|
|
179
|
+
const files = action.files ?? [];
|
|
180
|
+
return `await ${subject}.${this._asLocator(
|
|
181
|
+
action.selector
|
|
182
|
+
)}.setInputFiles(${formatObject(
|
|
183
|
+
files.length === 1 ? files[0] : files
|
|
184
|
+
)});`;
|
|
185
|
+
}
|
|
186
|
+
case 'press': {
|
|
187
|
+
const modifiers = toKeyboardModifiers(action.modifiers);
|
|
188
|
+
const shortcut = [...modifiers, action.key].join('+');
|
|
189
|
+
return `await ${subject}.${this._asLocator(
|
|
190
|
+
action.selector
|
|
191
|
+
)}.press(${quote(shortcut)});`;
|
|
192
|
+
}
|
|
193
|
+
case 'navigate':
|
|
194
|
+
return `await ${subject}.goto(${quote(action.url)});`;
|
|
195
|
+
case 'select': {
|
|
196
|
+
const opts = action.options ?? [];
|
|
197
|
+
return `await ${subject}.${this._asLocator(
|
|
198
|
+
action.selector
|
|
199
|
+
)}.selectOption(${formatObject(opts.length === 1 ? opts[0] : opts)});`;
|
|
200
|
+
}
|
|
201
|
+
case 'assertText':
|
|
202
|
+
return `${
|
|
203
|
+
this._isTest ? '' : '// '
|
|
204
|
+
}await expect(${subject}.${this._asLocator(action.selector)}).${
|
|
205
|
+
action.substring ? 'toContainText' : 'toHaveText'
|
|
206
|
+
}(${quote(action.text)});`;
|
|
207
|
+
case 'assertChecked':
|
|
208
|
+
return `${
|
|
209
|
+
this._isTest ? '' : '// '
|
|
210
|
+
}await expect(${subject}.${this._asLocator(action.selector)})${
|
|
211
|
+
action.checked ? '' : '.not'
|
|
212
|
+
}.toBeChecked();`;
|
|
213
|
+
case 'assertVisible':
|
|
214
|
+
return `${
|
|
215
|
+
this._isTest ? '' : '// '
|
|
216
|
+
}await expect(${subject}.${this._asLocator(
|
|
217
|
+
action.selector
|
|
218
|
+
)}).toBeVisible();`;
|
|
219
|
+
case 'assertValue': {
|
|
220
|
+
const assertion = action.value
|
|
221
|
+
? `toHaveValue(${quote(action.value)})`
|
|
222
|
+
: `toBeEmpty()`;
|
|
223
|
+
return `${
|
|
224
|
+
this._isTest ? '' : '// '
|
|
225
|
+
}await expect(${subject}.${this._asLocator(
|
|
226
|
+
action.selector
|
|
227
|
+
)}).${assertion};`;
|
|
228
|
+
}
|
|
229
|
+
case 'assertSnapshot': {
|
|
230
|
+
const commentIfNeeded = this._isTest ? '' : '// ';
|
|
231
|
+
return `${commentIfNeeded}await expect(${subject}.${this._asLocator(
|
|
232
|
+
action.selector
|
|
233
|
+
)}).toMatchAriaSnapshot(${quoteMultiline(
|
|
234
|
+
action.ariaSnapshot ?? '',
|
|
235
|
+
`${commentIfNeeded} `
|
|
236
|
+
)});`;
|
|
237
|
+
}
|
|
238
|
+
default:
|
|
239
|
+
return '';
|
|
240
|
+
}
|
|
241
|
+
}
|
|
242
|
+
}
|
|
243
|
+
|
|
244
|
+
export class JavaScriptFormatter {
|
|
245
|
+
private _baseIndent: string;
|
|
246
|
+
private _baseOffset: string;
|
|
247
|
+
private _lines: string[] = [];
|
|
248
|
+
|
|
249
|
+
constructor(offset = 0) {
|
|
250
|
+
this._baseIndent = ' '.repeat(2);
|
|
251
|
+
this._baseOffset = ' '.repeat(offset);
|
|
252
|
+
}
|
|
253
|
+
|
|
254
|
+
prepend(text: string) {
|
|
255
|
+
const trim = isMultilineString(text)
|
|
256
|
+
? (line: string) => line
|
|
257
|
+
: (line: string) => line.trim();
|
|
258
|
+
this._lines = text.trim().split('\n').map(trim).concat(this._lines);
|
|
259
|
+
}
|
|
260
|
+
|
|
261
|
+
add(text: string) {
|
|
262
|
+
const trim = isMultilineString(text)
|
|
263
|
+
? (line: string) => line
|
|
264
|
+
: (line: string) => line.trim();
|
|
265
|
+
this._lines.push(...text.trim().split('\n').map(trim));
|
|
266
|
+
}
|
|
267
|
+
|
|
268
|
+
newLine() {
|
|
269
|
+
this._lines.push('');
|
|
270
|
+
}
|
|
271
|
+
|
|
272
|
+
format(): string {
|
|
273
|
+
let spaces = '';
|
|
274
|
+
let previousLine = '';
|
|
275
|
+
return this._lines
|
|
276
|
+
.map((line: string) => {
|
|
277
|
+
if (line === '') return line;
|
|
278
|
+
if (line.startsWith('}') || line.startsWith(']'))
|
|
279
|
+
spaces = spaces.substring(this._baseIndent.length);
|
|
280
|
+
|
|
281
|
+
const extraSpaces = /^(for|while|if|try).*\(.*\)$/.test(previousLine)
|
|
282
|
+
? this._baseIndent
|
|
283
|
+
: '';
|
|
284
|
+
previousLine = line;
|
|
285
|
+
|
|
286
|
+
const callCarryOver = line.startsWith('.set');
|
|
287
|
+
line =
|
|
288
|
+
spaces + extraSpaces + (callCarryOver ? this._baseIndent : '') + line;
|
|
289
|
+
if (line.endsWith('{') || line.endsWith('['))
|
|
290
|
+
spaces += this._baseIndent;
|
|
291
|
+
return this._baseOffset + line;
|
|
292
|
+
})
|
|
293
|
+
.join('\n');
|
|
294
|
+
}
|
|
295
|
+
}
|
|
296
|
+
|
|
297
|
+
function isMultilineString(text: string) {
|
|
298
|
+
return text.match(/`[\S\s]*`/)?.[0].includes('\n');
|
|
299
|
+
}
|
|
@@ -23,10 +23,7 @@
|
|
|
23
23
|
*
|
|
24
24
|
*/
|
|
25
25
|
|
|
26
|
-
import {
|
|
27
|
-
JavaScriptLanguageGenerator,
|
|
28
|
-
JavaScriptFormatter,
|
|
29
|
-
} from 'playwright-core/lib/server/codegen/javascript';
|
|
26
|
+
import { JavaScriptLanguageGenerator, JavaScriptFormatter } from './codegen';
|
|
30
27
|
|
|
31
28
|
export type Step = {
|
|
32
29
|
actions: ActionInContext[];
|