@zohodesk/unit-testing-framework 0.0.12-experimental → 0.0.14-experimental

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.
@@ -4,6 +4,7 @@ Object.defineProperty(exports, "__esModule", {
4
4
  value: true
5
5
  });
6
6
  exports.default = void 0;
7
+ var _logger = require("../utils/logger");
7
8
  /**
8
9
  * default-reporter.js
9
10
  *
@@ -24,12 +25,12 @@ class DefaultReporter {
24
25
  }
25
26
  onRunStart(_results, _options) {
26
27
  this._startTime = Date.now();
27
- console.log('\n╔══════════════════════════════════════════╗');
28
- console.log('║ Unit Testing Framework – Test Run ║');
29
- console.log('╚══════════════════════════════════════════╝\n');
28
+ _logger.Logger.log(_logger.Logger.INFO_TYPE, '\n╔══════════════════════════════════════════╗');
29
+ _logger.Logger.log(_logger.Logger.INFO_TYPE, '║ Unit Testing Framework – Test Run ║');
30
+ _logger.Logger.log(_logger.Logger.INFO_TYPE, '╚══════════════════════════════════════════╝\n');
30
31
  }
31
32
  onTestStart(test) {
32
- console.log(` ▶ Running: ${test.path}`);
33
+ _logger.Logger.log(_logger.Logger.INFO_TYPE, ` ▶ Running: ${test.path}`);
33
34
  }
34
35
  onTestResult(_test, testResult, _aggregatedResults) {
35
36
  const {
@@ -38,7 +39,7 @@ class DefaultReporter {
38
39
  numPendingTests
39
40
  } = testResult;
40
41
  const icon = numFailingTests > 0 ? '✖' : '✔';
41
- console.log(` ${icon} Passed: ${numPassingTests} Failed: ${numFailingTests} Skipped: ${numPendingTests}`);
42
+ _logger.Logger.log(_logger.Logger.INFO_TYPE, ` ${icon} Passed: ${numPassingTests} Failed: ${numFailingTests} Skipped: ${numPendingTests}`);
42
43
  }
43
44
  onRunComplete(_contexts, results) {
44
45
  const elapsed = ((Date.now() - this._startTime) / 1000).toFixed(2);
@@ -47,12 +48,12 @@ class DefaultReporter {
47
48
  numFailedTests,
48
49
  numTotalTests
49
50
  } = results;
50
- console.log('\n──────────────────────────────────────────');
51
- console.log(` Total: ${numTotalTests}`);
52
- console.log(` Passed: ${numPassedTests}`);
53
- console.log(` Failed: ${numFailedTests}`);
54
- console.log(` Time: ${elapsed}s`);
55
- console.log('──────────────────────────────────────────\n');
51
+ _logger.Logger.log(_logger.Logger.INFO_TYPE, '\n──────────────────────────────────────────');
52
+ _logger.Logger.log(_logger.Logger.INFO_TYPE, ` Total: ${numTotalTests}`);
53
+ _logger.Logger.log(_logger.Logger.INFO_TYPE, ` Passed: ${numPassedTests}`);
54
+ _logger.Logger.log(_logger.Logger.INFO_TYPE, ` Failed: ${numFailedTests}`);
55
+ _logger.Logger.log(_logger.Logger.INFO_TYPE, ` Time: ${elapsed}s`);
56
+ _logger.Logger.log(_logger.Logger.INFO_TYPE, '──────────────────────────────────────────\n');
56
57
  }
57
58
  }
58
59
  exports.default = DefaultReporter;
@@ -22,6 +22,7 @@ function _interopRequireWildcard(e, t) { if ("function" == typeof WeakMap) var r
22
22
  * @property {string} [projectRoot] - Absolute path to the consumer project (default: cwd).
23
23
  * @property {boolean} [coverage] - Enable coverage collection.
24
24
  * @property {string[]} [testFiles] - Specific test file patterns to run.
25
+ * @property {string} [testPathPattern] - Regex pattern to match test file paths (e.g. 'myFile.test.js').
25
26
  * @property {boolean} [verbose] - Verbose output.
26
27
  * @property {number|string} [maxWorkers] - Worker concurrency (e.g. '50%' or 4).
27
28
  * @property {boolean} [silent] - Suppress console output from tests.
@@ -39,6 +40,7 @@ async function createJestRunner(options = {}) {
39
40
  projectRoot = process.cwd(),
40
41
  coverage,
41
42
  testFiles,
43
+ testPathPattern,
42
44
  verbose,
43
45
  maxWorkers,
44
46
  silent,
@@ -61,6 +63,7 @@ async function createJestRunner(options = {}) {
61
63
  // runCLI expects a yargs-like argv object.
62
64
  const argv = buildArgv(mergedConfig, {
63
65
  testFiles,
66
+ testPathPattern,
64
67
  watch,
65
68
  projectRoot
66
69
  });
@@ -84,12 +87,14 @@ async function createJestRunner(options = {}) {
84
87
  * @param {object} config - Merged Jest config.
85
88
  * @param {object} extra
86
89
  * @param {string[]} [extra.testFiles]
90
+ * @param {string} [extra.testPathPattern]
87
91
  * @param {boolean} [extra.watch]
88
92
  * @param {string} extra.projectRoot
89
93
  * @returns {object}
90
94
  */
91
95
  function buildArgv(config, {
92
96
  testFiles,
97
+ testPathPattern,
93
98
  watch,
94
99
  projectRoot
95
100
  }) {
@@ -113,5 +118,11 @@ function buildArgv(config, {
113
118
  _: testFiles ?? [],
114
119
  $0: 'unit-testing-framework'
115
120
  };
121
+
122
+ // If a specific test file/pattern is provided, use testPathPattern
123
+ // so Jest only runs matching test files.
124
+ if (testPathPattern) {
125
+ argv.testPathPattern = testPathPattern;
126
+ }
116
127
  return argv;
117
128
  }
@@ -0,0 +1,28 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports.Logger = void 0;
7
+ class LoggerImpl {
8
+ constructor() {
9
+ this.SUCCESS_TYPE = 'success';
10
+ this.FAILURE_TYPE = 'failure';
11
+ this.INFO_TYPE = 'info';
12
+ this.colors = {
13
+ 'success': ['\x1b[36m', '\x1b[0m'],
14
+ 'failure': ['\x1b[31m', '\x1b[0m'],
15
+ 'info': ['\x1b[33m', '\x1b[0m']
16
+ };
17
+ this.consoleLogger = console;
18
+ }
19
+ error(err) {
20
+ this.consoleLogger.error(err);
21
+ }
22
+ info() {}
23
+ log(type, message) {
24
+ const color = this.colors[type];
25
+ this.consoleLogger.log(`${color[0]}${message}${color[1]}\n`);
26
+ }
27
+ }
28
+ const Logger = exports.Logger = new LoggerImpl();
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@zohodesk/unit-testing-framework",
3
- "version": "0.0.12-experimental",
3
+ "version": "0.0.14-experimental",
4
4
  "description": "A modular Jest-based unit testing framework",
5
5
  "main": "./build/index.js",
6
6
  "exports": {
@@ -1,21 +0,0 @@
1
- "use strict";
2
-
3
- Object.defineProperty(exports, "__esModule", {
4
- value: true
5
- });
6
- exports.default = globalSetup;
7
- /**
8
- * Global Setup
9
- *
10
- * Runs once before the entire test suite.
11
- * Jest calls this module's default export.
12
- *
13
- * Consumer projects can override by setting `globalSetup`
14
- * in their jest.unit.config.js to their own setup file.
15
- */
16
-
17
- async function globalSetup(_globalConfig) {
18
- // Store start timestamp for reporting
19
- process.env.__UTL_START_TIME__ = Date.now().toString();
20
- console.log('[unit-testing-framework] Global setup complete.');
21
- }
@@ -1,24 +0,0 @@
1
- "use strict";
2
-
3
- Object.defineProperty(exports, "__esModule", {
4
- value: true
5
- });
6
- exports.default = globalTeardown;
7
- /**
8
- * Global Teardown
9
- *
10
- * Runs once after the entire test suite completes.
11
- * Jest calls this module's default export.
12
- *
13
- * Consumer projects can override by setting `globalTeardown`
14
- * in their jest.unit.config.js to their own teardown file.
15
- */
16
-
17
- async function globalTeardown(_globalConfig) {
18
- const startTime = Number(process.env.__UTL_START_TIME__ || Date.now());
19
- const elapsed = ((Date.now() - startTime) / 1000).toFixed(2);
20
- console.log(`[unit-testing-framework] Global teardown complete. Total time: ${elapsed}s`);
21
-
22
- // Cleanup environment variable
23
- delete process.env.__UTL_START_TIME__;
24
- }