@k03mad/actual-versions 1.1.0 → 1.1.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/app/cli.js CHANGED
@@ -2,7 +2,9 @@
2
2
 
3
3
  import {log} from '@k03mad/simple-log';
4
4
  import chalk from 'chalk';
5
- import {table} from 'table';
5
+ import {getBorderCharacters, table} from 'table';
6
+
7
+ import config from '../config.js';
6
8
 
7
9
  import * as api from './api.js';
8
10
 
@@ -22,4 +24,8 @@ const output = await Promise.all(
22
24
  }),
23
25
  );
24
26
 
25
- log(table(output));
27
+ const formattedTable = table(output, {
28
+ border: getBorderCharacters(config.table.border),
29
+ });
30
+
31
+ log(formattedTable);
package/config.js ADDED
@@ -0,0 +1,9 @@
1
+ export default {
2
+ version: {
3
+ re: String.raw`\d[\d.]+$`,
4
+ },
5
+ table: {
6
+ // https://www.npmjs.com/package/table#getbordercharacters
7
+ border: 'honeywell',
8
+ },
9
+ };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@k03mad/actual-versions",
3
- "version": "1.1.0",
3
+ "version": "1.1.2",
4
4
  "description": "Get tool actual version string",
5
5
  "maintainers": [
6
6
  "Kirill Molchanov <k03.mad@gmail.com"
@@ -19,7 +19,7 @@
19
19
  "node": ">=20"
20
20
  },
21
21
  "dependencies": {
22
- "@k03mad/request": "5.8.1",
22
+ "@k03mad/request": "6.0.3",
23
23
  "@k03mad/simple-log": "2.2.1",
24
24
  "chalk": "5.3.0",
25
25
  "table": "6.8.2"
@@ -27,7 +27,7 @@
27
27
  "devDependencies": {
28
28
  "@k03mad/eslint-config": "22.5.0",
29
29
  "eslint": "8.57.0",
30
- "husky": "9.1.1",
30
+ "husky": "9.1.4",
31
31
  "npm-run-all": "4.1.5",
32
32
  "strip-ansi": "7.1.0"
33
33
  },
package/tests/api.js CHANGED
@@ -2,24 +2,25 @@ import assert from 'node:assert/strict';
2
2
  import {describe, it} from 'node:test';
3
3
 
4
4
  import * as api from '../app/api.js';
5
+ import config from '../config.js';
5
6
 
6
- const TESTS = {
7
- getAriaVersion: /^\d\.\d+\.\d$/,
8
- getChromeVersion: /^\d{3}(?:\.\d+){3}$/,
9
- getCurlVersion: /^\d\.\d\.\d$/,
10
- };
7
+ const API_FUNCTIONS = [
8
+ 'getAriaVersion',
9
+ 'getChromeVersion',
10
+ 'getCurlVersion',
11
+ ];
11
12
 
12
- describe('api', () => {
13
- const steps = Object.entries(TESTS);
13
+ const versionRe = new RegExp(`^${config.version.re}`);
14
14
 
15
- it('coverage', () => {
16
- assert.equal(steps.length, Object.keys(api).length);
15
+ describe('api', () => {
16
+ it('check tests count', () => {
17
+ assert.equal(API_FUNCTIONS.length, Object.keys(api).length);
17
18
  });
18
19
 
19
- Object.entries(TESTS).forEach(([key, value]) => {
20
- it(key, async () => {
21
- const version = await api[key]();
22
- assert.match(version, value);
20
+ API_FUNCTIONS.forEach(fn => {
21
+ it(`check fn output: ${fn}()`, async () => {
22
+ const version = await api[fn]();
23
+ assert.match(version, versionRe);
23
24
  });
24
25
  });
25
26
  });
package/tests/cli.js CHANGED
@@ -4,17 +4,23 @@ import {before, describe, it} from 'node:test';
4
4
  import {promisify} from 'node:util';
5
5
 
6
6
  import stripAnsi from 'strip-ansi';
7
+ import {getBorderCharacters} from 'table';
8
+
9
+ import config from '../config.js';
7
10
 
8
11
  const cliFile = process.env.npm_package_bin_acver;
9
12
  const exec = promisify(cp.exec);
10
13
 
11
- const TESTS = [
12
- /^aria\s+\d\.\d+\.\d$/,
13
- /^chrome\s+\d{3}(?:\.\d+){3}$/,
14
- /^curl\s+\d\.\d\.\d$/,
14
+ const tableBorderChars = Object.values(getBorderCharacters(config.table.border));
15
+ const tableBorderCharsRe = new RegExp(tableBorderChars.join('|'), 'g');
16
+
17
+ const STDOUT_TOOLS = [
18
+ 'aria',
19
+ 'chrome',
20
+ 'curl',
15
21
  ];
16
22
 
17
- const TABLE_CHARS_RE = /[─│┼═║╔╗╚╝╟╢╤╧]+/g;
23
+ const versionRe = tool => new RegExp(`^${tool}\\s+${config.version.re}`);
18
24
 
19
25
  describe('cli', () => {
20
26
  let versions;
@@ -25,17 +31,19 @@ describe('cli', () => {
25
31
  versions = stdout
26
32
  .split('\n')
27
33
  .map(elem => stripAnsi(elem)
28
- .replaceAll(TABLE_CHARS_RE, '')
34
+ .replaceAll(tableBorderCharsRe, '')
29
35
  .trim(),
30
36
  )
31
37
  .filter(Boolean);
32
38
  });
33
39
 
34
- it('coverage', () => {
35
- assert.equal(TESTS.length, versions.length);
40
+ it('check tests count', () => {
41
+ assert.equal(STDOUT_TOOLS.length, versions.length);
36
42
  });
37
43
 
38
- TESTS.forEach((re, i) => {
39
- it(String(re), () => assert.match(versions[i], re));
44
+ STDOUT_TOOLS.forEach((tool, i) => {
45
+ it(`check stdout output: #${i + 1} tool: ${tool}`, () => {
46
+ assert.match(versions[i], versionRe(tool));
47
+ });
40
48
  });
41
49
  });