@sprucelabs/mercury-chunking-emitter 1.1.5 → 1.3.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/build/chunkingEmitter/ChunkingEmitter.d.ts +1 -1
- package/build/chunkingEmitter/MockChunkingEmitter.d.ts +5 -6
- package/build/chunkingEmitter/MockChunkingEmitter.js +8 -1
- package/build/esm/chunkingEmitter/ChunkingEmitter.d.ts +1 -1
- package/build/esm/chunkingEmitter/MockChunkingEmitter.d.ts +5 -6
- package/build/esm/chunkingEmitter/MockChunkingEmitter.js +8 -1
- package/package.json +1 -1
|
@@ -1,23 +1,22 @@
|
|
|
1
1
|
import { EventName } from '@sprucelabs/mercury-types';
|
|
2
|
-
import { ChunkingEmitter } from './ChunkingEmitter';
|
|
2
|
+
import { ChunkingEmitter, ChunkingEmitterEmitOptions } from './ChunkingEmitter';
|
|
3
3
|
export default class MockChunkingEmitter implements ChunkingEmitter {
|
|
4
4
|
private didEmit;
|
|
5
5
|
private emittedEventName?;
|
|
6
6
|
private emittedItems?;
|
|
7
7
|
private emittedPayloadKey?;
|
|
8
8
|
static lastInstance?: MockChunkingEmitter;
|
|
9
|
+
private emittedTarget?;
|
|
9
10
|
constructor();
|
|
10
11
|
static getLastInstance(): MockChunkingEmitter;
|
|
11
12
|
static reset(): void;
|
|
12
|
-
emit(options:
|
|
13
|
-
|
|
14
|
-
items: Record<string, unknown>[];
|
|
15
|
-
payloadKey: string;
|
|
16
|
-
}): Promise<void>;
|
|
13
|
+
emit(options: ChunkingEmitterEmitOptions): Promise<void>;
|
|
14
|
+
assertDidEmitTarget(target: Record<string, any>): void;
|
|
17
15
|
assertDidEmitPayloadKey(payloadKey: string): void;
|
|
18
16
|
getTotalErrors(): number;
|
|
19
17
|
assertEmittedItems(items: Record<string, any>[]): void;
|
|
20
18
|
assertDidEmit(): void;
|
|
21
19
|
assertDidEmitEventNamed(fqen: EventName): void;
|
|
22
20
|
assertEventHonorsChunkingSignature(fqen: EventName): void;
|
|
21
|
+
assertDidNotEmit(): void;
|
|
23
22
|
}
|
|
@@ -16,11 +16,15 @@ class MockChunkingEmitter {
|
|
|
16
16
|
this.lastInstance = undefined;
|
|
17
17
|
}
|
|
18
18
|
async emit(options) {
|
|
19
|
-
const { eventName, items, payloadKey } = options;
|
|
19
|
+
const { eventName, items, payloadKey, target } = options;
|
|
20
20
|
this.didEmit = true;
|
|
21
21
|
this.emittedEventName = eventName;
|
|
22
22
|
this.emittedItems = items;
|
|
23
23
|
this.emittedPayloadKey = payloadKey;
|
|
24
|
+
this.emittedTarget = target;
|
|
25
|
+
}
|
|
26
|
+
assertDidEmitTarget(target) {
|
|
27
|
+
test_utils_1.assert.isEqualDeep(this.emittedTarget, target, 'You did not chunkingEmitter.emit(...) the expected target!');
|
|
24
28
|
}
|
|
25
29
|
assertDidEmitPayloadKey(payloadKey) {
|
|
26
30
|
this.assertDidEmit();
|
|
@@ -50,5 +54,8 @@ class MockChunkingEmitter {
|
|
|
50
54
|
test_utils_1.assert.isTruthy(chunkField, 'Your event does not conform to the chunking signature. Please add a chunk field to your event payload. Add a field to your payload called chunk: chunkFieldDefinition()');
|
|
51
55
|
test_utils_1.assert.isEqualDeep(chunkField, (0, chunkFieldDefinition_1.chunkFieldDefinition)(), 'Your chunk field is there but not properly formed. Use chunkFieldDefinition() to define it.');
|
|
52
56
|
}
|
|
57
|
+
assertDidNotEmit() {
|
|
58
|
+
test_utils_1.assert.isFalse(this.didEmit, `You called chunkingEmitter.emit(...) but you should not have!`);
|
|
59
|
+
}
|
|
53
60
|
}
|
|
54
61
|
exports.default = MockChunkingEmitter;
|
|
@@ -1,23 +1,22 @@
|
|
|
1
1
|
import { EventName } from '@sprucelabs/mercury-types';
|
|
2
|
-
import { ChunkingEmitter } from './ChunkingEmitter';
|
|
2
|
+
import { ChunkingEmitter, ChunkingEmitterEmitOptions } from './ChunkingEmitter';
|
|
3
3
|
export default class MockChunkingEmitter implements ChunkingEmitter {
|
|
4
4
|
private didEmit;
|
|
5
5
|
private emittedEventName?;
|
|
6
6
|
private emittedItems?;
|
|
7
7
|
private emittedPayloadKey?;
|
|
8
8
|
static lastInstance?: MockChunkingEmitter;
|
|
9
|
+
private emittedTarget?;
|
|
9
10
|
constructor();
|
|
10
11
|
static getLastInstance(): MockChunkingEmitter;
|
|
11
12
|
static reset(): void;
|
|
12
|
-
emit(options:
|
|
13
|
-
|
|
14
|
-
items: Record<string, unknown>[];
|
|
15
|
-
payloadKey: string;
|
|
16
|
-
}): Promise<void>;
|
|
13
|
+
emit(options: ChunkingEmitterEmitOptions): Promise<void>;
|
|
14
|
+
assertDidEmitTarget(target: Record<string, any>): void;
|
|
17
15
|
assertDidEmitPayloadKey(payloadKey: string): void;
|
|
18
16
|
getTotalErrors(): number;
|
|
19
17
|
assertEmittedItems(items: Record<string, any>[]): void;
|
|
20
18
|
assertDidEmit(): void;
|
|
21
19
|
assertDidEmitEventNamed(fqen: EventName): void;
|
|
22
20
|
assertEventHonorsChunkingSignature(fqen: EventName): void;
|
|
21
|
+
assertDidNotEmit(): void;
|
|
23
22
|
}
|
|
@@ -24,13 +24,17 @@ export default class MockChunkingEmitter {
|
|
|
24
24
|
}
|
|
25
25
|
emit(options) {
|
|
26
26
|
return __awaiter(this, void 0, void 0, function* () {
|
|
27
|
-
const { eventName, items, payloadKey } = options;
|
|
27
|
+
const { eventName, items, payloadKey, target } = options;
|
|
28
28
|
this.didEmit = true;
|
|
29
29
|
this.emittedEventName = eventName;
|
|
30
30
|
this.emittedItems = items;
|
|
31
31
|
this.emittedPayloadKey = payloadKey;
|
|
32
|
+
this.emittedTarget = target;
|
|
32
33
|
});
|
|
33
34
|
}
|
|
35
|
+
assertDidEmitTarget(target) {
|
|
36
|
+
assert.isEqualDeep(this.emittedTarget, target, 'You did not chunkingEmitter.emit(...) the expected target!');
|
|
37
|
+
}
|
|
34
38
|
assertDidEmitPayloadKey(payloadKey) {
|
|
35
39
|
this.assertDidEmit();
|
|
36
40
|
assert.isEqual(this.emittedPayloadKey, payloadKey, `I expected chunkingEmitter.emit() with payloadKey '${payloadKey}'! But you emitted ${this.emittedPayloadKey || 'nothing'}`);
|
|
@@ -59,4 +63,7 @@ export default class MockChunkingEmitter {
|
|
|
59
63
|
assert.isTruthy(chunkField, 'Your event does not conform to the chunking signature. Please add a chunk field to your event payload. Add a field to your payload called chunk: chunkFieldDefinition()');
|
|
60
64
|
assert.isEqualDeep(chunkField, chunkFieldDefinition(), 'Your chunk field is there but not properly formed. Use chunkFieldDefinition() to define it.');
|
|
61
65
|
}
|
|
66
|
+
assertDidNotEmit() {
|
|
67
|
+
assert.isFalse(this.didEmit, `You called chunkingEmitter.emit(...) but you should not have!`);
|
|
68
|
+
}
|
|
62
69
|
}
|