@chaos-maker/core 0.2.0 → 0.4.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.
package/README.md CHANGED
@@ -1,6 +1,6 @@
1
1
  # @chaos-maker/core
2
2
 
3
- Core chaos engine for web applications. Intercepts `fetch`, `XMLHttpRequest`, and DOM mutations to inject controlled failures, latency, aborts, corruption, and UI disruptions.
3
+ Core chaos engine for web applications. Intercepts `fetch`, `XMLHttpRequest`, `WebSocket`, `EventSource`, DOM mutations, and Service Worker fetches to inject controlled failures, latency, aborts, corruption, drops, closes, and UI disruptions.
4
4
 
5
5
  Framework-agnostic. Works with Playwright, Cypress, Selenium, or any browser environment.
6
6
 
@@ -82,6 +82,9 @@ const config = new ChaosConfigBuilder()
82
82
  | Corruption | `network.corruptions` | Corrupt response bodies |
83
83
  | CORS | `network.cors` | Simulate CORS errors |
84
84
  | UI Assault | `ui.assaults` | Disable, hide, or remove DOM elements |
85
+ | WebSocket | `websocket.*` | Drop, delay, corrupt, or close socket messages |
86
+ | SSE | `sse.*` | Drop, delay, corrupt, or close EventSource events |
87
+ | GraphQL | `graphqlOperation` | Target one operation on a shared endpoint |
85
88
 
86
89
  ## Configuration Reference
87
90
 
@@ -93,6 +96,7 @@ const config = new ChaosConfigBuilder()
93
96
  | `statusCode` | `number` | Yes | HTTP status code (100-599) |
94
97
  | `probability` | `number` | Yes | 0.0-1.0 chance of applying |
95
98
  | `methods` | `string[]` | No | HTTP methods to match (default: all) |
99
+ | `graphqlOperation` | `string \| RegExp` | No | Operation name matcher for GraphQL requests |
96
100
  | `body` | `string` | No | Custom response body |
97
101
  | `statusText` | `string` | No | Custom status text |
98
102
  | `headers` | `Record<string, string>` | No | Custom response headers |
@@ -105,6 +109,7 @@ const config = new ChaosConfigBuilder()
105
109
  | `delayMs` | `number` | Yes | Delay in milliseconds |
106
110
  | `probability` | `number` | Yes | 0.0-1.0 chance of applying |
107
111
  | `methods` | `string[]` | No | HTTP methods to match |
112
+ | `graphqlOperation` | `string \| RegExp` | No | Operation name matcher for GraphQL requests |
108
113
 
109
114
  ### NetworkAbortConfig
110
115
 
@@ -114,6 +119,7 @@ const config = new ChaosConfigBuilder()
114
119
  | `probability` | `number` | Yes | 0.0-1.0 chance of applying |
115
120
  | `timeout` | `number` | No | ms before abort (0 or omitted = immediate) |
116
121
  | `methods` | `string[]` | No | HTTP methods to match |
122
+ | `graphqlOperation` | `string \| RegExp` | No | Operation name matcher for GraphQL requests |
117
123
 
118
124
  ### NetworkCorruptionConfig
119
125
 
@@ -123,6 +129,7 @@ const config = new ChaosConfigBuilder()
123
129
  | `strategy` | `CorruptionStrategy` | Yes | `'truncate'` \| `'malformed-json'` \| `'empty'` \| `'wrong-type'` |
124
130
  | `probability` | `number` | Yes | 0.0-1.0 chance of applying |
125
131
  | `methods` | `string[]` | No | HTTP methods to match |
132
+ | `graphqlOperation` | `string \| RegExp` | No | Operation name matcher for GraphQL requests |
126
133
 
127
134
  ### NetworkCorsConfig
128
135
 
@@ -131,6 +138,7 @@ const config = new ChaosConfigBuilder()
131
138
  | `urlPattern` | `string` | Yes | Substring match against request URL |
132
139
  | `probability` | `number` | Yes | 0.0-1.0 chance of applying |
133
140
  | `methods` | `string[]` | No | HTTP methods to match |
141
+ | `graphqlOperation` | `string \| RegExp` | No | Operation name matcher for GraphQL requests |
134
142
 
135
143
  ### UiAssaultConfig
136
144
 
@@ -140,6 +148,34 @@ const config = new ChaosConfigBuilder()
140
148
  | `action` | `string` | Yes | `'disable'` \| `'hide'` \| `'remove'` |
141
149
  | `probability` | `number` | Yes | 0.0-1.0 chance of applying |
142
150
 
151
+ ### SSEConfig
152
+
153
+ ```ts
154
+ sse: {
155
+ drops: [{ urlPattern: '/events', eventType: 'token', probability: 0.1 }],
156
+ delays: [{ urlPattern: '/events', delayMs: 500, probability: 1 }],
157
+ corruptions: [{ urlPattern: '/events', strategy: 'truncate', probability: 0.05 }],
158
+ closes: [{ urlPattern: '/events', afterMs: 2000, probability: 0.02 }],
159
+ }
160
+ ```
161
+
162
+ `eventType` defaults to `message`; use a named event or `'*'` for all data events.
163
+
164
+ ### GraphQL operation matching
165
+
166
+ ```ts
167
+ network: {
168
+ failures: [{
169
+ urlPattern: '/graphql',
170
+ graphqlOperation: 'GetUser',
171
+ statusCode: 503,
172
+ probability: 1,
173
+ }],
174
+ }
175
+ ```
176
+
177
+ `graphqlOperation` is an additional matcher on top of `urlPattern` and `methods`.
178
+
143
179
  ## Event System
144
180
 
145
181
  ```ts
@@ -151,7 +187,7 @@ const log = chaos.getLog(); // all events since start
151
187
  chaos.clearLog();
152
188
  ```
153
189
 
154
- Event types: `network:failure`, `network:latency`, `network:abort`, `network:corruption`, `network:cors`, `ui:assault`
190
+ Event types: `network:failure`, `network:latency`, `network:abort`, `network:corruption`, `network:cors`, `ui:assault`, `websocket:drop`, `websocket:delay`, `websocket:corrupt`, `websocket:close`, `sse:drop`, `sse:delay`, `sse:corrupt`, `sse:close`
155
191
 
156
192
  ## Config Validation
157
193
 
@@ -171,6 +207,28 @@ try {
171
207
  }
172
208
  ```
173
209
 
210
+ ## Service Worker chaos
211
+
212
+ Chaos applies to SW-originated fetches via the `@chaos-maker/core/sw` subpath. Zod + UI + builder are excluded from this bundle so it stays small enough for production SW deploys.
213
+
214
+ Classic SW (one line):
215
+
216
+ ```js
217
+ // user's sw.js
218
+ importScripts('/path/to/chaos-maker-sw.js'); // auto-installs
219
+ ```
220
+
221
+ Module SW:
222
+
223
+ ```js
224
+ import { installChaosSW } from '@chaos-maker/core/sw';
225
+ installChaosSW({ source: 'message' });
226
+ ```
227
+
228
+ Page-side config is delivered via `postMessage` + `MessageChannel` ack. Use the adapter helpers (`injectSWChaos` / `removeSWChaos` / `getSWChaosLog`) in `@chaos-maker/{playwright,cypress,webdriverio,puppeteer}`.
229
+
230
+ Limitations: `caches.match` hits bypass chaos (planned for v0.5.0); push/sync events not covered; cross-origin SWs not supported.
231
+
174
232
  ## License
175
233
 
176
234
  [MIT](../../LICENSE)