@zeesoft/i18n-verify 2.0.2 → 2.1.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.
Files changed (37) hide show
  1. package/dist/driver/adapters/cypress.js +2 -1
  2. package/dist/driver/adapters/nightwatch.js +43 -2
  3. package/dist/driver/baseDriver.js +24 -0
  4. package/dist/index.js +10 -5
  5. package/dist/lib/i18n.js +125 -43
  6. package/dist/{utils → lib}/reports.js +42 -27
  7. package/dist/lib/validator/string.js +2 -2
  8. package/dist/template/report.html +1678 -0
  9. package/dist/utils/cache.js +15 -15
  10. package/dist/utils/constants.js +8 -5
  11. package/dist/utils/file.js +8 -4
  12. package/dist/utils/logs.js +30 -11
  13. package/dist/utils/objects/cacheData.js +14 -33
  14. package/dist/utils/objects/metaData.js +7 -26
  15. package/dist/utils/objects/reportData.js +0 -18
  16. package/dist/utils/objects/statData.js +43 -28
  17. package/dist/utils/objects/stringData.js +4 -7
  18. package/dist/utils/reportFactory/base.js +15 -7
  19. package/dist/utils/reportFactory/html/index.js +13 -9
  20. package/dist/utils/reportFactory/html/template/body.js +110 -0
  21. package/dist/utils/reportFactory/html/template/css.js +446 -409
  22. package/dist/utils/reportFactory/html/template/html.js +15 -112
  23. package/dist/utils/reportFactory/html/template/javascript/data.js +59 -1
  24. package/dist/utils/reportFactory/html/template/javascript/global.js +19 -0
  25. package/dist/utils/reportFactory/html/template/javascript/grid.js +54 -80
  26. package/dist/utils/reportFactory/html/template/javascript/index.js +7 -7
  27. package/dist/utils/reportFactory/html/template/javascript/insight.js +226 -201
  28. package/dist/utils/reportFactory/html/template/javascript/menuBar.js +40 -35
  29. package/dist/utils/reportFactory/html/template/javascript/overview.js +725 -533
  30. package/dist/utils/reportFactory/index.js +4 -6
  31. package/dist/utils/reportFactory/table.js +95 -0
  32. package/dist/utils/resource.js +10 -6
  33. package/dist/utils/runtime.js +23 -3
  34. package/dist/utils/scripts/postinstall.js +3 -2
  35. package/package.json +8 -3
  36. package/types/index.d.ts +46 -0
  37. package/dist/utils/reportsTable.js +0 -71
@@ -4,30 +4,28 @@ Object.defineProperty(exports, "__esModule", {
4
4
  value: true
5
5
  });
6
6
  exports.default = void 0;
7
- var _config = _interopRequireDefault(require("../../lib/config.js"));
8
- var _cache = _interopRequireDefault(require("../cache.js"));
9
7
  var _constants = require("../constants.js");
10
8
  var _index = _interopRequireDefault(require("./html/index.js"));
11
9
  var _reportData = _interopRequireDefault(require("../objects/reportData.js"));
12
- var _cacheData = _interopRequireDefault(require("../objects/cacheData.js"));
13
10
  var _runtime = require("../runtime.js");
11
+ var _table = _interopRequireDefault(require("./table.js"));
14
12
  function _interopRequireDefault(e) { return e && e.__esModule ? e : { default: e }; }
15
13
  class ReportFactory {
16
14
  static #build(type) {
17
15
  switch (type) {
18
16
  case _constants.SUPPORTED_REPORT_TYPES.HTML:
19
17
  return new _index.default();
18
+ case _constants.SUPPORTED_REPORT_TYPES.ASCII_TABLE:
19
+ return new _table.default();
20
20
  default:
21
21
  throw new Error('unsupported report type requested');
22
22
  }
23
23
  }
24
24
  static export(type, path, name) {
25
25
  const builder = ReportFactory.#build(type);
26
- const data = new _cacheData.default(_cache.default.getData());
27
- const reportTime = new Date(_config.default.getLastRunTimeStamp()).toLocaleString();
26
+ const reportTime = new Date().toLocaleString();
28
27
  const appName = (0, _runtime.getRootProjectName)();
29
28
  const reportData = new _reportData.default({
30
- data,
31
29
  appName,
32
30
  reportTime
33
31
  });
@@ -0,0 +1,95 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports.default = void 0;
7
+ var _consoleTablePrinter = require("console-table-printer");
8
+ var _constants = require("../constants");
9
+ var _logs = _interopRequireDefault(require("../logs"));
10
+ var _base = _interopRequireDefault(require("./base"));
11
+ function _interopRequireDefault(e) { return e && e.__esModule ? e : { default: e }; }
12
+ class TableReport extends _base.default {
13
+ /**
14
+ * @type {Table}
15
+ */
16
+ #printer;
17
+ /**
18
+ * @type {Boolean}
19
+ */
20
+ #hasData = false;
21
+ static #column1 = 'STATUS';
22
+ static #column2 = 'COUNTS';
23
+ constructor() {
24
+ super(_constants.SUPPORTED_REPORT_TYPES.ASCII_TABLE);
25
+ this.#preparePrinter();
26
+ }
27
+ #preparePrinter() {
28
+ this.#printer = new _consoleTablePrinter.Table({
29
+ style: {
30
+ headerTop: {
31
+ left: '\u001B[94m╔\x1b[0m',
32
+ mid: '\u001B[94m╦\x1b[0m',
33
+ right: '\u001B[94m╗\x1b[0m',
34
+ other: '\u001B[94m═'
35
+ },
36
+ headerBottom: {
37
+ left: '\u001B[94m╟\x1b[0m',
38
+ mid: '\u001B[94m╬\x1b[0m',
39
+ right: '\u001B[94m╢\x1b[0m',
40
+ other: '\u001B[94m═'
41
+ },
42
+ tableBottom: {
43
+ left: '\u001B[94m╚\x1b[0m',
44
+ mid: '\u001B[94m╩\x1b[0m',
45
+ right: '\u001B[94m╝\x1b[0m',
46
+ other: '\u001B[94m═\x1b[0m'
47
+ },
48
+ vertical: '\u001B[94m║\x1b[0m'
49
+ },
50
+ columns: [{
51
+ name: TableReport.#column1,
52
+ alignment: 'left'
53
+ }, {
54
+ name: TableReport.#column2,
55
+ alignment: 'center'
56
+ }]
57
+ });
58
+ }
59
+
60
+ /**
61
+ * @override
62
+ */
63
+ buildContent() {
64
+ if (_constants.REPORT_COUNTS[_constants.I18N_STATUS.REVIEWED] > 0) {
65
+ this.#hasData = true;
66
+ for (const key in _constants.REPORT_COUNTS) {
67
+ if (key !== _constants.I18N_STATUS.REVIEWED) {
68
+ if (_constants.REPORT_COUNTS.hasOwnProperty(key)) {
69
+ this.#printer.addRows([{
70
+ STATUS: key,
71
+ COUNTS: `${_constants.REPORT_COUNTS[key]}`
72
+ }]);
73
+ }
74
+ } else {
75
+ this.#printer.addRows([{
76
+ STATUS: '\u001B[94m' + '═'.repeat(28) + '\x1b[0m',
77
+ COUNTS: '\u001B[94m' + '═'.repeat(8) + '\x1b[0m'
78
+ }]);
79
+ this.#printer.addRows([{
80
+ STATUS: 'OVERALL_REVIEWED',
81
+ COUNTS: `${_constants.REPORT_COUNTS[key]}`
82
+ }]);
83
+ }
84
+ }
85
+ }
86
+ }
87
+
88
+ /**
89
+ * @override
90
+ */
91
+ export() {
92
+ this.#hasData ? this.#printer.printTable() : _logs.default.info('There are no visbile elements with UI strings');
93
+ }
94
+ }
95
+ exports.default = TableReport;
@@ -7,7 +7,6 @@ exports.default = void 0;
7
7
  var _config = _interopRequireDefault(require("../lib/config.js"));
8
8
  var _constants = require("./constants.js");
9
9
  var _file = require("./file.js");
10
- var _logs = _interopRequireDefault(require("../utils/logs.js"));
11
10
  function _interopRequireDefault(e) { return e && e.__esModule ? e : { default: e }; }
12
11
  class Resource {
13
12
  static load() {
@@ -22,8 +21,8 @@ class Resource {
22
21
  Resource.#processFile(filePath, bundle);
23
22
  }
24
23
  } else {
25
- _logs.default.error(`${resourcePath} invalid resource path`);
26
- return; // throw runtime error
24
+ console.error(`${resourcePath} invalid resource path`);
25
+ return;
27
26
  }
28
27
  _config.default.setResourceBundle(bundle);
29
28
  }
@@ -35,7 +34,7 @@ class Resource {
35
34
  ext = (0, _file.getFileExtenstion)(filePath);
36
35
  if (_constants.RES_FILE_EXTENSIONS.includes(ext)) {
37
36
  if (!fileContent) {
38
- _logs.default.error(`${filePath} is empty or invalid`);
37
+ console.error(`${filePath} is empty or invalid`);
39
38
  return;
40
39
  }
41
40
  if (filePath.toLowerCase().includes('dnt')) {
@@ -44,11 +43,16 @@ class Resource {
44
43
  bundle['ignore'] = fileContent.split(/\r?\n/);
45
44
  // TODO: add locale validations for the following cases
46
45
  } else if (filePath.includes(locale)) {
47
- bundle[locale] = fileContent.split(/\r?\n/);
46
+ const lines = fileContent.split(/\r?\n/);
47
+ bundle[locale] = lines.map(removeHtmlTags);
48
48
  } else if (filePath.includes(defaultLocale)) {
49
49
  bundle[defaultLocale] = fileContent.split(/\r?\n/);
50
50
  }
51
51
  }
52
52
  }
53
53
  }
54
- exports.default = Resource;
54
+ exports.default = Resource;
55
+ function removeHtmlTags(str) {
56
+ const htmlTagPattern = /<\/?[^>]+>/gi;
57
+ return str.replace(htmlTagPattern, '');
58
+ }
@@ -3,14 +3,34 @@
3
3
  Object.defineProperty(exports, "__esModule", {
4
4
  value: true
5
5
  });
6
- exports.loadDependencies = void 0;
6
+ exports.loadDependencies = exports.getRootProjectPackageJson = exports.getRootProjectName = exports.getRootProjectMainDir = void 0;
7
7
  var _index = _interopRequireDefault(require("../lib/validator/index.js"));
8
- var _reports = _interopRequireDefault(require("./reports.js"));
8
+ var _reports = _interopRequireDefault(require("../lib/reports.js"));
9
9
  var _resource = _interopRequireDefault(require("./resource.js"));
10
+ var _cache = _interopRequireDefault(require("./cache.js"));
11
+ var _path = require("path");
12
+ var _file = require("./file.js");
10
13
  function _interopRequireDefault(e) { return e && e.__esModule ? e : { default: e }; }
11
14
  const loadDependencies = () => {
12
15
  _resource.default.load();
13
16
  _index.default.load();
14
17
  _reports.default.setup();
18
+ _cache.default.init();
15
19
  };
16
- exports.loadDependencies = loadDependencies;
20
+ exports.loadDependencies = loadDependencies;
21
+ const getRootProjectMainDir = () => {
22
+ let currentDir = __dirname;
23
+ while (currentDir !== (0, _path.parse)(currentDir).root) {
24
+ const packageJsonPath = (0, _file.joinPaths)(currentDir, 'package.json');
25
+ if ((0, _file.fileExists)(packageJsonPath) && !(0, _file.getFileContent)(packageJsonPath).match(/"name": "@zeesoft\/i18n-verify",/g) === null) {
26
+ return packageJsonPath;
27
+ }
28
+ currentDir = (0, _path.dirname)(currentDir);
29
+ }
30
+ return '';
31
+ };
32
+ exports.getRootProjectMainDir = getRootProjectMainDir;
33
+ const getRootProjectPackageJson = (rootProjectPath = getRootProjectMainDir()) => (0, _file.getFileContent)((0, _file.joinPaths)(rootProjectPath, 'package.json'));
34
+ exports.getRootProjectPackageJson = getRootProjectPackageJson;
35
+ const getRootProjectName = () => getRootProjectPackageJson()?.match(/"name": "([^"]+)",/)?.[1] || '';
36
+ exports.getRootProjectName = getRootProjectName;
@@ -3,8 +3,9 @@
3
3
  var _configFile = require("../configFile.js");
4
4
  var _constants = require("../constants.js");
5
5
  var _file = require("../file.js");
6
- const projectDir = (0, _file.joinPaths)(process.cwd(), '..', '..', '..');
7
- const packageJson = (0, _file.getFileContent)((0, _file.joinPaths)(projectDir, 'package.json'));
6
+ var _runtime = require("../runtime.js");
7
+ const projectDir = (0, _runtime.getRootProjectMainDir)();
8
+ const packageJson = (0, _runtime.getRootProjectPackageJson)(projectDir);
8
9
  let type = '';
9
10
  if (packageJson) {
10
11
  if (packageJson.includes('"nightwatch"')) {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@zeesoft/i18n-verify",
3
- "version": "2.0.2",
3
+ "version": "2.1.0",
4
4
  "description": "Library to perform I18n verification over Nightwatch or WebdriverIO frameworks",
5
5
  "main": "dist/index.js",
6
6
  "exports": {
@@ -16,7 +16,8 @@
16
16
  },
17
17
  "files": [
18
18
  "dist",
19
- "readme.md"
19
+ "readme.md",
20
+ "types"
20
21
  ],
21
22
  "keywords": [
22
23
  "Zeesoft",
@@ -32,13 +33,17 @@
32
33
  "engines": {
33
34
  "node": ">=16"
34
35
  },
36
+ "types": "types/index.d.ts",
35
37
  "devDependencies": {
36
38
  "@babel/cli": "^7.17.0",
37
39
  "@babel/core": "^7.17.0",
38
40
  "@babel/plugin-transform-modules-commonjs": "^7.17.0",
39
- "@babel/preset-env": "^7.17.0"
41
+ "@babel/preset-env": "^7.17.0",
42
+ "@types/nightwatch": "^2.3.31",
43
+ "@wdio/types": "^9.0.8"
40
44
  },
41
45
  "dependencies": {
46
+ "@types/selenium-webdriver": "^4.1.26",
42
47
  "chrono-node": "^2.7.6",
43
48
  "cldr-data": "^36.0.0",
44
49
  "console-table-printer": "^2.12.0",
@@ -0,0 +1,46 @@
1
+ import { NightwatchBrowser } from 'nightwatch';
2
+ import { WebDriver } from 'selenium-webdriver';
3
+
4
+ type Driver = NightwatchBrowser | WebdriverIO.Browser | WebDriver;
5
+ /**
6
+ *
7
+ * @summary sets driver and locale configurations required to run the i18n verification and
8
+ * it should be called before calling the verify function
9
+ *
10
+ * @param driver supported browser or driver object from the automation framework
11
+ * @param locale current locale to run automation
12
+ */
13
+ export function config(driver: Driver, locale: string): void;
14
+
15
+ /**
16
+ * @summary sets locale
17
+ * @param locale
18
+ */
19
+ export function setLocale(locale: string): void;
20
+
21
+ /**
22
+ * @summary generates ASCII table and prints on the stdout
23
+ */
24
+ export function genReportTable(): void;
25
+
26
+ /**
27
+ * @summary generates Html report and saves to L10n Report Path
28
+ */
29
+ export function genHtmlReport(): void;
30
+
31
+ /**
32
+ * @summary returns current locale
33
+ */
34
+ export function getLocale(): string;
35
+
36
+ /**
37
+ * @summary performs i18n verification to the supplied selector area
38
+ * `Note: "config" method should be called to configure driver and locale details before starting verification`
39
+ *
40
+ * @throws {Error} when verify is unable to build runner object
41
+ */
42
+ export function verify(args: {
43
+ verificationArea: string;
44
+ staticLocators: Array<string>;
45
+ description: string;
46
+ }): Promise<void>;
@@ -1,71 +0,0 @@
1
- "use strict";
2
-
3
- Object.defineProperty(exports, "__esModule", {
4
- value: true
5
- });
6
- exports.default = void 0;
7
- var _constants = require("./constants.js");
8
- var _consoleTablePrinter = require("console-table-printer");
9
- var _logs = _interopRequireDefault(require("./logs.js"));
10
- function _interopRequireDefault(e) { return e && e.__esModule ? e : { default: e }; }
11
- const column1 = 'STATUS';
12
- const column2 = 'COUNTS';
13
- class GenerateReportTable {
14
- static #printer = new _consoleTablePrinter.Table({
15
- style: {
16
- headerTop: {
17
- left: '\u001B[94m╔\x1b[0m',
18
- mid: '\u001B[94m╦\x1b[0m',
19
- right: '\u001B[94m╗\x1b[0m',
20
- other: '\u001B[94m═'
21
- },
22
- headerBottom: {
23
- left: '\u001B[94m╟\x1b[0m',
24
- mid: '\u001B[94m╬\x1b[0m',
25
- right: '\u001B[94m╢\x1b[0m',
26
- other: '\u001B[94m═'
27
- },
28
- tableBottom: {
29
- left: '\u001B[94m╚\x1b[0m',
30
- mid: '\u001B[94m╩\x1b[0m',
31
- right: '\u001B[94m╝\x1b[0m',
32
- other: '\u001B[94m═\x1b[0m'
33
- },
34
- vertical: '\u001B[94m║\x1b[0m'
35
- },
36
- columns: [{
37
- name: column1,
38
- alignment: 'left'
39
- }, {
40
- name: column2,
41
- alignment: 'center'
42
- }]
43
- });
44
- static generateTable() {
45
- if (_constants.REPORT_COUNTS[_constants.I18N_STATUS.REVIEWED] === 0) {
46
- _logs.default.info('There are no visbile elements with UI strings');
47
- return;
48
- }
49
- for (const key in _constants.REPORT_COUNTS) {
50
- if (key !== _constants.I18N_STATUS.REVIEWED) {
51
- if (_constants.REPORT_COUNTS.hasOwnProperty(key)) {
52
- GenerateReportTable.#printer.addRows([{
53
- STATUS: key,
54
- COUNTS: `${_constants.REPORT_COUNTS[key]}`
55
- }]);
56
- }
57
- } else {
58
- GenerateReportTable.#printer.addRows([{
59
- STATUS: '\u001B[94m' + '═'.repeat(28) + '\x1b[0m',
60
- COUNTS: '\u001B[94m' + '═'.repeat(8) + '\x1b[0m'
61
- }]);
62
- GenerateReportTable.#printer.addRows([{
63
- STATUS: 'OVERALL_REVIEWED',
64
- COUNTS: `${_constants.REPORT_COUNTS[key]}`
65
- }]);
66
- }
67
- }
68
- GenerateReportTable.#printer.printTable();
69
- }
70
- }
71
- exports.default = GenerateReportTable;