@checkly/playwright-core 1.51.11-beta.1 → 1.51.11

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.
Files changed (49) hide show
  1. package/package.json +1 -1
  2. package/lib/common/socksProxy.js +0 -569
  3. package/lib/common/timeoutSettings.js +0 -73
  4. package/lib/common/types.js +0 -5
  5. package/lib/generated/recorderSource.js +0 -7
  6. package/lib/image_tools/colorUtils.js +0 -98
  7. package/lib/image_tools/compare.js +0 -108
  8. package/lib/image_tools/imageChannel.js +0 -70
  9. package/lib/image_tools/stats.js +0 -102
  10. package/lib/protocol/transport.js +0 -82
  11. package/lib/server/recorder/codeGenerator.js +0 -154
  12. package/lib/server/recorder/csharp.js +0 -311
  13. package/lib/server/recorder/java.js +0 -249
  14. package/lib/server/recorder/javascript.js +0 -230
  15. package/lib/server/recorder/jsonl.js +0 -48
  16. package/lib/server/recorder/language.js +0 -45
  17. package/lib/server/recorder/python.js +0 -276
  18. package/lib/server/recorder/recorderActions.js +0 -6
  19. package/lib/server/recorder/utils.js +0 -46
  20. package/lib/third_party/diff_match_patch.js +0 -2222
  21. package/lib/utils/ascii.js +0 -31
  22. package/lib/utils/comparators.js +0 -171
  23. package/lib/utils/crypto.js +0 -174
  24. package/lib/utils/debug.js +0 -46
  25. package/lib/utils/debugLogger.js +0 -91
  26. package/lib/utils/env.js +0 -49
  27. package/lib/utils/eventsHelper.js +0 -38
  28. package/lib/utils/glob.js +0 -84
  29. package/lib/utils/happy-eyeballs.js +0 -210
  30. package/lib/utils/headers.js +0 -52
  31. package/lib/utils/hostPlatform.js +0 -133
  32. package/lib/utils/httpServer.js +0 -237
  33. package/lib/utils/linuxUtils.js +0 -78
  34. package/lib/utils/manualPromise.js +0 -109
  35. package/lib/utils/mimeType.js +0 -30
  36. package/lib/utils/multimap.js +0 -75
  37. package/lib/utils/network.js +0 -160
  38. package/lib/utils/processLauncher.js +0 -248
  39. package/lib/utils/profiler.js +0 -53
  40. package/lib/utils/rtti.js +0 -44
  41. package/lib/utils/semaphore.js +0 -51
  42. package/lib/utils/spawnAsync.js +0 -45
  43. package/lib/utils/task.js +0 -58
  44. package/lib/utils/time.js +0 -37
  45. package/lib/utils/traceUtils.js +0 -44
  46. package/lib/utils/userAgent.js +0 -105
  47. package/lib/utils/wsServer.js +0 -127
  48. package/lib/utils/zipFile.js +0 -75
  49. package/lib/vite/traceViewer/sw.bundle.js +0 -3
@@ -1,249 +0,0 @@
1
- "use strict";
2
-
3
- Object.defineProperty(exports, "__esModule", {
4
- value: true
5
- });
6
- exports.JavaLanguageGenerator = void 0;
7
- var _language = require("./language");
8
- var _utils = require("./utils");
9
- var _javascript = require("./javascript");
10
- var _stringUtils = require("../../utils/isomorphic/stringUtils");
11
- var _locatorGenerators = require("../../utils/isomorphic/locatorGenerators");
12
- /**
13
- * Copyright (c) Microsoft Corporation.
14
- *
15
- * Licensed under the Apache License, Version 2.0 (the "License");
16
- * you may not use this file except in compliance with the License.
17
- * You may obtain a copy of the License at
18
- *
19
- * http://www.apache.org/licenses/LICENSE-2.0
20
- *
21
- * Unless required by applicable law or agreed to in writing, software
22
- * distributed under the License is distributed on an "AS IS" BASIS,
23
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
24
- * See the License for the specific language governing permissions and
25
- * limitations under the License.
26
- */
27
-
28
- const deviceDescriptors = require('../deviceDescriptorsSource.json');
29
- class JavaLanguageGenerator {
30
- constructor(mode) {
31
- this.id = void 0;
32
- this.groupName = 'Java';
33
- this.name = void 0;
34
- this.highlighter = 'java';
35
- this._mode = void 0;
36
- if (mode === 'library') {
37
- this.name = 'Library';
38
- this.id = 'java';
39
- } else if (mode === 'junit') {
40
- this.name = 'JUnit';
41
- this.id = 'java-junit';
42
- } else {
43
- throw new Error(`Unknown Java language mode: ${mode}`);
44
- }
45
- this._mode = mode;
46
- }
47
- generateAction(actionInContext) {
48
- const action = actionInContext.action;
49
- const pageAlias = actionInContext.frame.pageAlias;
50
- const offset = this._mode === 'junit' ? 4 : 6;
51
- const formatter = new _javascript.JavaScriptFormatter(offset);
52
- if (this._mode !== 'library' && (action.name === 'openPage' || action.name === 'closePage')) return '';
53
- if (action.name === 'openPage') {
54
- formatter.add(`Page ${pageAlias} = context.newPage();`);
55
- if (action.url && action.url !== 'about:blank' && action.url !== 'chrome://newtab/') formatter.add(`${pageAlias}.navigate(${quote(action.url)});`);
56
- return formatter.format();
57
- }
58
- let subject;
59
- let inFrameLocator = false;
60
- if (actionInContext.frame.isMainFrame) {
61
- subject = pageAlias;
62
- } else {
63
- const locators = actionInContext.frame.selectorsChain.map(selector => `.frameLocator(${quote(selector)})`);
64
- subject = `${pageAlias}${locators.join('')}`;
65
- inFrameLocator = true;
66
- }
67
- const signals = (0, _language.toSignalMap)(action);
68
- if (signals.dialog) {
69
- formatter.add(` ${pageAlias}.onceDialog(dialog -> {
70
- System.out.println(String.format("Dialog message: %s", dialog.message()));
71
- dialog.dismiss();
72
- });`);
73
- }
74
- let code = this._generateActionCall(subject, action, inFrameLocator);
75
- if (signals.popup) {
76
- code = `Page ${signals.popup.popupAlias} = ${pageAlias}.waitForPopup(() -> {
77
- ${code}
78
- });`;
79
- }
80
- if (signals.download) {
81
- code = `Download download${signals.download.downloadAlias} = ${pageAlias}.waitForDownload(() -> {
82
- ${code}
83
- });`;
84
- }
85
- formatter.add(code);
86
- return formatter.format();
87
- }
88
- _generateActionCall(subject, action, inFrameLocator) {
89
- switch (action.name) {
90
- case 'openPage':
91
- throw Error('Not reached');
92
- case 'closePage':
93
- return `${subject}.close();`;
94
- case 'click':
95
- {
96
- let method = 'click';
97
- if (action.clickCount === 2) method = 'dblclick';
98
- const modifiers = (0, _utils.toModifiers)(action.modifiers);
99
- const options = {};
100
- if (action.button !== 'left') options.button = action.button;
101
- if (modifiers.length) options.modifiers = modifiers;
102
- if (action.clickCount > 2) options.clickCount = action.clickCount;
103
- if (action.position) options.position = action.position;
104
- const optionsText = formatClickOptions(options);
105
- return `${subject}.${this._asLocator(action.selector, inFrameLocator)}.${method}(${optionsText});`;
106
- }
107
- case 'check':
108
- return `${subject}.${this._asLocator(action.selector, inFrameLocator)}.check();`;
109
- case 'uncheck':
110
- return `${subject}.${this._asLocator(action.selector, inFrameLocator)}.uncheck();`;
111
- case 'fill':
112
- return `${subject}.${this._asLocator(action.selector, inFrameLocator)}.fill(${quote(action.text)});`;
113
- case 'setInputFiles':
114
- return `${subject}.${this._asLocator(action.selector, inFrameLocator)}.setInputFiles(${formatPath(action.files.length === 1 ? action.files[0] : action.files)});`;
115
- case 'press':
116
- {
117
- const modifiers = (0, _utils.toModifiers)(action.modifiers);
118
- const shortcut = [...modifiers, action.key].join('+');
119
- return `${subject}.${this._asLocator(action.selector, inFrameLocator)}.press(${quote(shortcut)});`;
120
- }
121
- case 'navigate':
122
- return `${subject}.navigate(${quote(action.url)});`;
123
- case 'select':
124
- return `${subject}.${this._asLocator(action.selector, inFrameLocator)}.selectOption(${formatSelectOption(action.options.length > 1 ? action.options : action.options[0])});`;
125
- case 'assertText':
126
- return `assertThat(${subject}.${this._asLocator(action.selector, inFrameLocator)}).${action.substring ? 'containsText' : 'hasText'}(${quote(action.text)});`;
127
- case 'assertChecked':
128
- return `assertThat(${subject}.${this._asLocator(action.selector, inFrameLocator)})${action.checked ? '' : '.not()'}.isChecked();`;
129
- case 'assertVisible':
130
- return `assertThat(${subject}.${this._asLocator(action.selector, inFrameLocator)}).isVisible();`;
131
- case 'assertValue':
132
- {
133
- const assertion = action.value ? `hasValue(${quote(action.value)})` : `isEmpty()`;
134
- return `assertThat(${subject}.${this._asLocator(action.selector, inFrameLocator)}).${assertion};`;
135
- }
136
- }
137
- }
138
- _asLocator(selector, inFrameLocator) {
139
- return (0, _locatorGenerators.asLocator)('java', selector, inFrameLocator);
140
- }
141
- generateHeader(options) {
142
- const formatter = new _javascript.JavaScriptFormatter();
143
- if (this._mode === 'junit') {
144
- formatter.add(`
145
- import com.microsoft.playwright.junit.UsePlaywright;
146
- import com.microsoft.playwright.Page;
147
- import com.microsoft.playwright.options.*;
148
-
149
- import org.junit.jupiter.api.*;
150
- import static com.microsoft.playwright.assertions.PlaywrightAssertions.*;
151
-
152
- @UsePlaywright
153
- public class TestExample {
154
- @Test
155
- void test(Page page) {`);
156
- return formatter.format();
157
- }
158
- formatter.add(`
159
- import com.microsoft.playwright.*;
160
- import com.microsoft.playwright.options.*;
161
- import static com.microsoft.playwright.assertions.PlaywrightAssertions.assertThat;
162
- import java.util.*;
163
-
164
- public class Example {
165
- public static void main(String[] args) {
166
- try (Playwright playwright = Playwright.create()) {
167
- Browser browser = playwright.${options.browserName}().launch(${formatLaunchOptions(options.launchOptions)});
168
- BrowserContext context = browser.newContext(${formatContextOptions(options.contextOptions, options.deviceName)});`);
169
- return formatter.format();
170
- }
171
- generateFooter(saveStorage) {
172
- const storageStateLine = saveStorage ? `\n context.storageState(new BrowserContext.StorageStateOptions().setPath(${quote(saveStorage)}));\n` : '';
173
- if (this._mode === 'junit') {
174
- return `${storageStateLine} }
175
- }`;
176
- }
177
- return `${storageStateLine} }
178
- }
179
- }`;
180
- }
181
- }
182
- exports.JavaLanguageGenerator = JavaLanguageGenerator;
183
- function formatPath(files) {
184
- if (Array.isArray(files)) {
185
- if (files.length === 0) return 'new Path[0]';
186
- return `new Path[] {${files.map(s => 'Paths.get(' + quote(s) + ')').join(', ')}}`;
187
- }
188
- return `Paths.get(${quote(files)})`;
189
- }
190
- function formatSelectOption(options) {
191
- if (Array.isArray(options)) {
192
- if (options.length === 0) return 'new String[0]';
193
- return `new String[] {${options.map(s => quote(s)).join(', ')}}`;
194
- }
195
- return quote(options);
196
- }
197
- function formatLaunchOptions(options) {
198
- const lines = [];
199
- if (!Object.keys(options).filter(key => options[key] !== undefined).length) return '';
200
- lines.push('new BrowserType.LaunchOptions()');
201
- if (options.channel) lines.push(` .setChannel(${quote(options.channel)})`);
202
- if (typeof options.headless === 'boolean') lines.push(` .setHeadless(false)`);
203
- return lines.join('\n');
204
- }
205
- function formatContextOptions(contextOptions, deviceName) {
206
- var _options$recordHar, _options$recordHar2, _options$recordHar3, _options$recordHar4, _options$recordHar5, _options$recordHar6, _options$recordHar7;
207
- const lines = [];
208
- if (!Object.keys(contextOptions).length && !deviceName) return '';
209
- const device = deviceName ? deviceDescriptors[deviceName] : {};
210
- const options = {
211
- ...device,
212
- ...contextOptions
213
- };
214
- lines.push('new Browser.NewContextOptions()');
215
- if (options.acceptDownloads) lines.push(` .setAcceptDownloads(true)`);
216
- if (options.bypassCSP) lines.push(` .setBypassCSP(true)`);
217
- if (options.colorScheme) lines.push(` .setColorScheme(ColorScheme.${options.colorScheme.toUpperCase()})`);
218
- if (options.deviceScaleFactor) lines.push(` .setDeviceScaleFactor(${options.deviceScaleFactor})`);
219
- if (options.geolocation) lines.push(` .setGeolocation(${options.geolocation.latitude}, ${options.geolocation.longitude})`);
220
- if (options.hasTouch) lines.push(` .setHasTouch(${options.hasTouch})`);
221
- if (options.isMobile) lines.push(` .setIsMobile(${options.isMobile})`);
222
- if (options.locale) lines.push(` .setLocale(${quote(options.locale)})`);
223
- if (options.proxy) lines.push(` .setProxy(new Proxy(${quote(options.proxy.server)}))`);
224
- if ((_options$recordHar = options.recordHar) !== null && _options$recordHar !== void 0 && _options$recordHar.content) lines.push(` .setRecordHarContent(HarContentPolicy.${(_options$recordHar2 = options.recordHar) === null || _options$recordHar2 === void 0 ? void 0 : _options$recordHar2.content.toUpperCase()})`);
225
- if ((_options$recordHar3 = options.recordHar) !== null && _options$recordHar3 !== void 0 && _options$recordHar3.mode) lines.push(` .setRecordHarMode(HarMode.${(_options$recordHar4 = options.recordHar) === null || _options$recordHar4 === void 0 ? void 0 : _options$recordHar4.mode.toUpperCase()})`);
226
- if ((_options$recordHar5 = options.recordHar) !== null && _options$recordHar5 !== void 0 && _options$recordHar5.omitContent) lines.push(` .setRecordHarOmitContent(true)`);
227
- if ((_options$recordHar6 = options.recordHar) !== null && _options$recordHar6 !== void 0 && _options$recordHar6.path) lines.push(` .setRecordHarPath(Paths.get(${quote(options.recordHar.path)}))`);
228
- if ((_options$recordHar7 = options.recordHar) !== null && _options$recordHar7 !== void 0 && _options$recordHar7.urlFilter) lines.push(` .setRecordHarUrlFilter(${quote(options.recordHar.urlFilter)})`);
229
- if (options.serviceWorkers) lines.push(` .setServiceWorkers(ServiceWorkerPolicy.${options.serviceWorkers.toUpperCase()})`);
230
- if (options.storageState) lines.push(` .setStorageStatePath(Paths.get(${quote(options.storageState)}))`);
231
- if (options.timezoneId) lines.push(` .setTimezoneId(${quote(options.timezoneId)})`);
232
- if (options.userAgent) lines.push(` .setUserAgent(${quote(options.userAgent)})`);
233
- if (options.viewport) lines.push(` .setViewportSize(${options.viewport.width}, ${options.viewport.height})`);
234
- return lines.join('\n');
235
- }
236
- function formatClickOptions(options) {
237
- const lines = [];
238
- if (options.button) lines.push(` .setButton(MouseButton.${options.button.toUpperCase()})`);
239
- if (options.modifiers) lines.push(` .setModifiers(Arrays.asList(${options.modifiers.map(m => `KeyboardModifier.${m.toUpperCase()}`).join(', ')}))`);
240
- if (options.clickCount) lines.push(` .setClickCount(${options.clickCount})`);
241
- if (options.position) lines.push(` .setPosition(${options.position.x}, ${options.position.y})`);
242
- if (!lines.length) return '';
243
- lines.unshift(`new Locator.ClickOptions()`);
244
- return lines.join('\n');
245
- }
246
- function quote(text) {
247
- return (0, _stringUtils.escapeWithQuotes)(text, '\"');
248
- }
249
- //# sourceMappingURL=java.js.map
@@ -1,230 +0,0 @@
1
- "use strict";
2
-
3
- Object.defineProperty(exports, "__esModule", {
4
- value: true
5
- });
6
- exports.JavaScriptLanguageGenerator = exports.JavaScriptFormatter = void 0;
7
- var _language = require("./language");
8
- var _utils = require("./utils");
9
- var _stringUtils = require("../../utils/isomorphic/stringUtils");
10
- var _locatorGenerators = require("../../utils/isomorphic/locatorGenerators");
11
- /**
12
- * Copyright (c) Microsoft Corporation.
13
- *
14
- * Licensed under the Apache License, Version 2.0 (the "License");
15
- * you may not use this file except in compliance with the License.
16
- * You may obtain a copy of the License at
17
- *
18
- * http://www.apache.org/licenses/LICENSE-2.0
19
- *
20
- * Unless required by applicable law or agreed to in writing, software
21
- * distributed under the License is distributed on an "AS IS" BASIS,
22
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
23
- * See the License for the specific language governing permissions and
24
- * limitations under the License.
25
- */
26
-
27
- const deviceDescriptors = require('../deviceDescriptorsSource.json');
28
- class JavaScriptLanguageGenerator {
29
- constructor(isTest) {
30
- this.id = void 0;
31
- this.groupName = 'Node.js';
32
- this.name = void 0;
33
- this.highlighter = 'javascript';
34
- this._isTest = void 0;
35
- this.id = isTest ? 'playwright-test' : 'javascript';
36
- this.name = isTest ? 'Test Runner' : 'Library';
37
- this._isTest = isTest;
38
- }
39
- generateAction(actionInContext) {
40
- const action = actionInContext.action;
41
- if (this._isTest && (action.name === 'openPage' || action.name === 'closePage')) return '';
42
- const pageAlias = actionInContext.frame.pageAlias;
43
- const formatter = new JavaScriptFormatter(2);
44
- if (action.name === 'openPage') {
45
- formatter.add(`const ${pageAlias} = await context.newPage();`);
46
- if (action.url && action.url !== 'about:blank' && action.url !== 'chrome://newtab/') formatter.add(`await ${pageAlias}.goto(${quote(action.url)});`);
47
- return formatter.format();
48
- }
49
- let subject;
50
- if (actionInContext.frame.isMainFrame) {
51
- subject = pageAlias;
52
- } else {
53
- const locators = actionInContext.frame.selectorsChain.map(selector => `.frameLocator(${quote(selector)})`);
54
- subject = `${pageAlias}${locators.join('')}`;
55
- }
56
- const signals = (0, _language.toSignalMap)(action);
57
- if (signals.dialog) {
58
- formatter.add(` ${pageAlias}.once('dialog', dialog => {
59
- console.log(\`Dialog message: $\{dialog.message()}\`);
60
- dialog.dismiss().catch(() => {});
61
- });`);
62
- }
63
- if (signals.popup) formatter.add(`const ${signals.popup.popupAlias}Promise = ${pageAlias}.waitForEvent('popup');`);
64
- if (signals.download) formatter.add(`const download${signals.download.downloadAlias}Promise = ${pageAlias}.waitForEvent('download');`);
65
- formatter.add(this._generateActionCall(subject, action));
66
- if (signals.popup) formatter.add(`const ${signals.popup.popupAlias} = await ${signals.popup.popupAlias}Promise;`);
67
- if (signals.download) formatter.add(`const download${signals.download.downloadAlias} = await download${signals.download.downloadAlias}Promise;`);
68
- return formatter.format();
69
- }
70
- _generateActionCall(subject, action) {
71
- switch (action.name) {
72
- case 'openPage':
73
- throw Error('Not reached');
74
- case 'closePage':
75
- return `await ${subject}.close();`;
76
- case 'click':
77
- {
78
- let method = 'click';
79
- if (action.clickCount === 2) method = 'dblclick';
80
- const modifiers = (0, _utils.toModifiers)(action.modifiers);
81
- const options = {};
82
- if (action.button !== 'left') options.button = action.button;
83
- if (modifiers.length) options.modifiers = modifiers;
84
- if (action.clickCount > 2) options.clickCount = action.clickCount;
85
- if (action.position) options.position = action.position;
86
- const optionsString = formatOptions(options, false);
87
- return `await ${subject}.${this._asLocator(action.selector)}.${method}(${optionsString});`;
88
- }
89
- case 'check':
90
- return `await ${subject}.${this._asLocator(action.selector)}.check();`;
91
- case 'uncheck':
92
- return `await ${subject}.${this._asLocator(action.selector)}.uncheck();`;
93
- case 'fill':
94
- return `await ${subject}.${this._asLocator(action.selector)}.fill(${quote(action.text)});`;
95
- case 'setInputFiles':
96
- return `await ${subject}.${this._asLocator(action.selector)}.setInputFiles(${formatObject(action.files.length === 1 ? action.files[0] : action.files)});`;
97
- case 'press':
98
- {
99
- const modifiers = (0, _utils.toModifiers)(action.modifiers);
100
- const shortcut = [...modifiers, action.key].join('+');
101
- return `await ${subject}.${this._asLocator(action.selector)}.press(${quote(shortcut)});`;
102
- }
103
- case 'navigate':
104
- return `await ${subject}.goto(${quote(action.url)});`;
105
- case 'select':
106
- return `await ${subject}.${this._asLocator(action.selector)}.selectOption(${formatObject(action.options.length > 1 ? action.options : action.options[0])});`;
107
- case 'assertText':
108
- return `${this._isTest ? '' : '// '}await expect(${subject}.${this._asLocator(action.selector)}).${action.substring ? 'toContainText' : 'toHaveText'}(${quote(action.text)});`;
109
- case 'assertChecked':
110
- return `${this._isTest ? '' : '// '}await expect(${subject}.${this._asLocator(action.selector)})${action.checked ? '' : '.not'}.toBeChecked();`;
111
- case 'assertVisible':
112
- return `${this._isTest ? '' : '// '}await expect(${subject}.${this._asLocator(action.selector)}).toBeVisible();`;
113
- case 'assertValue':
114
- {
115
- const assertion = action.value ? `toHaveValue(${quote(action.value)})` : `toBeEmpty()`;
116
- return `${this._isTest ? '' : '// '}await expect(${subject}.${this._asLocator(action.selector)}).${assertion};`;
117
- }
118
- }
119
- }
120
- _asLocator(selector) {
121
- return (0, _locatorGenerators.asLocator)('javascript', selector);
122
- }
123
- generateHeader(options) {
124
- if (this._isTest) return this.generateTestHeader(options);
125
- return this.generateStandaloneHeader(options);
126
- }
127
- generateFooter(saveStorage) {
128
- if (this._isTest) return this.generateTestFooter(saveStorage);
129
- return this.generateStandaloneFooter(saveStorage);
130
- }
131
- generateTestHeader(options) {
132
- const formatter = new JavaScriptFormatter();
133
- const useText = formatContextOptions(options.contextOptions, options.deviceName);
134
- formatter.add(`
135
- import { test, expect${options.deviceName ? ', devices' : ''} } from '@playwright/test';
136
- ${useText ? '\ntest.use(' + useText + ');\n' : ''}
137
- test('test', async ({ page }) => {`);
138
- return formatter.format();
139
- }
140
- generateTestFooter(saveStorage) {
141
- return `});`;
142
- }
143
- generateStandaloneHeader(options) {
144
- const formatter = new JavaScriptFormatter();
145
- formatter.add(`
146
- const { ${options.browserName}${options.deviceName ? ', devices' : ''} } = require('playwright');
147
-
148
- (async () => {
149
- const browser = await ${options.browserName}.launch(${formatObjectOrVoid(options.launchOptions)});
150
- const context = await browser.newContext(${formatContextOptions(options.contextOptions, options.deviceName)});`);
151
- return formatter.format();
152
- }
153
- generateStandaloneFooter(saveStorage) {
154
- const storageStateLine = saveStorage ? `\n await context.storageState({ path: ${quote(saveStorage)} });` : '';
155
- return `\n // ---------------------${storageStateLine}
156
- await context.close();
157
- await browser.close();
158
- })();`;
159
- }
160
- }
161
- exports.JavaScriptLanguageGenerator = JavaScriptLanguageGenerator;
162
- function formatOptions(value, hasArguments) {
163
- const keys = Object.keys(value);
164
- if (!keys.length) return '';
165
- return (hasArguments ? ', ' : '') + formatObject(value);
166
- }
167
- function formatObject(value, indent = ' ') {
168
- if (typeof value === 'string') return quote(value);
169
- if (Array.isArray(value)) return `[${value.map(o => formatObject(o)).join(', ')}]`;
170
- if (typeof value === 'object') {
171
- const keys = Object.keys(value).filter(key => value[key] !== undefined).sort();
172
- if (!keys.length) return '{}';
173
- const tokens = [];
174
- for (const key of keys) tokens.push(`${key}: ${formatObject(value[key])}`);
175
- return `{\n${indent}${tokens.join(`,\n${indent}`)}\n}`;
176
- }
177
- return String(value);
178
- }
179
- function formatObjectOrVoid(value, indent = ' ') {
180
- const result = formatObject(value, indent);
181
- return result === '{}' ? '' : result;
182
- }
183
- function formatContextOptions(options, deviceName) {
184
- const device = deviceName && deviceDescriptors[deviceName];
185
- if (!device) return formatObjectOrVoid(options);
186
- // Filter out all the properties from the device descriptor.
187
- let serializedObject = formatObjectOrVoid((0, _language.sanitizeDeviceOptions)(device, options));
188
- // When there are no additional context options, we still want to spread the device inside.
189
- if (!serializedObject) serializedObject = '{\n}';
190
- const lines = serializedObject.split('\n');
191
- lines.splice(1, 0, `...devices[${quote(deviceName)}],`);
192
- return lines.join('\n');
193
- }
194
- class JavaScriptFormatter {
195
- constructor(offset = 0) {
196
- this._baseIndent = void 0;
197
- this._baseOffset = void 0;
198
- this._lines = [];
199
- this._baseIndent = ' '.repeat(2);
200
- this._baseOffset = ' '.repeat(offset);
201
- }
202
- prepend(text) {
203
- this._lines = text.trim().split('\n').map(line => line.trim()).concat(this._lines);
204
- }
205
- add(text) {
206
- this._lines.push(...text.trim().split('\n').map(line => line.trim()));
207
- }
208
- newLine() {
209
- this._lines.push('');
210
- }
211
- format() {
212
- let spaces = '';
213
- let previousLine = '';
214
- return this._lines.map(line => {
215
- if (line === '') return line;
216
- if (line.startsWith('}') || line.startsWith(']')) spaces = spaces.substring(this._baseIndent.length);
217
- const extraSpaces = /^(for|while|if|try).*\(.*\)$/.test(previousLine) ? this._baseIndent : '';
218
- previousLine = line;
219
- const callCarryOver = line.startsWith('.set');
220
- line = spaces + extraSpaces + (callCarryOver ? this._baseIndent : '') + line;
221
- if (line.endsWith('{') || line.endsWith('[')) spaces += this._baseIndent;
222
- return this._baseOffset + line;
223
- }).join('\n');
224
- }
225
- }
226
- exports.JavaScriptFormatter = JavaScriptFormatter;
227
- function quote(text) {
228
- return (0, _stringUtils.escapeWithQuotes)(text, '\'');
229
- }
230
- //# sourceMappingURL=javascript.js.map
@@ -1,48 +0,0 @@
1
- "use strict";
2
-
3
- Object.defineProperty(exports, "__esModule", {
4
- value: true
5
- });
6
- exports.JsonlLanguageGenerator = void 0;
7
- var _locatorGenerators = require("../../utils/isomorphic/locatorGenerators");
8
- /**
9
- * Copyright (c) Microsoft Corporation.
10
- *
11
- * Licensed under the Apache License, Version 2.0 (the "License");
12
- * you may not use this file except in compliance with the License.
13
- * You may obtain a copy of the License at
14
- *
15
- * http://www.apache.org/licenses/LICENSE-2.0
16
- *
17
- * Unless required by applicable law or agreed to in writing, software
18
- * distributed under the License is distributed on an "AS IS" BASIS,
19
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
20
- * See the License for the specific language governing permissions and
21
- * limitations under the License.
22
- */
23
-
24
- class JsonlLanguageGenerator {
25
- constructor() {
26
- this.id = 'jsonl';
27
- this.groupName = '';
28
- this.name = 'JSONL';
29
- this.highlighter = 'javascript';
30
- }
31
- generateAction(actionInContext) {
32
- const locator = actionInContext.action.selector ? JSON.parse((0, _locatorGenerators.asLocator)('jsonl', actionInContext.action.selector)) : undefined;
33
- const entry = {
34
- ...actionInContext.action,
35
- pageAlias: actionInContext.frame.pageAlias,
36
- locator
37
- };
38
- return JSON.stringify(entry);
39
- }
40
- generateHeader(options) {
41
- return JSON.stringify(options);
42
- }
43
- generateFooter(saveStorage) {
44
- return '';
45
- }
46
- }
47
- exports.JsonlLanguageGenerator = JsonlLanguageGenerator;
48
- //# sourceMappingURL=jsonl.js.map
@@ -1,45 +0,0 @@
1
- "use strict";
2
-
3
- Object.defineProperty(exports, "__esModule", {
4
- value: true
5
- });
6
- exports.sanitizeDeviceOptions = sanitizeDeviceOptions;
7
- exports.toSignalMap = toSignalMap;
8
- /**
9
- * Copyright (c) Microsoft Corporation.
10
- *
11
- * Licensed under the Apache License, Version 2.0 (the "License");
12
- * you may not use this file except in compliance with the License.
13
- * You may obtain a copy of the License at
14
- *
15
- * http://www.apache.org/licenses/LICENSE-2.0
16
- *
17
- * Unless required by applicable law or agreed to in writing, software
18
- * distributed under the License is distributed on an "AS IS" BASIS,
19
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
20
- * See the License for the specific language governing permissions and
21
- * limitations under the License.
22
- */
23
-
24
- function sanitizeDeviceOptions(device, options) {
25
- // Filter out all the properties from the device descriptor.
26
- const cleanedOptions = {};
27
- for (const property in options) {
28
- if (JSON.stringify(device[property]) !== JSON.stringify(options[property])) cleanedOptions[property] = options[property];
29
- }
30
- return cleanedOptions;
31
- }
32
- function toSignalMap(action) {
33
- let popup;
34
- let download;
35
- let dialog;
36
- for (const signal of action.signals) {
37
- if (signal.name === 'popup') popup = signal;else if (signal.name === 'download') download = signal;else if (signal.name === 'dialog') dialog = signal;
38
- }
39
- return {
40
- popup,
41
- download,
42
- dialog
43
- };
44
- }
45
- //# sourceMappingURL=language.js.map