@zohodesk/unit-testing-framework 0.0.4-experimental → 0.0.6-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
@@ -15,22 +15,22 @@ Object.defineProperty(exports, "default", {
15
15
  return _jestRunner.default;
16
16
  }
17
17
  });
18
- Object.defineProperty(exports, "globalSetup", {
18
+ Object.defineProperty(exports, "getDefaultConfig", {
19
19
  enumerable: true,
20
20
  get: function () {
21
- return _setup.default;
21
+ return _defaultConfig.getDefaultConfig;
22
22
  }
23
23
  });
24
- Object.defineProperty(exports, "globalTeardown", {
24
+ Object.defineProperty(exports, "globalSetup", {
25
25
  enumerable: true,
26
26
  get: function () {
27
- return _teardown.default;
27
+ return _setup.default;
28
28
  }
29
29
  });
30
- Object.defineProperty(exports, "loadConfig", {
30
+ Object.defineProperty(exports, "globalTeardown", {
31
31
  enumerable: true,
32
32
  get: function () {
33
- return _configLoader.loadConfig;
33
+ return _teardown.default;
34
34
  }
35
35
  });
36
36
  Object.defineProperty(exports, "resolveReporters", {
@@ -40,7 +40,7 @@ Object.defineProperty(exports, "resolveReporters", {
40
40
  }
41
41
  });
42
42
  var _jestRunner = _interopRequireDefault(require("./src/runner/jest-runner.js"));
43
- var _configLoader = require("./src/config/config-loader.js");
43
+ var _defaultConfig = require("./src/config/default-config.js");
44
44
  var _reporterHandler = require("./src/reporters/reporter-handler.js");
45
45
  var _setup = _interopRequireDefault(require("./src/environment/setup.js"));
46
46
  var _teardown = _interopRequireDefault(require("./src/environment/teardown.js"));
@@ -32,8 +32,8 @@ function getDefaultConfig(projectRoot) {
32
32
  // so we root Jest at the project itself and rely on testMatch
33
33
  // to locate **/__tests__/**/* files at any depth.
34
34
  roots: [projectRoot],
35
- testMatch: ['**/__tests__/**/*.test.js', '**/__tests__/**/*.test.mjs', '**/__tests__/**/*.test.ts', '**/__tests__/**/*.spec.js', '**/__tests__/**/*.spec.mjs', '**/__tests__/**/*.spec.ts'],
36
- testPathIgnorePatterns: ['/node_modules/', '/dist/', '/build/'],
35
+ testMatch: ['**/__tests__/**/*.test.js'],
36
+ testPathIgnorePatterns: ['/node_modules/', '/build/'],
37
37
  // --------------- Environment ---------------
38
38
  testEnvironment: 'node',
39
39
  // --------------- Transform ---------------
@@ -0,0 +1,13 @@
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
+ }
@@ -5,7 +5,7 @@ Object.defineProperty(exports, "__esModule", {
5
5
  });
6
6
  exports.default = createJestRunner;
7
7
  var _path = _interopRequireDefault(require("path"));
8
- var _configLoader = require("../config/config-loader.js");
8
+ var _defaultConfig = require("../config/default-config.js");
9
9
  var _reporterHandler = require("../reporters/reporter-handler.js");
10
10
  function _interopRequireDefault(e) { return e && e.__esModule ? e : { default: e }; }
11
11
  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); } /**
@@ -20,8 +20,6 @@ function _interopRequireWildcard(e, t) { if ("function" == typeof WeakMap) var r
20
20
  /**
21
21
  * @typedef {object} RunnerOptions
22
22
  * @property {string} [projectRoot] - Absolute path to the consumer project (default: cwd).
23
- * @property {string} [configPath] - Path to consumer jest.unit.config.{js,mjs,json}.
24
- * @property {object} [inlineConfig] - Inline Jest config overrides (highest priority).
25
23
  * @property {boolean} [coverage] - Enable coverage collection.
26
24
  * @property {string[]} [testFiles] - Specific test file patterns to run.
27
25
  * @property {boolean} [verbose] - Verbose output.
@@ -39,8 +37,6 @@ function _interopRequireWildcard(e, t) { if ("function" == typeof WeakMap) var r
39
37
  async function createJestRunner(options = {}) {
40
38
  const {
41
39
  projectRoot = process.cwd(),
42
- configPath,
43
- inlineConfig = {},
44
40
  coverage,
45
41
  testFiles,
46
42
  verbose,
@@ -49,12 +45,8 @@ async function createJestRunner(options = {}) {
49
45
  watch = false
50
46
  } = options;
51
47
 
52
- // ── 1. Load & merge configuration ──────────────────────────
53
- const mergedConfig = await (0, _configLoader.loadConfig)({
54
- projectRoot,
55
- configPath,
56
- inlineConfig
57
- });
48
+ // ── 1. Get default configuration ───────────────────────────
49
+ const mergedConfig = (0, _defaultConfig.getDefaultConfig)(projectRoot);
58
50
 
59
51
  // ── 2. Apply CLI-level overrides ───────────────────────────
60
52
  if (coverage !== undefined) mergedConfig.collectCoverage = coverage;
package/package.json CHANGED
@@ -1,11 +1,11 @@
1
1
  {
2
2
  "name": "@zohodesk/unit-testing-framework",
3
- "version": "0.0.4-experimental",
3
+ "version": "0.0.6-experimental",
4
4
  "description": "A modular Jest-based unit testing framework",
5
5
  "main": "./build/index.js",
6
6
  "exports": {
7
7
  ".": "./build/index.js",
8
- "./config": "./build/src/config/config-loader.js",
8
+ "./config": "./build/src/config/default-config.js",
9
9
  "./reporters": "./build/src/reporters/reporter-handler.js",
10
10
  "./runner": "./build/src/runner/jest-runner.js"
11
11
  },
@@ -1,119 +0,0 @@
1
- "use strict";
2
-
3
- Object.defineProperty(exports, "__esModule", {
4
- value: true
5
- });
6
- exports.loadConfig = loadConfig;
7
- var _fs = _interopRequireDefault(require("fs"));
8
- var _path = _interopRequireDefault(require("path"));
9
- var _url = require("url");
10
- var _defaultConfig = require("./default-config.js");
11
- function _interopRequireDefault(e) { return e && e.__esModule ? e : { default: e }; }
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
- * config-loader.js
14
- *
15
- * Responsible for:
16
- * 1. Loading the framework default config.
17
- * 2. Loading optional consumer-level config (file or inline).
18
- * 3. Deep-merging them with consumer config taking priority.
19
- *
20
- * Merge priority (highest → lowest):
21
- * inline options > consumer config file > framework defaults
22
- */
23
- /**
24
- * Deep-merge two plain objects. Arrays are concatenated & de-duped.
25
- * `source` values override `target` values.
26
- */
27
- function deepMerge(target, source) {
28
- const output = {
29
- ...target
30
- };
31
- for (const key of Object.keys(source)) {
32
- const srcVal = source[key];
33
- const tgtVal = target[key];
34
- if (srcVal === undefined) continue;
35
- if (Array.isArray(srcVal) && Array.isArray(tgtVal)) {
36
- // Concatenate and de-duplicate
37
- output[key] = [...new Set([...tgtVal, ...srcVal])];
38
- } else if (srcVal !== null && typeof srcVal === 'object' && !Array.isArray(srcVal) && tgtVal !== null && typeof tgtVal === 'object' && !Array.isArray(tgtVal)) {
39
- output[key] = deepMerge(tgtVal, srcVal);
40
- } else {
41
- output[key] = srcVal;
42
- }
43
- }
44
- return output;
45
- }
46
-
47
- /**
48
- * Attempt to load a consumer config file.
49
- * Supports: .js (ESM), .mjs, .json, .ts (if ts-node is available).
50
- *
51
- * @param {string} configPath - Absolute path to the config file.
52
- * @returns {Promise<object>} Loaded configuration or empty object.
53
- */
54
- async function loadConfigFile(configPath) {
55
- if (!_fs.default.existsSync(configPath)) {
56
- return {};
57
- }
58
- const ext = _path.default.extname(configPath).toLowerCase();
59
- if (ext === '.json') {
60
- const raw = _fs.default.readFileSync(configPath, 'utf-8');
61
- return JSON.parse(raw);
62
- }
63
-
64
- // ESM dynamic import works for .js / .mjs
65
- const fileUrl = (0, _url.pathToFileURL)(configPath).href;
66
- const mod = await (specifier => new Promise(r => r(`${specifier}`)).then(s => _interopRequireWildcard(require(s))))(fileUrl);
67
- return mod.default ?? mod;
68
- }
69
-
70
- /**
71
- * Resolve the consumer config file path.
72
- * Search order:
73
- * 1. Explicit `configPath` option
74
- * 2. `jest.unit.config.js` in project root
75
- * 3. `jest.unit.config.mjs` in project root
76
- * 4. `jest.unit.config.json` in project root
77
- *
78
- * @param {string} projectRoot
79
- * @param {string} [explicitPath]
80
- * @returns {string|null}
81
- */
82
- function resolveConfigFilePath(projectRoot, explicitPath) {
83
- if (explicitPath) {
84
- const abs = _path.default.isAbsolute(explicitPath) ? explicitPath : _path.default.resolve(projectRoot, explicitPath);
85
- return _fs.default.existsSync(abs) ? abs : null;
86
- }
87
- const candidates = ['jest.unit.config.js', 'jest.unit.config.mjs', 'jest.unit.config.json'];
88
- for (const name of candidates) {
89
- const full = _path.default.resolve(projectRoot, name);
90
- if (_fs.default.existsSync(full)) return full;
91
- }
92
- return null;
93
- }
94
-
95
- /**
96
- * Load and merge configuration.
97
- *
98
- * @param {object} options
99
- * @param {string} options.projectRoot - Consumer project root (default: process.cwd()).
100
- * @param {string} [options.configPath] - Explicit path to consumer config.
101
- * @param {object} [options.inlineConfig] - Inline overrides (highest priority).
102
- * @returns {Promise<import('@jest/types').Config.InitialOptions>}
103
- */
104
- async function loadConfig({
105
- projectRoot = process.cwd(),
106
- configPath,
107
- inlineConfig = {}
108
- } = {}) {
109
- // 1. Framework defaults
110
- const defaults = (0, _defaultConfig.getDefaultConfig)(projectRoot);
111
-
112
- // 2. Consumer config file
113
- const resolvedPath = resolveConfigFilePath(projectRoot, configPath);
114
- const consumerFileConfig = resolvedPath ? await loadConfigFile(resolvedPath) : {};
115
-
116
- // 3. Merge: defaults ← consumer file ← inline
117
- const merged = deepMerge(deepMerge(defaults, consumerFileConfig), inlineConfig);
118
- return merged;
119
- }