@kiwiproject/kiwi-test-js 0.5.1 → 0.6.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.
@@ -46,6 +46,6 @@ declare class WaitFor {
46
46
  * will be returned.
47
47
  * @param cb The function to check if the condition is true or false.
48
48
  */
49
- until(cb: () => boolean): Promise<string>;
49
+ until(cb: () => boolean | Promise<boolean>): Promise<string>;
50
50
  }
51
51
  export {};
@@ -1,4 +1,13 @@
1
1
  "use strict";
2
+ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
3
+ function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
4
+ return new (P || (P = Promise))(function (resolve, reject) {
5
+ function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
6
+ function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
7
+ function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
8
+ step((generator = generator.apply(thisArg, _arguments || [])).next());
9
+ });
10
+ };
2
11
  var __importDefault = (this && this.__importDefault) || function (mod) {
3
12
  return (mod && mod.__esModule) ? mod : { "default": mod };
4
13
  };
@@ -71,37 +80,49 @@ class WaitFor {
71
80
  * @param cb The function to check if the condition is true or false.
72
81
  */
73
82
  until(cb) {
74
- const totalTries = this.timeoutMs / this.pollIntervalMs;
75
- const aliasText = this.alias ? `with alias ${this.alias} ` : "";
76
- if (this.verbose) {
77
- console.log(`Waiting for condition ${aliasText}for up to ${totalTries} attempts checking every ${this.pollIntervalMs} ms`);
78
- }
79
- return new Promise((resolve, reject) => {
80
- let tries = 1;
81
- const loop = () => {
82
- if (cb.apply(this)) {
83
- if (this.verbose) {
84
- console.log(`Condition ${aliasText}met after ${tries} of ${totalTries} tries`);
83
+ return __awaiter(this, void 0, void 0, function* () {
84
+ const totalTries = this.timeoutMs / this.pollIntervalMs;
85
+ const aliasText = this.alias ? `with alias ${this.alias} ` : "";
86
+ if (this.verbose) {
87
+ console.log(`Waiting for condition ${aliasText}for up to ${totalTries} attempts checking every ${this.pollIntervalMs} ms`);
88
+ }
89
+ return new Promise((resolve, reject) => {
90
+ let tries = 1;
91
+ const processResult = (result) => {
92
+ if (result) {
93
+ if (this.verbose) {
94
+ console.log(`Condition ${aliasText}met after ${tries} of ${totalTries} tries`);
95
+ }
96
+ resolve(`Condition ${aliasText}met after ${tries} of ${totalTries} tries`);
85
97
  }
86
- resolve(`Condition ${aliasText}met after ${tries} of ${totalTries} tries`);
87
- }
88
- else if (tries > totalTries) {
89
- if (this.verbose) {
90
- console.log(`Condition ${aliasText}was not met after ${totalTries} tries`);
98
+ else if (tries > totalTries) {
99
+ if (this.verbose) {
100
+ console.log(`Condition ${aliasText}was not met after ${totalTries} tries`);
101
+ }
102
+ reject(new Error(`Condition ${aliasText}was not met after ${totalTries} tries`));
103
+ }
104
+ else {
105
+ tries += 1;
106
+ setTimeout(loop, this.pollIntervalMs);
91
107
  }
92
- reject(new Error(`Condition ${aliasText}was not met after ${totalTries} tries`));
108
+ };
109
+ const loop = () => __awaiter(this, void 0, void 0, function* () {
110
+ const cbResult = cb.apply(this);
111
+ if (typeof cbResult === "boolean") {
112
+ processResult(cbResult);
113
+ }
114
+ else {
115
+ const cbPromiseResult = yield cbResult;
116
+ processResult(cbPromiseResult);
117
+ }
118
+ });
119
+ if (this.pollDelayMs > 0) {
120
+ setTimeout(loop, this.pollDelayMs);
93
121
  }
94
122
  else {
95
- tries += 1;
96
- setTimeout(loop, this.pollIntervalMs);
123
+ loop();
97
124
  }
98
- };
99
- if (this.pollDelayMs > 0) {
100
- setTimeout(loop, this.pollDelayMs);
101
- }
102
- else {
103
- loop();
104
- }
125
+ });
105
126
  });
106
127
  }
107
128
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@kiwiproject/kiwi-test-js",
3
- "version": "0.5.1",
3
+ "version": "0.6.0",
4
4
  "description": "kiwi-test-js is a test utility library. Most of these utilities are ports from the Java Kiwi-test library",
5
5
  "main": "dist/index.js",
6
6
  "types": "dist/index.d.ts",
@@ -29,7 +29,7 @@
29
29
  "@testcontainers/postgresql": "10.7.2",
30
30
  "convert": "5.0.0",
31
31
  "jest": "29.7.0",
32
- "mongodb": "6.4.0",
32
+ "mongodb": "6.5.0",
33
33
  "pg": "8.11.3",
34
34
  "redis": "4.6.13",
35
35
  "testcontainers": "10.7.2"
@@ -38,13 +38,13 @@
38
38
  "@babel/core": "7.24.0",
39
39
  "@babel/preset-env": "7.24.0",
40
40
  "@babel/preset-typescript": "7.23.3",
41
- "@types/node": "20.11.24",
41
+ "@types/node": "20.11.28",
42
42
  "@types/pg": "8.11.2",
43
- "@typescript-eslint/eslint-plugin": "7.1.0",
44
- "@typescript-eslint/parser": "7.0.2",
43
+ "@typescript-eslint/eslint-plugin": "7.2.0",
44
+ "@typescript-eslint/parser": "7.2.0",
45
45
  "babel-jest": "29.7.0",
46
46
  "eslint": "8.57.0",
47
47
  "prettier": "3.2.5",
48
- "typescript": "5.3.3"
48
+ "typescript": "5.4.2"
49
49
  }
50
50
  }