@api-client/core 0.14.10 → 0.15.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 (96) hide show
  1. package/RELEASE.md +163 -0
  2. package/RELEASE_SETUP.md +235 -0
  3. package/build/src/events/authorization/AuthorizationEvents.d.ts +1 -1
  4. package/build/src/events/authorization/AuthorizationEvents.d.ts.map +1 -1
  5. package/build/src/events/authorization/AuthorizationEvents.js +1 -1
  6. package/build/src/events/authorization/AuthorizationEvents.js.map +1 -1
  7. package/build/src/events/cookies/CookieEvents.d.ts +1 -1
  8. package/build/src/events/cookies/CookieEvents.d.ts.map +1 -1
  9. package/build/src/events/cookies/CookieEvents.js +1 -1
  10. package/build/src/events/cookies/CookieEvents.js.map +1 -1
  11. package/build/src/modeling/DomainImpactAnalysis.d.ts +22 -119
  12. package/build/src/modeling/DomainImpactAnalysis.d.ts.map +1 -1
  13. package/build/src/modeling/DomainImpactAnalysis.js +49 -155
  14. package/build/src/modeling/DomainImpactAnalysis.js.map +1 -1
  15. package/build/src/modeling/DomainValidation.d.ts +8 -0
  16. package/build/src/modeling/DomainValidation.d.ts.map +1 -0
  17. package/build/src/modeling/DomainValidation.js +99 -0
  18. package/build/src/modeling/DomainValidation.js.map +1 -0
  19. package/build/src/modeling/types.d.ts +70 -0
  20. package/build/src/modeling/types.d.ts.map +1 -1
  21. package/build/src/modeling/types.js.map +1 -1
  22. package/build/src/modeling/validation/rules.d.ts +2 -3
  23. package/build/src/modeling/validation/rules.d.ts.map +1 -1
  24. package/build/src/modeling/validation/rules.js.map +1 -1
  25. package/build/src/modeling/validation/semantic_validation.d.ts +31 -0
  26. package/build/src/modeling/validation/semantic_validation.d.ts.map +1 -0
  27. package/build/src/modeling/validation/semantic_validation.js +126 -0
  28. package/build/src/modeling/validation/semantic_validation.js.map +1 -0
  29. package/build/tsconfig.tsbuildinfo +1 -1
  30. package/data/models/example-generator-api.json +6 -6
  31. package/noop.ts +3 -0
  32. package/package.json +9 -4
  33. package/src/events/authorization/AuthorizationEvents.ts +1 -1
  34. package/src/events/cookies/CookieEvents.ts +1 -1
  35. package/src/modeling/DomainImpactAnalysis.ts +54 -239
  36. package/src/modeling/DomainValidation.ts +105 -0
  37. package/src/modeling/types.ts +86 -0
  38. package/src/modeling/validation/rules.ts +2 -4
  39. package/src/modeling/validation/semantic_validation.ts +145 -0
  40. package/tests/unit/events/EventsTestHelpers.ts +16 -0
  41. package/tests/unit/events/amf.spec.ts +151 -0
  42. package/tests/unit/events/authorization.spec.ts +150 -0
  43. package/tests/unit/events/cookie.spec.ts +274 -0
  44. package/tests/unit/events/encryption.spec.ts +108 -0
  45. package/tests/unit/events/events_polyfills.ts +77 -0
  46. package/tests/unit/events/process.spec.ts +120 -0
  47. package/tests/unit/events/reporting.spec.ts +82 -0
  48. package/tests/unit/events/telemetry.spec.ts +224 -0
  49. package/tests/unit/events/transport.spec.ts +139 -0
  50. package/tests/unit/modeling/domain_impact_analysis.spec.ts +0 -110
  51. package/tests/unit/modeling/domain_validation.spec.ts +94 -0
  52. package/tests/unit/modeling/validation/semantic_validation.spec.ts +91 -0
  53. package/tests/unit/models/environment.spec.ts +574 -0
  54. package/tests/unit/models/error_response.spec.ts +183 -0
  55. package/tests/unit/models/headers_array.spec.ts +86 -0
  56. package/tests/unit/models/http-actions/assertion/equal_assertion.spec.ts +103 -0
  57. package/tests/unit/models/http-actions/assertion/greater_than_assertion.spec.ts +91 -0
  58. package/tests/unit/models/http-actions/assertion/includes_assertion.spec.ts +71 -0
  59. package/tests/unit/models/http-actions/assertion/less_than_assertion.spec.ts +91 -0
  60. package/tests/unit/models/http-actions/assertion/matches_assertion.spec.ts +71 -0
  61. package/tests/unit/models/http-actions/assertion/matches_schema_assertion.spec.ts +117 -0
  62. package/tests/unit/models/http-actions/assertion/not_equal_assertion.spec.ts +103 -0
  63. package/tests/unit/models/http-actions/assertion/not_includes_assertion.spec.ts +71 -0
  64. package/tests/unit/models/http-actions/assertion/not_ok_assertion.spec.ts +47 -0
  65. package/tests/unit/models/http-actions/assertion/not_to_be_assertion.spec.ts +72 -0
  66. package/tests/unit/models/http-actions/assertion/ok_assertion.spec.ts +44 -0
  67. package/tests/unit/models/http-actions/assertion/to_be_assertion.spec.ts +71 -0
  68. package/tests/unit/models/http-actions/transformation/as_lower_case_step.spec.ts +47 -0
  69. package/tests/unit/models/http-actions/transformation/as_number_step.spec.ts +47 -0
  70. package/tests/unit/models/http-actions/transformation/as_upper_case_step.spec.ts +47 -0
  71. package/tests/unit/models/http-actions/transformation/round_step.spec.ts +69 -0
  72. package/tests/unit/models/http-actions/transformation/substring_step.spec.ts +85 -0
  73. package/tests/unit/models/http-actions/transformation/trim_step.spec.ts +44 -0
  74. package/tests/unit/models/http_cookie.spec.ts +516 -0
  75. package/tests/unit/models/http_history.spec.ts +443 -0
  76. package/tests/unit/models/project_folder.spec.ts +926 -0
  77. package/tests/unit/models/project_item.spec.ts +137 -0
  78. package/tests/unit/models/project_request.spec.ts +1047 -0
  79. package/tests/unit/models/project_schema.spec.ts +236 -0
  80. package/tests/unit/models/property.spec.ts +625 -0
  81. package/tests/unit/models/provider.spec.ts +102 -0
  82. package/tests/unit/models/request.spec.ts +1206 -0
  83. package/tests/unit/models/request_log.spec.ts +308 -0
  84. package/tests/unit/models/request_time.spec.ts +138 -0
  85. package/tests/unit/models/response_redirect.spec.ts +303 -0
  86. package/tests/unit/models/sent_request.spec.ts +206 -0
  87. package/tests/unit/models/server.spec.ts +195 -0
  88. package/tests/unit/models/thing.spec.ts +154 -0
  89. package/build/oauth-popup.html +0 -33
  90. /package/tests/unit/models/{Certificate.spec.ts → certificate.spec.ts} +0 -0
  91. /package/tests/unit/models/{HostRule.spec.ts → host_rule.spec.ts} +0 -0
  92. /package/tests/unit/models/{HttpProject.spec.ts → http_project.spec.ts} +0 -0
  93. /package/tests/unit/models/{HttpRequest.spec.ts → http_request.spec.ts} +0 -0
  94. /package/tests/unit/models/{HttpResponse.spec.ts → http_response.spec.ts} +0 -0
  95. /package/tests/unit/models/{License.spec.ts → license.spec.ts} +0 -0
  96. /package/tests/unit/models/{Response.spec.ts → response.spec.ts} +0 -0
@@ -0,0 +1,274 @@
1
+ import { test } from '@japa/runner'
2
+ import sinon from 'sinon'
3
+ import { EventTypes } from '../../../src/events/EventTypes.js'
4
+ import { Events } from '../../../src/events/Events.js'
5
+ import { IHttpCookie } from '../../../src/models/HttpCookie.js'
6
+ import { ContextUpdateEvent, ContextUpdateEventDetail, ContextChangeRecord } from '../../../src/events/BaseEvents.js'
7
+ import { ensureUnique } from './EventsTestHelpers.js'
8
+ import './events_polyfills.js'
9
+
10
+ test.group('Events > Cookie > EventTypes.Cookie', () => {
11
+ test('has the namespace', ({ assert }) => {
12
+ assert.typeOf(EventTypes.Cookie, 'object')
13
+ })
14
+
15
+ test('has "{prop}" property')
16
+ .with([
17
+ ['listAll', 'sessioncookielistall'],
18
+ ['listDomain', 'sessioncookielistdomain'],
19
+ ['listUrl', 'sessioncookielisturl'],
20
+ ['delete', 'sessioncookiedelete'],
21
+ ['deleteUrl', 'sessioncookiedeleteurl'],
22
+ ['update', 'sessioncookieupdate'],
23
+ ['updateBulk', 'sessioncookieupdatebulk'],
24
+ ])
25
+ .run(({ assert }, [prop, value]) => {
26
+ // @ts-expect-error Used in testing
27
+ assert.equal(EventTypes.Cookie[prop], value)
28
+ })
29
+
30
+ test('has State namespace', ({ assert }) => {
31
+ assert.typeOf(EventTypes.Cookie.State, 'object')
32
+ })
33
+
34
+ test('has frozen State namespace', ({ assert }) => {
35
+ assert.throws(() => {
36
+ // @ts-expect-error Used in testing
37
+ EventTypes.Cookie.State = { read: '' }
38
+ })
39
+ })
40
+
41
+ test('has "{prop}" property for State')
42
+ .with([
43
+ ['update', 'sessioncookiestateupdate'],
44
+ ['delete', 'sessioncookiestatedelete'],
45
+ ])
46
+ .run(({ assert }, [prop, value]) => {
47
+ // @ts-expect-error Used in testing
48
+ assert.equal(EventTypes.Cookie.State[prop], value)
49
+ })
50
+
51
+ test('has unique events for the namespace', () => {
52
+ ensureUnique('EventTypes.Cookie', EventTypes.Cookie)
53
+ })
54
+
55
+ test('has unique events for State namespace', () => {
56
+ ensureUnique('EventTypes.Cookie.State', EventTypes.Cookie.State)
57
+ })
58
+ })
59
+
60
+ test.group('Events > Cookie > Events.Cookie > listAll()', () => {
61
+ test('dispatches the event', async ({ assert }) => {
62
+ const spy = sinon.spy()
63
+ globalThis.addEventListener(EventTypes.Cookie.listAll, spy)
64
+ // In Node.js, document.body is not available.
65
+ // Assuming Events.Cookie.listAll dispatches globally or handles a null/undefined target.
66
+ Events.Cookie.listAll()
67
+ globalThis.removeEventListener(EventTypes.Cookie.listAll, spy)
68
+ assert.isTrue(spy.calledOnce)
69
+ })
70
+ })
71
+
72
+ test.group('Events > Cookie > Events.Cookie > listDomain()', () => {
73
+ const domain = 'dot.com'
74
+
75
+ test('dispatches the event', async ({ assert }) => {
76
+ const spy = sinon.spy()
77
+ globalThis.addEventListener(EventTypes.Cookie.listDomain, spy)
78
+ Events.Cookie.listDomain(domain)
79
+ globalThis.removeEventListener(EventTypes.Cookie.listDomain, spy)
80
+ assert.isTrue(spy.calledOnce)
81
+ })
82
+
83
+ test('has the domain property', async ({ assert }) => {
84
+ const spy = sinon.spy()
85
+ globalThis.addEventListener(EventTypes.Cookie.listDomain, spy)
86
+ Events.Cookie.listDomain(domain)
87
+ globalThis.removeEventListener(EventTypes.Cookie.listDomain, spy)
88
+ const e = spy.args[0][0] as CustomEvent
89
+ assert.deepEqual(e.detail.domain, domain)
90
+ })
91
+ })
92
+
93
+ test.group('Events > Cookie > Events.Cookie > listUrl()', () => {
94
+ const url = 'https://dot.com/path'
95
+
96
+ test('dispatches the event', async ({ assert }) => {
97
+ const spy = sinon.spy()
98
+ globalThis.addEventListener(EventTypes.Cookie.listUrl, spy)
99
+ Events.Cookie.listUrl(url)
100
+ globalThis.removeEventListener(EventTypes.Cookie.listUrl, spy)
101
+ assert.isTrue(spy.calledOnce)
102
+ })
103
+
104
+ test('has the url property', async ({ assert }) => {
105
+ const spy = sinon.spy()
106
+ globalThis.addEventListener(EventTypes.Cookie.listUrl, spy)
107
+ Events.Cookie.listUrl(url)
108
+ globalThis.removeEventListener(EventTypes.Cookie.listUrl, spy)
109
+ const e = spy.args[0][0] as CustomEvent
110
+ assert.deepEqual(e.detail.url, url)
111
+ })
112
+ })
113
+
114
+ test.group('Events > Cookie > Events.Cookie > delete()', () => {
115
+ const cookie: IHttpCookie = {
116
+ name: 'a',
117
+ value: 'b',
118
+ sameSite: 'no_restriction',
119
+ }
120
+
121
+ test('dispatches the event', async ({ assert }) => {
122
+ const spy = sinon.spy()
123
+ globalThis.addEventListener(EventTypes.Cookie.delete, spy)
124
+ Events.Cookie.delete([cookie])
125
+ globalThis.removeEventListener(EventTypes.Cookie.delete, spy)
126
+ assert.isTrue(spy.calledOnce)
127
+ })
128
+
129
+ test('has the cookies property', async ({ assert }) => {
130
+ const spy = sinon.spy()
131
+ globalThis.addEventListener(EventTypes.Cookie.delete, spy)
132
+ Events.Cookie.delete([cookie])
133
+ globalThis.removeEventListener(EventTypes.Cookie.delete, spy)
134
+ const e = spy.args[0][0] as CustomEvent
135
+ assert.deepEqual(e.detail.cookies, [cookie])
136
+ })
137
+ })
138
+
139
+ test.group('Events > Cookie > Events.Cookie > deleteUrl()', () => {
140
+ const url = 'https://dot.com/path'
141
+
142
+ test('dispatches the event', async ({ assert }) => {
143
+ const spy = sinon.spy()
144
+ globalThis.addEventListener(EventTypes.Cookie.deleteUrl, spy)
145
+ Events.Cookie.deleteUrl(url)
146
+ globalThis.removeEventListener(EventTypes.Cookie.deleteUrl, spy)
147
+ assert.isTrue(spy.calledOnce)
148
+ })
149
+
150
+ test('has the url property', async ({ assert }) => {
151
+ const spy = sinon.spy()
152
+ globalThis.addEventListener(EventTypes.Cookie.deleteUrl, spy)
153
+ Events.Cookie.deleteUrl(url)
154
+ globalThis.removeEventListener(EventTypes.Cookie.deleteUrl, spy)
155
+ const e = spy.args[0][0] as CustomEvent
156
+ assert.deepEqual(e.detail.url, url)
157
+ })
158
+
159
+ test('has the optional name property', async ({ assert }) => {
160
+ const name = 'test name'
161
+ const spy = sinon.spy()
162
+ globalThis.addEventListener(EventTypes.Cookie.deleteUrl, spy)
163
+ Events.Cookie.deleteUrl(url, name)
164
+ globalThis.removeEventListener(EventTypes.Cookie.deleteUrl, spy)
165
+ const e = spy.args[0][0] as CustomEvent
166
+ assert.deepEqual(e.detail.name, name)
167
+ })
168
+ })
169
+
170
+ test.group('Events > Cookie > Events.Cookie > update()', () => {
171
+ const cookie: IHttpCookie = {
172
+ name: 'a',
173
+ value: 'b',
174
+ sameSite: 'no_restriction',
175
+ }
176
+
177
+ test('dispatches the event', async ({ assert }) => {
178
+ const spy = sinon.spy()
179
+ globalThis.addEventListener(EventTypes.Cookie.update, spy)
180
+ Events.Cookie.update(cookie)
181
+ globalThis.removeEventListener(EventTypes.Cookie.update, spy)
182
+ assert.isTrue(spy.calledOnce)
183
+ })
184
+
185
+ test('has the detail property', async ({ assert }) => {
186
+ const spy = sinon.spy()
187
+ globalThis.addEventListener(EventTypes.Cookie.update, spy)
188
+ Events.Cookie.update(cookie)
189
+ globalThis.removeEventListener(EventTypes.Cookie.update, spy)
190
+ const e = spy.args[0][0] as ContextUpdateEvent<IHttpCookie>
191
+ const detail = e.detail as ContextUpdateEventDetail<IHttpCookie>
192
+ assert.deepEqual(detail.item, cookie)
193
+ })
194
+ })
195
+
196
+ test.group('Events > Cookie > Events.Cookie > updateBulk()', () => {
197
+ const cookie: IHttpCookie = {
198
+ name: 'a',
199
+ value: 'b',
200
+ sameSite: 'no_restriction',
201
+ }
202
+
203
+ test('dispatches the event', async ({ assert }) => {
204
+ const spy = sinon.spy()
205
+ globalThis.addEventListener(EventTypes.Cookie.updateBulk, spy)
206
+ Events.Cookie.updateBulk([cookie])
207
+ globalThis.removeEventListener(EventTypes.Cookie.updateBulk, spy)
208
+ assert.isTrue(spy.calledOnce)
209
+ })
210
+
211
+ test('has the cookies property', async ({ assert }) => {
212
+ const spy = sinon.spy()
213
+ globalThis.addEventListener(EventTypes.Cookie.updateBulk, spy)
214
+ Events.Cookie.updateBulk([cookie])
215
+ globalThis.removeEventListener(EventTypes.Cookie.updateBulk, spy)
216
+ const e = spy.args[0][0] as CustomEvent
217
+ assert.deepEqual(e.detail.cookies, [cookie])
218
+ })
219
+ })
220
+
221
+ test.group('Events > Cookie > Events.Cookie > State.delete()', () => {
222
+ const cookie: IHttpCookie = {
223
+ name: 'a',
224
+ value: 'b',
225
+ sameSite: 'no_restriction',
226
+ }
227
+
228
+ test('dispatches the event', async ({ assert }) => {
229
+ const spy = sinon.spy()
230
+ globalThis.addEventListener(EventTypes.Cookie.State.delete, spy)
231
+ Events.Cookie.State.delete(cookie)
232
+ globalThis.removeEventListener(EventTypes.Cookie.State.delete, spy)
233
+ assert.isTrue(spy.calledOnce)
234
+ })
235
+
236
+ test('has the cookie property', async ({ assert }) => {
237
+ const spy = sinon.spy()
238
+ globalThis.addEventListener(EventTypes.Cookie.State.delete, spy)
239
+ Events.Cookie.State.delete(cookie)
240
+ globalThis.removeEventListener(EventTypes.Cookie.State.delete, spy)
241
+ const e = spy.args[0][0] as CustomEvent
242
+ assert.deepEqual(e.detail.cookie, cookie)
243
+ })
244
+ })
245
+
246
+ test.group('Events > Cookie > Events.Cookie > State.update()', () => {
247
+ const cookie: IHttpCookie = {
248
+ name: 'a',
249
+ value: 'b',
250
+ sameSite: 'no_restriction',
251
+ }
252
+
253
+ const record: ContextChangeRecord<IHttpCookie> = {
254
+ item: cookie,
255
+ key: 'null',
256
+ }
257
+
258
+ test('dispatches the event', async ({ assert }) => {
259
+ const spy = sinon.spy()
260
+ globalThis.addEventListener(EventTypes.Cookie.State.update, spy)
261
+ Events.Cookie.State.update(record)
262
+ globalThis.removeEventListener(EventTypes.Cookie.State.update, spy)
263
+ assert.isTrue(spy.calledOnce)
264
+ })
265
+
266
+ test('has the change record', async ({ assert }) => {
267
+ const spy = sinon.spy()
268
+ globalThis.addEventListener(EventTypes.Cookie.State.update, spy)
269
+ Events.Cookie.State.update(record)
270
+ globalThis.removeEventListener(EventTypes.Cookie.State.update, spy)
271
+ const e = spy.args[0][0] as CustomEvent
272
+ assert.deepEqual(e.detail, record)
273
+ })
274
+ })
@@ -0,0 +1,108 @@
1
+ import { test } from '@japa/runner'
2
+ import sinon from 'sinon'
3
+ import { EventTypes } from '../../../src/events/EventTypes.js'
4
+ import { Events } from '../../../src/events/Events.js'
5
+ import { ensureUnique } from './EventsTestHelpers.js'
6
+ import './events_polyfills.js'
7
+
8
+ test.group('Events > Encryption > EventTypes.Encryption', () => {
9
+ test('has the namespace', ({ assert }) => {
10
+ assert.typeOf(EventTypes.Encryption, 'object')
11
+ })
12
+
13
+ test('has "{prop}" property')
14
+ .with([
15
+ { prop: 'encrypt', value: 'encryptionencrypt' },
16
+ { prop: 'decrypt', value: 'encryptiondecrypt' },
17
+ ])
18
+ .run(({ assert }, { prop, value }) => {
19
+ // @ts-expect-error Used in testing
20
+ assert.equal(EventTypes.Encryption[prop], value)
21
+ })
22
+
23
+ test('has unique events for the namespace', () => {
24
+ ensureUnique('EventTypes.Encryption', EventTypes.Encryption)
25
+ })
26
+ })
27
+
28
+ test.group('Events > Encryption > Events.Encryption > encrypt()', () => {
29
+ const data = 'export data'
30
+ const passphrase = 'passphrase data'
31
+ const method = 'aes'
32
+
33
+ test('dispatches the event', async ({ assert }) => {
34
+ const spy = sinon.spy()
35
+ globalThis.addEventListener(EventTypes.Encryption.encrypt, spy)
36
+ await Events.Encryption.encrypt(data, passphrase, method)
37
+ globalThis.removeEventListener(EventTypes.Encryption.encrypt, spy)
38
+ assert.isTrue(spy.calledOnce)
39
+ })
40
+
41
+ test('has the data on the event', async ({ assert }) => {
42
+ const spy = sinon.spy()
43
+ globalThis.addEventListener(EventTypes.Encryption.encrypt, spy)
44
+ await Events.Encryption.encrypt(data, passphrase, method)
45
+ globalThis.removeEventListener(EventTypes.Encryption.encrypt, spy)
46
+ const e = spy.args[0][0] as CustomEvent
47
+ assert.equal(e.detail.data, data)
48
+ })
49
+
50
+ test('has the passphrase on the event', async ({ assert }) => {
51
+ const spy = sinon.spy()
52
+ globalThis.addEventListener(EventTypes.Encryption.encrypt, spy)
53
+ await Events.Encryption.encrypt(data, passphrase, method)
54
+ globalThis.removeEventListener(EventTypes.Encryption.encrypt, spy)
55
+ const e = spy.args[0][0] as CustomEvent
56
+ assert.equal(e.detail.passphrase, passphrase)
57
+ })
58
+
59
+ test('has the method on the event', async ({ assert }) => {
60
+ const spy = sinon.spy()
61
+ globalThis.addEventListener(EventTypes.Encryption.encrypt, spy)
62
+ await Events.Encryption.encrypt(data, passphrase, method)
63
+ globalThis.removeEventListener(EventTypes.Encryption.encrypt, spy)
64
+ const e = spy.args[0][0] as CustomEvent
65
+ assert.equal(e.detail.method, method)
66
+ })
67
+ })
68
+
69
+ test.group('Events > Encryption > Events.Encryption > decrypt()', () => {
70
+ const data = 'export data'
71
+ const passphrase = 'passphrase data'
72
+ const method = 'aes'
73
+
74
+ test('dispatches the event', async ({ assert }) => {
75
+ const spy = sinon.spy()
76
+ globalThis.addEventListener(EventTypes.Encryption.decrypt, spy)
77
+ await Events.Encryption.decrypt(data, passphrase, method)
78
+ globalThis.removeEventListener(EventTypes.Encryption.decrypt, spy)
79
+ assert.isTrue(spy.calledOnce)
80
+ })
81
+
82
+ test('has the data on the event', async ({ assert }) => {
83
+ const spy = sinon.spy()
84
+ globalThis.addEventListener(EventTypes.Encryption.decrypt, spy)
85
+ await Events.Encryption.decrypt(data, passphrase, method)
86
+ globalThis.removeEventListener(EventTypes.Encryption.decrypt, spy)
87
+ const e = spy.args[0][0] as CustomEvent
88
+ assert.equal(e.detail.data, data)
89
+ })
90
+
91
+ test('has the passphrase on the event', async ({ assert }) => {
92
+ const spy = sinon.spy()
93
+ globalThis.addEventListener(EventTypes.Encryption.decrypt, spy)
94
+ await Events.Encryption.decrypt(data, passphrase, method)
95
+ globalThis.removeEventListener(EventTypes.Encryption.decrypt, spy)
96
+ const e = spy.args[0][0] as CustomEvent
97
+ assert.equal(e.detail.passphrase, passphrase)
98
+ })
99
+
100
+ test('has the method on the event', async ({ assert }) => {
101
+ const spy = sinon.spy()
102
+ globalThis.addEventListener(EventTypes.Encryption.decrypt, spy)
103
+ await Events.Encryption.decrypt(data, passphrase, method)
104
+ globalThis.removeEventListener(EventTypes.Encryption.decrypt, spy)
105
+ const e = spy.args[0][0] as CustomEvent
106
+ assert.equal(e.detail.method, method)
107
+ })
108
+ })
@@ -0,0 +1,77 @@
1
+ /* eslint-disable @typescript-eslint/no-explicit-any */
2
+ // Originally these tests were written for a browser environment.
3
+ // They are now adapted to run in a Node.js environment with polyfills for browser APIs.
4
+
5
+ // @ts-expect-error This is for testing.
6
+ globalThis.window = globalThis
7
+
8
+ // Polyfill for DOM EventTarget APIs in Node.js environment for testing
9
+ if (typeof globalThis.Event === 'undefined') {
10
+ class EventPolyfill {
11
+ type: string
12
+ bubbles: boolean
13
+ cancelable: boolean
14
+ composed: boolean
15
+ defaultPrevented = false
16
+ readonly timeStamp: number = Date.now()
17
+ // Stub other properties/methods as needed by the code under test
18
+ target: any | null = null // Using 'any' for simplicity in polyfill
19
+ currentTarget: any | null = null
20
+
21
+ constructor(type: string, eventInitDict?: EventInit) {
22
+ this.type = type
23
+ this.bubbles = eventInitDict?.bubbles ?? false
24
+ this.cancelable = eventInitDict?.cancelable ?? false
25
+ this.composed = eventInitDict?.composed ?? false
26
+ }
27
+
28
+ preventDefault(): void {
29
+ if (this.cancelable) {
30
+ this.defaultPrevented = true
31
+ }
32
+ }
33
+
34
+ stopPropagation(): void {
35
+ /* Stub */
36
+ }
37
+ stopImmediatePropagation(): void {
38
+ /* Stub */
39
+ }
40
+ }
41
+ ;(globalThis as any).Event = EventPolyfill
42
+ }
43
+
44
+ if (typeof globalThis.CustomEvent === 'undefined') {
45
+ class CustomEventPolyfill<T = any> extends (globalThis as any).Event {
46
+ detail: T
47
+
48
+ constructor(type: string, eventInitDict?: CustomEventInit<T>) {
49
+ super(type, eventInitDict)
50
+ this.detail = eventInitDict?.detail ?? (null as T)
51
+ }
52
+ }
53
+ ;(globalThis as any).CustomEvent = CustomEventPolyfill
54
+ }
55
+
56
+ if (typeof globalThis.addEventListener !== 'function') {
57
+ const eventListeners = new Map<string, Set<EventListenerOrEventListenerObject>>()
58
+
59
+ globalThis.addEventListener = (type: string, listener: EventListenerOrEventListenerObject): void => {
60
+ if (!eventListeners.has(type)) {
61
+ eventListeners.set(type, new Set())
62
+ }
63
+ eventListeners.get(type)!.add(listener)
64
+ }
65
+
66
+ globalThis.removeEventListener = (type: string, listener: EventListenerOrEventListenerObject): void => {
67
+ eventListeners.get(type)?.delete(listener)
68
+ }
69
+
70
+ globalThis.dispatchEvent = (event: Event): boolean => {
71
+ eventListeners.get(event.type)?.forEach((handler) => {
72
+ if (typeof handler === 'function') handler.call(globalThis, event)
73
+ else handler.handleEvent.call(globalThis, event)
74
+ })
75
+ return !event.defaultPrevented
76
+ }
77
+ }
@@ -0,0 +1,120 @@
1
+ import { test } from '@japa/runner'
2
+ import sinon from 'sinon'
3
+ import { EventTypes } from '../../../src/events/EventTypes.js'
4
+ import { Events } from '../../../src/events/Events.js'
5
+ import { ensureUnique } from './EventsTestHelpers.js'
6
+ import './events_polyfills.js'
7
+
8
+ test.group('Events > Process > EventTypes.Process', () => {
9
+ test('has the namespace', ({ assert }) => {
10
+ assert.typeOf(EventTypes.Process, 'object')
11
+ })
12
+
13
+ test('has "{prop}" property')
14
+ .with([
15
+ { prop: 'loadingStart', value: 'processloadingstart' },
16
+ { prop: 'loadingStop', value: 'processloadingstop' },
17
+ { prop: 'loadingError', value: 'processloadingerror' },
18
+ ])
19
+ .run(({ assert }, { prop, value }) => {
20
+ // @ts-expect-error Used in testing
21
+ assert.equal(EventTypes.Process[prop], value)
22
+ })
23
+
24
+ test('has unique events for the namespace', () => {
25
+ ensureUnique('EventTypes.Process', EventTypes.Process)
26
+ })
27
+ })
28
+
29
+ test.group('Events > Process > Events.Process > loadingStart()', () => {
30
+ const pid = 'process-id-1'
31
+ const message = 'test-message'
32
+
33
+ test('dispatches the event', ({ assert }) => {
34
+ const spy = sinon.spy()
35
+ globalThis.addEventListener(EventTypes.Process.loadingStart, spy)
36
+ Events.Process.loadingStart(pid, message)
37
+ globalThis.removeEventListener(EventTypes.Process.loadingStart, spy)
38
+ assert.isTrue(spy.calledOnce)
39
+ })
40
+
41
+ test('has the pid on the event', ({ assert }) => {
42
+ const spy = sinon.spy()
43
+ globalThis.addEventListener(EventTypes.Process.loadingStart, spy)
44
+ Events.Process.loadingStart(pid, message)
45
+ globalThis.removeEventListener(EventTypes.Process.loadingStart, spy)
46
+ const e = spy.args[0][0] as CustomEvent
47
+ assert.equal(e.detail.pid, pid)
48
+ })
49
+
50
+ test('has the message on the event', ({ assert }) => {
51
+ const spy = sinon.spy()
52
+ globalThis.addEventListener(EventTypes.Process.loadingStart, spy)
53
+ Events.Process.loadingStart(pid, message)
54
+ globalThis.removeEventListener(EventTypes.Process.loadingStart, spy)
55
+ const e = spy.args[0][0] as CustomEvent
56
+ assert.equal(e.detail.message, message)
57
+ })
58
+ })
59
+
60
+ test.group('Events > Process > Events.Process > loadingStop()', () => {
61
+ const pid = 'process-id-1'
62
+
63
+ test('dispatches the event', ({ assert }) => {
64
+ const spy = sinon.spy()
65
+ globalThis.addEventListener(EventTypes.Process.loadingStop, spy)
66
+ Events.Process.loadingStop(pid)
67
+ globalThis.removeEventListener(EventTypes.Process.loadingStop, spy)
68
+ assert.isTrue(spy.calledOnce)
69
+ })
70
+
71
+ test('has the pid on the event', ({ assert }) => {
72
+ const spy = sinon.spy()
73
+ globalThis.addEventListener(EventTypes.Process.loadingStop, spy)
74
+ Events.Process.loadingStop(pid)
75
+ globalThis.removeEventListener(EventTypes.Process.loadingStop, spy)
76
+ const e = spy.args[0][0] as CustomEvent
77
+ assert.equal(e.detail.pid, pid)
78
+ })
79
+ })
80
+
81
+ test.group('Events > Process > Events.Process > loadingError()', () => {
82
+ const pid = 'process-id-1'
83
+ const message = 'test-message'
84
+ const error = new Error('test-message')
85
+
86
+ test('dispatches the event', ({ assert }) => {
87
+ const spy = sinon.spy()
88
+ globalThis.addEventListener(EventTypes.Process.loadingError, spy)
89
+ Events.Process.loadingError(pid, message)
90
+ globalThis.removeEventListener(EventTypes.Process.loadingError, spy)
91
+ assert.isTrue(spy.calledOnce)
92
+ })
93
+
94
+ test('has the pid on the event', ({ assert }) => {
95
+ const spy = sinon.spy()
96
+ globalThis.addEventListener(EventTypes.Process.loadingError, spy)
97
+ Events.Process.loadingError(pid, message)
98
+ globalThis.removeEventListener(EventTypes.Process.loadingError, spy)
99
+ const e = spy.args[0][0] as CustomEvent
100
+ assert.equal(e.detail.pid, pid)
101
+ })
102
+
103
+ test('has the message on the event', ({ assert }) => {
104
+ const spy = sinon.spy()
105
+ globalThis.addEventListener(EventTypes.Process.loadingError, spy)
106
+ Events.Process.loadingError(pid, message)
107
+ globalThis.removeEventListener(EventTypes.Process.loadingError, spy)
108
+ const e = spy.args[0][0] as CustomEvent
109
+ assert.equal(e.detail.message, message)
110
+ })
111
+
112
+ test('has the optional error on the event', ({ assert }) => {
113
+ const spy = sinon.spy()
114
+ globalThis.addEventListener(EventTypes.Process.loadingError, spy)
115
+ Events.Process.loadingError(pid, message, error)
116
+ globalThis.removeEventListener(EventTypes.Process.loadingError, spy)
117
+ const e = spy.args[0][0] as CustomEvent
118
+ assert.deepEqual(e.detail.error, error)
119
+ })
120
+ })
@@ -0,0 +1,82 @@
1
+ import { test } from '@japa/runner'
2
+ import sinon from 'sinon'
3
+ import { EventTypes } from '../../../src/events/EventTypes.js'
4
+ import { Events } from '../../../src/events/Events.js'
5
+ import { ensureUnique } from './EventsTestHelpers.js'
6
+ import './events_polyfills.js'
7
+
8
+ test.group('Events > Reporting > EventTypes.Reporting', () => {
9
+ test('has the namespace', ({ assert }) => {
10
+ assert.typeOf(EventTypes.Reporting, 'object')
11
+ })
12
+
13
+ test('has "{prop}" property')
14
+ .with([{ prop: 'error', value: 'reporterror' }])
15
+ .run(({ assert }, { prop, value }) => {
16
+ // @ts-expect-error Used in testing
17
+ assert.equal(EventTypes.Reporting[prop], value)
18
+ })
19
+
20
+ test('has unique events for the namespace', () => {
21
+ ensureUnique('EventTypes.Reporting', EventTypes.Reporting)
22
+ })
23
+ })
24
+
25
+ test.group('Events > Reporting > Events.Reporting > error()', () => {
26
+ const err = new Error('Test Error')
27
+ const desc = 'test error description'
28
+ const cmp = 'test-component'
29
+
30
+ test('dispatches the event', ({ assert }) => {
31
+ const spy = sinon.spy()
32
+ globalThis.addEventListener(EventTypes.Reporting.error, spy)
33
+ Events.Reporting.error(desc)
34
+ globalThis.removeEventListener(EventTypes.Reporting.error, spy)
35
+ assert.isTrue(spy.calledOnce)
36
+ })
37
+
38
+ test('has the description on the event', ({ assert }) => {
39
+ const spy = sinon.spy()
40
+ globalThis.addEventListener(EventTypes.Reporting.error, spy)
41
+ Events.Reporting.error(desc)
42
+ globalThis.removeEventListener(EventTypes.Reporting.error, spy)
43
+ const e = spy.args[0][0] as CustomEvent
44
+ assert.equal(e.detail.description, desc)
45
+ })
46
+
47
+ test('has the error on the event when provided', ({ assert }) => {
48
+ const spy = sinon.spy()
49
+ globalThis.addEventListener(EventTypes.Reporting.error, spy)
50
+ Events.Reporting.error(desc, err)
51
+ globalThis.removeEventListener(EventTypes.Reporting.error, spy)
52
+ const e = spy.args[0][0] as CustomEvent
53
+ assert.deepEqual(e.detail.error, err)
54
+ })
55
+
56
+ test('error property is undefined when not provided', ({ assert }) => {
57
+ const spy = sinon.spy()
58
+ globalThis.addEventListener(EventTypes.Reporting.error, spy)
59
+ Events.Reporting.error(desc)
60
+ globalThis.removeEventListener(EventTypes.Reporting.error, spy)
61
+ const e = spy.args[0][0] as CustomEvent
62
+ assert.isUndefined(e.detail.error)
63
+ })
64
+
65
+ test('has the component on the event when provided', ({ assert }) => {
66
+ const spy = sinon.spy()
67
+ globalThis.addEventListener(EventTypes.Reporting.error, spy)
68
+ Events.Reporting.error(desc, err, cmp)
69
+ globalThis.removeEventListener(EventTypes.Reporting.error, spy)
70
+ const e = spy.args[0][0] as CustomEvent
71
+ assert.equal(e.detail.component, cmp)
72
+ })
73
+
74
+ test('component property is undefined when not provided', ({ assert }) => {
75
+ const spy = sinon.spy()
76
+ globalThis.addEventListener(EventTypes.Reporting.error, spy)
77
+ Events.Reporting.error(desc, err) // No component here
78
+ globalThis.removeEventListener(EventTypes.Reporting.error, spy)
79
+ const e = spy.args[0][0] as CustomEvent
80
+ assert.isUndefined(e.detail.component)
81
+ })
82
+ })