@elasticpath/component-test-framework 1.0.0 → 1.0.2

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/lib/api.d.ts CHANGED
@@ -13,7 +13,7 @@ declare class Api {
13
13
  isV3Response(data: V2Response | V3Response): data is V3Response;
14
14
  IsV2Response(data: V2Response | V3Response): data is V2Response;
15
15
  get errors(): Array<Error> | Array<any>;
16
- get axiosResponse(): ApiResponse | ApiArrayResponse;
16
+ get response(): ApiResponse | ApiArrayResponse;
17
17
  get(endpoint: string, abortOnError?: boolean): Promise<void>;
18
18
  post(endpoint: string, payload: ApiPayload, abortOnError?: boolean): Promise<void>;
19
19
  form(endpoint: string, form: FormData, abortOnError?: boolean): Promise<void>;
package/lib/api.js CHANGED
@@ -51,13 +51,13 @@ class Api {
51
51
  }
52
52
  get errors() {
53
53
  // Response data is never an array if there's errors
54
- if (Array.isArray(this.axiosResponse.data)) {
54
+ if (Array.isArray(this.response.data)) {
55
55
  Logger.error('Attempted to access errors on an array response');
56
56
  return null;
57
57
  }
58
- return this.axiosResponse.data.errors;
58
+ return this.response.data.errors;
59
59
  }
60
- get axiosResponse() {
60
+ get response() {
61
61
  var _a, _b;
62
62
  if (this.isError(this.axiosResponseObject)) {
63
63
  let status;
@@ -162,7 +162,7 @@ class Api {
162
162
  beautifyError(error) {
163
163
  var _a, _b, _c, _d;
164
164
  if (error.response) {
165
- Logger.error(`Failed requesting ${this.requestMethod.toUpperCase()} ${process.env.CUCUMBER_BASE_URL}${this.requestPath}`);
165
+ Logger.error(`Failed requesting ${this.requestMethod.toUpperCase()} ${process.env.CTF_BASE_URL}${this.requestPath}`);
166
166
  if (((_b = (_a = error.response) === null || _a === void 0 ? void 0 : _a.data) === null || _b === void 0 ? void 0 : _b.errors) !== undefined) {
167
167
  Logger.error((_d = (_c = error.response) === null || _c === void 0 ? void 0 : _c.data) === null || _d === void 0 ? void 0 : _d.errors);
168
168
  }
package/lib/api.js.map CHAN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I,CAAC,WAAW,EAAE,CAC5G,CAAA;YAED,IAAI,CAAA,MAAA,MAAA,KAAK,CAAC,QAAQ,0CAAE,IAAI,0CAAE,MAAM,MAAK,SAAS,EAAE;gBAC9C,MAAM,CAAC,KAAK,CAAC,MAAA,MAAA,KAAK,CAAC,QAAQ,0CAAE,IAAI,0CAAE,MAAM,CAAC,CAAA;aAC3C;SACF;aAAM;YACL,MAAM,CAAC,KAAK,CAAC,eAAe,EAAE,KAAK,EAAE,IAAI,CAAC,CAAA;SAC3C;IACH,CAAC;IAED,kDAAkD;IAC1C,OAAO,CAAC,QAAuB;QACrC,IAAI,CAAC,QAAQ,CAAC,IAAI,EAAE;YAClB,OAAO,IAAI,CAAA;SACZ;QAED,IAAI,KAAK,CAAC,OAAO,CAAC,QAAQ,CAAC,IAAI,CAAC,IAAI,CAAC,EAAE;YACrC,IAAI,QAAQ,CAAC,IAAI,CAAC,IAAI,CAAC,MAAM,KAAK,CAAC,EAAE;gBACnC,OAAO,IAAI,CAAA;aACZ;SACF;aAAM,IAAI,MAAM,CAAC,IAAI,CAAC,QAAQ,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC,MAAM,KAAK,CAAC,EAAE;YACvD,OAAO,IAAI,CAAA;SACZ;QAED,OAAO,KAAK,CAAA;IACd,CAAC;CACF;AAED,kBAAe,GAAG,CAAA","sourcesContent":["import Axios, { AxiosInstance, AxiosError, AxiosResponse, AxiosRequestConfig } from 'axios'\nimport * as AxiosLogger from 'axios-logger'\nimport * as FormData from 'form-data'\nimport { expect } from 'chai'\n\nimport { ApiPayload, ApiResponse, ApiArrayResponse, Error, V2Response, V3Response } from './api.interfaces'\nimport ResourceStore from './resource_store'\nimport * as Logger from './logger'\nimport { nullOrValue } from './utils'\n\nclass Api {\n public axiosInstance: AxiosInstance\n\n private axiosResponseObject: AxiosResponse | AxiosError\n\n private requestPath: string\n\n private requestMethod: string\n\n // We can't add this to the interceptors because we sometimes\n // need to overwrite this\n private readonly defaultHeaders: object\n\n private headers: object\n\n public constructor() {\n const { CUCUMBER_BASE_URL, CUCUMBER_LOGGING_LEVEL } = process.env\n\n this.defaultHeaders = {\n 'content-type': 'application/json',\n }\n this.headers = this.defaultHeaders\n\n this.axiosInstance = Axios.create({\n baseURL: CUCUMBER_BASE_URL,\n timeout: 4000,\n timeoutErrorMessage: `[Fail] Api request timed out. Is the service running on ${CUCUMBER_BASE_URL}`,\n })\n\n this.axiosInstance.interceptors.request.use((config: AxiosRequestConfig) => {\n // eslint-disable-next-line no-param-reassign\n config.headers.accept = 'application/json'\n return config\n })\n\n if (CUCUMBER_LOGGING_LEVEL === 'debug') {\n this.axiosInstance.interceptors.request.use(AxiosLogger.requestLogger)\n this.axiosInstance.interceptors.response.use(AxiosLogger.responseLogger)\n }\n }\n\n private isError(response): response is AxiosError {\n return (<AxiosError>this.axiosResponseObject).isAxiosError !== undefined\n }\n\n public isV3Response(data: V2Response | V3Response): data is V3Response {\n if (this.isError(this.axiosResponseObject)) {\n return false\n }\n\n return <V3Response>data.attributes !== undefined\n }\n\n public IsV2Response(data: V2Response | V3Response): data is V2Response {\n return !this.isV3Response(data)\n }\n\n public get errors(): Array<Error> | Array<any> {\n // Response data is never an array if there's errors\n if (Array.isArray(this.axiosResponse.data)) {\n Logger.error('Attempted to access errors on an array response')\n return null\n }\n\n return this.axiosResponse.data.errors\n }\n\n public get axiosResponse(): ApiResponse | ApiArrayResponse {\n if (this.isError(this.axiosResponseObject)) {\n let status\n\n // Status exists in a different place depending on an API request failure or\n // a general AxiosError\n if (Object.prototype.hasOwnProperty.call(this.axiosResponseObject, 'code')) {\n status = this.axiosResponseObject.code\n } else {\n status = this.axiosResponseObject.response.status\n }\n\n return {\n status: parseInt(status, 10),\n data: this.axiosResponseObject?.response?.data,\n } as ApiResponse\n }\n\n return {\n status: this.axiosResponseObject.status,\n // add everything else from the response\n ...this.axiosResponseObject.data,\n }\n }\n\n public async get(endpoint: string, abortOnError: boolean = true): Promise<void> {\n this.requestPath = endpoint\n this.requestMethod = 'GET'\n\n this.axiosResponseObject = await this.axiosInstance\n .get(endpoint, { headers: this.headers })\n .catch((err) => this.fail(err, abortOnError))\n\n if (!this.isError(this.axiosResponseObject) && !this.isEmpty(this.axiosResponseObject)) {\n ResourceStore.Store(this.axiosResponseObject.data)\n }\n }\n\n public async post(endpoint: string, payload: ApiPayload, abortOnError: boolean = true): Promise<void> {\n this.requestPath = endpoint\n this.requestMethod = 'POST'\n\n this.axiosResponseObject = await this.axiosInstance\n .post(endpoint, payload, { headers: this.headers })\n .catch((err) => this.fail(err, abortOnError))\n\n if (!this.isError(this.axiosResponseObject)) {\n ResourceStore.Store(this.axiosResponseObject.data)\n }\n }\n\n public async form(endpoint: string, form: FormData, abortOnError: boolean = true): Promise<void> {\n this.requestPath = endpoint\n this.requestMethod = 'POST'\n const headers = { ...this.headers, ...form.getHeaders() }\n\n this.axiosResponseObject = await this.axiosInstance\n .post(endpoint, form, { headers })\n .catch((err) => this.fail(err, abortOnError))\n\n if (!this.isError(this.axiosResponseObject)) {\n ResourceStore.Store(this.axiosResponseObject.data)\n }\n }\n\n public async put(endpoint: string, payload: ApiPayload, abortOnError: boolean = true): Promise<void> {\n this.requestPath = endpoint\n this.requestMethod = 'PUT'\n\n this.axiosResponseObject = await this.axiosInstance\n .put(endpoint, payload, { headers: this.headers })\n .catch((err) => this.fail(err, abortOnError))\n }\n\n public async delete(endpoint: string, payload?: ApiPayload, abortOnError: boolean = true): Promise<void> {\n this.requestPath = endpoint\n this.requestMethod = 'DELETE'\n // For some reason, axios delete requests specify the payload and headers in the same object\n const config = {\n ...payload,\n ...{ headers: this.headers },\n }\n\n this.axiosResponseObject = await this.axiosInstance\n .delete(endpoint, config)\n .catch((err) => this.fail(err, abortOnError))\n }\n\n // setHeaders will merge the new headers with the current ones, overwriting if\n // the same key exists. The value will use nullOrValue to properly map strings to literals ('null' => null)\n public setHeaders(newHeaders: object, reset: boolean = false, preserveValueType: boolean = false): void {\n if (reset) {\n this.headers = {}\n }\n\n Object.entries(newHeaders).forEach((h) => {\n let value = h[1]\n if (!preserveValueType) {\n value = nullOrValue(value)\n }\n return Object.assign(this.headers, {\n [h[0]]: value,\n })\n })\n }\n\n public deleteHeader(key: string) {\n delete this.headers[key]\n }\n\n private fail(error: AxiosError, abortOnError: boolean): AxiosError {\n if (abortOnError) {\n this.beautifyError(error)\n expect.fail(error.message)\n }\n\n return error\n }\n\n private beautifyError(error: any): void {\n if (error.response) {\n Logger.error(\n `Failed requesting ${this.requestMethod.toUpperCase()} ${process.env.CUCUMBER_BASE_URL}${this.requestPath}`,\n )\n\n if (error.response?.data?.errors !== undefined) {\n Logger.error(error.response?.data?.errors)\n }\n } else {\n Logger.error('[FATAL ERROR]', error, '\\n')\n }\n }\n\n // eslint-disable-next-line class-methods-use-this\n private isEmpty(response: AxiosResponse): boolean {\n if (!response.data) {\n return true\n }\n\n if (Array.isArray(response.data.data)) {\n if (response.data.data.length === 0) {\n return true\n }\n } else if (Object.keys(response.data.data).length === 0) {\n return true\n }\n\n return false\n }\n}\n\nexport default Api\n"]}
1
+ {"version":3,"file":"api.js","sourceRoot":"","sources":["../src/api.ts"],"names":[],"mappings":";;;;;;;;;;;AAAA,iCAA2F;AAC3F,4CAA2C;AAE3C,+BAA6B;AAG7B,qDAA4C;AAC5C,mCAAkC;AAClC,mCAAqC;AAErC,MAAM,GAAG;IAeP;QACE,MAAM,EAAE,iBAAiB,EAAE,sBAAsB,EAAE,GAAG,OAAO,CAAC,GAAG,CAAA;QAEjE,IAAI,CAAC,cAAc,GAAG;YACpB,cAAc,EAAE,kBAAkB;SACnC,CAAA;QACD,IAAI,CAAC,OAAO,GAAG,IAAI,CAAC,cAAc,CAAA;QAElC,IAAI,CAAC,aAAa,GAAG,eAAK,CAAC,MAAM,CAAC;YAChC,OAAO,EAAE,iBAAiB;YAC1B,OAAO,EAAE,IAAI;YACb,mBAAmB,EAAE,2DAA2D,iBAAiB,EAAE;SACpG,CAAC,CAAA;QAEF,IAAI,CAAC,a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AC,EAAE;gBACnC,OAAO,IAAI,CAAA;aACZ;SACF;aAAM,IAAI,MAAM,CAAC,IAAI,CAAC,QAAQ,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC,MAAM,KAAK,CAAC,EAAE;YACvD,OAAO,IAAI,CAAA;SACZ;QAED,OAAO,KAAK,CAAA;IACd,CAAC;CACF;AAED,kBAAe,GAAG,CAAA","sourcesContent":["import Axios, { AxiosInstance, AxiosError, AxiosResponse, AxiosRequestConfig } from 'axios'\nimport * as AxiosLogger from 'axios-logger'\nimport * as FormData from 'form-data'\nimport { expect } from 'chai'\n\nimport { ApiPayload, ApiResponse, ApiArrayResponse, Error, V2Response, V3Response } from './api.interfaces'\nimport ResourceStore from './resource_store'\nimport * as Logger from './logger'\nimport { nullOrValue } from './utils'\n\nclass Api {\n public axiosInstance: AxiosInstance\n\n private axiosResponseObject: AxiosResponse | AxiosError\n\n private requestPath: string\n\n private requestMethod: string\n\n // We can't add this to the interceptors because we sometimes\n // need to overwrite this\n private readonly defaultHeaders: object\n\n private headers: object\n\n public constructor() {\n const { CUCUMBER_BASE_URL, CUCUMBER_LOGGING_LEVEL } = process.env\n\n this.defaultHeaders = {\n 'content-type': 'application/json',\n }\n this.headers = this.defaultHeaders\n\n this.axiosInstance = Axios.create({\n baseURL: CUCUMBER_BASE_URL,\n timeout: 4000,\n timeoutErrorMessage: `[Fail] Api request timed out. Is the service running on ${CUCUMBER_BASE_URL}`,\n })\n\n this.axiosInstance.interceptors.request.use((config: AxiosRequestConfig) => {\n // eslint-disable-next-line no-param-reassign\n config.headers.accept = 'application/json'\n return config\n })\n\n if (CUCUMBER_LOGGING_LEVEL === 'debug') {\n this.axiosInstance.interceptors.request.use(AxiosLogger.requestLogger)\n this.axiosInstance.interceptors.response.use(AxiosLogger.responseLogger)\n }\n }\n\n private isError(response): response is AxiosError {\n return (<AxiosError>this.axiosResponseObject).isAxiosError !== undefined\n }\n\n public isV3Response(data: V2Response | V3Response): data is V3Response {\n if (this.isError(this.axiosResponseObject)) {\n return false\n }\n\n return <V3Response>data.attributes !== undefined\n }\n\n public IsV2Response(data: V2Response | V3Response): data is V2Response {\n return !this.isV3Response(data)\n }\n\n public get errors(): Array<Error> | Array<any> {\n // Response data is never an array if there's errors\n if (Array.isArray(this.response.data)) {\n Logger.error('Attempted to access errors on an array response')\n return null\n }\n\n return this.response.data.errors\n }\n\n public get response(): ApiResponse | ApiArrayResponse {\n if (this.isError(this.axiosResponseObject)) {\n let status\n\n // Status exists in a different place depending on an API request failure or\n // a general AxiosError\n if (Object.prototype.hasOwnProperty.call(this.axiosResponseObject, 'code')) {\n status = this.axiosResponseObject.code\n } else {\n status = this.axiosResponseObject.response.status\n }\n\n return {\n status: parseInt(status, 10),\n data: this.axiosResponseObject?.response?.data,\n } as ApiResponse\n }\n\n return {\n status: this.axiosResponseObject.status,\n // add everything else from the response\n ...this.axiosResponseObject.data,\n }\n }\n\n public async get(endpoint: string, abortOnError: boolean = true): Promise<void> {\n this.requestPath = endpoint\n this.requestMethod = 'GET'\n\n this.axiosResponseObject = await this.axiosInstance\n .get(endpoint, { headers: this.headers })\n .catch((err) => this.fail(err, abortOnError))\n\n if (!this.isError(this.axiosResponseObject) && !this.isEmpty(this.axiosResponseObject)) {\n ResourceStore.Store(this.axiosResponseObject.data)\n }\n }\n\n public async post(endpoint: string, payload: ApiPayload, abortOnError: boolean = true): Promise<void> {\n this.requestPath = endpoint\n this.requestMethod = 'POST'\n\n this.axiosResponseObject = await this.axiosInstance\n .post(endpoint, payload, { headers: this.headers })\n .catch((err) => this.fail(err, abortOnError))\n\n if (!this.isError(this.axiosResponseObject)) {\n ResourceStore.Store(this.axiosResponseObject.data)\n }\n }\n\n public async form(endpoint: string, form: FormData, abortOnError: boolean = true): Promise<void> {\n this.requestPath = endpoint\n this.requestMethod = 'POST'\n const headers = { ...this.headers, ...form.getHeaders() }\n\n this.axiosResponseObject = await this.axiosInstance\n .post(endpoint, form, { headers })\n .catch((err) => this.fail(err, abortOnError))\n\n if (!this.isError(this.axiosResponseObject)) {\n ResourceStore.Store(this.axiosResponseObject.data)\n }\n }\n\n public async put(endpoint: string, payload: ApiPayload, abortOnError: boolean = true): Promise<void> {\n this.requestPath = endpoint\n this.requestMethod = 'PUT'\n\n this.axiosResponseObject = await this.axiosInstance\n .put(endpoint, payload, { headers: this.headers })\n .catch((err) => this.fail(err, abortOnError))\n }\n\n public async delete(endpoint: string, payload?: ApiPayload, abortOnError: boolean = true): Promise<void> {\n this.requestPath = endpoint\n this.requestMethod = 'DELETE'\n // For some reason, axios delete requests specify the payload and headers in the same object\n const config = {\n ...payload,\n ...{ headers: this.headers },\n }\n\n this.axiosResponseObject = await this.axiosInstance\n .delete(endpoint, config)\n .catch((err) => this.fail(err, abortOnError))\n }\n\n // setHeaders will merge the new headers with the current ones, overwriting if\n // the same key exists. The value will use nullOrValue to properly map strings to literals ('null' => null)\n public setHeaders(newHeaders: object, reset: boolean = false, preserveValueType: boolean = false): void {\n if (reset) {\n this.headers = {}\n }\n\n Object.entries(newHeaders).forEach((h) => {\n let value = h[1]\n if (!preserveValueType) {\n value = nullOrValue(value)\n }\n return Object.assign(this.headers, {\n [h[0]]: value,\n })\n })\n }\n\n public deleteHeader(key: string) {\n delete this.headers[key]\n }\n\n private fail(error: AxiosError, abortOnError: boolean): AxiosError {\n if (abortOnError) {\n this.beautifyError(error)\n expect.fail(error.message)\n }\n\n return error\n }\n\n private beautifyError(error: any): void {\n if (error.response) {\n Logger.error(\n `Failed requesting ${this.requestMethod.toUpperCase()} ${process.env.CTF_BASE_URL}${this.requestPath}`,\n )\n\n if (error.response?.data?.errors !== undefined) {\n Logger.error(error.response?.data?.errors)\n }\n } else {\n Logger.error('[FATAL ERROR]', error, '\\n')\n }\n }\n\n // eslint-disable-next-line class-methods-use-this\n private isEmpty(response: AxiosResponse): boolean {\n if (!response.data) {\n return true\n }\n\n if (Array.isArray(response.data.data)) {\n if (response.data.data.length === 0) {\n return true\n }\n } else if (Object.keys(response.data.data).length === 0) {\n return true\n }\n\n return false\n }\n}\n\nexport default Api\n"]}
@@ -4,13 +4,13 @@ const elasticsearch_1 = require("@elastic/elasticsearch");
4
4
  const Logger = require("./logger");
5
5
  class Elasticsearch {
6
6
  constructor() {
7
- if (!process.env.ELS_URL) {
7
+ if (!process.env.CTF_ELS_URL) {
8
8
  Logger.error('No Elasticsearch URL specified');
9
9
  Logger.error('Please update the .env file to provide an ELS_URL');
10
10
  process.exit(1);
11
11
  }
12
12
  this.elsClient = new elasticsearch_1.Client({
13
- node: process.env.ELS_URL,
13
+ node: process.env.CTF_ELS_URL,
14
14
  });
15
15
  }
16
16
  get client() {
@@ -1 +1 @@
1
- {"version":3,"file":"elasticsearch.js","sourceRoot":"","sources":["../src/elasticsearch.ts"],"names":[],"mappings":";;AAAA,0DAA+C;AAC/C,mCAAkC;AAElC,MAAqB,aAAa;IAGhC;QACE,IAAI,CAAC,OAAO,CAAC,GAAG,CAAC,OAAO,EAAE;YACxB,MAAM,CAAC,KAAK,CAAC,gCAAgC,CAAC,CAAA;YAC9C,MAAM,CAAC,KAAK,CAAC,mDAAmD,CAAC,CAAA;YACjE,OAAO,CAAC,IAAI,CAAC,CAAC,CAAC,CAAA;SAChB;QACD,IAAI,CAAC,SAAS,GAAG,IAAI,sBAAM,CAAC;YAC1B,IAAI,EAAE,OAAO,CAAC,GAAG,CAAC,OAAO;SAC1B,CAAC,CAAA;IACJ,CAAC;IAED,IAAW,MAAM;QACf,OAAO,IAAI,CAAC,SAAS,CAAA;IACvB,CAAC;CACF;AAjBD,gCAiBC","sourcesContent":["import { Client } from '@elastic/elasticsearch'\nimport * as Logger from './logger'\n\nexport default class Elasticsearch {\n private readonly elsClient: Client\n\n public constructor() {\n if (!process.env.ELS_URL) {\n Logger.error('No Elasticsearch URL specified')\n Logger.error('Please update the .env file to provide an ELS_URL')\n process.exit(1)\n }\n this.elsClient = new Client({\n node: process.env.ELS_URL,\n })\n }\n\n public get client() {\n return this.elsClient\n }\n}\n"]}
1
+ {"version":3,"file":"elasticsearch.js","sourceRoot":"","sources":["../src/elasticsearch.ts"],"names":[],"mappings":";;AAAA,0DAA+C;AAC/C,mCAAkC;AAElC,MAAqB,aAAa;IAGhC;QACE,IAAI,CAAC,OAAO,CAAC,GAAG,CAAC,WAAW,EAAE;YAC5B,MAAM,CAAC,KAAK,CAAC,gCAAgC,CAAC,CAAA;YAC9C,MAAM,CAAC,KAAK,CAAC,mDAAmD,CAAC,CAAA;YACjE,OAAO,CAAC,IAAI,CAAC,CAAC,CAAC,CAAA;SAChB;QACD,IAAI,CAAC,SAAS,GAAG,IAAI,sBAAM,CAAC;YAC1B,IAAI,EAAE,OAAO,CAAC,GAAG,CAAC,WAAW;SAC9B,CAAC,CAAA;IACJ,CAAC;IAED,IAAW,MAAM;QACf,OAAO,IAAI,CAAC,SAAS,CAAA;IACvB,CAAC;CACF;AAjBD,gCAiBC","sourcesContent":["import { Client } from '@elastic/elasticsearch'\nimport * as Logger from './logger'\n\nexport default class Elasticsearch {\n private readonly elsClient: Client\n\n public constructor() {\n if (!process.env.CTF_ELS_URL) {\n Logger.error('No Elasticsearch URL specified')\n Logger.error('Please update the .env file to provide an ELS_URL')\n process.exit(1)\n }\n this.elsClient = new Client({\n node: process.env.CTF_ELS_URL,\n })\n }\n\n public get client() {\n return this.elsClient\n }\n}\n"]}
package/lib/logger.d.ts CHANGED
@@ -1,2 +1,2 @@
1
- export declare const debug: (...stuff: any) => void;
2
- export declare const error: (...stuff: any) => void;
1
+ export declare const debug: (...args: any) => void;
2
+ export declare const error: (...args: any) => void;
package/lib/logger.js CHANGED
@@ -2,15 +2,15 @@
2
2
  /* eslint-disable no-console */
3
3
  Object.defineProperty(exports, "__esModule", { value: true });
4
4
  exports.error = exports.debug = void 0;
5
- const debug = (...stuff) => {
6
- if (process.env.LOG_LEVEL !== 'debug') {
5
+ const debug = (...args) => {
6
+ if (process.env.CTF_LOG_LEVEL !== 'debug') {
7
7
  return;
8
8
  }
9
- console.log(stuff);
9
+ console.log(args);
10
10
  };
11
11
  exports.debug = debug;
12
- const error = (...stuff) => {
13
- console.error(...stuff);
12
+ const error = (...args) => {
13
+ console.error(...args);
14
14
  };
15
15
  exports.error = error;
16
16
  //# sourceMappingURL=logger.js.map
package/lib/logger.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"file":"logger.js","sourceRoot":"","sources":["../src/logger.ts"],"names":[],"mappings":";AAAA,+BAA+B;;;AAExB,MAAM,KAAK,GAAG,CAAC,GAAG,KAAU,EAAQ,EAAE;IAC3C,IAAI,OAAO,CAAC,GAAG,CAAC,SAAS,KAAK,OAAO,EAAE;QACrC,OAAM;KACP;IAED,OAAO,CAAC,GAAG,CAAC,KAAK,CAAC,CAAA;AACpB,CAAC,CAAA;AANY,QAAA,KAAK,SAMjB;AAEM,MAAM,KAAK,GAAG,CAAC,GAAG,KAAU,EAAQ,EAAE;IAC3C,OAAO,CAAC,KAAK,CAAC,GAAG,KAAK,CAAC,CAAA;AACzB,CAAC,CAAA;AAFY,QAAA,KAAK,SAEjB","sourcesContent":["/* eslint-disable no-console */\n\nexport const debug = (...stuff: any): void => {\n if (process.env.LOG_LEVEL !== 'debug') {\n return\n }\n\n console.log(stuff)\n}\n\nexport const error = (...stuff: any): void => {\n console.error(...stuff)\n}\n"]}
1
+ {"version":3,"file":"logger.js","sourceRoot":"","sources":["../src/logger.ts"],"names":[],"mappings":";AAAA,+BAA+B;;;AAExB,MAAM,KAAK,GAAG,CAAC,GAAG,IAAS,EAAQ,EAAE;IAC1C,IAAI,OAAO,CAAC,GAAG,CAAC,aAAa,KAAK,OAAO,EAAE;QACzC,OAAM;KACP;IAED,OAAO,CAAC,GAAG,CAAC,IAAI,CAAC,CAAA;AACnB,CAAC,CAAA;AANY,QAAA,KAAK,SAMjB;AAEM,MAAM,KAAK,GAAG,CAAC,GAAG,IAAS,EAAQ,EAAE;IAC1C,OAAO,CAAC,KAAK,CAAC,GAAG,IAAI,CAAC,CAAA;AACxB,CAAC,CAAA;AAFY,QAAA,KAAK,SAEjB","sourcesContent":["/* eslint-disable no-console */\n\nexport const debug = (...args: any): void => {\n if (process.env.CTF_LOG_LEVEL !== 'debug') {\n return\n }\n\n console.log(args)\n}\n\nexport const error = (...args: any): void => {\n console.error(...args)\n}\n"]}
package/lib/mongodb.js CHANGED
@@ -16,14 +16,16 @@ class MongoDB {
16
16
  * Sets up the MongoDB Client
17
17
  */
18
18
  constructor() {
19
- if (!process.env.MONGO_DSN) {
19
+ if (!process.env.CTF_MONGO_DSN) {
20
20
  Logger.error('No Mongo DSN specified');
21
21
  Logger.error('Please update the .env file to provide a MONGO_DSN');
22
22
  process.exit(1);
23
23
  }
24
- this.client = new mongodb_1.MongoClient(process.env.MONGO_DSN, {
25
- serverSelectionTimeoutMS: 4000,
26
- });
24
+ const mongoOptions = {
25
+ serverSelectionTimeoutMS: parseInt(process.env.CTF_MONGO_TIMEOUT, 10) || 4000,
26
+ directConnection: process.env.CTF_MONGO_DIRECT_CONNECTION === 'true',
27
+ };
28
+ this.client = new mongodb_1.MongoClient(process.env.CTF_MONGO_DSN, mongoOptions);
27
29
  }
28
30
  /**
29
31
  * Connects to the Mongo Database.
@@ -41,14 +43,14 @@ class MongoDB {
41
43
  */
42
44
  getAllCollections() {
43
45
  return __awaiter(this, void 0, void 0, function* () {
44
- return this.client.db(process.env.MONGO_DB).collections();
46
+ return this.client.db(process.env.CTF_MONGO_DB).collections();
45
47
  });
46
48
  }
47
49
  /**
48
50
  * Returns a specific Collection.
49
51
  */
50
52
  collection(name) {
51
- return this.client.db(process.env.MONGO_DB).collection(name);
53
+ return this.client.db(process.env.CTF_MONGO_DB).collection(name);
52
54
  }
53
55
  /**
54
56
  * Closes the MongoDB connection.
@@ -1 +1 @@
1
- {"version":3,"file":"mongodb.js","sourceRoot":"","sources":["../src/mongodb.ts"],"names":[],"mappings":";;;;;;;;;;;AAAA,qCAAqC;AAErC,mCAAkC;AAElC,MAAqB,OAAO;IAG1B;;OAEG;IACH;QACE,IAAI,CAAC,OAAO,CAAC,GAAG,CAAC,SAAS,EAAE;YAC1B,MAAM,CAAC,KAAK,CAAC,wBAAwB,CAAC,CAAA;YACtC,MAAM,CAAC,KAAK,CAAC,oDAAoD,CAAC,CAAA;YAClE,OAAO,CAAC,IAAI,CAAC,CAAC,CAAC,CAAA;SAChB;QAED,IAAI,CAAC,MAAM,GAAG,IAAI,qBAAW,CAAC,OAAO,CAAC,GAAG,CAAC,SAAS,EAAE;YACnD,wBAAwB,EAAE,IAAI;SAC/B,CAAC,CAAA;IACJ,CAAC;IAED;;OAEG;IACU,OAAO;;YAClB,MAAM,IAAI,CAAC,MAAM,CAAC,OAAO,EAAE,CAAC,KAAK,CAAC,CAAC,CAAC,EAAE,EAAE;gBACtC,MAAM,CAAC,KAAK,CAAC,+BAA+B,EAAE,CAAC,CAAC,CAAA;gBAChD,OAAO,CAAC,IAAI,CAAC,CAAC,CAAC,CAAA;YACjB,CAAC,CAAC,CAAA;QACJ,CAAC;KAAA;IAED;;OAEG;IACU,iBAAiB;;YAC5B,OAAO,IAAI,CAAC,MAAM,CAAC,EAAE,CAAC,OAAO,CAAC,GAAG,CAAC,QAAQ,CAAC,CAAC,WAAW,EAAE,CAAA;QAC3D,CAAC;KAAA;IAED;;OAEG;IACI,UAAU,CAAC,IAAY;QAC5B,OAAO,IAAI,CAAC,MAAM,CAAC,EAAE,CAAC,OAAO,CAAC,GAAG,CAAC,QAAQ,CAAC,CAAC,UAAU,CAAC,IAAI,CAAC,CAAA;IAC9D,CAAC;IAED;;;OAGG;IACU,KAAK;;YAChB,MAAM,IAAI,CAAC,MAAM,CAAC,KAAK,EAAE,CAAA;QAC3B,CAAC;KAAA;CACF;AAjDD,0BAiDC","sourcesContent":["import { MongoClient } from 'mongodb'\nimport type { Collection } from 'mongodb'\nimport * as Logger from './logger'\n\nexport default class MongoDB {\n private client: MongoClient\n\n /**\n * Sets up the MongoDB Client\n */\n public constructor() {\n if (!process.env.MONGO_DSN) {\n Logger.error('No Mongo DSN specified')\n Logger.error('Please update the .env file to provide a MONGO_DSN')\n process.exit(1)\n }\n\n this.client = new MongoClient(process.env.MONGO_DSN, {\n serverSelectionTimeoutMS: 4000,\n })\n }\n\n /**\n * Connects to the Mongo Database.\n */\n public async connect(): Promise<void> {\n await this.client.connect().catch((e) => {\n Logger.error('Could not connect to MongoDB:', e)\n process.exit(1)\n })\n }\n\n /**\n * Returns all MongoDB Collections.\n */\n public async getAllCollections(): Promise<Collection<any>[]> {\n return this.client.db(process.env.MONGO_DB).collections()\n }\n\n /**\n * Returns a specific Collection.\n */\n public collection(name: string): Collection {\n return this.client.db(process.env.MONGO_DB).collection(name)\n }\n\n /**\n * Closes the MongoDB connection.\n * @return Promise<void>\n */\n public async close(): Promise<void> {\n await this.client.close()\n }\n}\n"]}
1
+ {"version":3,"file":"mongodb.js","sourceRoot":"","sources":["../src/mongodb.ts"],"names":[],"mappings":";;;;;;;;;;;AAAA,qCAAyD;AAEzD,mCAAkC;AAElC,MAAqB,OAAO;IAG1B;;OAEG;IACH;QACE,IAAI,CAAC,OAAO,CAAC,GAAG,CAAC,aAAa,EAAE;YAC9B,MAAM,CAAC,KAAK,CAAC,wBAAwB,CAAC,CAAA;YACtC,MAAM,CAAC,KAAK,CAAC,oDAAoD,CAAC,CAAA;YAClE,OAAO,CAAC,IAAI,CAAC,CAAC,CAAC,CAAA;SAChB;QAED,MAAM,YAAY,GAAuB;YACvC,wBAAwB,EAAE,QAAQ,CAAC,OAAO,CAAC,GAAG,CAAC,iBAAiB,EAAE,EAAE,CAAC,IAAI,IAAI;YAC7E,gBAAgB,EAAE,OAAO,CAAC,GAAG,CAAC,2BAA2B,KAAK,MAAM;SACrE,CAAA;QAED,IAAI,CAAC,MAAM,GAAG,IAAI,qBAAW,CAAC,OAAO,CAAC,GAAG,CAAC,aAAa,EAAE,YAAY,CAAC,CAAA;IACxE,CAAC;IAED;;OAEG;IACU,OAAO;;YAClB,MAAM,IAAI,CAAC,MAAM,CAAC,OAAO,EAAE,CAAC,KAAK,CAAC,CAAC,CAAC,EAAE,EAAE;gBACtC,MAAM,CAAC,KAAK,CAAC,+BAA+B,EAAE,CAAC,CAAC,CAAA;gBAChD,OAAO,CAAC,IAAI,CAAC,CAAC,CAAC,CAAA;YACjB,CAAC,CAAC,CAAA;QACJ,CAAC;KAAA;IAED;;OAEG;IACU,iBAAiB;;YAC5B,OAAO,IAAI,CAAC,MAAM,CAAC,EAAE,CAAC,OAAO,CAAC,GAAG,CAAC,YAAY,CAAC,CAAC,WAAW,EAAE,CAAA;QAC/D,CAAC;KAAA;IAED;;OAEG;IACI,UAAU,CAAC,IAAY;QAC5B,OAAO,IAAI,CAAC,MAAM,CAAC,EAAE,CAAC,OAAO,CAAC,GAAG,CAAC,YAAY,CAAC,CAAC,UAAU,CAAC,IAAI,CAAC,CAAA;IAClE,CAAC;IAED;;;OAGG;IACU,KAAK;;YAChB,MAAM,IAAI,CAAC,MAAM,CAAC,KAAK,EAAE,CAAA;QAC3B,CAAC;KAAA;CACF;AApDD,0BAoDC","sourcesContent":["import { MongoClient, MongoClientOptions } from 'mongodb'\nimport type { Collection } from 'mongodb'\nimport * as Logger from './logger'\n\nexport default class MongoDB {\n private client: MongoClient\n\n /**\n * Sets up the MongoDB Client\n */\n public constructor() {\n if (!process.env.CTF_MONGO_DSN) {\n Logger.error('No Mongo DSN specified')\n Logger.error('Please update the .env file to provide a MONGO_DSN')\n process.exit(1)\n }\n\n const mongoOptions: MongoClientOptions = {\n serverSelectionTimeoutMS: parseInt(process.env.CTF_MONGO_TIMEOUT, 10) || 4000,\n directConnection: process.env.CTF_MONGO_DIRECT_CONNECTION === 'true',\n }\n\n this.client = new MongoClient(process.env.CTF_MONGO_DSN, mongoOptions)\n }\n\n /**\n * Connects to the Mongo Database.\n */\n public async connect(): Promise<void> {\n await this.client.connect().catch((e) => {\n Logger.error('Could not connect to MongoDB:', e)\n process.exit(1)\n })\n }\n\n /**\n * Returns all MongoDB Collections.\n */\n public async getAllCollections(): Promise<Collection<any>[]> {\n return this.client.db(process.env.CTF_MONGO_DB).collections()\n }\n\n /**\n * Returns a specific Collection.\n */\n public collection(name: string): Collection {\n return this.client.db(process.env.CTF_MONGO_DB).collection(name)\n }\n\n /**\n * Closes the MongoDB connection.\n * @return Promise<void>\n */\n public async close(): Promise<void> {\n await this.client.close()\n }\n}\n"]}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@elasticpath/component-test-framework",
3
- "version": "1.0.0",
3
+ "version": "1.0.2",
4
4
  "description": "A framework for component tests written using ts-flow",
5
5
  "main": "./lib/index.js",
6
6
  "directories": {
@@ -11,9 +11,10 @@
11
11
  ],
12
12
  "engines": {
13
13
  "npm": "Please use Yarn",
14
- "yarn": "^1.22.19",
15
- "node": "^16.15.0"
14
+ "yarn": ">=1.22.19",
15
+ "node": ">=16.15.0"
16
16
  },
17
+ "private": false,
17
18
  "scripts": {
18
19
  "test": "./node_modules/.bin/mocha tests/*.ts",
19
20
  "lint": "./node_modules/.bin/eslint src/**/*.ts --max-warnings 0",