zation-assured 3.0.0-dev.2 → 3.0.0-dev.6

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.
@@ -10,7 +10,7 @@ export declare class WhenBuilder<C extends Client<any, any>> {
10
10
  private readonly _client;
11
11
  private readonly _test;
12
12
  constructor(client: C, test: Test);
13
- static when<C extends Client<any, any>>(client: C, itShould?: string): WhenBuilder<C>;
13
+ static when<C extends Client<any, any>>(client: C, it?: string): WhenBuilder<C>;
14
14
  /**
15
15
  * @description
16
16
  * Creates a request test action.
@@ -15,8 +15,8 @@ class WhenBuilder {
15
15
  this._client = client;
16
16
  this._test = test;
17
17
  }
18
- static when(client, itShould) {
19
- return new WhenBuilder(client, new test_1.Test(itShould));
18
+ static when(client, it) {
19
+ return new WhenBuilder(client, new test_1.Test(it));
20
20
  }
21
21
  // noinspection JSUnusedGlobalSymbols
22
22
  /**
@@ -9,7 +9,7 @@ export declare class StandaloneChannelAsserter<C extends Channel<any, any>> exte
9
9
  subscribe(member?: any): StandaloneChannelAsserter<C>;
10
10
  /**
11
11
  * @description
12
- * Run the test.
12
+ * Runs the test.
13
13
  */
14
14
  test(): Promise<void>;
15
15
  protected self(): StandaloneChannelAsserter<C>;
@@ -43,7 +43,7 @@ class StandaloneChannelAsserter extends abstractChannelAsserter_1.AbstractChanne
43
43
  // noinspection JSUnusedGlobalSymbols
44
44
  /**
45
45
  * @description
46
- * Run the test.
46
+ * Runs the test.
47
47
  */
48
48
  test() {
49
49
  return __awaiter(this, void 0, void 0, function* () {
@@ -9,7 +9,7 @@ export declare class StandaloneClientAsserter<C extends Client<any, any>> extend
9
9
  connect(): StandaloneClientAsserter<C>;
10
10
  /**
11
11
  * @description
12
- * Run the test.
12
+ * Runs the test.
13
13
  */
14
14
  test(): Promise<void>;
15
15
  protected self(): StandaloneClientAsserter<C>;
@@ -43,7 +43,7 @@ class StandaloneClientAsserter extends abstractClientAsserter_1.AbstractClientAs
43
43
  // noinspection JSUnusedGlobalSymbols
44
44
  /**
45
45
  * @description
46
- * Run the test.
46
+ * Runs the test.
47
47
  */
48
48
  test() {
49
49
  return __awaiter(this, void 0, void 0, function* () {
@@ -15,6 +15,7 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
15
15
  };
16
16
  Object.defineProperty(exports, "__esModule", { value: true });
17
17
  exports.IntegratedResponseAsserter = void 0;
18
+ const zation_client_1 = require("zation-client");
18
19
  const valueAsserter_1 = require("../value/valueAsserter");
19
20
  const backErrorsFilterBuilder_1 = require("../../backError/backErrorsFilterBuilder");
20
21
  const abstractActionAsserter_1 = require("../abstractActionAsserter");
@@ -27,7 +28,16 @@ class IntegratedResponseAsserter extends abstractActionAsserter_1.AbstractAction
27
28
  }
28
29
  _executeAction() {
29
30
  return __awaiter(this, void 0, void 0, function* () {
30
- const resp = yield this.sendRequest();
31
+ let resp;
32
+ try {
33
+ resp = yield this.sendRequest();
34
+ }
35
+ catch (err) {
36
+ if (err instanceof zation_client_1.Response)
37
+ resp = err;
38
+ else
39
+ throw err;
40
+ }
31
41
  for (let i = 0; i < this.responseAsserters.length; i++)
32
42
  yield this.responseAsserters[i](resp);
33
43
  });
@@ -3,7 +3,7 @@ import { ValueAsserter } from "../value/valueAsserter";
3
3
  import { BackErrorsFilterBuilder } from "../../backError/backErrorsFilterBuilder";
4
4
  import { ResponseData } from "../../utils/types";
5
5
  export default class StandaloneResponseAsserter<R extends Response<any>> {
6
- private readonly test;
6
+ private readonly _test;
7
7
  private readonly responses;
8
8
  constructor(response: R | R[], description?: string);
9
9
  protected _forEachResponse(func: (response: R, i: number) => Promise<void> | void): Promise<void>;
@@ -46,4 +46,9 @@ export default class StandaloneResponseAsserter<R extends Response<any>> {
46
46
  * @param assert
47
47
  */
48
48
  assert(assert: (resp: R) => void | Promise<void>): StandaloneResponseAsserter<R>;
49
+ /**
50
+ * @description
51
+ * Runs the test.
52
+ */
53
+ test(): Promise<void>;
49
54
  }
@@ -20,7 +20,7 @@ const backErrorsFilterBuilder_1 = require("../../backError/backErrorsFilterBuild
20
20
  const assert = require('assert');
21
21
  class StandaloneResponseAsserter {
22
22
  constructor(response, description) {
23
- this.test = new test_1.Test(description);
23
+ this._test = new test_1.Test(description);
24
24
  this.responses = Array.isArray(response) ? response : [response];
25
25
  }
26
26
  _forEachResponse(func) {
@@ -39,7 +39,7 @@ class StandaloneResponseAsserter {
39
39
  * Asserts that the response is successful.
40
40
  */
41
41
  isSuccessful() {
42
- this.test.test(() => this._forEachResponse((resp, i) => __awaiter(this, void 0, void 0, function* () {
42
+ this._test.test(() => this._forEachResponse((resp, i) => __awaiter(this, void 0, void 0, function* () {
43
43
  assert(resp.successful, `Response: ${i} should be successful.` + this._respInfo(resp));
44
44
  })));
45
45
  return this;
@@ -50,7 +50,7 @@ class StandaloneResponseAsserter {
50
50
  * Asserts that the response is not successful.
51
51
  */
52
52
  isNotSuccessful() {
53
- this.test.test(() => this._forEachResponse((resp, i) => __awaiter(this, void 0, void 0, function* () {
53
+ this._test.test(() => this._forEachResponse((resp, i) => __awaiter(this, void 0, void 0, function* () {
54
54
  assert(!resp.successful, `Response: ${i} should be not successful.` + this._respInfo(resp));
55
55
  })));
56
56
  return this;
@@ -61,7 +61,7 @@ class StandaloneResponseAsserter {
61
61
  * Asserts that the response has a result.
62
62
  */
63
63
  hasResult() {
64
- this.test.test(() => this._forEachResponse((resp, i) => __awaiter(this, void 0, void 0, function* () {
64
+ this._test.test(() => this._forEachResponse((resp, i) => __awaiter(this, void 0, void 0, function* () {
65
65
  assert(resp.result != null, `Response: ${i} should have a result.`
66
66
  + this._respInfo(resp));
67
67
  })));
@@ -74,14 +74,14 @@ class StandaloneResponseAsserter {
74
74
  */
75
75
  result() {
76
76
  return new valueAsserter_1.ValueAsserter(this, (test) => {
77
- this.test.test(() => this._forEachResponse((resp, i) => __awaiter(this, void 0, void 0, function* () {
77
+ this._test.test(() => this._forEachResponse((resp, i) => __awaiter(this, void 0, void 0, function* () {
78
78
  test(resp.result, `response: ${i} result`);
79
79
  })));
80
80
  });
81
81
  }
82
82
  hasError(filter) {
83
83
  if (filter !== undefined) {
84
- this.test.test(() => this._forEachResponse((resp, i) => __awaiter(this, void 0, void 0, function* () {
84
+ this._test.test(() => this._forEachResponse((resp, i) => __awaiter(this, void 0, void 0, function* () {
85
85
  assert(resp.filter(filter).length > 0, `Response: ${i} should have at least one back error that matches the filter: ${JSON.stringify(filter)}.`
86
86
  + this._respInfo(resp));
87
87
  })));
@@ -99,10 +99,20 @@ class StandaloneResponseAsserter {
99
99
  * @param assert
100
100
  */
101
101
  assert(assert) {
102
- this.test.test(() => this._forEachResponse((resp) => __awaiter(this, void 0, void 0, function* () {
102
+ this._test.test(() => this._forEachResponse((resp) => __awaiter(this, void 0, void 0, function* () {
103
103
  yield assert(resp);
104
104
  })));
105
105
  return this;
106
106
  }
107
+ // noinspection JSUnusedGlobalSymbols
108
+ /**
109
+ * @description
110
+ * Runs the test.
111
+ */
112
+ test() {
113
+ return __awaiter(this, void 0, void 0, function* () {
114
+ return this._test.execute();
115
+ });
116
+ }
107
117
  }
108
118
  exports.default = StandaloneResponseAsserter;
@@ -10,7 +10,7 @@ export declare class StandaloneDataboxAsserter<D extends Databox<any, any, any,
10
10
  connect(member?: DataboxMember<D>): StandaloneDataboxAsserter<D>;
11
11
  /**
12
12
  * @description
13
- * Run the test.
13
+ * Runs the test.
14
14
  */
15
15
  test(): Promise<void>;
16
16
  protected self(): StandaloneDataboxAsserter<D>;
@@ -43,7 +43,7 @@ class StandaloneDataboxAsserter extends abstractDataboxAsserter_1.AbstractDatabo
43
43
  // noinspection JSUnusedGlobalSymbols
44
44
  /**
45
45
  * @description
46
- * Run the test.
46
+ * Runs the test.
47
47
  */
48
48
  test() {
49
49
  return __awaiter(this, void 0, void 0, function* () {
@@ -2,8 +2,8 @@ declare type Action = () => Promise<void> | void;
2
2
  export declare class Test {
3
3
  private readonly _subTests;
4
4
  private currentSubTest;
5
- private readonly _description?;
6
- constructor(description?: string);
5
+ private readonly _it?;
6
+ constructor(it?: string);
7
7
  newSubTest(): void;
8
8
  beforeTest(action: Action): void;
9
9
  test(action: Action): void;
@@ -17,9 +17,9 @@ Object.defineProperty(exports, "__esModule", { value: true });
17
17
  exports.Test = void 0;
18
18
  const waitSymbol = Symbol();
19
19
  class Test {
20
- constructor(description) {
20
+ constructor(it) {
21
21
  this._subTests = [];
22
- this._description = description;
22
+ this._it = it;
23
23
  this.newSubTest();
24
24
  }
25
25
  newSubTest() {
@@ -49,11 +49,11 @@ class Test {
49
49
  }
50
50
  execute() {
51
51
  return __awaiter(this, void 0, void 0, function* () {
52
- if (this._description != null) {
52
+ if (this._it != null) {
53
53
  if (global['it'] == null)
54
54
  throw new Error("Please install a test runner like mocha or jest.");
55
55
  return new Promise((resolve, reject) => {
56
- global['it'](this._description, () => __awaiter(this, void 0, void 0, function* () {
56
+ global['it'](this._it, () => __awaiter(this, void 0, void 0, function* () {
57
57
  try {
58
58
  yield this._run();
59
59
  resolve();
package/package.json CHANGED
@@ -1,14 +1,13 @@
1
1
  {
2
2
  "name": "zation-assured",
3
- "version": "3.0.0-dev.2",
3
+ "version": "3.0.0-dev.6",
4
4
  "license": "MIT",
5
5
  "description": "Library For Testing Zation Servers",
6
6
  "main": "dist/index.js",
7
7
  "types": "dist/index.d.ts",
8
8
  "scripts": {
9
9
  "prepublishOnly": "npm run build",
10
- "build": "gulp compile",
11
- "test": "nyc --reporter=html mocha -- ./test/**/*.test.js"
10
+ "build": "gulp compile"
12
11
  },
13
12
  "repository": {
14
13
  "type": "git",
@@ -42,7 +41,7 @@
42
41
  "@types/node": "^12.7.2",
43
42
  "chai": "^4.3.3",
44
43
  "path": "0.12.7",
45
- "zation-client": "^3.0.0-dev.4",
44
+ "zation-client": "^3.0.0-dev.11",
46
45
  "queric": "^2.0.0"
47
46
  },
48
47
  "devDependencies": {