suitest-js-api 3.6.0 → 3.7.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.
@@ -58,6 +58,11 @@ const KEY = {
58
58
  UP_ARROW: '[[Up arrow]]',
59
59
  SEARCH: '[[Search]]',
60
60
  DONE: '[[Done]]',
61
+ UP: '[[Up]]',
62
+ DOWN: '[[Down]]',
63
+ LEFT: '[[Left]]',
64
+ RIGHT: '[[Right]]',
65
+ OK: '[[Ok]]',
61
66
  };
62
67
 
63
68
  Object.freeze(KEY);
@@ -43,10 +43,21 @@ const builder = yargs => {
43
43
  describe: 'Will launch user command with --inspect-brk execArgv, used for debugging',
44
44
  global: false,
45
45
  })
46
+ .option('override-config-file', {
47
+ describe: 'Specifies an additional config file which properties have precedence over properties in a standard configuration file.',
48
+ global: false,
49
+ type: 'string',
50
+ })
51
+ .option('base-config-file', {
52
+ describe: 'Path to a config file to override standard configuration files. Standard configuration files are ignored.',
53
+ global: false,
54
+ type: 'string',
55
+ })
46
56
  .option('config-file', {
47
57
  describe: texts.cliConfig(),
48
58
  global: false,
49
59
  type: 'string',
60
+ deprecate: 'Can have unexpected behaviour. Use --base-config-file or --override-config-file.',
50
61
  })
51
62
  .option('default-timeout', {
52
63
  describe: texts.defaultTimeout(),
@@ -58,9 +58,17 @@ const DEFAULT_PATHS = [
58
58
  * @param {String} filePath path to file
59
59
  */
60
60
  function readConfigFile(filePath) {
61
+ const extension = path.extname(filePath);
62
+ if (extension === '.js') {
63
+ if (!path.isAbsolute(filePath)) {
64
+ // ensure correct handling of relative paths, we want to prevent searching in __dirname
65
+ filePath = path.join(process.cwd(), filePath);
66
+ }
67
+ return require(filePath);
68
+ }
61
69
  const fileContent = fs.readFileSync(filePath, 'utf8');
62
70
 
63
- switch (path.extname(filePath)) {
71
+ switch (extension) {
64
72
  case '.yaml':
65
73
  case '.yml':
66
74
  return yaml.load(fileContent);
@@ -68,8 +76,8 @@ function readConfigFile(filePath) {
68
76
  return JSON5.parse(fileContent);
69
77
  case '.ini':
70
78
  return ini.parse(fileContent);
71
- case '.js':
72
- return require(filePath);
79
+ case '.json':
80
+ return JSON.parse(fileContent);
73
81
  default:
74
82
  try {
75
83
  return JSON.parse(fileContent);
@@ -158,6 +166,7 @@ function findConfigUpToRoot(pathToSearch, filename) {
158
166
  * Searches for 'extends' property for other config file and if presents merge them.
159
167
  * cli arguments are not parsed.
160
168
  * If file found, but json invalid, throw error.
169
+ * @param {string} [pathToConfig] expicit path to configuration file
161
170
  * @returns {Object}
162
171
  */
163
172
  function readRcConfig(pathToConfig) {
@@ -170,9 +179,6 @@ function readRcConfig(pathToConfig) {
170
179
  .filter(defaultConfig => IS_WINDOWS ? defaultConfig.isGeneral : true);
171
180
 
172
181
  for (const defaultConfig of defaultConfigurations) {
173
- if (mainConfigFilePath) {
174
- break;
175
- }
176
182
  if (
177
183
  fs.existsSync(defaultConfig.path) &&
178
184
  fs.lstatSync(defaultConfig.path).isDirectory()
@@ -181,6 +187,9 @@ function readRcConfig(pathToConfig) {
181
187
  defaultConfig.deepSearch ?
182
188
  findConfigUpToRoot :
183
189
  findConfig)(defaultConfig.path, defaultConfig.filename);
190
+ if (mainConfigFilePath) {
191
+ break;
192
+ }
184
193
  }
185
194
  }
186
195
  }
@@ -210,14 +219,14 @@ function readRcConfig(pathToConfig) {
210
219
  }
211
220
 
212
221
  /**
213
- * Read json config file provided by user.
222
+ * Read config file provided by user.
214
223
  * @param {string} path - path to config file
215
224
  * @throws {SuitestError}
216
- * @returns {Object} - parsed json
225
+ * @returns {Object} - parsed config file
217
226
  */
218
227
  function readUserConfig(path) {
219
228
  try {
220
- return JSON.parse(fs.readFileSync(path));
229
+ return readConfigFile(path);
221
230
  } catch (error) {
222
231
  throw new SuitestError(invalidUserConfig(path, error.message), error.code);
223
232
  }
@@ -229,8 +238,20 @@ function readUserConfig(path) {
229
238
  * @returns {{ownArgs: Object, userCommandArgs: string[]}}
230
239
  */
231
240
  const composeConfig = (argv) => {
232
- const rcConfig = readRcConfig(argv.configFile);
233
- const configFilePath = argv.configFile || rcConfig.configFile;
241
+ if (argv.configFile) {
242
+ console.warn('Warning: You are using deprecated argument --config-file. Please use --override-config-file or --base-config-file instead.');
243
+ if (argv.baseConfigFile || argv.overrideConfigFile) {
244
+ throw new SuitestError('Combination of deprecated --config-file with either --base-config-file or --override-config-file is not allowed');
245
+ }
246
+ }
247
+ const rcConfig = readRcConfig(argv.baseConfigFile || argv.configFile);
248
+ if (rcConfig.configFile) {
249
+ console.warn('Warning: You are using deprecated option configFile. Please use overrideConfigFile instead.');
250
+ }
251
+ if ((argv.configFile || rcConfig.configFile) && (argv.baseConfigFile || argv.overrideConfigFile || rcConfig.overrideConfigFile)) {
252
+ throw new SuitestError('Combination of deprecated configFile with --base-config-file or --override-config-file or overrideConfigFile is not allowed');
253
+ }
254
+ const configFilePath = argv.overrideConfigFile || rcConfig.overrideConfigFile || argv.configFile || rcConfig.configFile;
234
255
  const userConfig = configFilePath ? readUserConfig(configFilePath) : {};
235
256
 
236
257
  const ownArgs = {
package/lib/texts.js CHANGED
@@ -41,7 +41,7 @@ module.exports = {
41
41
  invalidInputMessage: (methodName, field) =>
42
42
  `provided for .${methodName} function.` + (field ? ` ${field}` : ''),
43
43
  invalidConfigObj: () => 'provided for configuration object.',
44
- invalidUserConfig: template`Failed to process config file '${0}'.\n\t${1}.\n\tMake sure path is correct and file is in valid json format.`,
44
+ invalidUserConfig: template`Failed to process config file '${0}'.\n\t${1}.\n\tMake sure path is correct and file is in valid format.`,
45
45
  circularDependencyError: (path) => `Circular dependency found on ${path} path.`,
46
46
 
47
47
  // WebSockets errors
@@ -362,6 +362,7 @@ schemas[validationKeys.CONFIGURE] = {
362
362
  'properties': {
363
363
  'appConfigId': {'type': 'string'},
364
364
  'concurrency': {'type': 'number'},
365
+ 'overrideConfigFile': {'type': 'string'},
365
366
  'configFile': {'type': 'string'},
366
367
  'deviceId': {'type': 'string'},
367
368
  'disallowCrashReports': {'type': 'boolean'},
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "suitest-js-api",
3
- "version": "3.6.0",
3
+ "version": "3.7.0",
4
4
  "main": "index.js",
5
5
  "repository": "git@github.com:SuitestAutomation/suitest-js-api.git",
6
6
  "author": "Suitest <hello@suite.st>",
@@ -56,4 +56,4 @@ interface ApplicationAbandonedChain extends
56
56
  {}
57
57
 
58
58
  type ApplicationQueryResult = string;
59
- type ApplicationEvalResult = boolean | void;
59
+ type ApplicationEvalResult = boolean | undefined;
@@ -75,4 +75,4 @@ interface BrightScriptExpressionAbandonedChain extends
75
75
  {}
76
76
 
77
77
  type BrightScriptExpressionQueryResult = string;
78
- type BrightScriptExpressionEvalResult = boolean | void;
78
+ type BrightScriptExpressionEvalResult = boolean | undefined;
@@ -10,4 +10,4 @@ export interface ClearAppDataChain extends
10
10
 
11
11
  interface ClearAppDataAbandonedChain extends AbstractChain {}
12
12
 
13
- type ClearAppDataEvalResult = void | boolean;
13
+ type ClearAppDataEvalResult = undefined | boolean;
@@ -9,4 +9,4 @@ export interface CloseAppChain extends
9
9
 
10
10
  interface CloseAppAbandonedChain extends AbstractChain {}
11
11
 
12
- type CloseAppEvalResult = void | boolean;
12
+ type CloseAppEvalResult = undefined | boolean;
@@ -71,5 +71,5 @@ interface CookieEvalModifiers<T> extends
71
71
 
72
72
  interface CookieAbandonedChain extends AbstractChain {}
73
73
 
74
- type CookieQueryResult = string | void;
75
- type CookieEvalResult = boolean | void;
74
+ type CookieQueryResult = string | undefined;
75
+ type CookieEvalResult = boolean | undefined;
@@ -151,5 +151,5 @@ interface ElementBaseEvalChain<TSelf> extends
151
151
 
152
152
  interface ElementAbandonedChain extends AbstractChain {}
153
153
 
154
- type ElementQueryResult = ElementProps | void;
155
- type ElementEvalResult = boolean | void;
154
+ type ElementQueryResult = ElementProps | undefined;
155
+ type ElementEvalResult = boolean | undefined;
@@ -9,4 +9,4 @@ export interface ExecuteBrightScriptChain extends
9
9
 
10
10
  interface ExecuteBrightScriptAbandonedChain extends AbstractChain {}
11
11
 
12
- type ExecuteBrightScriptEvalResult = boolean | void;
12
+ type ExecuteBrightScriptEvalResult = boolean | undefined;
@@ -9,4 +9,4 @@ export interface ExecuteCommandChain extends
9
9
 
10
10
  interface ExecuteCommandAbandonedChain extends AbstractChain {}
11
11
 
12
- type ExecuteCommandEvalResult = boolean | void;
12
+ type ExecuteCommandEvalResult = boolean | undefined;
@@ -75,4 +75,4 @@ interface JsExpressionAbandonedChain extends
75
75
  {}
76
76
 
77
77
  type JsExpressionQueryResult = string;
78
- type JsExpressionEvalResult = boolean | void;
78
+ type JsExpressionEvalResult = boolean | undefined;
@@ -77,4 +77,4 @@ interface LocationAbandonedChain extends
77
77
  {}
78
78
 
79
79
  type LocationQueryResult = string;
80
- type LocationEvalResult = boolean | void;
80
+ type LocationEvalResult = boolean | undefined;
@@ -35,4 +35,4 @@ interface NetworkRequestEvalChain<T> extends
35
35
 
36
36
  interface NetworkRequestAbandonedChain extends AbstractChain {}
37
37
 
38
- type NetworkRequestEvalResult = boolean | void;
38
+ type NetworkRequestEvalResult = boolean | undefined;
@@ -13,4 +13,4 @@ export interface OpenAppChain extends
13
13
 
14
14
  interface OpenAppAbandonedChain extends AbstractChain {}
15
15
 
16
- type OpenAppEvalResult = void | boolean;
16
+ type OpenAppEvalResult = undefined | boolean;
@@ -9,4 +9,4 @@ export interface OpenUrlChain extends
9
9
 
10
10
  interface OpenUrlAbandonedChain extends AbstractChain {}
11
11
 
12
- type OpenUrlEvalResult = void | boolean;
12
+ type OpenUrlEvalResult = undefined | boolean;
@@ -47,5 +47,5 @@ interface PlayStationVideoBaseEvalChain<TSelf> extends
47
47
 
48
48
  interface PlayStationVideoAbandonedChain extends AbstractChain {}
49
49
 
50
- type PlayStationVideoQueryResult = PlayStationVideoProps | void;
51
- type PlayStationVideoEvalResult = boolean | void;
50
+ type PlayStationVideoQueryResult = PlayStationVideoProps | undefined;
51
+ type PlayStationVideoEvalResult = boolean | undefined;
@@ -9,4 +9,4 @@ export interface PollUrlChain extends
9
9
 
10
10
  interface PollUrlAbandonedChain extends AbstractChain {}
11
11
 
12
- type PollUrlEvalResult = void | boolean;
12
+ type PollUrlEvalResult = undefined | boolean;
@@ -52,4 +52,4 @@ interface PositionEmptyChain extends PositionBaseEvalChain<PositionEmptyChain> {
52
52
  interface PositionAbandonedChain extends AbstractChain {}
53
53
 
54
54
  type PositionQueryResult = string;
55
- type PositionEvalResult = boolean | void;
55
+ type PositionEvalResult = boolean | undefined;
@@ -38,4 +38,4 @@ interface PressButtonEmptyChain extends PressButtonBaseEvalChain<PressButtonEmpt
38
38
  interface PressButtonAbandonedChain extends AbstractChain {}
39
39
 
40
40
  type PressButtonQueryResult = string;
41
- type PressButtonEvalResult = boolean | void;
41
+ type PressButtonEvalResult = boolean | undefined;
@@ -45,4 +45,4 @@ interface RelativePositionEmptyChain extends RelativePositionBaseEvalChain<Relat
45
45
  interface RelativePositionAbandonedChain extends AbstractChain {}
46
46
 
47
47
  type RelativePositionQueryResult = string;
48
- type RelativePositionEvalResult = boolean | void;
48
+ type RelativePositionEvalResult = boolean | undefined;
@@ -9,4 +9,4 @@ export interface SleepChain extends
9
9
 
10
10
  interface SleepAbandonedChain extends AbstractChain {}
11
11
 
12
- type SleepEvalResult = void | boolean;
12
+ type SleepEvalResult = undefined | boolean;
@@ -9,4 +9,4 @@ export interface SuspendAppChain extends
9
9
 
10
10
  interface SuspendAppAbandonedChain extends AbstractChain {}
11
11
 
12
- type SuspendAppEvalResult = void | boolean;
12
+ type SuspendAppEvalResult = undefined | boolean;
@@ -88,5 +88,5 @@ interface VideoBaseEvalChain<TSelf> extends
88
88
 
89
89
  interface VideoAbandonedChain extends AbstractChain {}
90
90
 
91
- type VideoQueryResult = ElementProps | void;
92
- type VideoEvalResult = boolean | void;
91
+ type VideoQueryResult = ElementProps | undefined;
92
+ type VideoEvalResult = boolean | undefined;
@@ -54,4 +54,4 @@ interface WindowEmptyChain extends WindowBaseEvalChain<WindowEmptyChain> {}
54
54
  interface WindowAbandonedChain extends AbstractChain {}
55
55
 
56
56
  type WindowQueryResult = string;
57
- type WindowEvalResult = boolean | void;
57
+ type WindowEvalResult = boolean | undefined;
@@ -57,4 +57,9 @@ export type Keys = {
57
57
  UP_ARROW: '[[Up arrow]]',
58
58
  SEARCH: '[[Search]]',
59
59
  DONE: '[[Done]]',
60
+ UP: '[[Up]]',
61
+ DOWN: '[[Down]]',
62
+ LEFT: '[[Left]]',
63
+ RIGHT: '[[Right]]',
64
+ OK: '[[Ok]]',
60
65
  }