@itmetsam/samurai-framework 0.21.5 → 0.22.0

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 (141) hide show
  1. package/dist/api.d.ts +6 -1
  2. package/dist/api.js +1 -0
  3. package/dist/browser/browser-context.d.ts +18 -6
  4. package/dist/browser/browser-context.js +25 -7
  5. package/dist/browser/browser.d.ts +4 -4
  6. package/dist/browser/browser.js +11 -8
  7. package/dist/browser/chrome-launch.js +9 -1
  8. package/dist/browser/context-cookie-store.d.ts +17 -0
  9. package/dist/browser/context-cookie-store.js +90 -0
  10. package/dist/browser/index.d.ts +3 -1
  11. package/dist/browser/index.js +1 -1
  12. package/dist/browser/keyboard.d.ts +35 -0
  13. package/dist/browser/keyboard.js +83 -0
  14. package/dist/browser/mouse.d.ts +42 -0
  15. package/dist/browser/mouse.js +66 -0
  16. package/dist/browser/page-navigation.d.ts +0 -2
  17. package/dist/browser/page-navigation.js +1 -6
  18. package/dist/browser/page.d.ts +18 -8
  19. package/dist/browser/page.js +18 -9
  20. package/dist/browser/storage-state.d.ts +0 -2
  21. package/dist/browser/storage-state.js +0 -20
  22. package/dist/browser/use-applier.d.ts +16 -5
  23. package/dist/browser/use-applier.js +44 -17
  24. package/dist/browser/use-commands.d.ts +36 -0
  25. package/dist/browser/use-commands.js +120 -0
  26. package/dist/cli/args.d.ts +8 -4
  27. package/dist/cli/args.js +8 -5
  28. package/dist/cli/console-reporter.js +5 -1
  29. package/dist/cli/main.js +1 -0
  30. package/dist/cli/usage.d.ts +1 -1
  31. package/dist/cli/usage.js +4 -1
  32. package/dist/config/base-url.d.ts +4 -0
  33. package/dist/config/base-url.js +6 -0
  34. package/dist/config/config.js +6 -0
  35. package/dist/config/fully-parallel.d.ts +3 -0
  36. package/dist/config/fully-parallel.js +6 -0
  37. package/dist/config/group-use.d.ts +8 -0
  38. package/dist/config/group-use.js +41 -0
  39. package/dist/config/resolved-config.d.ts +2 -0
  40. package/dist/config/resolved-config.js +3 -0
  41. package/dist/config/storage-state-file.d.ts +3 -0
  42. package/dist/config/storage-state-file.js +20 -0
  43. package/dist/config/use-options.d.ts +3 -1
  44. package/dist/config/use-options.js +70 -14
  45. package/dist/config/web-server-options.d.ts +7 -0
  46. package/dist/config/web-server-options.js +111 -0
  47. package/dist/locator/check-actions.js +1 -1
  48. package/dist/locator/drag-actions.d.ts +17 -0
  49. package/dist/locator/drag-actions.js +80 -0
  50. package/dist/locator/element-actions.d.ts +10 -4
  51. package/dist/locator/element-actions.js +23 -16
  52. package/dist/locator/element-state.d.ts +5 -0
  53. package/dist/locator/element-state.js +2 -1
  54. package/dist/locator/event-actions.d.ts +10 -0
  55. package/dist/locator/event-actions.js +81 -0
  56. package/dist/locator/input-actions.d.ts +2 -11
  57. package/dist/locator/input-actions.js +3 -56
  58. package/dist/locator/key-actions.d.ts +11 -0
  59. package/dist/locator/key-actions.js +52 -0
  60. package/dist/locator/key-map.d.ts +16 -0
  61. package/dist/locator/key-map.js +76 -0
  62. package/dist/locator/locator.d.ts +35 -5
  63. package/dist/locator/locator.js +70 -16
  64. package/dist/locator/page-scripts.d.ts +2 -0
  65. package/dist/locator/page-scripts.js +7 -0
  66. package/dist/locator/pointer-actions.d.ts +44 -0
  67. package/dist/locator/pointer-actions.js +117 -0
  68. package/dist/locator/pointer-element-actions.d.ts +21 -0
  69. package/dist/locator/pointer-element-actions.js +42 -0
  70. package/dist/request/api-request-context.d.ts +65 -0
  71. package/dist/request/api-request-context.js +198 -0
  72. package/dist/request/api-response.d.ts +34 -0
  73. package/dist/request/api-response.js +57 -0
  74. package/dist/request/cookie-jar.d.ts +48 -0
  75. package/dist/request/cookie-jar.js +164 -0
  76. package/dist/request/http-transport.d.ts +31 -0
  77. package/dist/request/http-transport.js +113 -0
  78. package/dist/request/redirect.d.ts +10 -0
  79. package/dist/request/redirect.js +21 -0
  80. package/dist/request/request-body.d.ts +27 -0
  81. package/dist/request/request-body.js +71 -0
  82. package/dist/request/request.d.ts +16 -0
  83. package/dist/request/request.js +20 -0
  84. package/dist/runner/all-hooks.d.ts +7 -1
  85. package/dist/runner/all-hooks.js +17 -1
  86. package/dist/runner/fixture-defs.js +1 -0
  87. package/dist/runner/fixtures.d.ts +4 -1
  88. package/dist/runner/fixtures.js +3 -2
  89. package/dist/runner/global-hooks.d.ts +13 -0
  90. package/dist/runner/global-hooks.js +66 -0
  91. package/dist/runner/options.d.ts +13 -2
  92. package/dist/runner/output-tail.d.ts +14 -0
  93. package/dist/runner/output-tail.js +30 -0
  94. package/dist/runner/pool-schedule.d.ts +22 -0
  95. package/dist/runner/pool-schedule.js +55 -0
  96. package/dist/runner/pool-units.d.ts +34 -0
  97. package/dist/runner/pool-units.js +85 -0
  98. package/dist/runner/pooled-run.d.ts +7 -5
  99. package/dist/runner/pooled-run.js +19 -9
  100. package/dist/runner/registry.js +6 -2
  101. package/dist/runner/reporter.d.ts +10 -0
  102. package/dist/runner/reporter.js +12 -2
  103. package/dist/runner/request-fixture.d.ts +14 -0
  104. package/dist/runner/request-fixture.js +25 -0
  105. package/dist/runner/run-hooks.d.ts +16 -0
  106. package/dist/runner/run-hooks.js +52 -0
  107. package/dist/runner/run-test.js +7 -2
  108. package/dist/runner/run.d.ts +1 -0
  109. package/dist/runner/run.js +1 -0
  110. package/dist/runner/select.d.ts +15 -4
  111. package/dist/runner/select.js +38 -12
  112. package/dist/runner/serial-run.d.ts +23 -0
  113. package/dist/runner/serial-run.js +88 -0
  114. package/dist/runner/serial.d.ts +34 -0
  115. package/dist/runner/serial.js +63 -0
  116. package/dist/runner/shard.d.ts +22 -0
  117. package/dist/runner/shard.js +73 -0
  118. package/dist/runner/suite.d.ts +3 -3
  119. package/dist/runner/suite.js +4 -3
  120. package/dist/runner/test-function.d.ts +13 -1
  121. package/dist/runner/test-info.js +2 -1
  122. package/dist/runner/test-runner.d.ts +1 -0
  123. package/dist/runner/test-runner.js +62 -18
  124. package/dist/runner/use-options.d.ts +4 -4
  125. package/dist/runner/use-options.js +10 -3
  126. package/dist/runner/wait-for-url.d.ts +20 -0
  127. package/dist/runner/wait-for-url.js +65 -0
  128. package/dist/runner/web-server.d.ts +16 -0
  129. package/dist/runner/web-server.js +165 -0
  130. package/dist/runner/worker-pool.d.ts +13 -5
  131. package/dist/runner/worker-pool.js +85 -51
  132. package/dist/runner/worker-protocol.d.ts +8 -0
  133. package/dist/runner/worker-session.js +3 -1
  134. package/dist/runner/worker.d.ts +2 -0
  135. package/dist/runner/worker.js +7 -1
  136. package/dist/types/config.d.ts +83 -0
  137. package/dist/types/test.d.ts +18 -0
  138. package/dist/types/use.d.ts +45 -7
  139. package/package.json +1 -1
  140. package/dist/browser/emulation.d.ts +0 -61
  141. package/dist/browser/emulation.js +0 -180
@@ -1,180 +0,0 @@
1
- import { isUnsupported, UnsupportedOperationError, } from "../transport/unsupported.js";
2
- const ORIENTATIONS = [
3
- "portrait-primary",
4
- "portrait-secondary",
5
- "landscape-primary",
6
- "landscape-secondary",
7
- ];
8
- /** A part of the options could not be applied; what was applied before it stays applied */
9
- export class EmulationError extends Error {
10
- constructor(failed, applied, cause) {
11
- const detail = cause instanceof Error ? cause.message : String(cause);
12
- super(`emulate(): ${failed} failed${applied.length ? ` after applying ${applied.join(", ")}` : ""}: ${detail}`);
13
- this.name = "EmulationError";
14
- this.failed = failed;
15
- this.applied = applied;
16
- this.cause = cause;
17
- }
18
- }
19
- /** The browser does not implement an emulation command */
20
- export class EmulationUnsupportedError extends UnsupportedOperationError {
21
- constructor(option, applied) {
22
- super(`emulate(): ${option} is not supported by the browser`);
23
- this.name = "EmulationUnsupportedError";
24
- this.option = option;
25
- this.applied = applied;
26
- }
27
- }
28
- const isNumber = (value) => typeof value === "number" && Number.isFinite(value);
29
- const isPositiveInteger = (value) => Number.isInteger(value) && value > 0;
30
- /** Turns the options into commands, in a fixed order; throws RangeError for an invalid value, before anything is sent */
31
- function plan(options) {
32
- const steps = [];
33
- if (options.locale !== undefined) {
34
- if (options.locale !== null) {
35
- try {
36
- if (options.locale === "" ||
37
- Intl.getCanonicalLocales(options.locale).length !== 1)
38
- throw new RangeError();
39
- }
40
- catch {
41
- throw new RangeError(`emulate(): invalid locale "${options.locale}"`);
42
- }
43
- }
44
- steps.push({
45
- option: "locale",
46
- method: "emulation.setLocaleOverride",
47
- params: { locale: options.locale },
48
- });
49
- }
50
- if (options.timezone !== undefined) {
51
- if (options.timezone !== null) {
52
- try {
53
- new Intl.DateTimeFormat(undefined, { timeZone: options.timezone });
54
- }
55
- catch {
56
- throw new RangeError(`emulate(): unknown timezone "${options.timezone}"`);
57
- }
58
- }
59
- steps.push({
60
- option: "timezone",
61
- method: "emulation.setTimezoneOverride",
62
- params: { timezone: options.timezone },
63
- });
64
- }
65
- if (options.userAgent !== undefined) {
66
- if (options.userAgent === "")
67
- throw new RangeError("emulate(): userAgent must not be empty");
68
- steps.push({
69
- option: "userAgent",
70
- method: "emulation.setUserAgentOverride",
71
- params: { userAgent: options.userAgent },
72
- });
73
- }
74
- if (options.geolocation !== undefined) {
75
- const place = options.geolocation;
76
- if (place !== null) {
77
- if (!isNumber(place.latitude) ||
78
- place.latitude < -90 ||
79
- place.latitude > 90) {
80
- throw new RangeError("emulate(): latitude must be between -90 and 90");
81
- }
82
- if (!isNumber(place.longitude) ||
83
- place.longitude < -180 ||
84
- place.longitude > 180) {
85
- throw new RangeError("emulate(): longitude must be between -180 and 180");
86
- }
87
- if (place.accuracy !== undefined &&
88
- (!isNumber(place.accuracy) || place.accuracy < 0)) {
89
- throw new RangeError("emulate(): accuracy must be 0 or more");
90
- }
91
- }
92
- steps.push({
93
- option: "geolocation",
94
- method: "emulation.setGeolocationOverride",
95
- params: { coordinates: place },
96
- });
97
- }
98
- if (options.offline !== undefined) {
99
- steps.push({
100
- option: "offline",
101
- method: "emulation.setNetworkConditions",
102
- params: {
103
- networkConditions: options.offline ? { type: "offline" } : null,
104
- },
105
- });
106
- }
107
- if (options.orientation !== undefined) {
108
- let screenOrientation = null;
109
- if (options.orientation !== null) {
110
- const type = (options.orientation === "portrait" ||
111
- options.orientation === "landscape"
112
- ? `${options.orientation}-primary`
113
- : options.orientation);
114
- if (!ORIENTATIONS.includes(type))
115
- throw new RangeError(`emulate(): unknown orientation "${options.orientation}"`);
116
- screenOrientation = {
117
- natural: type.startsWith("portrait") ? "portrait" : "landscape",
118
- type,
119
- };
120
- }
121
- steps.push({
122
- option: "orientation",
123
- method: "emulation.setScreenOrientationOverride",
124
- params: { screenOrientation },
125
- });
126
- }
127
- if (options.screen !== undefined) {
128
- const area = options.screen;
129
- if (area !== null &&
130
- !(isPositiveInteger(area.width) && isPositiveInteger(area.height))) {
131
- throw new RangeError("emulate(): screen width and height must be positive integers");
132
- }
133
- steps.push({
134
- option: "screen",
135
- method: "emulation.setScreenSettingsOverride",
136
- params: { screenArea: area },
137
- });
138
- }
139
- if (options.touch !== undefined) {
140
- if (options.touch !== null && !isPositiveInteger(options.touch)) {
141
- throw new RangeError("emulate(): touch must be a positive integer");
142
- }
143
- steps.push({
144
- option: "touch",
145
- method: "emulation.setTouchOverride",
146
- params: { maxTouchPoints: options.touch },
147
- });
148
- }
149
- if (options.javaScriptEnabled !== undefined) {
150
- steps.push({
151
- option: "javaScriptEnabled",
152
- method: "emulation.setScriptingEnabled",
153
- params: { enabled: options.javaScriptEnabled === false ? false : null },
154
- });
155
- }
156
- return steps;
157
- }
158
- /** Throws RangeError when a value is invalid, without sending anything */
159
- export function validateEmulation(options) {
160
- plan(options);
161
- }
162
- /**
163
- * Applies the options to `target`, one command after the other. Nothing is rolled back when one fails:
164
- * the error says what was applied.
165
- */
166
- export async function applyEmulation(connector, target, options) {
167
- const applied = [];
168
- for (const step of plan(options)) {
169
- try {
170
- await connector.send(step.method, { ...step.params, ...target });
171
- }
172
- catch (err) {
173
- if (isUnsupported(err)) {
174
- throw new EmulationUnsupportedError(step.option, applied);
175
- }
176
- throw new EmulationError(step.option, applied, err);
177
- }
178
- applied.push(step.option);
179
- }
180
- }