@kiwiproject/kiwi-test-js 0.1.0 → 0.1.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.
@@ -1,5 +1,18 @@
1
- declare function startElasticSearchContainer(): Promise<void>;
1
+ /**
2
+ * Starts an Elastic search container and stores the container information in global.ELASTIC_SEARCH_CONTAINER.
3
+ *
4
+ * @param image The image name/version to use for elastic search. Defaults to elasticsearch:8.6.1.
5
+ */
6
+ declare function startElasticSearchContainer(image?: string): Promise<void>;
7
+ /**
8
+ * Stops a previously started Elastic search container. Error will be thrown if startElasticSearchContainer was not
9
+ * previously called.
10
+ */
2
11
  declare function stopElasticSearchContainer(): Promise<void>;
12
+ /**
13
+ * Retrieves the URL for accessing the running Elastic Search container. Error will be thrown if startElasticSearchContainer
14
+ * was not previously called.
15
+ */
3
16
  declare function getElasticSearchUrl(): string;
4
17
  export declare const ElasticSearchExtension: {
5
18
  startElasticSearchContainer: typeof startElasticSearchContainer;
@@ -12,13 +12,22 @@ Object.defineProperty(exports, "__esModule", { value: true });
12
12
  exports.ElasticSearchExtension = void 0;
13
13
  const kiwi_js_1 = require("@kiwiproject/kiwi-js");
14
14
  const elasticsearch_1 = require("@testcontainers/elasticsearch");
15
- function startElasticSearchContainer() {
15
+ /**
16
+ * Starts an Elastic search container and stores the container information in global.ELASTIC_SEARCH_CONTAINER.
17
+ *
18
+ * @param image The image name/version to use for elastic search. Defaults to elasticsearch:8.6.1.
19
+ */
20
+ function startElasticSearchContainer(image = "elasticsearch:8.6.1") {
16
21
  return __awaiter(this, void 0, void 0, function* () {
17
- global.ELASTIC_SEARCH_CONTAINER = yield new elasticsearch_1.ElasticsearchContainer("elasticsearch:8.6.1")
22
+ global.ELASTIC_SEARCH_CONTAINER = yield new elasticsearch_1.ElasticsearchContainer(image)
18
23
  .withEnvironment({ "xpack.security.enabled": "false" })
19
24
  .start();
20
25
  });
21
26
  }
27
+ /**
28
+ * Stops a previously started Elastic search container. Error will be thrown if startElasticSearchContainer was not
29
+ * previously called.
30
+ */
22
31
  function stopElasticSearchContainer() {
23
32
  return __awaiter(this, void 0, void 0, function* () {
24
33
  kiwi_js_1.KiwiPreconditions.checkState(global.ELASTIC_SEARCH_CONTAINER !== undefined, "Elastic Search container has not been previously started");
@@ -26,6 +35,10 @@ function stopElasticSearchContainer() {
26
35
  global.ELASTIC_SEARCH_CONTAINER = undefined;
27
36
  });
28
37
  }
38
+ /**
39
+ * Retrieves the URL for accessing the running Elastic Search container. Error will be thrown if startElasticSearchContainer
40
+ * was not previously called.
41
+ */
29
42
  function getElasticSearchUrl() {
30
43
  kiwi_js_1.KiwiPreconditions.checkState(global.ELASTIC_SEARCH_CONTAINER !== undefined, "Elastic Search container has not been previously started");
31
44
  return global.ELASTIC_SEARCH_CONTAINER.getHttpUrl();
@@ -1,9 +1,24 @@
1
- declare function startMinioSearchContainer(accessKey: string, secretKey: string): Promise<void>;
2
- declare function stopMinioSearchContainer(): Promise<void>;
1
+ /**
2
+ * Starts a Minio container and stores the container information in global.MINIO_CONTAINER
3
+ *
4
+ * @param accessKey The access key configured to connect. Defaults to minioadmin.
5
+ * @param secretKey The secret key configured to connect. Defaults to keyboard cat.
6
+ * @param image The image name/version to use for minio. Defaults to minio/minio:RELEASE.2023-08-09T23-30-22Z.
7
+ */
8
+ declare function startMinioContainer(accessKey?: string, secretKey?: string, image?: string): Promise<void>;
9
+ /**
10
+ * Stops a previously started Minio container. Error will be thrown if startMinioContainer has not been
11
+ * previously called.
12
+ */
13
+ declare function stopMinioContainer(): Promise<void>;
14
+ /**
15
+ * Retrieves the mapped external port of the started Minio container. Error will be thrown if startMinioContainer was
16
+ * not previously called.
17
+ */
3
18
  declare function getMinioPort(): number;
4
19
  export declare const MinioExtension: {
5
- startMinioSearchContainer: typeof startMinioSearchContainer;
6
- stopMinioSearchContainer: typeof stopMinioSearchContainer;
20
+ startMinioContainer: typeof startMinioContainer;
21
+ stopMinioContainer: typeof stopMinioContainer;
7
22
  getMinioPort: typeof getMinioPort;
8
23
  };
9
24
  export {};
@@ -12,36 +12,49 @@ Object.defineProperty(exports, "__esModule", { value: true });
12
12
  exports.MinioExtension = void 0;
13
13
  const kiwi_js_1 = require("@kiwiproject/kiwi-js");
14
14
  const testcontainers_1 = require("testcontainers");
15
- function startMinioSearchContainer(accessKey, secretKey) {
15
+ /**
16
+ * Starts a Minio container and stores the container information in global.MINIO_CONTAINER
17
+ *
18
+ * @param accessKey The access key configured to connect. Defaults to minioadmin.
19
+ * @param secretKey The secret key configured to connect. Defaults to keyboard cat.
20
+ * @param image The image name/version to use for minio. Defaults to minio/minio:RELEASE.2023-08-09T23-30-22Z.
21
+ */
22
+ function startMinioContainer(accessKey = "minioadmin", secretKey = "keyboard cat", image = "minio/minio:RELEASE.2023-08-09T23-30-22Z") {
16
23
  return __awaiter(this, void 0, void 0, function* () {
17
- console.log(accessKey);
18
- console.log(secretKey);
19
- global.MINIO_CONTAINER = yield new testcontainers_1.GenericContainer('quay.io/minio/minio:latest')
24
+ global.MINIO_CONTAINER = yield new testcontainers_1.GenericContainer(image)
20
25
  .withEnvironment({
21
- MINIO_BROWSER: 'off',
26
+ MINIO_BROWSER: "off",
22
27
  MINIO_ROOT_USER: accessKey,
23
28
  MINIO_ROOT_PASSWORD: secretKey,
24
29
  })
25
30
  .withExposedPorts(9000)
26
31
  .withWaitStrategy(testcontainers_1.Wait.forAll([testcontainers_1.Wait.forListeningPorts(), testcontainers_1.Wait.forLogMessage(/1 Online/)]))
27
- .withTmpFs({ '/data': 'rw,noexec,nosuid' })
28
- .withCommand(['server', '/data'])
32
+ .withTmpFs({ "/data": "rw,noexec,nosuid" })
33
+ .withCommand(["server", "/data"])
29
34
  .start();
30
35
  });
31
36
  }
32
- function stopMinioSearchContainer() {
37
+ /**
38
+ * Stops a previously started Minio container. Error will be thrown if startMinioContainer has not been
39
+ * previously called.
40
+ */
41
+ function stopMinioContainer() {
33
42
  return __awaiter(this, void 0, void 0, function* () {
34
43
  kiwi_js_1.KiwiPreconditions.checkState(global.MINIO_CONTAINER !== undefined, "Minio container has not been previously started");
35
44
  yield global.MINIO_CONTAINER.stop();
36
45
  global.MINIO_CONTAINER = undefined;
37
46
  });
38
47
  }
48
+ /**
49
+ * Retrieves the mapped external port of the started Minio container. Error will be thrown if startMinioContainer was
50
+ * not previously called.
51
+ */
39
52
  function getMinioPort() {
40
53
  kiwi_js_1.KiwiPreconditions.checkState(global.MINIO_CONTAINER !== undefined, "Minio container has not been previously started");
41
54
  return global.MINIO_CONTAINER.getMappedPort(9000);
42
55
  }
43
56
  exports.MinioExtension = {
44
- startMinioSearchContainer,
45
- stopMinioSearchContainer,
57
+ startMinioContainer,
58
+ stopMinioContainer,
46
59
  getMinioPort,
47
60
  };
@@ -1,6 +1,24 @@
1
- declare function startMongoContainer(): Promise<void>;
1
+ /**
2
+ * Starts a Mongo container and stores the container information in global.MONGO_CONTAINER.
3
+ *
4
+ * @param image The image name/version to use for mongo. Defaults to mongo:6.
5
+ */
6
+ declare function startMongoContainer(image?: string): Promise<void>;
7
+ /**
8
+ * Stops a previously started Mongo container. Error will be thrown if startMongoContainer is not
9
+ * previously called.
10
+ */
2
11
  declare function stopMongoContainer(): Promise<void>;
12
+ /**
13
+ * Retrieves the base connection URL for accessing the running Mongo. Error will be thrown if startMongoContainer
14
+ * is not previously called.
15
+ */
3
16
  declare function getMongoBaseUrl(): string;
17
+ /**
18
+ * Retrieves the base connection URL plus the given db name for accessing the running Mongo. Error will be thrown if
19
+ * startMongoContainer is not previously called.
20
+ * @param dbName The name of the database in mongo to connect.
21
+ */
4
22
  declare function getMongoUriWithDb(dbName: string): string;
5
23
  export declare const MongoExtension: {
6
24
  startMongoContainer: typeof startMongoContainer;
@@ -12,13 +12,22 @@ Object.defineProperty(exports, "__esModule", { value: true });
12
12
  exports.MongoExtension = void 0;
13
13
  const kiwi_js_1 = require("@kiwiproject/kiwi-js");
14
14
  const testcontainers_1 = require("testcontainers");
15
- function startMongoContainer() {
15
+ /**
16
+ * Starts a Mongo container and stores the container information in global.MONGO_CONTAINER.
17
+ *
18
+ * @param image The image name/version to use for mongo. Defaults to mongo:6.
19
+ */
20
+ function startMongoContainer(image = "mongo:6") {
16
21
  return __awaiter(this, void 0, void 0, function* () {
17
- global.MONGO_CONTAINER = yield new testcontainers_1.GenericContainer("mongo")
22
+ global.MONGO_CONTAINER = yield new testcontainers_1.GenericContainer(image)
18
23
  .withExposedPorts(27017)
19
24
  .start();
20
25
  });
21
26
  }
27
+ /**
28
+ * Stops a previously started Mongo container. Error will be thrown if startMongoContainer is not
29
+ * previously called.
30
+ */
22
31
  function stopMongoContainer() {
23
32
  return __awaiter(this, void 0, void 0, function* () {
24
33
  kiwi_js_1.KiwiPreconditions.checkState(global.MONGO_CONTAINER !== undefined, "Mongo container has not been previously started");
@@ -26,12 +35,21 @@ function stopMongoContainer() {
26
35
  global.MONGO_CONTAINER = undefined;
27
36
  });
28
37
  }
38
+ /**
39
+ * Retrieves the base connection URL for accessing the running Mongo. Error will be thrown if startMongoContainer
40
+ * is not previously called.
41
+ */
29
42
  function getMongoBaseUrl() {
30
43
  kiwi_js_1.KiwiPreconditions.checkState(global.MONGO_CONTAINER !== undefined, "Mongo container has not been previously started");
31
44
  const host = global.MONGO_CONTAINER.getHost();
32
45
  const port = global.MONGO_CONTAINER.getMappedPort(27017);
33
46
  return `mongodb://${host}:${port}/`;
34
47
  }
48
+ /**
49
+ * Retrieves the base connection URL plus the given db name for accessing the running Mongo. Error will be thrown if
50
+ * startMongoContainer is not previously called.
51
+ * @param dbName The name of the database in mongo to connect.
52
+ */
35
53
  function getMongoUriWithDb(dbName) {
36
54
  return `${getMongoBaseUrl()}${dbName}`;
37
55
  }
@@ -1,7 +1,32 @@
1
- declare function startPostgresContainer(): Promise<void>;
1
+ /**
2
+ * Starts a Postgres container and stores the container information in global.POSTGRES_CONTAINER.
3
+ *
4
+ * @param image The image name/version to use for postgres. Defaults to postgres:15.
5
+ */
6
+ declare function startPostgresContainer(image?: string): Promise<void>;
7
+ /**
8
+ * Stops a previously started Postgres container. Error will be thrown if startPostgresContainer is not
9
+ * previously called.
10
+ */
2
11
  declare function stopPostgresContainer(): Promise<void>;
12
+ /**
13
+ * Retrieves the base URL for accessing the running Postgres container. Error will be thrown if
14
+ * startPostgresContainer is not previously called.
15
+ */
3
16
  declare function getPostgresBaseUrl(): string;
17
+ /**
18
+ * Retrieves the base URL plus a given database for accessing the running Postgres container. Error will be thrown if
19
+ * startPostgresContainer is not previously called.
20
+ *
21
+ * @param dbName The name of the database to add to the connection string.
22
+ */
4
23
  declare function getPostgresUriWithDb(dbName: string): string;
24
+ /**
25
+ * Creates a new database with the given name in the running Postgres. Error will be thrown if
26
+ * startPostgresContainer is not previously called.
27
+ *
28
+ * @param dbName The name of the database to create.
29
+ */
5
30
  declare function setupNewDatabase(dbName: string): Promise<void>;
6
31
  export declare const PostgresExtension: {
7
32
  startPostgresContainer: typeof startPostgresContainer;
@@ -13,11 +13,20 @@ exports.PostgresExtension = void 0;
13
13
  const kiwi_js_1 = require("@kiwiproject/kiwi-js");
14
14
  const postgresql_1 = require("@testcontainers/postgresql");
15
15
  const pg_1 = require("pg");
16
- function startPostgresContainer() {
16
+ /**
17
+ * Starts a Postgres container and stores the container information in global.POSTGRES_CONTAINER.
18
+ *
19
+ * @param image The image name/version to use for postgres. Defaults to postgres:15.
20
+ */
21
+ function startPostgresContainer(image = "postgres:15") {
17
22
  return __awaiter(this, void 0, void 0, function* () {
18
- global.POSTGRES_CONTAINER = yield new postgresql_1.PostgreSqlContainer().start();
23
+ global.POSTGRES_CONTAINER = yield new postgresql_1.PostgreSqlContainer(image).start();
19
24
  });
20
25
  }
26
+ /**
27
+ * Stops a previously started Postgres container. Error will be thrown if startPostgresContainer is not
28
+ * previously called.
29
+ */
21
30
  function stopPostgresContainer() {
22
31
  return __awaiter(this, void 0, void 0, function* () {
23
32
  kiwi_js_1.KiwiPreconditions.checkState(global.POSTGRES_CONTAINER !== undefined, "Postgres container has not been previously started");
@@ -25,13 +34,29 @@ function stopPostgresContainer() {
25
34
  global.POSTGRES_CONTAINER = undefined;
26
35
  });
27
36
  }
37
+ /**
38
+ * Retrieves the base URL for accessing the running Postgres container. Error will be thrown if
39
+ * startPostgresContainer is not previously called.
40
+ */
28
41
  function getPostgresBaseUrl() {
29
42
  kiwi_js_1.KiwiPreconditions.checkState(global.POSTGRES_CONTAINER !== undefined, "Postgres container has not been previously started");
30
43
  return global.POSTGRES_CONTAINER.getConnectionUri();
31
44
  }
45
+ /**
46
+ * Retrieves the base URL plus a given database for accessing the running Postgres container. Error will be thrown if
47
+ * startPostgresContainer is not previously called.
48
+ *
49
+ * @param dbName The name of the database to add to the connection string.
50
+ */
32
51
  function getPostgresUriWithDb(dbName) {
33
52
  return getPostgresBaseUrl().replace(/\/test$/, `/${dbName}`);
34
53
  }
54
+ /**
55
+ * Creates a new database with the given name in the running Postgres. Error will be thrown if
56
+ * startPostgresContainer is not previously called.
57
+ *
58
+ * @param dbName The name of the database to create.
59
+ */
35
60
  function setupNewDatabase(dbName) {
36
61
  return __awaiter(this, void 0, void 0, function* () {
37
62
  const dbClient = new pg_1.Client({
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@kiwiproject/kiwi-test-js",
3
- "version": "0.1.0",
3
+ "version": "0.1.1",
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",