@amazon/vinyl-util 1.2.0 → 2.0.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.
Files changed (81) hide show
  1. package/dist/browserTestUtil/index.js +1850 -1850
  2. package/dist/browserTestUtil/index.js.map +4 -4
  3. package/dist/browserTestUtil/types/current/index.d.ts +17 -17
  4. package/dist/browserTestUtil/types/current/index.d.ts.map +1 -1
  5. package/dist/browserTestUtil/types/current/index.js +17 -17
  6. package/dist/browserTestUtil/types/current/tsconfig.tsbuildinfo +1 -1
  7. package/dist/browserTestUtil/types/ts3.7/index.d.ts +17 -17
  8. package/dist/browserTestUtil/types/ts4.1/index.d.ts +17 -17
  9. package/dist/browserTestUtil/types/ts4.7/index.d.ts +17 -17
  10. package/dist/index.cjs +4997 -4967
  11. package/dist/index.cjs.map +4 -4
  12. package/dist/index.js +4997 -4967
  13. package/dist/index.js.map +4 -4
  14. package/dist/polyfill/index.d.ts +1 -0
  15. package/dist/polyfill/index.d.ts.map +1 -1
  16. package/dist/polyfill/index.js +166 -103
  17. package/dist/polyfill/index.js.map +3 -3
  18. package/dist/polyfill/tsconfig.tsbuildinfo +1 -1
  19. package/dist/test/benchmark.es5.js +68 -68
  20. package/dist/test/benchmark.js +1518 -1517
  21. package/dist/test/benchmark.js.map +4 -4
  22. package/dist/testUtil/index.js +418 -418
  23. package/dist/testUtil/index.js.map +4 -4
  24. package/dist/testUtil/types/current/index.d.ts +16 -16
  25. package/dist/testUtil/types/current/index.d.ts.map +1 -1
  26. package/dist/testUtil/types/current/index.js +16 -16
  27. package/dist/testUtil/types/current/reporters/LogReporter.d.ts +1 -0
  28. package/dist/testUtil/types/current/reporters/LogReporter.d.ts.map +1 -1
  29. package/dist/testUtil/types/current/reporters/LogReporter.js +8 -0
  30. package/dist/testUtil/types/current/tsconfig.tsbuildinfo +1 -1
  31. package/dist/testUtil/types/current/util/event/createEventSpy.d.ts.map +1 -1
  32. package/dist/testUtil/types/current/util/event/createEventSpy.js +6 -4
  33. package/dist/testUtil/types/ts3.7/index.d.ts +16 -16
  34. package/dist/testUtil/types/ts3.7/reporters/LogReporter.d.ts +1 -0
  35. package/dist/testUtil/types/ts4.1/index.d.ts +16 -16
  36. package/dist/testUtil/types/ts4.1/reporters/LogReporter.d.ts +1 -0
  37. package/dist/testUtil/types/ts4.7/index.d.ts +16 -16
  38. package/dist/testUtil/types/ts4.7/reporters/LogReporter.d.ts +1 -0
  39. package/dist/types/current/event/nextEventAsPromise.d.ts +14 -4
  40. package/dist/types/current/event/nextEventAsPromise.d.ts.map +1 -1
  41. package/dist/types/current/event/nextEventAsPromise.js +8 -2
  42. package/dist/types/current/index.d.ts +114 -113
  43. package/dist/types/current/index.d.ts.map +1 -1
  44. package/dist/types/current/index.js +114 -113
  45. package/dist/types/current/tsconfig.tsbuildinfo +1 -1
  46. package/dist/types/current/util/async/poll.d.ts +34 -0
  47. package/dist/types/current/util/async/poll.d.ts.map +1 -0
  48. package/dist/types/current/util/async/poll.js +31 -0
  49. package/dist/types/current/util/async/sleep.d.ts +2 -1
  50. package/dist/types/current/util/async/sleep.d.ts.map +1 -1
  51. package/dist/types/current/util/async/timeout.d.ts +32 -10
  52. package/dist/types/current/util/async/timeout.d.ts.map +1 -1
  53. package/dist/types/current/util/async/timeout.js +7 -11
  54. package/dist/types/current/util/map/map.d.ts +1 -2
  55. package/dist/types/current/util/map/map.d.ts.map +1 -1
  56. package/dist/types/current/util/url/resolveUrl.d.ts +2 -1
  57. package/dist/types/current/util/url/resolveUrl.d.ts.map +1 -1
  58. package/dist/types/current/util/url/resolveUrl.js +9 -3
  59. package/dist/types/ts3.7/event/nextEventAsPromise.d.ts +14 -4
  60. package/dist/types/ts3.7/index.d.ts +114 -113
  61. package/dist/types/ts3.7/util/async/poll.d.ts +34 -0
  62. package/dist/types/ts3.7/util/async/sleep.d.ts +2 -1
  63. package/dist/types/ts3.7/util/async/timeout.d.ts +32 -10
  64. package/dist/types/ts3.7/util/map/map.d.ts +1 -2
  65. package/dist/types/ts3.7/util/url/resolveUrl.d.ts +2 -1
  66. package/dist/types/ts4.1/event/nextEventAsPromise.d.ts +14 -4
  67. package/dist/types/ts4.1/index.d.ts +114 -113
  68. package/dist/types/ts4.1/util/async/poll.d.ts +34 -0
  69. package/dist/types/ts4.1/util/async/sleep.d.ts +2 -1
  70. package/dist/types/ts4.1/util/async/timeout.d.ts +32 -10
  71. package/dist/types/ts4.1/util/map/map.d.ts +1 -2
  72. package/dist/types/ts4.1/util/url/resolveUrl.d.ts +2 -1
  73. package/dist/types/ts4.7/event/nextEventAsPromise.d.ts +14 -4
  74. package/dist/types/ts4.7/index.d.ts +114 -113
  75. package/dist/types/ts4.7/util/async/poll.d.ts +34 -0
  76. package/dist/types/ts4.7/util/async/sleep.d.ts +2 -1
  77. package/dist/types/ts4.7/util/async/timeout.d.ts +32 -10
  78. package/dist/types/ts4.7/util/map/map.d.ts +1 -2
  79. package/dist/types/ts4.7/util/url/resolveUrl.d.ts +2 -1
  80. package/dist/unit/types/current/tsconfig.tsbuildinfo +1 -1
  81. package/package.json +13 -15
@@ -19,280 +19,123 @@ var __spreadValues = (a, b) => {
19
19
  var __spreadProps = (a, b) => __defProps(a, __getOwnPropDescs(b));
20
20
  var __publicField = (obj, key, value) => __defNormalProp(obj, typeof key !== "symbol" ? key + "" : key, value);
21
21
 
22
- // test/testUtil/util/initializeUncaughtErrorLogging.ts
23
- var loggingUncaughtErrors = false;
24
- function initializeUncaughtErrorLogging() {
25
- if (loggingUncaughtErrors) return;
26
- loggingUncaughtErrors = true;
27
- window.addEventListener("error", (event) => {
28
- console.error("uncaught error event:", event);
29
- });
30
- window.addEventListener("unhandledrejection", (event) => {
31
- console.error("unhandled rejection:", event);
32
- });
22
+ // test/testUtil/error/uncaughtErrorUtil.ts
23
+ import { parseStackLocation } from "@amazon/vinyl-util";
24
+ import {
25
+ MockErrorEvent,
26
+ MockPromiseRejectionEvent
27
+ } from "@amazon/vinyl-util/browserTestUtil";
28
+ function createRangeSurrounding(error) {
29
+ var _a, _b;
30
+ const location2 = parseStackLocation(error.stack);
31
+ if (!location2) {
32
+ pending("Cannot parse stacks in this environment.");
33
+ return { start: null, end: null };
34
+ }
35
+ return {
36
+ start: {
37
+ source: location2.source,
38
+ file: location2.file,
39
+ row: location2.row,
40
+ col: ((_a = location2.col) != null ? _a : 0) - 1
41
+ },
42
+ end: {
43
+ source: location2.source,
44
+ file: location2.file,
45
+ row: location2.row,
46
+ col: ((_b = location2.col) != null ? _b : 0) + 1
47
+ }
48
+ };
49
+ }
50
+ function throwMockError(target, error) {
51
+ expect(target.removeEventListener).not.toHaveBeenCalled();
52
+ const event = new MockErrorEvent();
53
+ event.type = "error";
54
+ event.error = error;
55
+ target.dispatchEvent(event);
56
+ }
57
+ function rejectMockPromise(target, reason) {
58
+ expect(target.removeEventListener).not.toHaveBeenCalled();
59
+ const event = new MockPromiseRejectionEvent();
60
+ event.type = "unhandledrejection";
61
+ event.reason = reason;
62
+ event.promise = Promise.reject(reason).catch(() => void 0);
63
+ target.dispatchEvent(event);
33
64
  }
34
65
 
35
- // test/testUtil/util/event/createEventSpy.ts
36
- import { Deferred, substitute, withTimeout } from "@amazon/vinyl-util";
37
- var createSpy = jasmine.createSpy;
38
- function createEventSpy(host, type) {
39
- const spy = createSpy(String(type));
40
- let nextCall = new Deferred();
41
- spy.and.callFake(() => {
42
- nextCall.resolve(spy.calls.mostRecent().args[0]);
43
- nextCall = new Deferred();
44
- });
45
- const unsub = host.on(type, spy);
46
- return Object.assign(spy, {
47
- next(timeout = 5, timeoutMessage = `event '{type}' has not been dispatched after {timeout}s.`) {
48
- return withTimeout(
49
- nextCall,
50
- timeout,
51
- substitute(timeoutMessage, {
52
- type,
53
- timeout
54
- })
55
- );
56
- },
57
- dispose: unsub
66
+ // test/testUtil/global/overrideGlobalInit.ts
67
+ function overrideGlobalInit(initHandle, initOverride) {
68
+ beforeEach(() => {
69
+ initHandle.set(initOverride);
58
70
  });
71
+ return initHandle;
59
72
  }
60
73
 
61
- // test/testUtil/reporters/LogReporter.ts
62
- import { LogLevel } from "@amazon/vinyl-util";
63
- var UPDATE_INTERVAL = 1;
64
- var MAX_LOGS_BUFFER = 200;
65
- var LogReporter = class {
66
- constructor() {
67
- /**
68
- * The first failed spec.
69
- *
70
- * Jasmine's spec result in `jasmineDone` does not provide these correctly in
71
- * failedExpectations, save this from `specDone`.
72
- */
73
- __publicField(this, "failedResult", null);
74
- __publicField(this, "totalSpecs", 0);
75
- __publicField(this, "totalCompleted", 0);
76
- /**
77
- * The timestamp of the last progress update.
78
- */
79
- __publicField(this, "lastProgressTimestamp", 0);
80
- __publicField(this, "updateInterval", UPDATE_INTERVAL);
81
- __publicField(this, "maxLogsBuffer", MAX_LOGS_BUFFER);
82
- __publicField(this, "consoleInterceptor", new ConsoleInterceptor());
83
- __publicField(this, "logs", []);
84
- this.consoleInterceptor.onLog = (entry) => {
85
- this.logs.push(entry);
86
- if (this.logs.length >= this.maxLogsBuffer)
87
- this.maybeReportProgress(true);
88
- };
89
- }
90
- jasmineStarted(suiteInfo) {
91
- this.onStarted({
92
- totalSpecs: suiteInfo.totalSpecsDefined
93
- }).catch((e) => {
94
- console.error(`'done' failed to report`, e);
95
- });
96
- this.totalCompleted = 0;
97
- this.totalSpecs = suiteInfo.totalSpecsDefined;
98
- }
99
- specDone(result) {
100
- if (!this.failedResult && result.status === "failed")
101
- this.failedResult = result;
102
- this.totalCompleted++;
103
- this.maybeReportProgress();
104
- }
105
- jasmineDone(runDetails) {
106
- var _a;
107
- this.maybeReportProgress(true);
108
- this.consoleInterceptor.dispose();
109
- const reason = this.failedResult ? `${this.failedResult.fullName}:
110
- ${(_a = this.failedResult.failedExpectations[0]) == null ? void 0 : _a.message}` : runDetails.overallStatus === "incomplete" ? runDetails.incompleteReason : "";
111
- const body = {
112
- // one of: 'passed', 'failed', 'incomplete'
113
- overallStatus: runDetails.overallStatus === "incomplete" ? "passed" : runDetails.overallStatus,
114
- totalCompleted: this.totalCompleted,
115
- totalSpecs: this.totalSpecs,
116
- reason
117
- };
118
- this.onDone(body).catch((_) => {
119
- this.onDone(body).catch((e) => {
120
- console.error(`'done' failed to report`, e);
121
- });
122
- });
123
- }
124
- /**
125
- * If there has not been a progress update within `updateInterval`, emit another progress
126
- * event.
127
- * @private
128
- */
129
- maybeReportProgress(force = false) {
130
- const now = Date.now();
131
- if (force || now - this.lastProgressTimestamp > this.updateInterval * 1e3) {
132
- const logs = this.logs.slice();
133
- this.logs.length = 0;
134
- this.onProgress({
135
- totalCompleted: this.totalCompleted,
136
- totalSpecs: this.totalSpecs,
137
- logs
138
- }).catch((e) => {
139
- console.error(`'progress' failed to report`, e);
140
- });
141
- this.lastProgressTimestamp = now;
142
- }
143
- }
144
- };
145
- var consoleMethods = [
146
- "debug",
147
- "log",
148
- "info",
149
- "warn",
150
- "error"
151
- ];
152
- var consoleMethodLevels = {
153
- debug: LogLevel.DEBUG,
154
- log: LogLevel.DEBUG,
155
- warn: LogLevel.WARN,
156
- info: LogLevel.INFO,
157
- error: LogLevel.ERROR
74
+ // test/testUtil/mock/event/emptyLogTarget.ts
75
+ var emptyLogTarget = {
76
+ logPrefix: "path"
158
77
  };
159
- var ConsoleInterceptor = class {
78
+
79
+ // test/testUtil/mock/event/MockEventHost.ts
80
+ import { EventHostImpl } from "@amazon/vinyl-util";
81
+ import { createSpyFactory } from "@amazon/vinyl-util/browserTestUtil";
82
+ var MockEventHost = class extends EventHostImpl {
160
83
  constructor() {
161
- __publicField(this, "originalMethods");
162
- /**
163
- * Invoked on every log statement.
164
- */
165
- __publicField(this, "onLog", null);
166
- this.originalMethods = {};
167
- for (const consoleMethod of consoleMethods) {
168
- this.originalMethods[consoleMethod] = console[consoleMethod];
169
- console[consoleMethod] = (...args) => {
170
- var _a;
171
- if (this.onLog)
172
- this.onLog({
173
- level: (_a = consoleMethodLevels[consoleMethod]) != null ? _a : LogLevel.DEBUG,
174
- timestamp: /* @__PURE__ */ new Date(),
175
- messages: args
176
- });
177
- this.originalMethods[consoleMethod].apply(console, args);
178
- };
179
- }
180
- }
181
- dispose() {
182
- for (const consoleMethod of consoleMethods) {
183
- console[consoleMethod] = this.originalMethods[consoleMethod];
184
- }
84
+ super(...arguments);
85
+ __publicField(this, "spyFactory", createSpyFactory((key) => {
86
+ return super[key].bind(this);
87
+ }));
88
+ __publicField(this, "logPrefix", "MockEventHost");
89
+ __publicField(this, "hasAnyListeners", this.spyFactory("hasAnyListeners"));
90
+ __publicField(this, "hasListeners", this.spyFactory("hasListeners"));
91
+ __publicField(this, "dispatch", this.spyFactory("dispatch"));
92
+ __publicField(this, "on", this.spyFactory("on"));
93
+ __publicField(this, "dispose", this.spyFactory("dispose"));
185
94
  }
186
95
  };
187
96
 
188
- // test/testUtil/reporters/RestApiReporter.ts
189
- import { stringifyLogLevel } from "@amazon/vinyl-util";
190
- var RestApiReporter = class _RestApiReporter extends LogReporter {
191
- constructor(reportApi) {
192
- super();
193
- __publicField(this, "reportApi", reportApi);
194
- }
195
- /**
196
- * Installs this reporter if this is a Browser environment and the report api has been provided as a query
197
- * parameter.
198
- * @param searchParam
199
- */
200
- static installFromSearchParam(searchParam = "reportApi") {
201
- if (typeof location === "undefined") return;
202
- const url = new URL("about:blank");
203
- url.search = location.search;
204
- const reportApi = url.searchParams.get(searchParam);
205
- if (reportApi) {
206
- jasmine.getEnv().addReporter(new _RestApiReporter(reportApi));
207
- initializeUncaughtErrorLogging();
208
- }
209
- }
210
- onStarted(action) {
211
- return this.doRequest("started", action);
212
- }
213
- onProgress(action) {
214
- return this.doRequest("progress", {
215
- totalCompleted: action.totalCompleted,
216
- totalSpecs: action.totalSpecs,
217
- logs: action.logs.map((logEntry) => [
218
- stringifyLogLevel(logEntry.level),
219
- logEntry.timestamp.toISOString(),
220
- logArgsToStr(logEntry.messages)
221
- ])
222
- });
223
- }
224
- onDone(action) {
225
- return this.doRequest("done", action);
226
- }
227
- /**
228
- * If the reportApi url was set in the URL parameters, report to that URL the test progress.
229
- *
230
- * @param action One of: 'started', 'progress', or 'done'
231
- * @param body
232
- * @private
233
- */
234
- async doRequest(action, body) {
235
- if (!this.reportApi) return;
236
- const response = await fetch(`${this.reportApi}/${action}`, {
237
- method: "POST",
238
- headers: {
239
- "Content-Type": "application/json"
240
- },
241
- body: JSON.stringify(body)
242
- });
243
- if (!response.ok)
244
- throw new Error(`${response.status} Error: ${response.statusText}`);
245
- return await response.json();
97
+ // test/testUtil/mock/logging/MockLogger.ts
98
+ import { loggerRef, LogLevel } from "@amazon/vinyl-util";
99
+ import { createSpyFactory as createSpyFactory2 } from "@amazon/vinyl-util/browserTestUtil";
100
+ var createSpy = jasmine.createSpy;
101
+ var spyFactory = createSpyFactory2();
102
+ var MockLogger = class extends MockEventHost {
103
+ constructor() {
104
+ super(...arguments);
105
+ __publicField(this, "logLevel", LogLevel.DEBUG);
106
+ __publicField(this, "log", spyFactory("log").and.callFake((target, level, ...messages) => {
107
+ switch (level) {
108
+ // Delegates logs to spies separated by log level.
109
+ case LogLevel.VERBOSE:
110
+ this.verbose(target, ...messages);
111
+ break;
112
+ case LogLevel.DEBUG:
113
+ this.debug(target, ...messages);
114
+ break;
115
+ case LogLevel.INFO:
116
+ this.info(target, ...messages);
117
+ break;
118
+ case LogLevel.WARN:
119
+ this.warn(target, ...messages);
120
+ break;
121
+ case LogLevel.ERROR:
122
+ this.error(target, ...messages);
123
+ break;
124
+ }
125
+ }));
126
+ __publicField(this, "verbose", createSpy("verbose"));
127
+ __publicField(this, "debug", createSpy("debug"));
128
+ __publicField(this, "info", createSpy("info"));
129
+ __publicField(this, "warn", createSpy("warn"));
130
+ __publicField(this, "error", createSpy("error"));
246
131
  }
247
132
  };
248
- function logArgsToStr(args) {
249
- return args.map((arg) => {
250
- if (arg != null && typeof arg === "object") {
251
- try {
252
- return JSON.stringify(arg);
253
- } catch (_) {
254
- return String(arg);
255
- }
256
- } else {
257
- return String(arg);
258
- }
259
- }).join(" ");
133
+ function useMockLogger() {
134
+ return overrideGlobalInit(loggerRef, () => new MockLogger());
260
135
  }
261
136
 
262
- // test/testUtil/patch/addPatchTests.ts
263
- import { expectNothing } from "@amazon/vinyl-util/browserTestUtil";
264
- function addPatchTests(flagName, description, optionsProvider) {
265
- let options;
266
- beforeEach(() => {
267
- options = optionsProvider();
268
- });
269
- afterEach(() => {
270
- options == null ? void 0 : options.patchedRef.dispose();
271
- });
272
- it("sets the default flag to true only if the issue can be reproduced", async () => {
273
- const canReproduce = await options.canReproduce(options.target);
274
- if (canReproduce) {
275
- if (!options.actualFlag)
276
- fail(`expected patch flag '${flagName}' to be true`);
277
- } else {
278
- if (options.actualFlag) {
279
- const message = `flag '${flagName}' was true but issue not reproduced`;
280
- if (options.allowFalseNegative) console.warn(message);
281
- else fail(message);
282
- }
283
- }
284
- expectNothing();
285
- });
286
- describe(`when the ${flagName} is true`, () => {
287
- it(description, async () => {
288
- if (options.actualFlag) {
289
- if (await options.canReproduce(options.patchedRef.patched))
290
- fail("patch did not resolve issue");
291
- }
292
- expectNothing();
293
- });
294
- });
295
- }
137
+ // test/testUtil/mock/navigator/setMockNavigator.ts
138
+ import { MockNavigator } from "@amazon/vinyl-util/browserTestUtil";
296
139
 
297
140
  // test/testUtil/mock/util/spyOnPropertySafe.ts
298
141
  function spyOnPropertySafe(object, property) {
@@ -306,17 +149,12 @@ function spyOnPropertySafe(object, property) {
306
149
  return spyOnProperty(object, property, "get");
307
150
  }
308
151
 
309
- // test/testUtil/mock/persistence/MockPersistence.ts
310
- import { createSpyFactory } from "@amazon/vinyl-util/browserTestUtil";
311
- var MockPersistence = class {
312
- constructor() {
313
- __publicField(this, "spyFactory", createSpyFactory());
314
- __publicField(this, "clear", this.spyFactory("clear"));
315
- __publicField(this, "get", this.spyFactory("get"));
316
- __publicField(this, "remove", this.spyFactory("remove"));
317
- __publicField(this, "set", this.spyFactory("set"));
318
- }
319
- };
152
+ // test/testUtil/mock/navigator/setMockNavigator.ts
153
+ function setMockNavigator() {
154
+ const navigator = new MockNavigator();
155
+ spyOnPropertySafe(globalThis, "navigator").and.returnValue(navigator);
156
+ return navigator;
157
+ }
320
158
 
321
159
  // test/testUtil/mock/network/emptyRequestInfo.ts
322
160
  import {
@@ -385,180 +223,342 @@ var emptyAbortError = __spreadProps(__spreadValues({}, emptyInternalError), {
385
223
  type: RequestFailureType.ABORT
386
224
  });
387
225
 
388
- // test/testUtil/mock/network/MockRequester.ts
226
+ // test/testUtil/mock/network/MockNetworkInformation.ts
227
+ import { MockEventTarget } from "@amazon/vinyl-util/browserTestUtil";
228
+ var MockNetworkInformation = class extends MockEventTarget {
229
+ constructor() {
230
+ super(...arguments);
231
+ __publicField(this, "downlink");
232
+ __publicField(this, "effectiveType", "4g");
233
+ __publicField(this, "rtt", 0);
234
+ __publicField(this, "saveData", false);
235
+ __publicField(this, "type");
236
+ }
237
+ };
238
+
239
+ // test/testUtil/mock/network/MockNetworkMetricsController.ts
240
+ import { EMPTY_NETWORK_METRICS } from "@amazon/vinyl-util";
389
241
  import { createSpyFactory as createSpyFactory3 } from "@amazon/vinyl-util/browserTestUtil";
242
+ var spyFactory2 = createSpyFactory3();
243
+ var MockNetworkMetricsController = class extends MockEventHost {
244
+ constructor() {
245
+ super(...arguments);
246
+ __publicField(this, "maxHistorySize", 0);
247
+ __publicField(this, "metrics", EMPTY_NETWORK_METRICS);
248
+ __publicField(this, "addMetricsEntry", spyFactory2("addMetricsEntry"));
249
+ __publicField(this, "getServiceMetrics", spyFactory2("getServiceMetrics"));
250
+ __publicField(this, "addDownlinkTransferEntry", spyFactory2("addDownlinkTransferEntry"));
251
+ }
252
+ };
390
253
 
391
- // test/testUtil/mock/event/MockEventHost.ts
392
- import { EventHostImpl } from "@amazon/vinyl-util";
393
- import { createSpyFactory as createSpyFactory2 } from "@amazon/vinyl-util/browserTestUtil";
394
- var MockEventHost = class extends EventHostImpl {
254
+ // test/testUtil/mock/network/MockNetworkState.ts
255
+ import { createSpyFactory as createSpyFactory4 } from "@amazon/vinyl-util/browserTestUtil";
256
+ var spyFactory3 = createSpyFactory4();
257
+ var MockNetworkState = class extends MockEventHost {
395
258
  constructor() {
396
259
  super(...arguments);
397
- __publicField(this, "spyFactory", createSpyFactory2((key) => {
398
- return super[key].bind(this);
399
- }));
400
- __publicField(this, "logPrefix", "MockEventHost");
401
- __publicField(this, "hasAnyListeners", this.spyFactory("hasAnyListeners"));
402
- __publicField(this, "hasListeners", this.spyFactory("hasListeners"));
403
- __publicField(this, "dispatch", this.spyFactory("dispatch"));
404
- __publicField(this, "on", this.spyFactory("on"));
405
- __publicField(this, "dispose", this.spyFactory("dispose"));
260
+ __publicField(this, "onLine", false);
261
+ __publicField(this, "nextOnLine", spyFactory3("nextOnLine"));
406
262
  }
407
263
  };
408
264
 
409
265
  // test/testUtil/mock/network/MockRequester.ts
410
- var spyFactory = createSpyFactory3();
266
+ import { createSpyFactory as createSpyFactory5 } from "@amazon/vinyl-util/browserTestUtil";
267
+ var spyFactory4 = createSpyFactory5();
411
268
  var MockRequester = class extends MockEventHost {
412
269
  constructor() {
413
270
  super(...arguments);
414
- __publicField(this, "request", spyFactory("request"));
271
+ __publicField(this, "request", spyFactory4("request"));
272
+ }
273
+ };
274
+
275
+ // test/testUtil/mock/persistence/MockPersistence.ts
276
+ import { createSpyFactory as createSpyFactory6 } from "@amazon/vinyl-util/browserTestUtil";
277
+ var MockPersistence = class {
278
+ constructor() {
279
+ __publicField(this, "spyFactory", createSpyFactory6());
280
+ __publicField(this, "clear", this.spyFactory("clear"));
281
+ __publicField(this, "get", this.spyFactory("get"));
282
+ __publicField(this, "remove", this.spyFactory("remove"));
283
+ __publicField(this, "set", this.spyFactory("set"));
284
+ }
285
+ };
286
+
287
+ // test/testUtil/patch/addPatchTests.ts
288
+ import { expectNothing } from "@amazon/vinyl-util/browserTestUtil";
289
+ function addPatchTests(flagName, description, optionsProvider) {
290
+ let options;
291
+ beforeEach(() => {
292
+ options = optionsProvider();
293
+ });
294
+ afterEach(() => {
295
+ options == null ? void 0 : options.patchedRef.dispose();
296
+ });
297
+ it("sets the default flag to true only if the issue can be reproduced", async () => {
298
+ const canReproduce = await options.canReproduce(options.target);
299
+ if (canReproduce) {
300
+ if (!options.actualFlag)
301
+ fail(`expected patch flag '${flagName}' to be true`);
302
+ } else {
303
+ if (options.actualFlag) {
304
+ const message = `flag '${flagName}' was true but issue not reproduced`;
305
+ if (options.allowFalseNegative) console.warn(message);
306
+ else fail(message);
307
+ }
308
+ }
309
+ expectNothing();
310
+ });
311
+ describe(`when the ${flagName} is true`, () => {
312
+ it(description, async () => {
313
+ if (options.actualFlag) {
314
+ if (await options.canReproduce(options.patchedRef.patched))
315
+ fail("patch did not resolve issue");
316
+ }
317
+ expectNothing();
318
+ });
319
+ });
320
+ }
321
+
322
+ // test/testUtil/reporters/LogReporter.ts
323
+ import { LogLevel as LogLevel2 } from "@amazon/vinyl-util";
324
+ var UPDATE_INTERVAL = 1;
325
+ var MAX_LOGS_BUFFER = 200;
326
+ var LogReporter = class {
327
+ constructor() {
328
+ /**
329
+ * The first failed spec.
330
+ *
331
+ * Jasmine's spec result in `jasmineDone` does not provide these correctly in
332
+ * failedExpectations, save this from `specDone`.
333
+ */
334
+ __publicField(this, "failedResult", null);
335
+ __publicField(this, "totalSpecs", 0);
336
+ __publicField(this, "totalCompleted", 0);
337
+ /**
338
+ * The timestamp of the last progress update.
339
+ */
340
+ __publicField(this, "lastProgressTimestamp", 0);
341
+ __publicField(this, "updateInterval", UPDATE_INTERVAL);
342
+ __publicField(this, "maxLogsBuffer", MAX_LOGS_BUFFER);
343
+ __publicField(this, "consoleInterceptor", new ConsoleInterceptor());
344
+ __publicField(this, "logs", []);
345
+ this.consoleInterceptor.onLog = (entry) => {
346
+ this.logs.push(entry);
347
+ if (this.logs.length >= this.maxLogsBuffer)
348
+ this.maybeReportProgress(true);
349
+ };
350
+ }
351
+ jasmineStarted(suiteInfo) {
352
+ this.onStarted({
353
+ totalSpecs: suiteInfo.totalSpecsDefined
354
+ }).catch((e) => {
355
+ console.error(`'done' failed to report`, e);
356
+ });
357
+ this.totalCompleted = 0;
358
+ this.totalSpecs = suiteInfo.totalSpecsDefined;
359
+ }
360
+ specStarted(result) {
361
+ console.info(`Running spec: ${result.fullName}`);
362
+ this.maybeReportProgress();
363
+ }
364
+ specDone(result) {
365
+ if (!this.failedResult && result.status === "failed")
366
+ this.failedResult = result;
367
+ this.totalCompleted++;
368
+ this.maybeReportProgress();
369
+ }
370
+ jasmineDone(runDetails) {
371
+ var _a;
372
+ this.maybeReportProgress(true);
373
+ this.consoleInterceptor.dispose();
374
+ const reason = this.failedResult ? `${this.failedResult.fullName}:
375
+ ${(_a = this.failedResult.failedExpectations[0]) == null ? void 0 : _a.message}` : runDetails.overallStatus === "incomplete" ? runDetails.incompleteReason : "";
376
+ const body = {
377
+ // one of: 'passed', 'failed', 'incomplete'
378
+ overallStatus: runDetails.overallStatus === "incomplete" ? "passed" : runDetails.overallStatus,
379
+ totalCompleted: this.totalCompleted,
380
+ totalSpecs: this.totalSpecs,
381
+ reason
382
+ };
383
+ this.onDone(body).catch((_) => {
384
+ this.onDone(body).catch((e) => {
385
+ console.error(`'done' failed to report`, e);
386
+ });
387
+ });
388
+ }
389
+ /**
390
+ * If there has not been a progress update within `updateInterval`, emit another progress
391
+ * event.
392
+ * @private
393
+ */
394
+ maybeReportProgress(force = false) {
395
+ const now = Date.now();
396
+ if (force || now - this.lastProgressTimestamp > this.updateInterval * 1e3) {
397
+ const logs = this.logs.slice();
398
+ this.logs.length = 0;
399
+ this.onProgress({
400
+ totalCompleted: this.totalCompleted,
401
+ totalSpecs: this.totalSpecs,
402
+ logs
403
+ }).catch((e) => {
404
+ console.error(`'progress' failed to report`, e);
405
+ });
406
+ this.lastProgressTimestamp = now;
407
+ }
415
408
  }
416
409
  };
417
-
418
- // test/testUtil/mock/network/MockNetworkState.ts
419
- import { createSpyFactory as createSpyFactory4 } from "@amazon/vinyl-util/browserTestUtil";
420
- var spyFactory2 = createSpyFactory4();
421
- var MockNetworkState = class extends MockEventHost {
422
- constructor() {
423
- super(...arguments);
424
- __publicField(this, "onLine", false);
425
- __publicField(this, "nextOnLine", spyFactory2("nextOnLine"));
426
- }
410
+ var consoleMethods = [
411
+ "debug",
412
+ "log",
413
+ "info",
414
+ "warn",
415
+ "error"
416
+ ];
417
+ var consoleMethodLevels = {
418
+ debug: LogLevel2.DEBUG,
419
+ log: LogLevel2.DEBUG,
420
+ warn: LogLevel2.WARN,
421
+ info: LogLevel2.INFO,
422
+ error: LogLevel2.ERROR
427
423
  };
428
-
429
- // test/testUtil/mock/network/MockNetworkMetricsController.ts
430
- import { EMPTY_NETWORK_METRICS } from "@amazon/vinyl-util";
431
- import { createSpyFactory as createSpyFactory5 } from "@amazon/vinyl-util/browserTestUtil";
432
- var spyFactory3 = createSpyFactory5();
433
- var MockNetworkMetricsController = class extends MockEventHost {
424
+ var ConsoleInterceptor = class {
434
425
  constructor() {
435
- super(...arguments);
436
- __publicField(this, "maxHistorySize", 0);
437
- __publicField(this, "metrics", EMPTY_NETWORK_METRICS);
438
- __publicField(this, "addMetricsEntry", spyFactory3("addMetricsEntry"));
439
- __publicField(this, "getServiceMetrics", spyFactory3("getServiceMetrics"));
440
- __publicField(this, "addDownlinkTransferEntry", spyFactory3("addDownlinkTransferEntry"));
426
+ __publicField(this, "originalMethods");
427
+ /**
428
+ * Invoked on every log statement.
429
+ */
430
+ __publicField(this, "onLog", null);
431
+ this.originalMethods = {};
432
+ for (const consoleMethod of consoleMethods) {
433
+ this.originalMethods[consoleMethod] = console[consoleMethod];
434
+ console[consoleMethod] = (...args) => {
435
+ var _a;
436
+ if (this.onLog)
437
+ this.onLog({
438
+ level: (_a = consoleMethodLevels[consoleMethod]) != null ? _a : LogLevel2.DEBUG,
439
+ timestamp: /* @__PURE__ */ new Date(),
440
+ messages: args
441
+ });
442
+ this.originalMethods[consoleMethod].apply(console, args);
443
+ };
444
+ }
441
445
  }
442
- };
443
-
444
- // test/testUtil/mock/network/MockNetworkInformation.ts
445
- import { MockEventTarget } from "@amazon/vinyl-util/browserTestUtil";
446
- var MockNetworkInformation = class extends MockEventTarget {
447
- constructor() {
448
- super(...arguments);
449
- __publicField(this, "downlink");
450
- __publicField(this, "effectiveType", "4g");
451
- __publicField(this, "rtt", 0);
452
- __publicField(this, "saveData", false);
453
- __publicField(this, "type");
446
+ dispose() {
447
+ for (const consoleMethod of consoleMethods) {
448
+ console[consoleMethod] = this.originalMethods[consoleMethod];
449
+ }
454
450
  }
455
451
  };
456
452
 
457
- // test/testUtil/mock/navigator/setMockNavigator.ts
458
- import { MockNavigator } from "@amazon/vinyl-util/browserTestUtil";
459
- function setMockNavigator() {
460
- const navigator = new MockNavigator();
461
- spyOnPropertySafe(globalThis, "navigator").and.returnValue(navigator);
462
- return navigator;
463
- }
464
-
465
- // test/testUtil/mock/logging/MockLogger.ts
466
- import { loggerRef, LogLevel as LogLevel2 } from "@amazon/vinyl-util";
467
- import { createSpyFactory as createSpyFactory6 } from "@amazon/vinyl-util/browserTestUtil";
468
-
469
- // test/testUtil/global/overrideGlobalInit.ts
470
- function overrideGlobalInit(initHandle, initOverride) {
471
- beforeEach(() => {
472
- initHandle.set(initOverride);
453
+ // test/testUtil/util/initializeUncaughtErrorLogging.ts
454
+ var loggingUncaughtErrors = false;
455
+ function initializeUncaughtErrorLogging() {
456
+ if (loggingUncaughtErrors) return;
457
+ loggingUncaughtErrors = true;
458
+ window.addEventListener("error", (event) => {
459
+ console.error("uncaught error event:", event);
460
+ });
461
+ window.addEventListener("unhandledrejection", (event) => {
462
+ console.error("unhandled rejection:", event);
473
463
  });
474
- return initHandle;
475
464
  }
476
465
 
477
- // test/testUtil/mock/logging/MockLogger.ts
478
- var createSpy2 = jasmine.createSpy;
479
- var spyFactory4 = createSpyFactory6();
480
- var MockLogger = class extends MockEventHost {
481
- constructor() {
482
- super(...arguments);
483
- __publicField(this, "logLevel", LogLevel2.DEBUG);
484
- __publicField(this, "log", spyFactory4("log").and.callFake((target, level, ...messages) => {
485
- switch (level) {
486
- // Delegates logs to spies separated by log level.
487
- case LogLevel2.VERBOSE:
488
- this.verbose(target, ...messages);
489
- break;
490
- case LogLevel2.DEBUG:
491
- this.debug(target, ...messages);
492
- break;
493
- case LogLevel2.INFO:
494
- this.info(target, ...messages);
495
- break;
496
- case LogLevel2.WARN:
497
- this.warn(target, ...messages);
498
- break;
499
- case LogLevel2.ERROR:
500
- this.error(target, ...messages);
501
- break;
502
- }
503
- }));
504
- __publicField(this, "verbose", createSpy2("verbose"));
505
- __publicField(this, "debug", createSpy2("debug"));
506
- __publicField(this, "info", createSpy2("info"));
507
- __publicField(this, "warn", createSpy2("warn"));
508
- __publicField(this, "error", createSpy2("error"));
466
+ // test/testUtil/reporters/RestApiReporter.ts
467
+ import { stringifyLogLevel } from "@amazon/vinyl-util";
468
+ var RestApiReporter = class _RestApiReporter extends LogReporter {
469
+ constructor(reportApi) {
470
+ super();
471
+ __publicField(this, "reportApi", reportApi);
472
+ }
473
+ /**
474
+ * Installs this reporter if this is a Browser environment and the report api has been provided as a query
475
+ * parameter.
476
+ * @param searchParam
477
+ */
478
+ static installFromSearchParam(searchParam = "reportApi") {
479
+ if (typeof location === "undefined") return;
480
+ const url = new URL("about:blank");
481
+ url.search = location.search;
482
+ const reportApi = url.searchParams.get(searchParam);
483
+ if (reportApi) {
484
+ jasmine.getEnv().addReporter(new _RestApiReporter(reportApi));
485
+ initializeUncaughtErrorLogging();
486
+ }
487
+ }
488
+ onStarted(action) {
489
+ return this.doRequest("started", action);
490
+ }
491
+ onProgress(action) {
492
+ return this.doRequest("progress", {
493
+ totalCompleted: action.totalCompleted,
494
+ totalSpecs: action.totalSpecs,
495
+ logs: action.logs.map((logEntry) => [
496
+ stringifyLogLevel(logEntry.level),
497
+ logEntry.timestamp.toISOString(),
498
+ logArgsToStr(logEntry.messages)
499
+ ])
500
+ });
501
+ }
502
+ onDone(action) {
503
+ return this.doRequest("done", action);
504
+ }
505
+ /**
506
+ * If the reportApi url was set in the URL parameters, report to that URL the test progress.
507
+ *
508
+ * @param action One of: 'started', 'progress', or 'done'
509
+ * @param body
510
+ * @private
511
+ */
512
+ async doRequest(action, body) {
513
+ if (!this.reportApi) return;
514
+ const response = await fetch(`${this.reportApi}/${action}`, {
515
+ method: "POST",
516
+ headers: {
517
+ "Content-Type": "application/json"
518
+ },
519
+ body: JSON.stringify(body)
520
+ });
521
+ if (!response.ok)
522
+ throw new Error(`${response.status} Error: ${response.statusText}`);
523
+ return await response.json();
509
524
  }
510
525
  };
511
- function useMockLogger() {
512
- return overrideGlobalInit(loggerRef, () => new MockLogger());
526
+ function logArgsToStr(args) {
527
+ return args.map((arg) => {
528
+ if (arg != null && typeof arg === "object") {
529
+ try {
530
+ return JSON.stringify(arg);
531
+ } catch (_) {
532
+ return String(arg);
533
+ }
534
+ } else {
535
+ return String(arg);
536
+ }
537
+ }).join(" ");
513
538
  }
514
539
 
515
- // test/testUtil/mock/event/emptyLogTarget.ts
516
- var emptyLogTarget = {
517
- logPrefix: "path"
518
- };
519
-
520
- // test/testUtil/error/uncaughtErrorUtil.ts
521
- import { parseStackLocation } from "@amazon/vinyl-util";
522
- import {
523
- MockErrorEvent,
524
- MockPromiseRejectionEvent
525
- } from "@amazon/vinyl-util/browserTestUtil";
526
- function createRangeSurrounding(error) {
527
- var _a, _b;
528
- const location2 = parseStackLocation(error.stack);
529
- if (!location2) {
530
- pending("Cannot parse stacks in this environment.");
531
- return { start: null, end: null };
532
- }
533
- return {
534
- start: {
535
- source: location2.source,
536
- file: location2.file,
537
- row: location2.row,
538
- col: ((_a = location2.col) != null ? _a : 0) - 1
540
+ // test/testUtil/util/event/createEventSpy.ts
541
+ import { Deferred, substitute, withTimeout } from "@amazon/vinyl-util";
542
+ var createSpy2 = jasmine.createSpy;
543
+ function createEventSpy(host, type) {
544
+ const spy = createSpy2(String(type));
545
+ let nextCall = new Deferred();
546
+ spy.and.callFake(() => {
547
+ nextCall.resolve(spy.calls.mostRecent().args[0]);
548
+ nextCall = new Deferred();
549
+ });
550
+ const unsub = host.on(type, spy);
551
+ return Object.assign(spy, {
552
+ next(timeout = 5, timeoutMessage = `event '{type}' has not been dispatched after {timeout}s.`) {
553
+ return withTimeout(nextCall, timeout, {
554
+ message: substitute(timeoutMessage, {
555
+ type,
556
+ timeout
557
+ })
558
+ });
539
559
  },
540
- end: {
541
- source: location2.source,
542
- file: location2.file,
543
- row: location2.row,
544
- col: ((_b = location2.col) != null ? _b : 0) + 1
545
- }
546
- };
547
- }
548
- function throwMockError(target, error) {
549
- expect(target.removeEventListener).not.toHaveBeenCalled();
550
- const event = new MockErrorEvent();
551
- event.type = "error";
552
- event.error = error;
553
- target.dispatchEvent(event);
554
- }
555
- function rejectMockPromise(target, reason) {
556
- expect(target.removeEventListener).not.toHaveBeenCalled();
557
- const event = new MockPromiseRejectionEvent();
558
- event.type = "unhandledrejection";
559
- event.reason = reason;
560
- event.promise = Promise.reject(reason).catch(() => void 0);
561
- target.dispatchEvent(event);
560
+ dispose: unsub
561
+ });
562
562
  }
563
563
  export {
564
564
  LogReporter,