@zohodesk/unit-testing-framework 0.0.21-experimental → 0.0.23-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.
package/build/index.js CHANGED
@@ -9,11 +9,5 @@ Object.defineProperty(exports, "createJestRunner", {
9
9
  return _jestRunner.default;
10
10
  }
11
11
  });
12
- Object.defineProperty(exports, "default", {
13
- enumerable: true,
14
- get: function () {
15
- return _jestRunner.default;
16
- }
17
- });
18
12
  var _jestRunner = _interopRequireDefault(require("./src/runner/jest-runner.js"));
19
13
  function _interopRequireDefault(e) { return e && e.__esModule ? e : { default: e }; }
@@ -6,41 +6,12 @@ Object.defineProperty(exports, "__esModule", {
6
6
  exports.getDefaultConfig = getDefaultConfig;
7
7
  var _path = _interopRequireDefault(require("path"));
8
8
  function _interopRequireDefault(e) { return e && e.__esModule ? e : { default: e }; }
9
- /**
10
- * default-config.js
11
- *
12
- * Framework-level default Jest configuration.
13
- * Consumer projects can override any of these values
14
- * via their own config file or inline options.
15
- */
16
-
17
- // NOTE: __dirname is available after Babel transpiles ESM → CJS.
18
- // Do not add import.meta.url workarounds here.
19
-
20
- /**
21
- * Returns the default Jest configuration object.
22
- * Paths are resolved relative to the consumer's project root
23
- * (passed at runtime), NOT relative to this package.
24
- *
25
- * @param {string} projectRoot - Absolute path to the consumer project root.
26
- * @returns {import('@jest/types').Config.InitialOptions}
27
- */
28
9
  function getDefaultConfig(projectRoot) {
29
10
  return {
30
- // --------------- Roots & File Discovery ---------------
31
- // __tests__ folders can be nested anywhere under the project,
32
- // so we root Jest at the project itself and rely on testMatch
33
- // to locate **/__tests__/**/* files at any depth.
34
- rootDir: process.cwd(),
11
+ rootDir: projectRoot,
35
12
  testMatch: ['**/__tests__/**/*.test.js'],
36
- testPathIgnorePatterns: ['/node_modules/', '/build/', '/uat/'],
37
- // --------------- Environment ---------------
13
+ testPathIgnorePatterns: ['/build/'],
38
14
  testEnvironment: 'jsdom',
39
- // --------------- Transform ---------------
40
- // Use babel-jest to transform ESM (import/export) and JSX in
41
- // consumer source & test files. Consumer's own babel config
42
- // (babel.config.js / .babelrc) will be picked up automatically.
43
- // If none exists, the fallback preset-env handles plain ESM → CJS.
44
15
  transform: {
45
16
  '\\.[jt]sx?$': ['babel-jest', {
46
17
  presets: [['@babel/preset-env', {
@@ -50,27 +21,16 @@ function getDefaultConfig(projectRoot) {
50
21
  }]]
51
22
  }]
52
23
  },
53
- transformIgnorePatterns: ['/node_modules/'],
54
- // --------------- Reporters ---------------
55
24
  reporters: ['default', 'html-report'],
56
- // --------------- Parallelism & Performance ---------------
57
- maxWorkers: '50%',
58
- // Use half of available CPUs
59
- maxConcurrency: 5,
60
- // --------------- Timeouts ---------------
61
- testTimeout: 30_000,
62
- // 30 seconds per test
25
+ testTimeout: 20_000,
26
+ // 20 seconds per test
63
27
 
64
28
  // --------------- Setup Files ---------------
65
29
  // Injects `jest` into globalThis so ESM test files don't need
66
30
  // `import { jest } from '@jest/globals'` manually.
67
31
  setupFiles: [_path.default.resolve(__dirname, '..', 'environment', 'globals-inject.js')],
68
- // --------------- Module Resolution ---------------
69
- moduleFileExtensions: ['js', 'mjs', 'ts', 'json', 'node'],
70
- // --------------- Misc ---------------
71
- verbose: true,
32
+ moduleFileExtensions: ['js', 'mjs', 'json', 'node'],
72
33
  passWithNoTests: true,
73
- clearMocks: true,
74
- resetMocks: false
34
+ clearMocks: true
75
35
  };
76
36
  }
@@ -10,16 +10,15 @@ function _interopRequireDefault(e) { return e && e.__esModule ? e : { default: e
10
10
  * reporter-handler.js
11
11
  *
12
12
  * Resolves the final reporters array for Jest configuration.
13
+ * All reporters are framework-controlled — consumers cannot supply custom reporters.
13
14
  *
14
- * Supports:
15
+ * Built-in aliases:
15
16
  * - 'default' → Jest built-in default reporter
16
17
  * - 'framework-default' → This package's DefaultReporter
17
- * - Absolute pathsConsumer-supplied reporter modules
18
- * - [reporterPath, options] tuples
18
+ * - 'html-report'This package's HTML reporter
19
19
  */
20
20
 
21
21
  // NOTE: __dirname is available after Babel transpiles ESM → CJS.
22
- // Do not add import.meta.url workarounds here.
23
22
 
24
23
  const BUILTIN_ALIASES = {
25
24
  'framework-default': _path.default.resolve(__dirname, 'default-reporter.js'),
@@ -30,10 +29,9 @@ const BUILTIN_ALIASES = {
30
29
  * Resolve a single reporter entry.
31
30
  *
32
31
  * @param {string | [string, object]} entry
33
- * @param {string} projectRoot
34
32
  * @returns {string | [string, object]}
35
33
  */
36
- function resolveEntry(entry, projectRoot) {
34
+ function resolveEntry(entry) {
37
35
  const isArray = Array.isArray(entry);
38
36
  const name = isArray ? entry[0] : entry;
39
37
  const opts = isArray ? entry[1] : undefined;
@@ -44,23 +42,17 @@ function resolveEntry(entry, projectRoot) {
44
42
  return opts ? [resolved, opts] : resolved;
45
43
  }
46
44
 
47
- // 'default' and package names are passed through as-is
48
- if (name === 'default' || !name.startsWith('.')) {
49
- return entry;
50
- }
51
-
52
- // Relative paths → resolve from consumer project root
53
- const abs = _path.default.resolve(projectRoot, name);
54
- return opts ? [abs, opts] : abs;
45
+ // 'default' and any other entries pass through as-is
46
+ return entry;
55
47
  }
56
48
 
57
49
  /**
58
50
  * Resolve the reporters array for final Jest config.
59
51
  *
60
- * @param {Array<string | [string, object]>} reporters - Raw reporters from merged config.
61
- * @param {string} projectRoot - Consumer project root.
52
+ * @param {Array<string | [string, object]>} reporters - Raw reporters from config.
53
+ * @param {string} [projectRoot] - Consumer project root (unused, kept for API compatibility).
62
54
  * @returns {Array<string | [string, object]>}
63
55
  */
64
- function resolveReporters(reporters = ['default'], projectRoot = process.cwd()) {
65
- return reporters.map(entry => resolveEntry(entry, projectRoot));
56
+ function resolveReporters(reporters = ['default'], projectRoot) {
57
+ return reporters.map(entry => resolveEntry(entry));
66
58
  }
@@ -5,57 +5,22 @@ Object.defineProperty(exports, "__esModule", {
5
5
  });
6
6
  exports.default = createJestRunner;
7
7
  var _runnerBase = require("./runner-base.js");
8
- /**
9
- * jest-runner.js
10
- *
11
- * Core module that runs Jest programmatically via @jest/core's runCLI.
12
- *
13
- * Exported as default from the package's index.js so consumers do:
14
- * import createJestRunner from 'unit-testing-framework';
15
- * await createJestRunner({ projectRoot: process.cwd() });
16
- */
17
-
18
- /**
19
- * @typedef {object} RunnerOptions
20
- * @property {string} [projectRoot] - Absolute path to the consumer project (default: cwd).
21
- * @property {string[]} [testFiles] - Specific test file patterns to run.
22
- * @property {string} [testPathPattern] - Regex pattern to match test file paths (e.g. 'myFile.test.js').
23
- * @property {boolean} [verbose] - Verbose output.
24
- * @property {number|string} [maxWorkers] - Worker concurrency (e.g. '50%' or 4).
25
- * @property {boolean} [silent] - Suppress console output from tests.
26
- * @property {boolean} [watch] - Run in watch mode.
27
- */
28
-
29
- /**
30
- * Create and execute a Jest test run.
31
- *
32
- * @param {RunnerOptions} [options={}]
33
- * @returns {Promise<import('@jest/core').AggregatedResult>} Jest aggregated results.
34
- */
8
+ var _defaultConfig = require("../config/default-config.js");
35
9
  async function createJestRunner(options = {}) {
36
10
  const {
37
11
  projectRoot = process.cwd(),
38
- testFiles,
39
12
  testPathPattern,
40
- verbose,
41
- maxWorkers,
42
- silent,
43
13
  watch = false
44
14
  } = options;
45
15
 
46
- // ── 1. Build base config with overrides ────────────────────
47
- const config = (0, _runnerBase.createBaseConfig)(projectRoot, {
48
- verbose,
49
- maxWorkers,
50
- silent
51
- });
16
+ // ── 1. Build framework-controlled config ───────────────────
17
+ const config = (0, _defaultConfig.getDefaultConfig)(projectRoot);
52
18
 
53
19
  // ── 2. Resolve reporters ───────────────────────────────────
54
20
  (0, _runnerBase.resolveConfigReporters)(config, projectRoot);
55
21
 
56
22
  // ── 3. Build argv & run Jest ───────────────────────────────
57
23
  const argv = (0, _runnerBase.buildArgv)(config, {
58
- testFiles,
59
24
  testPathPattern,
60
25
  watch,
61
26
  projectRoot
@@ -4,99 +4,29 @@ Object.defineProperty(exports, "__esModule", {
4
4
  value: true
5
5
  });
6
6
  exports.buildArgv = buildArgv;
7
- exports.createBaseConfig = createBaseConfig;
8
7
  exports.executeJest = executeJest;
9
8
  exports.resolveConfigReporters = resolveConfigReporters;
10
- var _defaultConfig = require("../config/default-config.js");
11
9
  var _reporterHandler = require("../reporters/reporter-handler.js");
12
- function _interopRequireWildcard(e, t) { if ("function" == typeof WeakMap) var r = new WeakMap(), n = new WeakMap(); return (_interopRequireWildcard = function (e, t) { if (!t && e && e.__esModule) return e; var o, i, f = { __proto__: null, default: e }; if (null === e || "object" != typeof e && "function" != typeof e) return f; if (o = t ? n : r) { if (o.has(e)) return o.get(e); o.set(e, f); } for (const t in e) "default" !== t && {}.hasOwnProperty.call(e, t) && ((i = (o = Object.defineProperty) && Object.getOwnPropertyDescriptor(e, t)) && (i.get || i.set) ? o(f, t, i) : f[t] = e[t]); return f; })(e, t); } /**
13
- * runner-base.js
14
- *
15
- * Shared utilities for the Jest test runner.
16
- * Keeps common logic in one place for reuse.
17
- */
18
- /**
19
- * Create the base Jest config with common CLI overrides applied.
20
- *
21
- * @param {string} projectRoot
22
- * @param {object} [overrides]
23
- * @param {boolean} [overrides.verbose]
24
- * @param {number|string} [overrides.maxWorkers]
25
- * @param {boolean} [overrides.silent]
26
- * @returns {import('@jest/types').Config.InitialOptions}
27
- */
28
- function createBaseConfig(projectRoot, overrides = {}) {
29
- const config = (0, _defaultConfig.getDefaultConfig)(projectRoot);
30
- if (overrides.verbose !== undefined) config.verbose = overrides.verbose;
31
- if (overrides.maxWorkers !== undefined) config.maxWorkers = overrides.maxWorkers;
32
- if (overrides.silent !== undefined) config.silent = overrides.silent;
33
- return config;
34
- }
35
-
36
- /**
37
- * Resolve reporter aliases in the config and return the updated config.
38
- *
39
- * @param {object} config - Mutable Jest config.
40
- * @param {string} projectRoot
41
- * @returns {object} The same config reference (mutated).
42
- */
10
+ function _interopRequireWildcard(e, t) { if ("function" == typeof WeakMap) var r = new WeakMap(), n = new WeakMap(); return (_interopRequireWildcard = function (e, t) { if (!t && e && e.__esModule) return e; var o, i, f = { __proto__: null, default: e }; if (null === e || "object" != typeof e && "function" != typeof e) return f; if (o = t ? n : r) { if (o.has(e)) return o.get(e); o.set(e, f); } for (const t in e) "default" !== t && {}.hasOwnProperty.call(e, t) && ((i = (o = Object.defineProperty) && Object.getOwnPropertyDescriptor(e, t)) && (i.get || i.set) ? o(f, t, i) : f[t] = e[t]); return f; })(e, t); }
43
11
  function resolveConfigReporters(config, projectRoot) {
44
- config.reporters = (0, _reporterHandler.resolveReporters)(config.reporters, projectRoot);
45
- return config;
12
+ return {
13
+ ...config,
14
+ reporters: (0, _reporterHandler.resolveReporters)(config.reporters, projectRoot)
15
+ };
46
16
  }
47
-
48
- /**
49
- * Build a yargs-compatible argv object that runCLI understands.
50
- *
51
- * @param {object} config - Merged Jest config.
52
- * @param {object} params
53
- * @param {string[]} [params.testFiles] - Explicit test file patterns.
54
- * @param {string} [params.testPathPattern] - Regex to filter test files.
55
- * @param {boolean} [params.watch] - Watch mode flag.
56
- * @param {string} params.projectRoot - Consumer project root.
57
- * @returns {object}
58
- */
59
17
  function buildArgv(config, {
60
- testFiles,
61
18
  testPathPattern,
62
- watch = false,
63
- projectRoot
19
+ watch = false
64
20
  }) {
65
21
  const argv = {
66
- // Serialise the config so Jest uses our merged config
67
- // instead of searching for jest.config.* files.
68
22
  config: JSON.stringify(config),
69
- // Project root for resolution
70
- rootDir: projectRoot,
71
- // Flags
72
- watch,
73
- watchAll: false,
74
- ci: process.env.CI === 'true',
75
- // Pass-through values that CLI users might expect
76
- verbose: config.verbose ?? true,
77
- passWithNoTests: config.passWithNoTests ?? true,
78
- maxWorkers: config.maxWorkers ?? '50%',
79
- silent: config.silent ?? false,
80
- // Do not search for config files automatically
81
- _: testFiles ?? [],
82
- $0: 'unit-testing-framework'
23
+ watch
83
24
  };
84
-
85
- // Jest 30 uses `testPathPatterns` (plural, array) instead of
86
- // the old `testPathPattern` (singular, string) from Jest ≤29.
87
25
  if (testPathPattern) {
88
26
  argv.testPathPatterns = [testPathPattern];
89
27
  }
90
28
  return argv;
91
29
  }
92
-
93
- /**
94
- * Lazy-import @jest/core and execute runCLI.
95
- *
96
- * @param {object} argv - yargs-style argv for runCLI.
97
- * @param {string} projectRoot
98
- * @returns {Promise<import('@jest/core').AggregatedResult>}
99
- */
100
30
  async function executeJest(argv, projectRoot) {
101
31
  const {
102
32
  runCLI
package/package.json CHANGED
@@ -1,13 +1,10 @@
1
1
  {
2
2
  "name": "@zohodesk/unit-testing-framework",
3
- "version": "0.0.21-experimental",
3
+ "version": "0.0.23-experimental",
4
4
  "description": "A modular Jest-based unit testing framework",
5
5
  "main": "./build/index.js",
6
6
  "exports": {
7
- ".": "./build/index.js",
8
- "./config": "./build/src/config/default-config.js",
9
- "./reporters": "./build/src/reporters/reporter-handler.js",
10
- "./runner": "./build/src/runner/jest-runner.js"
7
+ ".": "./build/index.js"
11
8
  },
12
9
  "files": [
13
10
  "build/"
@@ -1,9 +0,0 @@
1
- "use strict";
2
-
3
- class configConstants {
4
- static DEFAULT_CONFIG_DIR = 'default';
5
- static UNIT_CONFIG_FILE = 'unit.config.js';
6
- static STAGE_CONFIG_MAP_FILE = 'test-slices/conf_path_map.properties';
7
- static TEST_SLICE_FOLDER = 'test-slices';
8
- }
9
- module.exports = configConstants;
@@ -1,13 +0,0 @@
1
- "use strict";
2
-
3
- Object.defineProperty(exports, "__esModule", {
4
- value: true
5
- });
6
- exports.mergeObjects = mergeObjects;
7
- // Utility function to merge objects using spread operator
8
- function mergeObjects(obj1, obj2) {
9
- return {
10
- ...obj1,
11
- ...obj2
12
- };
13
- }