@wdio/logger 7.0.0-beta.1 → 7.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/build/index.d.ts CHANGED
@@ -1,3 +1,6 @@
1
+ /**
2
+ * environment check to allow to use this package in a web context
3
+ */
1
4
  declare let mode: any;
2
5
  export default mode;
3
6
  //# sourceMappingURL=index.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAOA,QAAA,IAAI,IAAI,KAA2B,CAAA;AAcnC,eAAe,IAAI,CAAA"}
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAEA;;GAEG;AAGH,QAAA,IAAI,IAAI,KAA2B,CAAA;AAcnC,eAAe,IAAI,CAAA"}
package/build/index.js CHANGED
@@ -1,8 +1,21 @@
1
1
  "use strict";
2
+ /* istanbul ignore file */
2
3
  Object.defineProperty(exports, "__esModule", { value: true });
4
+ /**
5
+ * environment check to allow to use this package in a web context
6
+ */
7
+ // By default, import the web code using a literal require, so that in webpack
8
+ // contexts, it will always be bundled
3
9
  let mode = require('./web').default;
10
+ // Then, if we're in a Node.js context, require the node version of this module
11
+ // using a variable, so that it will _not_ be included in a bundle, either
12
+ // during compilation or execution
4
13
  if (typeof process !== 'undefined' && typeof process.release !== 'undefined' && process.release.name === 'node') {
5
14
  const nodeMode = './node';
6
15
  mode = require(nodeMode).default;
7
16
  }
17
+ // The net result will be that in a Node context, we'll have required both
18
+ // files but will use the correct one, and in the web context, we'll have only
19
+ // required the web file, thus ensuring that the Node file and related
20
+ // dependencies will not be bundled inadvertently.
8
21
  exports.default = mode;
package/build/node.js CHANGED
@@ -26,15 +26,27 @@ const matches = {
26
26
  RESULT: 'RESULT'
27
27
  };
28
28
  const SERIALIZERS = [{
29
+ /**
30
+ * display error stack
31
+ */
29
32
  matches: (err) => err instanceof Error,
30
33
  serialize: (err) => err.stack
31
34
  }, {
35
+ /**
36
+ * color commands blue
37
+ */
32
38
  matches: (log) => log === matches.COMMAND,
33
39
  serialize: (log) => chalk_1.default.magenta(log)
34
40
  }, {
41
+ /**
42
+ * color data yellow
43
+ */
35
44
  matches: (log) => log === matches.DATA,
36
45
  serialize: (log) => chalk_1.default.yellow(log)
37
46
  }, {
47
+ /**
48
+ * color result cyan
49
+ */
38
50
  matches: (log) => log === matches.RESULT,
39
51
  serialize: (log) => chalk_1.default.cyan(log)
40
52
  }];
@@ -46,9 +58,16 @@ const originalFactory = loglevel_1.default.methodFactory;
46
58
  const wdioLoggerMethodFactory = function (methodName, logLevel, loggerName) {
47
59
  const rawMethod = originalFactory(methodName, logLevel, loggerName);
48
60
  return (...args) => {
61
+ /**
62
+ * create logFile lazily
63
+ */
49
64
  if (!logFile && process.env.WDIO_LOG_PATH) {
50
65
  logFile = fs_1.default.createWriteStream(process.env.WDIO_LOG_PATH);
51
66
  }
67
+ /**
68
+ * split `prefixer: value` sting to `prefixer: ` and `value`
69
+ * so that SERIALIZERS can match certain string
70
+ */
52
71
  const match = Object.values(matches).filter(x => args[0].endsWith(`: ${x}`))[0];
53
72
  if (match) {
54
73
  const prefixStr = args.shift().slice(0, -match.length - 1);
@@ -64,6 +83,9 @@ const wdioLoggerMethodFactory = function (methodName, logLevel, loggerName) {
64
83
  });
65
84
  const logText = strip_ansi_1.default(`${util_1.default.format.apply(this, args)}\n`);
66
85
  if (logFile && logFile.writable) {
86
+ /**
87
+ * empty logging cache if stuff got logged before
88
+ */
67
89
  if (logCache.size) {
68
90
  logCache.forEach((log) => {
69
91
  if (logFile) {
@@ -79,6 +101,9 @@ const wdioLoggerMethodFactory = function (methodName, logLevel, loggerName) {
79
101
  };
80
102
  };
81
103
  function getLogger(name) {
104
+ /**
105
+ * check if logger was already initiated
106
+ */
82
107
  if (loggers[name]) {
83
108
  return loggers[name];
84
109
  }
@@ -99,7 +124,12 @@ function getLogger(name) {
99
124
  return loggers[name];
100
125
  }
101
126
  exports.default = getLogger;
127
+ /**
128
+ * Wait for writable stream to be flushed.
129
+ * Calling this prevents part of the logs in the very env to be lost.
130
+ */
102
131
  getLogger.waitForBuffer = async () => new Promise(resolve => {
132
+ // @ts-ignore
103
133
  if (logFile && Array.isArray(logFile.writableBuffer) && logFile.writableBuffer.length !== 0) {
104
134
  return setTimeout(async () => {
105
135
  await getLogger.waitForBuffer();
@@ -116,16 +146,28 @@ getLogger.clearLogger = () => {
116
146
  logFile = null;
117
147
  };
118
148
  getLogger.setLogLevelsConfig = (logLevels = {}, wdioLogLevel = DEFAULT_LEVEL) => {
149
+ /**
150
+ * set log level
151
+ */
119
152
  if (process.env.WDIO_LOG_LEVEL === undefined) {
120
153
  process.env.WDIO_LOG_LEVEL = wdioLogLevel;
121
154
  }
122
155
  logLevelsConfig = {};
156
+ /**
157
+ * build logLevelsConfig object
158
+ */
123
159
  Object.entries(logLevels).forEach(([logName, logLevel]) => {
124
160
  const logLevelName = getLogLevelName(logName);
125
161
  logLevelsConfig[logLevelName] = logLevel;
126
162
  });
163
+ /**
164
+ * set log level for each logger
165
+ */
127
166
  Object.keys(loggers).forEach(logName => {
128
167
  const logLevelName = getLogLevelName(logName);
168
+ /**
169
+ * either apply log level from logLevels object or use global logLevel
170
+ */
129
171
  const logLevel = typeof logLevelsConfig[logLevelName] !== 'undefined' ? logLevelsConfig[logLevelName] : process.env.WDIO_LOG_LEVEL;
130
172
  loggers[logName].setLevel(logLevel);
131
173
  });
package/build/web.js CHANGED
@@ -1,16 +1,22 @@
1
1
  "use strict";
2
+ /* istanbul ignore file */
2
3
  Object.defineProperty(exports, "__esModule", { value: true });
3
4
  const LOG_METHODS = ['error', 'warn', 'info', 'debug', 'trace', 'silent'];
4
5
  function getLogger(component) {
5
6
  return LOG_METHODS.reduce((acc, cur) => {
6
7
  const prop = cur;
8
+ // check if the method is available on console (web doesn't have
9
+ // 'silent', for example) before adding to acc
10
+ // eslint-disable-next-line no-console
7
11
  if (console[prop]) {
12
+ // eslint-disable-next-line no-console
8
13
  acc[prop] = console[prop].bind(console, `${component}:`);
9
14
  }
10
15
  return acc;
11
16
  }, {});
12
17
  }
13
18
  exports.default = getLogger;
19
+ // logging interface expects a 'setLevel' method
14
20
  getLogger.setLevel = () => { };
15
21
  getLogger.setLogLevelsConfig = () => { };
16
22
  getLogger.waitForBuffer = () => { };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@wdio/logger",
3
- "version": "7.0.0-beta.1",
3
+ "version": "7.0.0",
4
4
  "description": "A helper utility for logging of WebdriverIO packages",
5
5
  "author": "Christian Bromann <christian@saucelabs.com>",
6
6
  "homepage": "https://github.com/webdriverio/webdriverio/tree/main/packages/wdio-logger",
@@ -32,5 +32,5 @@
32
32
  "publishConfig": {
33
33
  "access": "public"
34
34
  },
35
- "gitHead": "8d9ac36cadb5ccba689ce76173ef0545ee72df86"
35
+ "gitHead": "b03188f55479f936d9ca899967883d929cde191c"
36
36
  }