@kiwiproject/kiwi-test-js 0.5.1 → 1.0.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/README.md +1 -1
- package/dist/elasticsearch/elastic-search-extension.d.ts +1 -1
- package/dist/elasticsearch/elastic-search-extension.js +3 -3
- package/dist/minio/minio-extension.js +2 -2
- package/dist/mongo/mongo-extension.js +2 -2
- package/dist/postgres/postgres-extension.js +2 -2
- package/dist/redis/redis-extension.js +2 -2
- package/dist/waitForIt/waitForIt.d.ts +1 -1
- package/dist/waitForIt/waitForIt.js +48 -28
- package/package.json +40 -26
package/README.md
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
### KiwiTestJS
|
|
2
|
-
[](https://github.com/kiwiproject/kiwi-test-js/actions?query=
|
|
2
|
+
[](https://github.com/kiwiproject/kiwi-test-js/actions/workflows/build.yml?query=branch%3Amain)
|
|
3
3
|
[](https://sonarcloud.io/dashboard?id=kiwiproject_kiwi-test-js)
|
|
4
4
|
[](https://sonarcloud.io/dashboard?id=kiwiproject_kiwi-test-js)
|
|
5
5
|
[](https://opensource.org/licenses/MIT)
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* Starts an Elastic search container and stores the container information in global.ELASTIC_SEARCH_CONTAINER.
|
|
3
3
|
*
|
|
4
|
-
* @param image The image name/version to use for elastic search. Defaults to elasticsearch:
|
|
4
|
+
* @param image The image name/version to use for elastic search. Defaults to elasticsearch:9.0.2.
|
|
5
5
|
*/
|
|
6
6
|
declare function startElasticSearchContainer(image?: string): Promise<void>;
|
|
7
7
|
/**
|
|
@@ -16,10 +16,10 @@ const elasticsearch_2 = require("@elastic/elasticsearch");
|
|
|
16
16
|
/**
|
|
17
17
|
* Starts an Elastic search container and stores the container information in global.ELASTIC_SEARCH_CONTAINER.
|
|
18
18
|
*
|
|
19
|
-
* @param image The image name/version to use for elastic search. Defaults to elasticsearch:
|
|
19
|
+
* @param image The image name/version to use for elastic search. Defaults to elasticsearch:9.0.2.
|
|
20
20
|
*/
|
|
21
|
-
function startElasticSearchContainer(
|
|
22
|
-
return __awaiter(this,
|
|
21
|
+
function startElasticSearchContainer() {
|
|
22
|
+
return __awaiter(this, arguments, void 0, function* (image = "elasticsearch:9.0.2") {
|
|
23
23
|
const container = yield new elasticsearch_1.ElasticsearchContainer(image)
|
|
24
24
|
.withEnvironment({ "xpack.security.enabled": "false" })
|
|
25
25
|
.start();
|
|
@@ -19,8 +19,8 @@ const testcontainers_1 = require("testcontainers");
|
|
|
19
19
|
* @param secretKey The secret key configured to connect. Defaults to keyboard cat.
|
|
20
20
|
* @param image The image name/version to use for minio. Defaults to minio/minio:RELEASE.2023-08-09T23-30-22Z.
|
|
21
21
|
*/
|
|
22
|
-
function startMinioContainer(
|
|
23
|
-
return __awaiter(this,
|
|
22
|
+
function startMinioContainer() {
|
|
23
|
+
return __awaiter(this, arguments, void 0, function* (accessKey = "minioadmin", secretKey = "keyboard cat", image = "minio/minio:RELEASE.2023-08-09T23-30-22Z") {
|
|
24
24
|
const container = yield new testcontainers_1.GenericContainer(image)
|
|
25
25
|
.withEnvironment({
|
|
26
26
|
MINIO_BROWSER: "off",
|
|
@@ -18,8 +18,8 @@ const mongodb_1 = require("mongodb");
|
|
|
18
18
|
*
|
|
19
19
|
* @param image The image name/version to use for mongo. Defaults to mongo:6.
|
|
20
20
|
*/
|
|
21
|
-
function startMongoContainer(
|
|
22
|
-
return __awaiter(this,
|
|
21
|
+
function startMongoContainer() {
|
|
22
|
+
return __awaiter(this, arguments, void 0, function* (image = "mongo:6") {
|
|
23
23
|
const container = yield new testcontainers_1.GenericContainer(image)
|
|
24
24
|
.withExposedPorts(27017)
|
|
25
25
|
.start();
|
|
@@ -18,8 +18,8 @@ const pg_1 = require("pg");
|
|
|
18
18
|
*
|
|
19
19
|
* @param image The image name/version to use for postgres. Defaults to postgres:15.
|
|
20
20
|
*/
|
|
21
|
-
function startPostgresContainer(
|
|
22
|
-
return __awaiter(this,
|
|
21
|
+
function startPostgresContainer() {
|
|
22
|
+
return __awaiter(this, arguments, void 0, function* (image = "postgres:15") {
|
|
23
23
|
const container = yield new postgresql_1.PostgreSqlContainer(image).start();
|
|
24
24
|
process.env.POSTGRES_EXTENSION_BASE_URI = container.getConnectionUri();
|
|
25
25
|
// NOTE: This will only work if tests are runInBand (i.e. not in parallel)
|
|
@@ -18,8 +18,8 @@ const redis_1 = require("redis");
|
|
|
18
18
|
*
|
|
19
19
|
* @param image The image name/version to use for redis. Defaults to redis:7.
|
|
20
20
|
*/
|
|
21
|
-
function startRedisContainer(
|
|
22
|
-
return __awaiter(this,
|
|
21
|
+
function startRedisContainer() {
|
|
22
|
+
return __awaiter(this, arguments, void 0, function* (image = "redis:7") {
|
|
23
23
|
const container = yield new testcontainers_1.GenericContainer(image)
|
|
24
24
|
.withExposedPorts(6379)
|
|
25
25
|
.start();
|
|
@@ -1,9 +1,18 @@
|
|
|
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
|
};
|
|
5
14
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
-
exports.wait =
|
|
15
|
+
exports.wait = wait;
|
|
7
16
|
const convert_1 = __importDefault(require("convert"));
|
|
8
17
|
/**
|
|
9
18
|
* Creates a new wait condition with defaults.
|
|
@@ -13,7 +22,6 @@ const convert_1 = __importDefault(require("convert"));
|
|
|
13
22
|
function wait() {
|
|
14
23
|
return new WaitFor();
|
|
15
24
|
}
|
|
16
|
-
exports.wait = wait;
|
|
17
25
|
class WaitFor {
|
|
18
26
|
constructor() {
|
|
19
27
|
this.timeoutMs = 4000;
|
|
@@ -71,37 +79,49 @@ class WaitFor {
|
|
|
71
79
|
* @param cb The function to check if the condition is true or false.
|
|
72
80
|
*/
|
|
73
81
|
until(cb) {
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
if (
|
|
84
|
-
|
|
82
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
83
|
+
const totalTries = this.timeoutMs / this.pollIntervalMs;
|
|
84
|
+
const aliasText = this.alias ? `with alias ${this.alias} ` : "";
|
|
85
|
+
if (this.verbose) {
|
|
86
|
+
console.log(`Waiting for condition ${aliasText}for up to ${totalTries} attempts checking every ${this.pollIntervalMs} ms`);
|
|
87
|
+
}
|
|
88
|
+
return new Promise((resolve, reject) => {
|
|
89
|
+
let tries = 1;
|
|
90
|
+
const processResult = (result) => {
|
|
91
|
+
if (result) {
|
|
92
|
+
if (this.verbose) {
|
|
93
|
+
console.log(`Condition ${aliasText}met after ${tries} of ${totalTries} tries`);
|
|
94
|
+
}
|
|
95
|
+
resolve(`Condition ${aliasText}met after ${tries} of ${totalTries} tries`);
|
|
85
96
|
}
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
97
|
+
else if (tries > totalTries) {
|
|
98
|
+
if (this.verbose) {
|
|
99
|
+
console.log(`Condition ${aliasText}was not met after ${totalTries} tries`);
|
|
100
|
+
}
|
|
101
|
+
reject(new Error(`Condition ${aliasText}was not met after ${totalTries} tries`));
|
|
91
102
|
}
|
|
92
|
-
|
|
103
|
+
else {
|
|
104
|
+
tries += 1;
|
|
105
|
+
setTimeout(loop, this.pollIntervalMs);
|
|
106
|
+
}
|
|
107
|
+
};
|
|
108
|
+
const loop = () => __awaiter(this, void 0, void 0, function* () {
|
|
109
|
+
const cbResult = cb.apply(this);
|
|
110
|
+
if (typeof cbResult === "boolean") {
|
|
111
|
+
processResult(cbResult);
|
|
112
|
+
}
|
|
113
|
+
else {
|
|
114
|
+
const cbPromiseResult = yield cbResult;
|
|
115
|
+
processResult(cbPromiseResult);
|
|
116
|
+
}
|
|
117
|
+
});
|
|
118
|
+
if (this.pollDelayMs > 0) {
|
|
119
|
+
setTimeout(loop, this.pollDelayMs);
|
|
93
120
|
}
|
|
94
121
|
else {
|
|
95
|
-
|
|
96
|
-
setTimeout(loop, this.pollIntervalMs);
|
|
122
|
+
loop();
|
|
97
123
|
}
|
|
98
|
-
};
|
|
99
|
-
if (this.pollDelayMs > 0) {
|
|
100
|
-
setTimeout(loop, this.pollDelayMs);
|
|
101
|
-
}
|
|
102
|
-
else {
|
|
103
|
-
loop();
|
|
104
|
-
}
|
|
124
|
+
});
|
|
105
125
|
});
|
|
106
126
|
}
|
|
107
127
|
}
|
package/package.json
CHANGED
|
@@ -1,16 +1,25 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@kiwiproject/kiwi-test-js",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "1.0.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",
|
|
7
7
|
"files": [
|
|
8
8
|
"/dist"
|
|
9
9
|
],
|
|
10
|
+
"repository": {
|
|
11
|
+
"type": "git",
|
|
12
|
+
"url": "git+https://github.com/kiwiproject/kiwi-test-js.git"
|
|
13
|
+
},
|
|
14
|
+
"publishConfig": {
|
|
15
|
+
"access": "public",
|
|
16
|
+
"provenance": true
|
|
17
|
+
},
|
|
10
18
|
"scripts": {
|
|
11
|
-
"
|
|
12
|
-
"
|
|
13
|
-
"
|
|
19
|
+
"build": "tsc",
|
|
20
|
+
"format": "npx prettier --ignore-path .gitignore --write \"**/*.+(ts|js|json)\"",
|
|
21
|
+
"lint": "npx eslint --fix src",
|
|
22
|
+
"test": "npx jest --coverage --collectCoverageFrom=src/**/*.ts"
|
|
14
23
|
},
|
|
15
24
|
"jest": {
|
|
16
25
|
"testPathIgnorePatterns": [
|
|
@@ -22,29 +31,34 @@
|
|
|
22
31
|
]
|
|
23
32
|
},
|
|
24
33
|
"dependencies": {
|
|
25
|
-
"@elastic/elasticsearch": "
|
|
26
|
-
"@jest/globals": "
|
|
27
|
-
"@kiwiproject/kiwi-js": "0.
|
|
28
|
-
"@testcontainers/elasticsearch": "
|
|
29
|
-
"@testcontainers/postgresql": "
|
|
30
|
-
"convert": "
|
|
31
|
-
"jest": "
|
|
32
|
-
"mongodb": "
|
|
33
|
-
"pg": "8.
|
|
34
|
-
"redis": "
|
|
35
|
-
"testcontainers": "
|
|
34
|
+
"@elastic/elasticsearch": "9.2.0",
|
|
35
|
+
"@jest/globals": "30.2.0",
|
|
36
|
+
"@kiwiproject/kiwi-js": "1.0.0",
|
|
37
|
+
"@testcontainers/elasticsearch": "11.11.0",
|
|
38
|
+
"@testcontainers/postgresql": "11.11.0",
|
|
39
|
+
"convert": "6.0.0",
|
|
40
|
+
"jest": "30.2.0",
|
|
41
|
+
"mongodb": "7.0.0",
|
|
42
|
+
"pg": "8.17.1",
|
|
43
|
+
"redis": "5.10.0",
|
|
44
|
+
"testcontainers": "11.11.0"
|
|
36
45
|
},
|
|
37
46
|
"devDependencies": {
|
|
38
|
-
"@babel/core": "7.
|
|
39
|
-
"
|
|
40
|
-
"@babel/preset-
|
|
41
|
-
"@
|
|
42
|
-
"@
|
|
43
|
-
"@
|
|
44
|
-
"@
|
|
45
|
-
"
|
|
46
|
-
"
|
|
47
|
-
"
|
|
48
|
-
"
|
|
47
|
+
"@babel/core": "7.28.6",
|
|
48
|
+
"semantic-release": "25.0.2",
|
|
49
|
+
"@babel/preset-env": "7.28.6",
|
|
50
|
+
"@babel/preset-typescript": "7.28.5",
|
|
51
|
+
"@eslint/eslintrc": "3.3.3",
|
|
52
|
+
"@eslint/js": "9.39.2",
|
|
53
|
+
"@types/node": "25.0.9",
|
|
54
|
+
"@types/pg": "8.16.0",
|
|
55
|
+
"babel-jest": "30.2.0",
|
|
56
|
+
"eslint": "9.39.2",
|
|
57
|
+
"eslint-config-prettier": "10.1.8",
|
|
58
|
+
"eslint-plugin-prettier": "5.5.5",
|
|
59
|
+
"globals": "17.0.0",
|
|
60
|
+
"prettier": "3.8.0",
|
|
61
|
+
"typescript": "5.9.3",
|
|
62
|
+
"typescript-eslint": "8.53.0"
|
|
49
63
|
}
|
|
50
64
|
}
|