zation-assured 0.6.3 → 3.0.0-dev.1

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 (151) hide show
  1. package/LICENSE +1 -1
  2. package/README.md +55 -2
  3. package/dist/index.d.ts +2 -2
  4. package/dist/index.js +3 -9
  5. package/dist/lib/api/assert.d.ts +16 -9
  6. package/dist/lib/api/assert.js +16 -12
  7. package/dist/lib/api/testHelper.d.ts +0 -8
  8. package/dist/lib/api/testHelper.js +6 -83
  9. package/dist/lib/api/when.d.ts +41 -45
  10. package/dist/lib/api/when.js +42 -55
  11. package/dist/lib/helper/asserter/abstractActionAsserter.d.ts +68 -0
  12. package/dist/lib/helper/asserter/{rootSendAsserter.js → abstractActionAsserter.js} +23 -67
  13. package/dist/lib/helper/asserter/assertStarter.d.ts +5 -0
  14. package/dist/lib/helper/asserter/assertStarter.js +16 -0
  15. package/dist/lib/helper/asserter/channel/abstractChannelAsserter.d.ts +20 -29
  16. package/dist/lib/helper/asserter/channel/abstractChannelAsserter.js +44 -85
  17. package/dist/lib/helper/asserter/channel/channelAsserter.d.ts +3 -3
  18. package/dist/lib/helper/asserter/channel/channelAsserter.js +2 -2
  19. package/dist/lib/helper/asserter/channel/standaloneChannelAsserter.d.ts +5 -5
  20. package/dist/lib/helper/asserter/channel/standaloneChannelAsserter.js +6 -6
  21. package/dist/lib/helper/asserter/client/abstractClientAsserter.d.ts +20 -38
  22. package/dist/lib/helper/asserter/client/abstractClientAsserter.js +82 -184
  23. package/dist/lib/helper/asserter/client/clientAsserter.d.ts +3 -3
  24. package/dist/lib/helper/asserter/client/clientAsserter.js +2 -2
  25. package/dist/lib/helper/asserter/client/standaloneClientAsserter.d.ts +5 -5
  26. package/dist/lib/helper/asserter/client/standaloneClientAsserter.js +6 -6
  27. package/dist/lib/helper/asserter/controller/integratedResponseAsserter.d.ts +52 -0
  28. package/dist/lib/helper/asserter/controller/integratedResponseAsserter.js +112 -0
  29. package/dist/lib/helper/asserter/controller/standaloneResponseAsserter.d.ts +49 -0
  30. package/dist/lib/helper/asserter/controller/standaloneResponseAsserter.js +108 -0
  31. package/dist/lib/helper/asserter/databox/abstractDataboxAsserter.d.ts +29 -36
  32. package/dist/lib/helper/asserter/databox/abstractDataboxAsserter.js +44 -80
  33. package/dist/lib/helper/asserter/databox/databoxAsserter.d.ts +3 -3
  34. package/dist/lib/helper/asserter/databox/databoxAsserter.js +2 -2
  35. package/dist/lib/helper/asserter/databox/standaloneDataboxAsserter.d.ts +6 -5
  36. package/dist/lib/helper/asserter/databox/standaloneDataboxAsserter.js +6 -6
  37. package/dist/lib/helper/asserter/event/abstractEventAsserter.d.ts +12 -4
  38. package/dist/lib/helper/asserter/event/abstractEventAsserter.js +25 -10
  39. package/dist/lib/helper/asserter/event/codeMetadataEventAsserter.d.ts +21 -0
  40. package/dist/lib/helper/asserter/event/codeMetadataEventAsserter.js +47 -0
  41. package/dist/lib/helper/asserter/event/dataEventAsserter.d.ts +13 -3
  42. package/dist/lib/helper/asserter/event/dataEventAsserter.js +22 -4
  43. package/dist/lib/helper/asserter/receiver/integratedTransmitAsserter.d.ts +9 -0
  44. package/dist/lib/helper/asserter/receiver/{transmitAsserter.js → integratedTransmitAsserter.js} +9 -9
  45. package/dist/lib/helper/asserter/value/abstractValueAsserter.d.ts +10 -12
  46. package/dist/lib/helper/asserter/value/abstractValueAsserter.js +46 -50
  47. package/dist/lib/helper/asserter/value/standaloneValueAsserter.d.ts +3 -3
  48. package/dist/lib/helper/asserter/value/standaloneValueAsserter.js +6 -6
  49. package/dist/lib/helper/asserter/value/valueAsserter.d.ts +4 -4
  50. package/dist/lib/helper/asserter/value/valueAsserter.js +4 -4
  51. package/dist/lib/helper/backError/backErrorsFilterBuilder.d.ts +12 -0
  52. package/dist/lib/helper/backError/backErrorsFilterBuilder.js +29 -0
  53. package/dist/lib/helper/console/logger.js +2 -2
  54. package/dist/lib/helper/definitions/optionTypes.d.ts +8 -0
  55. package/dist/lib/helper/definitions/optionTypes.js +7 -0
  56. package/dist/lib/helper/test/test.d.ts +2 -2
  57. package/dist/lib/helper/test/test.js +8 -6
  58. package/dist/lib/helper/timeout/timeoutAssert.js +2 -2
  59. package/dist/lib/helper/utils/actionUtils.d.ts +5 -18
  60. package/dist/lib/helper/utils/actionUtils.js +14 -43
  61. package/dist/lib/helper/utils/types.d.ts +20 -0
  62. package/dist/lib/helper/utils/types.js +7 -0
  63. package/package.json +7 -9
  64. package/dist/lib/api/before.d.ts +0 -3
  65. package/dist/lib/api/before.js +0 -20
  66. package/dist/lib/api/client.d.ts +0 -3
  67. package/dist/lib/api/client.js +0 -11
  68. package/dist/lib/api/describe.d.ts +0 -1
  69. package/dist/lib/api/describe.js +0 -6
  70. package/dist/lib/api/instanceManager.d.ts +0 -8
  71. package/dist/lib/api/instanceManager.js +0 -48
  72. package/dist/lib/api/testArea.d.ts +0 -3
  73. package/dist/lib/api/testArea.js +0 -41
  74. package/dist/lib/api/testServerManager.d.ts +0 -19
  75. package/dist/lib/api/testServerManager.js +0 -100
  76. package/dist/lib/helper/asserter/abstractClientAsserter.d.ts +0 -102
  77. package/dist/lib/helper/asserter/abstractClientAsserter.js +0 -293
  78. package/dist/lib/helper/asserter/anyAsserter.d.ts +0 -62
  79. package/dist/lib/helper/asserter/anyAsserter.js +0 -130
  80. package/dist/lib/helper/asserter/channelEventAsserter.d.ts +0 -34
  81. package/dist/lib/helper/asserter/channelEventAsserter.js +0 -84
  82. package/dist/lib/helper/asserter/channelPubAsserter.d.ts +0 -53
  83. package/dist/lib/helper/asserter/channelPubAsserter.js +0 -126
  84. package/dist/lib/helper/asserter/clientAsserter.d.ts +0 -13
  85. package/dist/lib/helper/asserter/clientAsserter.js +0 -26
  86. package/dist/lib/helper/asserter/controller/responseAsserter.d.ts +0 -74
  87. package/dist/lib/helper/asserter/controller/responseAsserter.js +0 -138
  88. package/dist/lib/helper/asserter/dataEventAsserter.d.ts +0 -40
  89. package/dist/lib/helper/asserter/dataEventAsserter.js +0 -113
  90. package/dist/lib/helper/asserter/event/abstractDataEventAsserter.d.ts +0 -13
  91. package/dist/lib/helper/asserter/event/abstractDataEventAsserter.js +0 -36
  92. package/dist/lib/helper/asserter/event/codeDataEventAsserter.d.ts +0 -14
  93. package/dist/lib/helper/asserter/event/codeDataEventAsserter.js +0 -40
  94. package/dist/lib/helper/asserter/eventAsserter.d.ts +0 -41
  95. package/dist/lib/helper/asserter/eventAsserter.js +0 -115
  96. package/dist/lib/helper/asserter/objectAsserter.d.ts +0 -55
  97. package/dist/lib/helper/asserter/objectAsserter.js +0 -113
  98. package/dist/lib/helper/asserter/receiver/transmitAsserter.d.ts +0 -9
  99. package/dist/lib/helper/asserter/responseAsserter.d.ts +0 -129
  100. package/dist/lib/helper/asserter/responseAsserter.js +0 -260
  101. package/dist/lib/helper/asserter/rootSendAsserter.d.ts +0 -89
  102. package/dist/lib/helper/asserter/standaloneClientAsserter.d.ts +0 -11
  103. package/dist/lib/helper/asserter/standaloneClientAsserter.js +0 -38
  104. package/dist/lib/helper/assured/clientAssured.d.ts +0 -2
  105. package/dist/lib/helper/assured/clientAssured.js +0 -11
  106. package/dist/lib/helper/assured/responseAssured.d.ts +0 -17
  107. package/dist/lib/helper/assured/responseAssured.js +0 -72
  108. package/dist/lib/helper/backError/backErrorFilterBuilder.d.ts +0 -13
  109. package/dist/lib/helper/backError/backErrorFilterBuilder.js +0 -32
  110. package/dist/lib/helper/builder/controller/abstractRequestBuilder.d.ts +0 -53
  111. package/dist/lib/helper/builder/controller/abstractRequestBuilder.js +0 -69
  112. package/dist/lib/helper/builder/controller/authRequestBuilder.d.ts +0 -15
  113. package/dist/lib/helper/builder/controller/authRequestBuilder.js +0 -30
  114. package/dist/lib/helper/builder/controller/standardRequestBuilder.d.ts +0 -15
  115. package/dist/lib/helper/builder/controller/standardRequestBuilder.js +0 -30
  116. package/dist/lib/helper/builder/controller/validationCheckRequestBuilder.d.ts +0 -21
  117. package/dist/lib/helper/builder/controller/validationCheckRequestBuilder.js +0 -40
  118. package/dist/lib/helper/builder/receiver/packageBuilder.d.ts +0 -45
  119. package/dist/lib/helper/builder/receiver/packageBuilder.js +0 -67
  120. package/dist/lib/helper/controller/request/abstractRequestBuilder.d.ts +0 -53
  121. package/dist/lib/helper/controller/request/abstractRequestBuilder.js +0 -68
  122. package/dist/lib/helper/controller/request/authRequestBuilder.d.ts +0 -15
  123. package/dist/lib/helper/controller/request/authRequestBuilder.js +0 -29
  124. package/dist/lib/helper/controller/request/standardRequestBuilder.d.ts +0 -15
  125. package/dist/lib/helper/controller/request/standardRequestBuilder.js +0 -29
  126. package/dist/lib/helper/controller/request/validationCheckRequestBuilder.d.ts +0 -21
  127. package/dist/lib/helper/controller/request/validationCheckRequestBuilder.js +0 -39
  128. package/dist/lib/helper/data/test.d.ts +0 -13
  129. package/dist/lib/helper/data/test.js +0 -89
  130. package/dist/lib/helper/do/actionUtils.d.ts +0 -24
  131. package/dist/lib/helper/do/actionUtils.js +0 -70
  132. package/dist/lib/helper/do/doUtils.d.ts +0 -24
  133. package/dist/lib/helper/do/doUtils.js +0 -80
  134. package/dist/lib/helper/error/backErrorFilterBuilder.d.ts +0 -13
  135. package/dist/lib/helper/error/backErrorFilterBuilder.js +0 -34
  136. package/dist/lib/helper/error/taskErrorFilterBuilder.d.ts +0 -13
  137. package/dist/lib/helper/error/taskErrorFilterBuilder.js +0 -34
  138. package/dist/lib/helper/request/abstractRequestBuilder.d.ts +0 -53
  139. package/dist/lib/helper/request/abstractRequestBuilder.js +0 -68
  140. package/dist/lib/helper/request/authRequestBuilder.d.ts +0 -15
  141. package/dist/lib/helper/request/authRequestBuilder.js +0 -29
  142. package/dist/lib/helper/request/requestBuilder.d.ts +0 -46
  143. package/dist/lib/helper/request/requestBuilder.js +0 -76
  144. package/dist/lib/helper/request/standardRequestBuilder.d.ts +0 -15
  145. package/dist/lib/helper/request/standardRequestBuilder.js +0 -29
  146. package/dist/lib/helper/request/validationCheckRequestBuilder.d.ts +0 -21
  147. package/dist/lib/helper/request/validationCheckRequestBuilder.js +0 -39
  148. package/dist/lib/helper/request/validationRequestBuilder.d.ts +0 -35
  149. package/dist/lib/helper/request/validationRequestBuilder.js +0 -61
  150. package/dist/lib/helper/utils/clientUtils.d.ts +0 -4
  151. package/dist/lib/helper/utils/clientUtils.js +0 -29
@@ -0,0 +1,68 @@
1
+ import { Channel, Databox, Client } from "zation-client";
2
+ import { Test } from "../test/test";
3
+ import { WhenBuilder } from "../../api/when";
4
+ import { ClientAsserter } from "./client/clientAsserter";
5
+ import { DataboxAsserter } from "./databox/databoxAsserter";
6
+ import { ChannelAsserter } from "./channel/channelAsserter";
7
+ export declare abstract class AbstractActionAsserter<T, C extends Client<any, any>> {
8
+ protected readonly _test: Test;
9
+ protected readonly _client: C;
10
+ private _shouldThrowTimeoutError;
11
+ protected constructor(test: Test, client: C);
12
+ protected abstract _executeAction(): Promise<void>;
13
+ private _createTest;
14
+ /**
15
+ * @description
16
+ * Asserts that the when action should not throw or throw a TimeoutError.
17
+ * @param assertion
18
+ */
19
+ throwsTimeoutError(assertion?: boolean): T;
20
+ /**
21
+ * @description
22
+ * Runs a extra test action and asserts that no error will be thrown.
23
+ * AssertionErrors will be rethrown, and all other errors will fail
24
+ * the test with the provided message or the concrete error.
25
+ * @param action
26
+ * @param failMsg If not provided, the concrete error is used.
27
+ */
28
+ action(action: (client: C) => void | Promise<void>, failMsg?: string): T;
29
+ /**
30
+ * @description
31
+ * Start with a new when and link them to one test.
32
+ */
33
+ get and(): WhenBuilder<C>;
34
+ /**
35
+ * @description
36
+ * Create assertions on the client.
37
+ */
38
+ client(): ClientAsserter<T, C>;
39
+ /**
40
+ * @description
41
+ * Create assertions on other clients.
42
+ * Notice that this method will not automatically connect the clients.
43
+ */
44
+ otherClients<C extends Client<any, any>>(...clients: C[]): ClientAsserter<T, C>;
45
+ /**
46
+ * @description
47
+ * Create assertions on other databoxes.
48
+ * Notice that this method will not automatically connect the databoxes.
49
+ */
50
+ otherDataboxes<D extends Databox<any, any, any, any>>(...databoxes: D[]): DataboxAsserter<T, D>;
51
+ /**
52
+ * @description
53
+ * Create assertions on other channels.
54
+ * Notice that this method will not automatically subscribe to the channels.
55
+ */
56
+ otherChannels<C extends Channel<any, any>>(...channels: C[]): ChannelAsserter<T, C>;
57
+ /**
58
+ * @description
59
+ * Runs the test.
60
+ */
61
+ test(): Promise<void>;
62
+ /**
63
+ * @description
64
+ * Returns self.
65
+ * For fluent programing with inheritance.
66
+ */
67
+ protected abstract self(): T;
68
+ }
@@ -1,8 +1,8 @@
1
1
  "use strict";
2
2
  /*
3
- Author: Luca Scaringella
3
+ Author: Ing. Luca Gian Scaringella
4
4
  GitHub: LucaCode
5
- ©Copyright by Luca Scaringella
5
+ Copyright(c) Ing. Luca Gian Scaringella
6
6
  */
7
7
  var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
8
8
  function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
@@ -14,7 +14,7 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
14
14
  });
15
15
  };
16
16
  Object.defineProperty(exports, "__esModule", { value: true });
17
- exports.RootSendAsserter = void 0;
17
+ exports.AbstractActionAsserter = void 0;
18
18
  const zation_client_1 = require("zation-client");
19
19
  const when_1 = require("../../api/when");
20
20
  const clientAsserter_1 = require("./client/clientAsserter");
@@ -22,39 +22,24 @@ const actionUtils_1 = require("../utils/actionUtils");
22
22
  const databoxAsserter_1 = require("./databox/databoxAsserter");
23
23
  const channelAsserter_1 = require("./channel/channelAsserter");
24
24
  const assert = require('assert');
25
- class RootSendAsserter {
25
+ class AbstractActionAsserter {
26
26
  constructor(test, client) {
27
- this.autoConnectedClient = false;
28
27
  this._shouldThrowTimeoutError = false;
29
- this._shouldThrowConnectionRequiredError = false;
30
28
  this._test = test;
31
29
  this._client = client;
32
30
  this._createTest();
33
31
  }
34
32
  _createTest() {
35
33
  this._test.test(() => __awaiter(this, void 0, void 0, function* () {
36
- if (!this._client.isConnected() && this.autoConnectedClient) {
37
- yield this._client.connect();
38
- }
39
34
  try {
40
35
  yield this._executeAction();
41
- if (this._shouldThrowTimeoutError) {
36
+ if (this._shouldThrowTimeoutError)
42
37
  assert.fail('Send should throw a timeout error.');
43
- }
44
- if (this._shouldThrowConnectionRequiredError) {
45
- assert.fail('Send should throw a connection required error.');
46
- }
47
38
  }
48
39
  catch (e) {
49
40
  if (e instanceof zation_client_1.TimeoutError) {
50
- if (!this._shouldThrowTimeoutError) {
41
+ if (!this._shouldThrowTimeoutError)
51
42
  assert.fail('Send should not throw a timeout error.');
52
- }
53
- }
54
- else if (e instanceof zation_client_1.ConnectionRequiredError) {
55
- if (!this._shouldThrowConnectionRequiredError) {
56
- assert.fail('Send should not throw a connection required error.');
57
- }
58
43
  }
59
44
  else
60
45
  throw e;
@@ -65,49 +50,24 @@ class RootSendAsserter {
65
50
  // noinspection JSUnusedGlobalSymbols
66
51
  /**
67
52
  * @description
68
- * Asserts that send should throw a timeout error.
69
- * @param value
70
- */
71
- throwsTimeoutError(value = true) {
72
- this._shouldThrowTimeoutError = value;
73
- return this.self();
74
- }
75
- // noinspection JSUnusedGlobalSymbols
76
- /**
77
- * @description
78
- * Asserts that send should throw a connection required error.
79
- * @param value
53
+ * Asserts that the when action should not throw or throw a TimeoutError.
54
+ * @param assertion
80
55
  */
81
- throwsConnectionRequiredError(value = true) {
82
- this._shouldThrowConnectionRequiredError = value;
83
- return this.self();
84
- }
85
- // noinspection JSUnusedGlobalSymbols
86
- /**
87
- * @description
88
- * This function lets you do an extra action on the client and asserts that no error is thrown.
89
- * When an error throws, it lets the test fail with the provided message or the concrete error.
90
- * @param action
91
- * @param message if not provided it throws the specific error.
92
- */
93
- action(action, message) {
94
- actionUtils_1.default.action(this._test, () => action(this._client), message);
95
- this._test.pushSyncWait();
56
+ throwsTimeoutError(assertion = true) {
57
+ this._shouldThrowTimeoutError = assertion;
96
58
  return this.self();
97
59
  }
98
60
  // noinspection JSUnusedGlobalSymbols
99
61
  /**
100
62
  * @description
101
- * This function lets you do an extra action on the client and
102
- * asserts that an error or an error instance of a specific class is thrown.
103
- * When no error is thrown, or the error does not match with the given classes
104
- * (only if at least one class is given), it lets the test fail with the provided message.
63
+ * Runs a extra test action and asserts that no error will be thrown.
64
+ * AssertionErrors will be rethrown, and all other errors will fail
65
+ * the test with the provided message or the concrete error.
105
66
  * @param action
106
- * @param message
107
- * @param validErrorClasses
67
+ * @param failMsg If not provided, the concrete error is used.
108
68
  */
109
- actionShouldThrow(action, message, ...validErrorClasses) {
110
- actionUtils_1.default.actionShouldThrow(this._test, () => action(this._client), message, ...validErrorClasses);
69
+ action(action, failMsg) {
70
+ this._test.test(() => actionUtils_1.default.runAction(() => action(this._client), failMsg));
111
71
  this._test.pushSyncWait();
112
72
  return this.self();
113
73
  }
@@ -116,14 +76,14 @@ class RootSendAsserter {
116
76
  * @description
117
77
  * Start with a new when and link them to one test.
118
78
  */
119
- and() {
79
+ get and() {
120
80
  this._test.newSubTest();
121
81
  return new when_1.WhenBuilder(this._client, this._test);
122
82
  }
123
83
  // noinspection JSUnusedGlobalSymbols
124
84
  /**
125
85
  * @description
126
- * Assert client.
86
+ * Create assertions on the client.
127
87
  */
128
88
  client() {
129
89
  return new clientAsserter_1.ClientAsserter([this._client], this._test, this.self());
@@ -131,7 +91,7 @@ class RootSendAsserter {
131
91
  // noinspection JSUnusedGlobalSymbols
132
92
  /**
133
93
  * @description
134
- * Assert other clients.
94
+ * Create assertions on other clients.
135
95
  * Notice that this method will not automatically connect the clients.
136
96
  */
137
97
  otherClients(...clients) {
@@ -140,7 +100,7 @@ class RootSendAsserter {
140
100
  // noinspection JSUnusedGlobalSymbols
141
101
  /**
142
102
  * @description
143
- * Assert other databoxes.
103
+ * Create assertions on other databoxes.
144
104
  * Notice that this method will not automatically connect the databoxes.
145
105
  */
146
106
  otherDataboxes(...databoxes) {
@@ -149,7 +109,7 @@ class RootSendAsserter {
149
109
  // noinspection JSUnusedGlobalSymbols
150
110
  /**
151
111
  * @description
152
- * Assert other channels.
112
+ * Create assertions on other channels.
153
113
  * Notice that this method will not automatically subscribe to the channels.
154
114
  */
155
115
  otherChannels(...channels) {
@@ -159,15 +119,11 @@ class RootSendAsserter {
159
119
  /**
160
120
  * @description
161
121
  * Runs the test.
162
- * @param autoConnect
163
- * Will auto connect the client
164
- * if the client is not connected to the server.
165
122
  */
166
- test(autoConnect = false) {
123
+ test() {
167
124
  return __awaiter(this, void 0, void 0, function* () {
168
- this.autoConnectedClient = autoConnect;
169
125
  return this._test.execute();
170
126
  });
171
127
  }
172
128
  }
173
- exports.RootSendAsserter = RootSendAsserter;
129
+ exports.AbstractActionAsserter = AbstractActionAsserter;
@@ -0,0 +1,5 @@
1
+ export default class AssertStarter<T> {
2
+ private readonly asserter;
3
+ constructor(asserter: T);
4
+ get assertThat(): T;
5
+ }
@@ -0,0 +1,16 @@
1
+ "use strict";
2
+ /*
3
+ Author: Ing. Luca Gian Scaringella
4
+ GitHub: LucaCode
5
+ Copyright(c) Ing. Luca Gian Scaringella
6
+ */
7
+ Object.defineProperty(exports, "__esModule", { value: true });
8
+ class AssertStarter {
9
+ constructor(asserter) {
10
+ this.asserter = asserter;
11
+ }
12
+ get assertThat() {
13
+ return this.asserter;
14
+ }
15
+ }
16
+ exports.default = AssertStarter;
@@ -1,64 +1,55 @@
1
1
  import { Test } from "../../test/test";
2
- import { Channel } from 'zation-client';
2
+ import { Channel, DataType } from 'zation-client';
3
3
  import { DataEventAsserter } from "../event/dataEventAsserter";
4
4
  import { ValueAsserter } from "../value/valueAsserter";
5
- import { CodeDataEventAsserter } from "../event/codeDataEventAsserter";
6
- export declare abstract class AbstractChannelAsserter<T> {
5
+ import { CodeMetadataEventAsserter } from "../event/codeMetadataEventAsserter";
6
+ import { ChannelEvents, ChannelMember } from "../../utils/types";
7
+ export declare abstract class AbstractChannelAsserter<T, C extends Channel<any, any>> {
7
8
  protected _test: Test;
8
- protected channels: Channel[];
9
+ protected channels: C[];
9
10
  protected abstract self(): T;
10
- protected constructor(channels: Channel[], test: Test);
11
- protected _forEachChannel(func: (channel: Channel, i: number) => Promise<void>): Promise<void>;
11
+ protected constructor(channels: C[], test: Test);
12
+ protected _forEachChannel(func: (channel: C, i: number) => Promise<void>): Promise<void>;
12
13
  /**
13
14
  * @description
14
15
  * Asserts that the channel is subscribed.
15
16
  * @param timeout
16
- * With this parameter, you can set a time limit in that the assertion must be successful.
17
+ * Sets a time limit in that the assertion must be successful.
17
18
  */
18
19
  isSubscribed(timeout?: number): T;
19
20
  /**
20
21
  * @description
21
22
  * Asserts that the channel is unsubscribed.
22
23
  * @param timeout
23
- * With this parameter, you can set a time limit in that the assertion must be successful.
24
+ * Sets a time limit in that the assertion must be successful.
24
25
  */
25
26
  isUnsubscribed(timeout?: number): T;
26
27
  /**
27
28
  * Asserts the current member of the channel.
28
29
  */
29
- member(): ValueAsserter<T>;
30
+ member(): ValueAsserter<ChannelMember<C>, T>;
30
31
  /**
31
32
  * @description
32
- * This function lets you do extra actions on each channel and asserts that no error is thrown.
33
- * When an error throws, it lets the test fail with the provided message or the concrete error.
33
+ * Runs a extra test action and asserts that no error will be thrown.
34
+ * AssertionErrors will be rethrown, and all other errors will fail
35
+ * the test with the provided message or the concrete error.
34
36
  * @param action
35
- * @param message if not provided it throws the specific error.
37
+ * @param failMsg If not provided, the concrete error is used.
36
38
  */
37
- action(action: (channel: Channel, index: number) => void | Promise<void>, message?: string): T;
38
- /**
39
- * @description
40
- * This function lets you do extra actions on each channel and
41
- * asserts that an error or an error instance of a specific class is thrown.
42
- * When no error is thrown, or the error does not match with the given classes
43
- * (only if at least one class is given), it lets the test fail with the provided message.
44
- * @param action
45
- * @param message
46
- * @param validErrorClasses
47
- */
48
- actionShouldThrow(action: (channel: Channel, index: number) => void | Promise<void>, message: string, ...validErrorClasses: any[]): T;
39
+ action(action: (channel: C, index: number) => void | Promise<void>, failMsg?: string): T;
49
40
  /**
50
41
  * @description
51
42
  * Asserts that the channel should get a publish.
52
43
  */
53
- getsPublish(event: string): DataEventAsserter<T>;
44
+ getsPublish<E extends keyof ChannelEvents<C>>(event: E): DataEventAsserter<T, [ChannelEvents<C>[E], DataType], 0>;
54
45
  /**
55
46
  * @description
56
- * Asserts that the channel should trigger an Close event.
47
+ * Asserts that the channel should trigger an close event.
57
48
  */
58
- closeTriggers(): CodeDataEventAsserter<T>;
49
+ closeTriggers(): CodeMetadataEventAsserter<T, [number | string | undefined, any], 0, 1>;
59
50
  /**
60
51
  * @description
61
- * Asserts that the channel should trigger an KickOut event.
52
+ * Asserts that the channel should trigger an kick out event.
62
53
  */
63
- kickOutTriggers(): CodeDataEventAsserter<T>;
54
+ kickOutTriggers(): CodeMetadataEventAsserter<T, [number | string | undefined, any], 0, 1>;
64
55
  }
@@ -1,8 +1,8 @@
1
1
  "use strict";
2
2
  /*
3
- Author: Luca Scaringella
3
+ Author: Ing. Luca Gian Scaringella
4
4
  GitHub: LucaCode
5
- ©Copyright by Luca Scaringella
5
+ Copyright(c) Ing. Luca Gian Scaringella
6
6
  */
7
7
  var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
8
8
  function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
@@ -19,7 +19,7 @@ const timeoutAssert_1 = require("../../timeout/timeoutAssert");
19
19
  const actionUtils_1 = require("../../utils/actionUtils");
20
20
  const dataEventAsserter_1 = require("../event/dataEventAsserter");
21
21
  const valueAsserter_1 = require("../value/valueAsserter");
22
- const codeDataEventAsserter_1 = require("../event/codeDataEventAsserter");
22
+ const codeMetadataEventAsserter_1 = require("../event/codeMetadataEventAsserter");
23
23
  class AbstractChannelAsserter {
24
24
  constructor(channels, test) {
25
25
  this._test = test;
@@ -27,11 +27,7 @@ class AbstractChannelAsserter {
27
27
  }
28
28
  _forEachChannel(func) {
29
29
  return __awaiter(this, void 0, void 0, function* () {
30
- let promises = [];
31
- this.channels.forEach((c, i) => {
32
- promises.push(func(c, i));
33
- });
34
- yield Promise.all(promises);
30
+ yield Promise.all(this.channels.map((ch, i) => func(ch, i)));
35
31
  });
36
32
  }
37
33
  // noinspection JSUnusedGlobalSymbols
@@ -39,20 +35,18 @@ class AbstractChannelAsserter {
39
35
  * @description
40
36
  * Asserts that the channel is subscribed.
41
37
  * @param timeout
42
- * With this parameter, you can set a time limit in that the assertion must be successful.
38
+ * Sets a time limit in that the assertion must be successful.
43
39
  */
44
40
  isSubscribed(timeout = 0) {
45
- this._test.test(() => __awaiter(this, void 0, void 0, function* () {
46
- yield this._forEachChannel((ch, i) => __awaiter(this, void 0, void 0, function* () {
47
- if (ch.isSubscribed(false))
48
- return;
49
- const toa = new timeoutAssert_1.TimeoutAssert(`Channel: ${i} should be subscribed.`, timeout);
50
- ch.onceSubscribe(() => {
51
- toa.resolve();
52
- });
53
- yield toa.set();
54
- }));
55
- }));
41
+ this._test.test(() => this._forEachChannel((ch, i) => __awaiter(this, void 0, void 0, function* () {
42
+ if (ch.isSubscribed(false))
43
+ return;
44
+ const toa = new timeoutAssert_1.TimeoutAssert(`Channel: ${i} should be subscribed.`, timeout);
45
+ ch.onceSubscribe(() => {
46
+ toa.resolve();
47
+ });
48
+ yield toa.set();
49
+ })));
56
50
  return this.self();
57
51
  }
58
52
  // noinspection JSUnusedGlobalSymbols
@@ -60,20 +54,18 @@ class AbstractChannelAsserter {
60
54
  * @description
61
55
  * Asserts that the channel is unsubscribed.
62
56
  * @param timeout
63
- * With this parameter, you can set a time limit in that the assertion must be successful.
57
+ * Sets a time limit in that the assertion must be successful.
64
58
  */
65
59
  isUnsubscribed(timeout = 0) {
66
- this._test.test(() => __awaiter(this, void 0, void 0, function* () {
67
- yield this._forEachChannel((ch, i) => __awaiter(this, void 0, void 0, function* () {
68
- if (!ch.isSubscribed(false))
69
- return;
70
- const toa = new timeoutAssert_1.TimeoutAssert(`Channel: ${i} should be unsubscribed.`, timeout);
71
- ch.onceUnsubscribe(() => {
72
- toa.resolve();
73
- });
74
- yield toa.set();
75
- }));
76
- }));
60
+ this._test.test(() => this._forEachChannel((ch, i) => __awaiter(this, void 0, void 0, function* () {
61
+ if (!ch.isSubscribed(false))
62
+ return;
63
+ const toa = new timeoutAssert_1.TimeoutAssert(`Channel: ${i} should be unsubscribed.`, timeout);
64
+ ch.onceUnsubscribe(() => {
65
+ toa.resolve();
66
+ });
67
+ yield toa.set();
68
+ })));
77
69
  return this.self();
78
70
  }
79
71
  // noinspection JSUnusedGlobalSymbols
@@ -81,44 +73,23 @@ class AbstractChannelAsserter {
81
73
  * Asserts the current member of the channel.
82
74
  */
83
75
  member() {
84
- return new valueAsserter_1.ValueAsserter(this.self(), 'Channel', (test) => {
85
- this._test.test(() => __awaiter(this, void 0, void 0, function* () {
86
- yield this._forEachChannel((ch, i) => __awaiter(this, void 0, void 0, function* () {
87
- test(ch.member, ` ${i} channel:`);
88
- }));
89
- }));
76
+ return new valueAsserter_1.ValueAsserter(this.self(), (test) => {
77
+ this._test.test(() => this._forEachChannel((ch, i) => __awaiter(this, void 0, void 0, function* () {
78
+ test(ch.member, `Channel: ${i} member:`);
79
+ })));
90
80
  });
91
81
  }
92
82
  // noinspection JSUnusedGlobalSymbols
93
83
  /**
94
84
  * @description
95
- * This function lets you do extra actions on each channel and asserts that no error is thrown.
96
- * When an error throws, it lets the test fail with the provided message or the concrete error.
85
+ * Runs a extra test action and asserts that no error will be thrown.
86
+ * AssertionErrors will be rethrown, and all other errors will fail
87
+ * the test with the provided message or the concrete error.
97
88
  * @param action
98
- * @param message if not provided it throws the specific error.
89
+ * @param failMsg If not provided, the concrete error is used.
99
90
  */
100
- action(action, message) {
101
- this.channels.forEach((channel, index) => {
102
- actionUtils_1.default.action(this._test, () => action(channel, index), message);
103
- });
104
- this._test.pushSyncWait();
105
- return this.self();
106
- }
107
- // noinspection JSUnusedGlobalSymbols
108
- /**
109
- * @description
110
- * This function lets you do extra actions on each channel and
111
- * asserts that an error or an error instance of a specific class is thrown.
112
- * When no error is thrown, or the error does not match with the given classes
113
- * (only if at least one class is given), it lets the test fail with the provided message.
114
- * @param action
115
- * @param message
116
- * @param validErrorClasses
117
- */
118
- actionShouldThrow(action, message, ...validErrorClasses) {
119
- this.channels.forEach((channel, index) => {
120
- actionUtils_1.default.actionShouldThrow(this._test, () => action(channel, index), message, ...validErrorClasses);
121
- });
91
+ action(action, failMsg) {
92
+ this._test.test(() => this._forEachChannel((channel, index) => actionUtils_1.default.runAction(() => action(channel, index), failMsg)));
122
93
  this._test.pushSyncWait();
123
94
  return this.self();
124
95
  }
@@ -129,40 +100,28 @@ class AbstractChannelAsserter {
129
100
  */
130
101
  getsPublish(event) {
131
102
  return new dataEventAsserter_1.DataEventAsserter(this.channels.map(ch => {
132
- return (listener) => {
133
- ch.oncePublish(event, (data) => {
134
- listener(data);
135
- });
136
- };
137
- }), "Channel", `Publish - ${event}`, this._test, this.self());
103
+ return (listener) => ch.oncePublish(event, listener);
104
+ }), "channel", `publish - ${event}`, this._test, this.self(), 0);
138
105
  }
139
106
  // noinspection JSUnusedGlobalSymbols
140
107
  /**
141
108
  * @description
142
- * Asserts that the channel should trigger an Close event.
109
+ * Asserts that the channel should trigger an close event.
143
110
  */
144
111
  closeTriggers() {
145
- return new codeDataEventAsserter_1.CodeDataEventAsserter(this.channels.map(ch => {
146
- return (listener) => {
147
- ch.onceClose((code, data) => {
148
- listener(data, code);
149
- });
150
- };
151
- }), "Channel", "Close", this._test, this.self());
112
+ return new codeMetadataEventAsserter_1.CodeMetadataEventAsserter(this.channels.map(ch => {
113
+ return (listener) => ch.onceClose(listener);
114
+ }), "Channel", "close", this._test, this.self(), 0, 1);
152
115
  }
153
116
  // noinspection JSUnusedGlobalSymbols
154
117
  /**
155
118
  * @description
156
- * Asserts that the channel should trigger an KickOut event.
119
+ * Asserts that the channel should trigger an kick out event.
157
120
  */
158
121
  kickOutTriggers() {
159
- return new codeDataEventAsserter_1.CodeDataEventAsserter(this.channels.map(ch => {
160
- return (listener) => {
161
- ch.onceKickOut((code, data) => {
162
- listener(data, code);
163
- });
164
- };
165
- }), "Channel", "KickOut", this._test, this.self());
122
+ return new codeMetadataEventAsserter_1.CodeMetadataEventAsserter(this.channels.map(ch => {
123
+ return (listener) => ch.onceKickOut(listener);
124
+ }), "Channel", "kick out", this._test, this.self(), 0, 1);
166
125
  }
167
126
  }
168
127
  exports.AbstractChannelAsserter = AbstractChannelAsserter;
@@ -1,13 +1,13 @@
1
1
  import { Channel } from 'zation-client';
2
2
  import { Test } from "../../test/test";
3
3
  import { AbstractChannelAsserter } from "./abstractChannelAsserter";
4
- export declare class ChannelAsserter<T> extends AbstractChannelAsserter<ChannelAsserter<T>> {
4
+ export declare class ChannelAsserter<T, C extends Channel<any, any>> extends AbstractChannelAsserter<ChannelAsserter<T, C>, C> {
5
5
  private readonly _source;
6
- constructor(channels: Channel[], test: Test, source: T);
6
+ constructor(channels: C[], test: Test, source: T);
7
7
  /**
8
8
  * @description
9
9
  * End the channel asserter.
10
10
  */
11
11
  end(): T;
12
- protected self(): ChannelAsserter<T>;
12
+ protected self(): ChannelAsserter<T, C>;
13
13
  }
@@ -1,8 +1,8 @@
1
1
  "use strict";
2
2
  /*
3
- Author: Luca Scaringella
3
+ Author: Ing. Luca Gian Scaringella
4
4
  GitHub: LucaCode
5
- ©Copyright by Luca Scaringella
5
+ Copyright(c) Ing. Luca Gian Scaringella
6
6
  */
7
7
  Object.defineProperty(exports, "__esModule", { value: true });
8
8
  exports.ChannelAsserter = void 0;
@@ -1,16 +1,16 @@
1
1
  import { Channel } from 'zation-client';
2
2
  import { AbstractChannelAsserter } from "./abstractChannelAsserter";
3
- export declare class StandaloneChannelAsserter extends AbstractChannelAsserter<StandaloneChannelAsserter> {
4
- constructor(channel: Channel | Channel[], itTestDescription?: string);
3
+ export declare class StandaloneChannelAsserter<C extends Channel<any, any>> extends AbstractChannelAsserter<StandaloneChannelAsserter<C>, C> {
4
+ constructor(channel: C | C[], description?: string);
5
5
  /**
6
6
  * @description
7
- * Will subscribe all channels (before the test).
7
+ * Subscribes all channels (before the test).
8
8
  */
9
- subscribe(member?: any): StandaloneChannelAsserter;
9
+ subscribe(member?: any): StandaloneChannelAsserter<C>;
10
10
  /**
11
11
  * @description
12
12
  * Run the test.
13
13
  */
14
14
  test(): Promise<void>;
15
- protected self(): StandaloneChannelAsserter;
15
+ protected self(): StandaloneChannelAsserter<C>;
16
16
  }
@@ -1,8 +1,8 @@
1
1
  "use strict";
2
2
  /*
3
- Author: Luca Scaringella
3
+ Author: Ing. Luca Gian Scaringella
4
4
  GitHub: LucaCode
5
- ©Copyright by Luca Scaringella
5
+ Copyright(c) Ing. Luca Gian Scaringella
6
6
  */
7
7
  var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
8
8
  function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
@@ -19,13 +19,13 @@ const test_1 = require("../../test/test");
19
19
  const abstractChannelAsserter_1 = require("./abstractChannelAsserter");
20
20
  const chai_1 = require("chai");
21
21
  class StandaloneChannelAsserter extends abstractChannelAsserter_1.AbstractChannelAsserter {
22
- constructor(channel, itTestDescription) {
23
- super(Array.isArray(channel) ? channel : [channel], new test_1.Test(itTestDescription));
22
+ constructor(channel, description) {
23
+ super(Array.isArray(channel) ? channel : [channel], new test_1.Test(description));
24
24
  }
25
25
  // noinspection JSUnusedGlobalSymbols
26
26
  /**
27
27
  * @description
28
- * Will subscribe all channels (before the test).
28
+ * Subscribes all channels (before the test).
29
29
  */
30
30
  subscribe(member) {
31
31
  this._test.beforeTest(() => __awaiter(this, void 0, void 0, function* () {
@@ -34,7 +34,7 @@ class StandaloneChannelAsserter extends abstractChannelAsserter_1.AbstractChanne
34
34
  yield channel.subscribe(member);
35
35
  }
36
36
  catch (err) {
37
- chai_1.assert.fail(`Cannot subscribe to the channel ${index}. Error -> ` + err.stack);
37
+ chai_1.assert.fail(`Cannot subscribe to the channel ${index}. Error -> ` + err);
38
38
  }
39
39
  })));
40
40
  }));