@zohodesk/unit-testing-framework 0.0.29-experimental → 0.0.30-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.
|
@@ -0,0 +1,74 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.deepMerge = deepMerge;
|
|
7
|
+
exports.loadUserConfig = loadUserConfig;
|
|
8
|
+
exports.resolveConfig = resolveConfig;
|
|
9
|
+
var _fs = _interopRequireDefault(require("fs"));
|
|
10
|
+
var _path = _interopRequireDefault(require("path"));
|
|
11
|
+
var _defaultConfig = require("./default-config.js");
|
|
12
|
+
var _logger = require("../utils/logger.js");
|
|
13
|
+
function _interopRequireDefault(e) { return e && e.__esModule ? e : { default: e }; }
|
|
14
|
+
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); }
|
|
15
|
+
const CONFIG_FILE_NAMES = ['ut.config.js', 'ut.config.mjs', 'ut.config.json'];
|
|
16
|
+
function isPlainObject(value) {
|
|
17
|
+
return value !== null && typeof value === 'object' && !Array.isArray(value);
|
|
18
|
+
}
|
|
19
|
+
function deepMerge(target, source) {
|
|
20
|
+
const result = {
|
|
21
|
+
...target
|
|
22
|
+
};
|
|
23
|
+
for (const key of Object.keys(source)) {
|
|
24
|
+
const targetVal = target[key];
|
|
25
|
+
const sourceVal = source[key];
|
|
26
|
+
if (Array.isArray(targetVal) && Array.isArray(sourceVal)) {
|
|
27
|
+
result[key] = [...targetVal, ...sourceVal];
|
|
28
|
+
} else if (isPlainObject(targetVal) && isPlainObject(sourceVal)) {
|
|
29
|
+
result[key] = deepMerge(targetVal, sourceVal);
|
|
30
|
+
} else {
|
|
31
|
+
result[key] = sourceVal;
|
|
32
|
+
}
|
|
33
|
+
}
|
|
34
|
+
return result;
|
|
35
|
+
}
|
|
36
|
+
async function loadUserConfig(projectRoot, configPath) {
|
|
37
|
+
let resolvedPath = null;
|
|
38
|
+
if (configPath) {
|
|
39
|
+
resolvedPath = _path.default.resolve(projectRoot, configPath);
|
|
40
|
+
if (!_fs.default.existsSync(resolvedPath)) {
|
|
41
|
+
_logger.Logger.error(`Config file not found: ${resolvedPath}`);
|
|
42
|
+
return null;
|
|
43
|
+
}
|
|
44
|
+
} else {
|
|
45
|
+
for (const fileName of CONFIG_FILE_NAMES) {
|
|
46
|
+
const candidate = _path.default.resolve(projectRoot, fileName);
|
|
47
|
+
if (_fs.default.existsSync(candidate)) {
|
|
48
|
+
resolvedPath = candidate;
|
|
49
|
+
_logger.Logger.info(`Auto-discovered config: ${fileName}`);
|
|
50
|
+
break;
|
|
51
|
+
}
|
|
52
|
+
}
|
|
53
|
+
}
|
|
54
|
+
if (!resolvedPath) {
|
|
55
|
+
return null;
|
|
56
|
+
}
|
|
57
|
+
if (resolvedPath.endsWith('.json')) {
|
|
58
|
+
const raw = _fs.default.readFileSync(resolvedPath, 'utf-8');
|
|
59
|
+
return JSON.parse(raw);
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
// .js or .mjs — use dynamic import
|
|
63
|
+
const module = await (specifier => new Promise(r => r(`${specifier}`)).then(s => _interopRequireWildcard(require(s))))(resolvedPath);
|
|
64
|
+
return module.default || module;
|
|
65
|
+
}
|
|
66
|
+
async function resolveConfig(projectRoot, configPath) {
|
|
67
|
+
const defaultConfig = (0, _defaultConfig.getDefaultConfig)(projectRoot);
|
|
68
|
+
const userConfig = await loadUserConfig(projectRoot, configPath);
|
|
69
|
+
if (userConfig) {
|
|
70
|
+
_logger.Logger.info('Merging user config with default config');
|
|
71
|
+
return userConfig;
|
|
72
|
+
}
|
|
73
|
+
return defaultConfig;
|
|
74
|
+
}
|
|
@@ -4,21 +4,47 @@ Object.defineProperty(exports, "__esModule", {
|
|
|
4
4
|
value: true
|
|
5
5
|
});
|
|
6
6
|
exports.default = createJestRunner;
|
|
7
|
+
var _fs = _interopRequireDefault(require("fs"));
|
|
8
|
+
var _path = _interopRequireDefault(require("path"));
|
|
7
9
|
var _runnerBase = require("./runner-base.js");
|
|
8
|
-
var
|
|
10
|
+
var _configLoader = require("../config/config-loader.js");
|
|
11
|
+
var _logger = require("../utils/logger.js");
|
|
12
|
+
function _interopRequireDefault(e) { return e && e.__esModule ? e : { default: e }; }
|
|
13
|
+
function resolveTestFiles(testFiles, projectRoot) {
|
|
14
|
+
const files = testFiles.split(',').map(f => f.trim()).filter(Boolean);
|
|
15
|
+
const resolved = [];
|
|
16
|
+
for (const file of files) {
|
|
17
|
+
const abs = _path.default.resolve(projectRoot, file);
|
|
18
|
+
if (_fs.default.existsSync(abs)) {
|
|
19
|
+
resolved.push(abs);
|
|
20
|
+
} else {
|
|
21
|
+
_logger.Logger.error(`Test file not found: ${abs}`);
|
|
22
|
+
}
|
|
23
|
+
}
|
|
24
|
+
if (resolved.length === 0) {
|
|
25
|
+
return null;
|
|
26
|
+
}
|
|
27
|
+
return resolved;
|
|
28
|
+
}
|
|
9
29
|
async function createJestRunner(options = {}) {
|
|
10
30
|
const {
|
|
11
31
|
projectRoot = process.cwd(),
|
|
32
|
+
testFiles,
|
|
12
33
|
testPathPattern,
|
|
13
|
-
|
|
34
|
+
configPath,
|
|
35
|
+
watch = false
|
|
14
36
|
} = options;
|
|
15
37
|
|
|
16
|
-
// ── 1.
|
|
17
|
-
const config = (0,
|
|
38
|
+
// ── 1. Resolve config (auto-discover / configPath / default) ──
|
|
39
|
+
const config = await (0, _configLoader.resolveConfig)(projectRoot, configPath);
|
|
18
40
|
|
|
19
|
-
// ── 2.
|
|
41
|
+
// ── 2. Resolve test file pattern ──────────────────────────────
|
|
42
|
+
const rawPattern = testFiles || testPathPattern;
|
|
43
|
+
const pattern = rawPattern && rawPattern.includes(',') ? resolveTestFiles(rawPattern, projectRoot) : rawPattern;
|
|
44
|
+
|
|
45
|
+
// ── 3. Build argv & run Jest ──────────────────────────────────
|
|
20
46
|
const argv = (0, _runnerBase.buildArgv)(config, {
|
|
21
|
-
|
|
47
|
+
testMatch: pattern,
|
|
22
48
|
watch,
|
|
23
49
|
projectRoot
|
|
24
50
|
});
|
|
@@ -7,15 +7,15 @@ exports.buildArgv = buildArgv;
|
|
|
7
7
|
exports.executeJest = executeJest;
|
|
8
8
|
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); }
|
|
9
9
|
function buildArgv(config, {
|
|
10
|
-
|
|
10
|
+
testMatch,
|
|
11
11
|
watch = false
|
|
12
12
|
}) {
|
|
13
13
|
const argv = {
|
|
14
14
|
config: JSON.stringify(config),
|
|
15
15
|
watch
|
|
16
16
|
};
|
|
17
|
-
if (
|
|
18
|
-
argv.
|
|
17
|
+
if (testMatch) {
|
|
18
|
+
argv.testMatch = testMatch;
|
|
19
19
|
}
|
|
20
20
|
return argv;
|
|
21
21
|
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@zohodesk/unit-testing-framework",
|
|
3
|
-
"version": "0.0.
|
|
3
|
+
"version": "0.0.30-experimental",
|
|
4
4
|
"description": "A modular Jest-based unit testing framework",
|
|
5
5
|
"main": "./build/index.js",
|
|
6
6
|
"exports": {
|
|
@@ -25,11 +25,11 @@
|
|
|
25
25
|
"@jest/types": "30.2.0",
|
|
26
26
|
"babel-jest": "30.2.0",
|
|
27
27
|
"jest-environment-jsdom": "30.2.0",
|
|
28
|
-
"jest-html-reporter": "4.3.0"
|
|
28
|
+
"jest-html-reporter": "4.3.0",
|
|
29
|
+
"jest": "30.2.0"
|
|
29
30
|
},
|
|
30
31
|
"devDependencies": {
|
|
31
32
|
"@babel/cli": "7.28.6",
|
|
32
|
-
"@babel/plugin-transform-modules-commonjs": "7.28.6"
|
|
33
|
-
"jest": "30.2.0"
|
|
33
|
+
"@babel/plugin-transform-modules-commonjs": "7.28.6"
|
|
34
34
|
}
|
|
35
35
|
}
|