testit-js-commons 2.1.2 → 2.1.4

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.
@@ -55,7 +55,14 @@ var Utils;
55
55
  }
56
56
  Utils.generateFileName = generateFileName;
57
57
  function readFile(path) {
58
- return fs_1.default.readFileSync(path).toString();
58
+ let fileContents;
59
+ try {
60
+ fileContents = fs_1.default.readFileSync(path).toString();
61
+ }
62
+ catch (err) {
63
+ fileContents = "";
64
+ }
65
+ return fileContents;
59
66
  }
60
67
  Utils.readFile = readFile;
61
68
  function writeFile(path, content) {
@@ -3,5 +3,8 @@ import { IConfigComposer } from "./config.type";
3
3
  export declare const DEFAULT_CONFIG_FILE = "tms.config.json";
4
4
  export declare class ConfigComposer implements IConfigComposer {
5
5
  compose(base?: Partial<AdapterConfig>): AdapterConfig;
6
- merge(file: AdapterConfig, env?: Partial<EnvironmentOptions>, base?: Partial<AdapterConfig>): AdapterConfig;
6
+ mergeAll(file: AdapterConfig, env?: Partial<EnvironmentOptions>, base?: Partial<AdapterConfig>): AdapterConfig;
7
+ merge(env?: Partial<EnvironmentOptions>, base?: Partial<AdapterConfig>): AdapterConfig;
8
+ private resolveAllProperties;
9
+ private resolveProperties;
7
10
  }
@@ -32,28 +32,68 @@ class ConfigComposer {
32
32
  var _a;
33
33
  const environment = parseEnvConfig();
34
34
  const content = common_1.Utils.readFile((_a = environment === null || environment === void 0 ? void 0 : environment.TMS_CONFIG_FILE) !== null && _a !== void 0 ? _a : exports.DEFAULT_CONFIG_FILE);
35
- const config = JSON.parse(content);
36
- if (config.privateToken) {
37
- console.warn(`
35
+ if (content !== "") {
36
+ const config = JSON.parse(content);
37
+ if (config.privateToken) {
38
+ console.warn(`
38
39
  The configuration file specifies a private token. It is not safe.
39
- Use TMS_PRIVATE_TOKEN environment variable
40
- `);
40
+ Use TMS_PRIVATE_TOKEN environment variable`);
41
+ }
42
+ return this.mergeAll(config, environment, base);
41
43
  }
42
- return this.merge(config, environment, base);
44
+ return this.merge(environment, base);
43
45
  }
44
- merge(file, env, base) {
45
- var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k, _l, _m, _o, _p, _q, _r, _s, _t;
46
+ mergeAll(file, env, base) {
47
+ var _a, _b, _c, _d, _e, _f;
46
48
  return {
47
- url: (_b = (_a = base === null || base === void 0 ? void 0 : base.url) !== null && _a !== void 0 ? _a : env === null || env === void 0 ? void 0 : env.TMS_URL) !== null && _b !== void 0 ? _b : file.url,
48
- projectId: (_d = (_c = base === null || base === void 0 ? void 0 : base.projectId) !== null && _c !== void 0 ? _c : env === null || env === void 0 ? void 0 : env.TMS_PROJECT_ID) !== null && _d !== void 0 ? _d : file.projectId,
49
- testRunId: (_f = (_e = base === null || base === void 0 ? void 0 : base.testRunId) !== null && _e !== void 0 ? _e : env === null || env === void 0 ? void 0 : env.TMS_TEST_RUN_ID) !== null && _f !== void 0 ? _f : file.testRunId,
50
- testRunName: (_h = (_g = base === null || base === void 0 ? void 0 : base.testRunName) !== null && _g !== void 0 ? _g : env === null || env === void 0 ? void 0 : env.TMS_TEST_RUN_NAME) !== null && _h !== void 0 ? _h : file.testRunName,
51
- privateToken: (_k = (_j = base === null || base === void 0 ? void 0 : base.privateToken) !== null && _j !== void 0 ? _j : env === null || env === void 0 ? void 0 : env.TMS_PRIVATE_TOKEN) !== null && _k !== void 0 ? _k : file.privateToken,
52
- adapterMode: (_o = (_m = (_l = base === null || base === void 0 ? void 0 : base.adapterMode) !== null && _l !== void 0 ? _l : env === null || env === void 0 ? void 0 : env.TMS_ADAPTER_MODE) !== null && _m !== void 0 ? _m : file.adapterMode) !== null && _o !== void 0 ? _o : 0,
53
- configurationId: (_q = (_p = base === null || base === void 0 ? void 0 : base.configurationId) !== null && _p !== void 0 ? _p : env === null || env === void 0 ? void 0 : env.TMS_CONFIGURATION_ID) !== null && _q !== void 0 ? _q : file.configurationId,
54
- automaticCreationTestCases: (_t = (_s = (_r = base === null || base === void 0 ? void 0 : base.automaticCreationTestCases) !== null && _r !== void 0 ? _r : env === null || env === void 0 ? void 0 : env.TMS_AUTOMATIC_CREATION_TEST_CASES) !== null && _s !== void 0 ? _s : file.automaticCreationTestCases) !== null && _t !== void 0 ? _t : false,
49
+ url: this.resolveAllProperties(file.url, env === null || env === void 0 ? void 0 : env.TMS_URL, base === null || base === void 0 ? void 0 : base.url),
50
+ projectId: this.resolveAllProperties(file.projectId, env === null || env === void 0 ? void 0 : env.TMS_PROJECT_ID, base === null || base === void 0 ? void 0 : base.projectId),
51
+ testRunId: this.resolveAllProperties(file.testRunId, env === null || env === void 0 ? void 0 : env.TMS_TEST_RUN_ID, base === null || base === void 0 ? void 0 : base.testRunId),
52
+ testRunName: this.resolveAllProperties(file.testRunName, env === null || env === void 0 ? void 0 : env.TMS_TEST_RUN_NAME, base === null || base === void 0 ? void 0 : base.testRunName) == "" ? undefined : this.resolveAllProperties(file.testRunName, env === null || env === void 0 ? void 0 : env.TMS_TEST_RUN_NAME, base === null || base === void 0 ? void 0 : base.testRunName),
53
+ privateToken: this.resolveAllProperties(file.privateToken, env === null || env === void 0 ? void 0 : env.TMS_PRIVATE_TOKEN, base === null || base === void 0 ? void 0 : base.privateToken),
54
+ adapterMode: (_c = (_b = (_a = file.adapterMode) !== null && _a !== void 0 ? _a : env === null || env === void 0 ? void 0 : env.TMS_ADAPTER_MODE) !== null && _b !== void 0 ? _b : base === null || base === void 0 ? void 0 : base.adapterMode) !== null && _c !== void 0 ? _c : 0,
55
+ configurationId: this.resolveAllProperties(file.configurationId, env === null || env === void 0 ? void 0 : env.TMS_CONFIGURATION_ID, base === null || base === void 0 ? void 0 : base.configurationId),
56
+ automaticCreationTestCases: (_f = (_e = (_d = file.automaticCreationTestCases) !== null && _d !== void 0 ? _d : env === null || env === void 0 ? void 0 : env.TMS_AUTOMATIC_CREATION_TEST_CASES) !== null && _e !== void 0 ? _e : base === null || base === void 0 ? void 0 : base.automaticCreationTestCases) !== null && _f !== void 0 ? _f : false,
55
57
  };
56
58
  }
59
+ merge(env, base) {
60
+ var _a, _b, _c, _d;
61
+ return {
62
+ url: this.resolveProperties(env === null || env === void 0 ? void 0 : env.TMS_URL, base === null || base === void 0 ? void 0 : base.url),
63
+ projectId: this.resolveProperties(env === null || env === void 0 ? void 0 : env.TMS_PROJECT_ID, base === null || base === void 0 ? void 0 : base.projectId),
64
+ testRunId: this.resolveProperties(env === null || env === void 0 ? void 0 : env.TMS_TEST_RUN_ID, base === null || base === void 0 ? void 0 : base.testRunId),
65
+ testRunName: this.resolveProperties(env === null || env === void 0 ? void 0 : env.TMS_TEST_RUN_NAME, base === null || base === void 0 ? void 0 : base.testRunName) == "" ? undefined : this.resolveProperties(env === null || env === void 0 ? void 0 : env.TMS_TEST_RUN_NAME, base === null || base === void 0 ? void 0 : base.testRunName),
66
+ privateToken: this.resolveProperties(env === null || env === void 0 ? void 0 : env.TMS_PRIVATE_TOKEN, base === null || base === void 0 ? void 0 : base.privateToken),
67
+ adapterMode: (_b = (_a = base === null || base === void 0 ? void 0 : base.adapterMode) !== null && _a !== void 0 ? _a : env === null || env === void 0 ? void 0 : env.TMS_ADAPTER_MODE) !== null && _b !== void 0 ? _b : 0,
68
+ configurationId: this.resolveProperties(env === null || env === void 0 ? void 0 : env.TMS_CONFIGURATION_ID, base === null || base === void 0 ? void 0 : base.configurationId),
69
+ automaticCreationTestCases: (_d = (_c = env === null || env === void 0 ? void 0 : env.TMS_AUTOMATIC_CREATION_TEST_CASES) !== null && _c !== void 0 ? _c : base === null || base === void 0 ? void 0 : base.automaticCreationTestCases) !== null && _d !== void 0 ? _d : false,
70
+ };
71
+ }
72
+ resolveAllProperties(file, env, base) {
73
+ if (base && base.trim()) {
74
+ return base;
75
+ }
76
+ else if (env && env.trim()) {
77
+ return env;
78
+ }
79
+ else if (file && file.trim()) {
80
+ return file;
81
+ }
82
+ else {
83
+ return "";
84
+ }
85
+ }
86
+ resolveProperties(env, base) {
87
+ if (base && base.trim()) {
88
+ return base;
89
+ }
90
+ else if (env && env.trim()) {
91
+ return env;
92
+ }
93
+ else {
94
+ return "";
95
+ }
96
+ }
57
97
  }
58
98
  exports.ConfigComposer = ConfigComposer;
59
99
  function parseEnvConfig() {
@@ -1,5 +1,6 @@
1
1
  import { AdapterConfig, EnvironmentOptions } from "../../common";
2
2
  export interface IConfigComposer {
3
3
  compose(base?: Partial<AdapterConfig>): AdapterConfig;
4
- merge(file: AdapterConfig, env?: Partial<EnvironmentOptions>, base?: Partial<AdapterConfig>): AdapterConfig;
4
+ mergeAll(file: AdapterConfig, env?: Partial<EnvironmentOptions>, base?: Partial<AdapterConfig>): AdapterConfig;
5
+ merge(env?: Partial<EnvironmentOptions>, base?: Partial<AdapterConfig>): AdapterConfig;
5
6
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "testit-js-commons",
3
- "version": "2.1.2",
3
+ "version": "2.1.4",
4
4
  "description": "JavaScript commons for Test IT",
5
5
  "main": "lib/index.js",
6
6
  "types": "lib/index.d.ts",