@zohodesk/unit-testing-framework 0.0.20-experimental → 0.0.22-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/src/config/default-config.js +5 -8
- package/build/src/reporters/reporter-handler.js +10 -18
- package/build/src/runner/jest-runner.js +9 -21
- package/build/src/runner/runner-base.js +9 -21
- package/package.json +2 -5
- package/build/src/constants/configConstants.js +0 -9
- package/build/src/helpers/mergeObjects.js +0 -13
|
@@ -9,18 +9,15 @@ function _interopRequireDefault(e) { return e && e.__esModule ? e : { default: e
|
|
|
9
9
|
/**
|
|
10
10
|
* default-config.js
|
|
11
11
|
*
|
|
12
|
-
* Framework-level
|
|
13
|
-
*
|
|
14
|
-
*
|
|
12
|
+
* Framework-level Jest configuration.
|
|
13
|
+
* All settings are managed internally by the library.
|
|
14
|
+
* Consumer projects do not need any Jest config files.
|
|
15
15
|
*/
|
|
16
16
|
|
|
17
17
|
// NOTE: __dirname is available after Babel transpiles ESM → CJS.
|
|
18
|
-
// Do not add import.meta.url workarounds here.
|
|
19
18
|
|
|
20
19
|
/**
|
|
21
|
-
* Returns the
|
|
22
|
-
* Paths are resolved relative to the consumer's project root
|
|
23
|
-
* (passed at runtime), NOT relative to this package.
|
|
20
|
+
* Returns the framework-controlled Jest configuration.
|
|
24
21
|
*
|
|
25
22
|
* @param {string} projectRoot - Absolute path to the consumer project root.
|
|
26
23
|
* @returns {import('@jest/types').Config.InitialOptions}
|
|
@@ -33,7 +30,7 @@ function getDefaultConfig(projectRoot) {
|
|
|
33
30
|
// to locate **/__tests__/**/* files at any depth.
|
|
34
31
|
rootDir: process.cwd(),
|
|
35
32
|
testMatch: ['**/__tests__/**/*.test.js'],
|
|
36
|
-
testPathIgnorePatterns: ['/node_modules/', '/build/'
|
|
33
|
+
testPathIgnorePatterns: ['/node_modules/', '/build/'],
|
|
37
34
|
// --------------- Environment ---------------
|
|
38
35
|
testEnvironment: 'jsdom',
|
|
39
36
|
// --------------- Transform ---------------
|
|
@@ -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
|
-
*
|
|
15
|
+
* Built-in aliases:
|
|
15
16
|
* - 'default' → Jest built-in default reporter
|
|
16
17
|
* - 'framework-default' → This package's DefaultReporter
|
|
17
|
-
* -
|
|
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
|
|
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
|
|
48
|
-
|
|
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
|
|
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
|
|
65
|
-
return reporters.map(entry => resolveEntry(entry
|
|
56
|
+
function resolveReporters(reporters = ['default'], projectRoot) {
|
|
57
|
+
return reporters.map(entry => resolveEntry(entry));
|
|
66
58
|
}
|
|
@@ -9,21 +9,18 @@ var _runnerBase = require("./runner-base.js");
|
|
|
9
9
|
* jest-runner.js
|
|
10
10
|
*
|
|
11
11
|
* Core module that runs Jest programmatically via @jest/core's runCLI.
|
|
12
|
+
* All Jest configuration is managed internally by the framework.
|
|
12
13
|
*
|
|
13
|
-
*
|
|
14
|
-
* import createJestRunner from 'unit-testing-framework';
|
|
15
|
-
* await createJestRunner(
|
|
14
|
+
* Usage (consumer):
|
|
15
|
+
* import createJestRunner from '@zohodesk/unit-testing-framework';
|
|
16
|
+
* await createJestRunner();
|
|
16
17
|
*/
|
|
17
18
|
|
|
18
19
|
/**
|
|
19
20
|
* @typedef {object} RunnerOptions
|
|
20
|
-
* @property {string} [projectRoot]
|
|
21
|
-
* @property {string[]
|
|
22
|
-
* @property {
|
|
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.
|
|
21
|
+
* @property {string} [projectRoot] - Absolute path to the consumer project (default: cwd).
|
|
22
|
+
* @property {string} [testPathPattern] - Regex to filter test file paths (e.g. 'myFile.test.js').
|
|
23
|
+
* @property {boolean} [watch] - Run in watch mode.
|
|
27
24
|
*/
|
|
28
25
|
|
|
29
26
|
/**
|
|
@@ -35,27 +32,18 @@ var _runnerBase = require("./runner-base.js");
|
|
|
35
32
|
async function createJestRunner(options = {}) {
|
|
36
33
|
const {
|
|
37
34
|
projectRoot = process.cwd(),
|
|
38
|
-
testFiles,
|
|
39
35
|
testPathPattern,
|
|
40
|
-
verbose,
|
|
41
|
-
maxWorkers,
|
|
42
|
-
silent,
|
|
43
36
|
watch = false
|
|
44
37
|
} = options;
|
|
45
38
|
|
|
46
|
-
// ── 1. Build
|
|
47
|
-
const config = (0, _runnerBase.createBaseConfig)(projectRoot
|
|
48
|
-
verbose,
|
|
49
|
-
maxWorkers,
|
|
50
|
-
silent
|
|
51
|
-
});
|
|
39
|
+
// ── 1. Build framework-controlled config ───────────────────
|
|
40
|
+
const config = (0, _runnerBase.createBaseConfig)(projectRoot);
|
|
52
41
|
|
|
53
42
|
// ── 2. Resolve reporters ───────────────────────────────────
|
|
54
43
|
(0, _runnerBase.resolveConfigReporters)(config, projectRoot);
|
|
55
44
|
|
|
56
45
|
// ── 3. Build argv & run Jest ───────────────────────────────
|
|
57
46
|
const argv = (0, _runnerBase.buildArgv)(config, {
|
|
58
|
-
testFiles,
|
|
59
47
|
testPathPattern,
|
|
60
48
|
watch,
|
|
61
49
|
projectRoot
|
|
@@ -13,24 +13,16 @@ function _interopRequireWildcard(e, t) { if ("function" == typeof WeakMap) var r
|
|
|
13
13
|
* runner-base.js
|
|
14
14
|
*
|
|
15
15
|
* Shared utilities for the Jest test runner.
|
|
16
|
-
*
|
|
16
|
+
* All configuration is framework-controlled — no consumer overrides.
|
|
17
17
|
*/
|
|
18
18
|
/**
|
|
19
|
-
* Create the
|
|
19
|
+
* Create the framework-controlled Jest config.
|
|
20
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]
|
|
21
|
+
* @param {string} projectRoot - Consumer project root directory.
|
|
26
22
|
* @returns {import('@jest/types').Config.InitialOptions}
|
|
27
23
|
*/
|
|
28
|
-
function createBaseConfig(projectRoot
|
|
29
|
-
|
|
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;
|
|
24
|
+
function createBaseConfig(projectRoot) {
|
|
25
|
+
return (0, _defaultConfig.getDefaultConfig)(projectRoot);
|
|
34
26
|
}
|
|
35
27
|
|
|
36
28
|
/**
|
|
@@ -48,22 +40,20 @@ function resolveConfigReporters(config, projectRoot) {
|
|
|
48
40
|
/**
|
|
49
41
|
* Build a yargs-compatible argv object that runCLI understands.
|
|
50
42
|
*
|
|
51
|
-
* @param {object} config -
|
|
43
|
+
* @param {object} config - Jest config from the framework.
|
|
52
44
|
* @param {object} params
|
|
53
|
-
* @param {string[]} [params.testFiles] - Explicit test file patterns.
|
|
54
45
|
* @param {string} [params.testPathPattern] - Regex to filter test files.
|
|
55
46
|
* @param {boolean} [params.watch] - Watch mode flag.
|
|
56
47
|
* @param {string} params.projectRoot - Consumer project root.
|
|
57
48
|
* @returns {object}
|
|
58
49
|
*/
|
|
59
50
|
function buildArgv(config, {
|
|
60
|
-
testFiles,
|
|
61
51
|
testPathPattern,
|
|
62
52
|
watch = false,
|
|
63
53
|
projectRoot
|
|
64
54
|
}) {
|
|
65
55
|
const argv = {
|
|
66
|
-
// Serialise the config so Jest uses our
|
|
56
|
+
// Serialise the config so Jest uses our framework config
|
|
67
57
|
// instead of searching for jest.config.* files.
|
|
68
58
|
config: JSON.stringify(config),
|
|
69
59
|
// Project root for resolution
|
|
@@ -72,13 +62,13 @@ function buildArgv(config, {
|
|
|
72
62
|
watch,
|
|
73
63
|
watchAll: false,
|
|
74
64
|
ci: process.env.CI === 'true',
|
|
75
|
-
//
|
|
65
|
+
// Framework-controlled values
|
|
76
66
|
verbose: config.verbose ?? true,
|
|
77
67
|
passWithNoTests: config.passWithNoTests ?? true,
|
|
78
68
|
maxWorkers: config.maxWorkers ?? '50%',
|
|
79
69
|
silent: config.silent ?? false,
|
|
80
70
|
// Do not search for config files automatically
|
|
81
|
-
_:
|
|
71
|
+
_: [],
|
|
82
72
|
$0: 'unit-testing-framework'
|
|
83
73
|
};
|
|
84
74
|
|
|
@@ -87,7 +77,6 @@ function buildArgv(config, {
|
|
|
87
77
|
if (testPathPattern) {
|
|
88
78
|
argv.testPathPatterns = [testPathPattern];
|
|
89
79
|
}
|
|
90
|
-
console.log('Jest CLI argv:', argv);
|
|
91
80
|
return argv;
|
|
92
81
|
}
|
|
93
82
|
|
|
@@ -105,6 +94,5 @@ async function executeJest(argv, projectRoot) {
|
|
|
105
94
|
const {
|
|
106
95
|
results
|
|
107
96
|
} = await runCLI(argv, [projectRoot]);
|
|
108
|
-
console.log('Jest run results:', results);
|
|
109
97
|
return results;
|
|
110
98
|
}
|
package/package.json
CHANGED
|
@@ -1,13 +1,10 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@zohodesk/unit-testing-framework",
|
|
3
|
-
"version": "0.0.
|
|
3
|
+
"version": "0.0.22-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
|
-
}
|