zation-assured 0.6.3 → 3.0.0-dev.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.
- package/LICENSE +1 -1
- package/README.md +55 -2
- package/dist/index.d.ts +2 -2
- package/dist/index.js +3 -9
- package/dist/lib/api/assert.d.ts +21 -14
- package/dist/lib/api/assert.js +17 -13
- package/dist/lib/api/testHelper.d.ts +0 -8
- package/dist/lib/api/testHelper.js +6 -83
- package/dist/lib/api/when.d.ts +41 -45
- package/dist/lib/api/when.js +42 -55
- package/dist/lib/helper/asserter/abstractActionAsserter.d.ts +68 -0
- package/dist/lib/helper/asserter/{rootSendAsserter.js → abstractActionAsserter.js} +23 -67
- package/dist/lib/helper/asserter/assertStarter.d.ts +5 -0
- package/dist/lib/helper/asserter/assertStarter.js +16 -0
- package/dist/lib/helper/asserter/channel/abstractChannelAsserter.d.ts +20 -29
- package/dist/lib/helper/asserter/channel/abstractChannelAsserter.js +44 -85
- package/dist/lib/helper/asserter/channel/channelAsserter.d.ts +3 -3
- package/dist/lib/helper/asserter/channel/channelAsserter.js +2 -2
- package/dist/lib/helper/asserter/channel/standaloneChannelAsserter.d.ts +6 -6
- package/dist/lib/helper/asserter/channel/standaloneChannelAsserter.js +7 -7
- package/dist/lib/helper/asserter/client/abstractClientAsserter.d.ts +20 -38
- package/dist/lib/helper/asserter/client/abstractClientAsserter.js +82 -184
- package/dist/lib/helper/asserter/client/clientAsserter.d.ts +3 -3
- package/dist/lib/helper/asserter/client/clientAsserter.js +2 -2
- package/dist/lib/helper/asserter/client/standaloneClientAsserter.d.ts +6 -6
- package/dist/lib/helper/asserter/client/standaloneClientAsserter.js +7 -7
- package/dist/lib/helper/asserter/controller/integratedResponseAsserter.d.ts +52 -0
- package/dist/lib/helper/asserter/controller/integratedResponseAsserter.js +122 -0
- package/dist/lib/helper/asserter/controller/standaloneResponseAsserter.d.ts +54 -0
- package/dist/lib/helper/asserter/controller/standaloneResponseAsserter.js +118 -0
- package/dist/lib/helper/asserter/databox/abstractDataboxAsserter.d.ts +29 -36
- package/dist/lib/helper/asserter/databox/abstractDataboxAsserter.js +44 -80
- package/dist/lib/helper/asserter/databox/databoxAsserter.d.ts +3 -3
- package/dist/lib/helper/asserter/databox/databoxAsserter.js +2 -2
- package/dist/lib/helper/asserter/databox/standaloneDataboxAsserter.d.ts +7 -6
- package/dist/lib/helper/asserter/databox/standaloneDataboxAsserter.js +7 -7
- package/dist/lib/helper/asserter/event/abstractEventAsserter.d.ts +12 -4
- package/dist/lib/helper/asserter/event/abstractEventAsserter.js +25 -10
- package/dist/lib/helper/asserter/event/codeMetadataEventAsserter.d.ts +21 -0
- package/dist/lib/helper/asserter/event/codeMetadataEventAsserter.js +47 -0
- package/dist/lib/helper/asserter/event/dataEventAsserter.d.ts +13 -3
- package/dist/lib/helper/asserter/event/dataEventAsserter.js +22 -4
- package/dist/lib/helper/asserter/receiver/integratedTransmitAsserter.d.ts +9 -0
- package/dist/lib/helper/asserter/receiver/{transmitAsserter.js → integratedTransmitAsserter.js} +9 -9
- package/dist/lib/helper/asserter/value/abstractValueAsserter.d.ts +13 -15
- package/dist/lib/helper/asserter/value/abstractValueAsserter.js +49 -53
- package/dist/lib/helper/asserter/value/standaloneValueAsserter.d.ts +3 -3
- package/dist/lib/helper/asserter/value/standaloneValueAsserter.js +6 -6
- package/dist/lib/helper/asserter/value/valueAsserter.d.ts +4 -4
- package/dist/lib/helper/asserter/value/valueAsserter.js +4 -4
- package/dist/lib/helper/backError/backErrorsFilterBuilder.d.ts +12 -0
- package/dist/lib/helper/backError/backErrorsFilterBuilder.js +29 -0
- package/dist/lib/helper/console/logger.js +2 -2
- package/dist/lib/helper/definitions/optionTypes.d.ts +8 -0
- package/dist/lib/helper/definitions/optionTypes.js +7 -0
- package/dist/lib/helper/test/test.d.ts +2 -2
- package/dist/lib/helper/test/test.js +8 -6
- package/dist/lib/helper/timeout/timeoutAssert.js +2 -2
- package/dist/lib/helper/utils/actionUtils.d.ts +5 -18
- package/dist/lib/helper/utils/actionUtils.js +14 -43
- package/dist/lib/helper/utils/types.d.ts +20 -0
- package/dist/lib/helper/utils/types.js +7 -0
- package/package.json +9 -12
- package/dist/lib/api/before.d.ts +0 -3
- package/dist/lib/api/before.js +0 -20
- package/dist/lib/api/client.d.ts +0 -3
- package/dist/lib/api/client.js +0 -11
- package/dist/lib/api/describe.d.ts +0 -1
- package/dist/lib/api/describe.js +0 -6
- package/dist/lib/api/instanceManager.d.ts +0 -8
- package/dist/lib/api/instanceManager.js +0 -48
- package/dist/lib/api/testArea.d.ts +0 -3
- package/dist/lib/api/testArea.js +0 -41
- package/dist/lib/api/testServerManager.d.ts +0 -19
- package/dist/lib/api/testServerManager.js +0 -100
- package/dist/lib/helper/asserter/abstractClientAsserter.d.ts +0 -102
- package/dist/lib/helper/asserter/abstractClientAsserter.js +0 -293
- package/dist/lib/helper/asserter/anyAsserter.d.ts +0 -62
- package/dist/lib/helper/asserter/anyAsserter.js +0 -130
- package/dist/lib/helper/asserter/channelEventAsserter.d.ts +0 -34
- package/dist/lib/helper/asserter/channelEventAsserter.js +0 -84
- package/dist/lib/helper/asserter/channelPubAsserter.d.ts +0 -53
- package/dist/lib/helper/asserter/channelPubAsserter.js +0 -126
- package/dist/lib/helper/asserter/clientAsserter.d.ts +0 -13
- package/dist/lib/helper/asserter/clientAsserter.js +0 -26
- package/dist/lib/helper/asserter/controller/responseAsserter.d.ts +0 -74
- package/dist/lib/helper/asserter/controller/responseAsserter.js +0 -138
- package/dist/lib/helper/asserter/dataEventAsserter.d.ts +0 -40
- package/dist/lib/helper/asserter/dataEventAsserter.js +0 -113
- package/dist/lib/helper/asserter/event/abstractDataEventAsserter.d.ts +0 -13
- package/dist/lib/helper/asserter/event/abstractDataEventAsserter.js +0 -36
- package/dist/lib/helper/asserter/event/codeDataEventAsserter.d.ts +0 -14
- package/dist/lib/helper/asserter/event/codeDataEventAsserter.js +0 -40
- package/dist/lib/helper/asserter/eventAsserter.d.ts +0 -41
- package/dist/lib/helper/asserter/eventAsserter.js +0 -115
- package/dist/lib/helper/asserter/objectAsserter.d.ts +0 -55
- package/dist/lib/helper/asserter/objectAsserter.js +0 -113
- package/dist/lib/helper/asserter/receiver/transmitAsserter.d.ts +0 -9
- package/dist/lib/helper/asserter/responseAsserter.d.ts +0 -129
- package/dist/lib/helper/asserter/responseAsserter.js +0 -260
- package/dist/lib/helper/asserter/rootSendAsserter.d.ts +0 -89
- package/dist/lib/helper/asserter/standaloneClientAsserter.d.ts +0 -11
- package/dist/lib/helper/asserter/standaloneClientAsserter.js +0 -38
- package/dist/lib/helper/assured/clientAssured.d.ts +0 -2
- package/dist/lib/helper/assured/clientAssured.js +0 -11
- package/dist/lib/helper/assured/responseAssured.d.ts +0 -17
- package/dist/lib/helper/assured/responseAssured.js +0 -72
- package/dist/lib/helper/backError/backErrorFilterBuilder.d.ts +0 -13
- package/dist/lib/helper/backError/backErrorFilterBuilder.js +0 -32
- package/dist/lib/helper/builder/controller/abstractRequestBuilder.d.ts +0 -53
- package/dist/lib/helper/builder/controller/abstractRequestBuilder.js +0 -69
- package/dist/lib/helper/builder/controller/authRequestBuilder.d.ts +0 -15
- package/dist/lib/helper/builder/controller/authRequestBuilder.js +0 -30
- package/dist/lib/helper/builder/controller/standardRequestBuilder.d.ts +0 -15
- package/dist/lib/helper/builder/controller/standardRequestBuilder.js +0 -30
- package/dist/lib/helper/builder/controller/validationCheckRequestBuilder.d.ts +0 -21
- package/dist/lib/helper/builder/controller/validationCheckRequestBuilder.js +0 -40
- package/dist/lib/helper/builder/receiver/packageBuilder.d.ts +0 -45
- package/dist/lib/helper/builder/receiver/packageBuilder.js +0 -67
- package/dist/lib/helper/controller/request/abstractRequestBuilder.d.ts +0 -53
- package/dist/lib/helper/controller/request/abstractRequestBuilder.js +0 -68
- package/dist/lib/helper/controller/request/authRequestBuilder.d.ts +0 -15
- package/dist/lib/helper/controller/request/authRequestBuilder.js +0 -29
- package/dist/lib/helper/controller/request/standardRequestBuilder.d.ts +0 -15
- package/dist/lib/helper/controller/request/standardRequestBuilder.js +0 -29
- package/dist/lib/helper/controller/request/validationCheckRequestBuilder.d.ts +0 -21
- package/dist/lib/helper/controller/request/validationCheckRequestBuilder.js +0 -39
- package/dist/lib/helper/data/test.d.ts +0 -13
- package/dist/lib/helper/data/test.js +0 -89
- package/dist/lib/helper/do/actionUtils.d.ts +0 -24
- package/dist/lib/helper/do/actionUtils.js +0 -70
- package/dist/lib/helper/do/doUtils.d.ts +0 -24
- package/dist/lib/helper/do/doUtils.js +0 -80
- package/dist/lib/helper/error/backErrorFilterBuilder.d.ts +0 -13
- package/dist/lib/helper/error/backErrorFilterBuilder.js +0 -34
- package/dist/lib/helper/error/taskErrorFilterBuilder.d.ts +0 -13
- package/dist/lib/helper/error/taskErrorFilterBuilder.js +0 -34
- package/dist/lib/helper/request/abstractRequestBuilder.d.ts +0 -53
- package/dist/lib/helper/request/abstractRequestBuilder.js +0 -68
- package/dist/lib/helper/request/authRequestBuilder.d.ts +0 -15
- package/dist/lib/helper/request/authRequestBuilder.js +0 -29
- package/dist/lib/helper/request/requestBuilder.d.ts +0 -46
- package/dist/lib/helper/request/requestBuilder.js +0 -76
- package/dist/lib/helper/request/standardRequestBuilder.d.ts +0 -15
- package/dist/lib/helper/request/standardRequestBuilder.js +0 -29
- package/dist/lib/helper/request/validationCheckRequestBuilder.d.ts +0 -21
- package/dist/lib/helper/request/validationCheckRequestBuilder.js +0 -39
- package/dist/lib/helper/request/validationRequestBuilder.d.ts +0 -35
- package/dist/lib/helper/request/validationRequestBuilder.js +0 -61
- package/dist/lib/helper/utils/clientUtils.d.ts +0 -4
- 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
|
-
|
|
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.
|
|
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
|
|
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
|
|
69
|
-
* @param
|
|
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
|
-
|
|
82
|
-
this.
|
|
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
|
-
*
|
|
102
|
-
*
|
|
103
|
-
*
|
|
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
|
|
107
|
-
* @param validErrorClasses
|
|
67
|
+
* @param failMsg If not provided, the concrete error is used.
|
|
108
68
|
*/
|
|
109
|
-
|
|
110
|
-
actionUtils_1.default.
|
|
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
|
-
*
|
|
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
|
-
*
|
|
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
|
-
*
|
|
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
|
-
*
|
|
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(
|
|
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.
|
|
129
|
+
exports.AbstractActionAsserter = AbstractActionAsserter;
|
|
@@ -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 {
|
|
6
|
-
|
|
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:
|
|
9
|
+
protected channels: C[];
|
|
9
10
|
protected abstract self(): T;
|
|
10
|
-
protected constructor(channels:
|
|
11
|
-
protected _forEachChannel(func: (channel:
|
|
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
|
-
*
|
|
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
|
-
*
|
|
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
|
-
*
|
|
33
|
-
*
|
|
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
|
|
37
|
+
* @param failMsg If not provided, the concrete error is used.
|
|
36
38
|
*/
|
|
37
|
-
action(action: (channel:
|
|
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:
|
|
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
|
|
47
|
+
* Asserts that the channel should trigger an close event.
|
|
57
48
|
*/
|
|
58
|
-
closeTriggers():
|
|
49
|
+
closeTriggers(): CodeMetadataEventAsserter<T, [number | string | undefined, any], 0, 1>;
|
|
59
50
|
/**
|
|
60
51
|
* @description
|
|
61
|
-
* Asserts that the channel should trigger an
|
|
52
|
+
* Asserts that the channel should trigger an kick out event.
|
|
62
53
|
*/
|
|
63
|
-
kickOutTriggers():
|
|
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
|
-
|
|
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
|
|
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
|
-
|
|
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
|
-
*
|
|
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
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
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
|
-
*
|
|
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
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
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(),
|
|
85
|
-
this._test.test(() => __awaiter(this, void 0, void 0, function* () {
|
|
86
|
-
|
|
87
|
-
|
|
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
|
-
*
|
|
96
|
-
*
|
|
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
|
|
89
|
+
* @param failMsg If not provided, the concrete error is used.
|
|
99
90
|
*/
|
|
100
|
-
action(action,
|
|
101
|
-
this.
|
|
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
|
-
|
|
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
|
|
109
|
+
* Asserts that the channel should trigger an close event.
|
|
143
110
|
*/
|
|
144
111
|
closeTriggers() {
|
|
145
|
-
return new
|
|
146
|
-
return (listener) =>
|
|
147
|
-
|
|
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
|
|
119
|
+
* Asserts that the channel should trigger an kick out event.
|
|
157
120
|
*/
|
|
158
121
|
kickOutTriggers() {
|
|
159
|
-
return new
|
|
160
|
-
return (listener) =>
|
|
161
|
-
|
|
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
|
|
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:
|
|
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
|
-
|
|
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:
|
|
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
|
-
*
|
|
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
|
+
* Runs 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
|
-
|
|
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,
|
|
23
|
-
super(Array.isArray(channel) ? channel : [channel], new test_1.Test(
|
|
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
|
-
*
|
|
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
|
|
37
|
+
chai_1.assert.fail(`Cannot subscribe to the channel ${index}. Error -> ` + err);
|
|
38
38
|
}
|
|
39
39
|
})));
|
|
40
40
|
}));
|
|
@@ -43,7 +43,7 @@ class StandaloneChannelAsserter extends abstractChannelAsserter_1.AbstractChanne
|
|
|
43
43
|
// noinspection JSUnusedGlobalSymbols
|
|
44
44
|
/**
|
|
45
45
|
* @description
|
|
46
|
-
*
|
|
46
|
+
* Runs the test.
|
|
47
47
|
*/
|
|
48
48
|
test() {
|
|
49
49
|
return __awaiter(this, void 0, void 0, function* () {
|