@zohodesk/unit-testing-framework 0.0.22-experimental → 0.0.24-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,38 +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 Jest configuration.
|
|
13
|
-
* All settings are managed internally by the library.
|
|
14
|
-
* Consumer projects do not need any Jest config files.
|
|
15
|
-
*/
|
|
16
|
-
|
|
17
|
-
// NOTE: __dirname is available after Babel transpiles ESM → CJS.
|
|
18
|
-
|
|
19
|
-
/**
|
|
20
|
-
* Returns the framework-controlled Jest configuration.
|
|
21
|
-
*
|
|
22
|
-
* @param {string} projectRoot - Absolute path to the consumer project root.
|
|
23
|
-
* @returns {import('@jest/types').Config.InitialOptions}
|
|
24
|
-
*/
|
|
25
9
|
function getDefaultConfig(projectRoot) {
|
|
26
10
|
return {
|
|
27
|
-
|
|
28
|
-
// __tests__ folders can be nested anywhere under the project,
|
|
29
|
-
// so we root Jest at the project itself and rely on testMatch
|
|
30
|
-
// to locate **/__tests__/**/* files at any depth.
|
|
31
|
-
rootDir: process.cwd(),
|
|
11
|
+
rootDir: projectRoot,
|
|
32
12
|
testMatch: ['**/__tests__/**/*.test.js'],
|
|
33
|
-
testPathIgnorePatterns: ['/
|
|
34
|
-
// --------------- Environment ---------------
|
|
13
|
+
testPathIgnorePatterns: ['/build/'],
|
|
35
14
|
testEnvironment: 'jsdom',
|
|
36
|
-
// --------------- Transform ---------------
|
|
37
|
-
// Use babel-jest to transform ESM (import/export) and JSX in
|
|
38
|
-
// consumer source & test files. Consumer's own babel config
|
|
39
|
-
// (babel.config.js / .babelrc) will be picked up automatically.
|
|
40
|
-
// If none exists, the fallback preset-env handles plain ESM → CJS.
|
|
41
15
|
transform: {
|
|
42
16
|
'\\.[jt]sx?$': ['babel-jest', {
|
|
43
17
|
presets: [['@babel/preset-env', {
|
|
@@ -47,27 +21,16 @@ function getDefaultConfig(projectRoot) {
|
|
|
47
21
|
}]]
|
|
48
22
|
}]
|
|
49
23
|
},
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
// --------------- Parallelism & Performance ---------------
|
|
54
|
-
maxWorkers: '50%',
|
|
55
|
-
// Use half of available CPUs
|
|
56
|
-
maxConcurrency: 5,
|
|
57
|
-
// --------------- Timeouts ---------------
|
|
58
|
-
testTimeout: 30_000,
|
|
59
|
-
// 30 seconds per test
|
|
24
|
+
reporters: ['default', _path.default.resolve(__dirname, '..', 'reporters', 'html-reporter.js')],
|
|
25
|
+
testTimeout: 20_000,
|
|
26
|
+
// 20 seconds per test
|
|
60
27
|
|
|
61
28
|
// --------------- Setup Files ---------------
|
|
62
29
|
// Injects `jest` into globalThis so ESM test files don't need
|
|
63
30
|
// `import { jest } from '@jest/globals'` manually.
|
|
64
31
|
setupFiles: [_path.default.resolve(__dirname, '..', 'environment', 'globals-inject.js')],
|
|
65
|
-
|
|
66
|
-
moduleFileExtensions: ['js', 'mjs', 'ts', 'json', 'node'],
|
|
67
|
-
// --------------- Misc ---------------
|
|
68
|
-
verbose: true,
|
|
32
|
+
moduleFileExtensions: ['js', 'mjs', 'json', 'node'],
|
|
69
33
|
passWithNoTests: true,
|
|
70
|
-
clearMocks: true
|
|
71
|
-
resetMocks: false
|
|
34
|
+
clearMocks: true
|
|
72
35
|
};
|
|
73
36
|
}
|
|
@@ -5,30 +5,7 @@ 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
|
-
* All Jest configuration is managed internally by the framework.
|
|
13
|
-
*
|
|
14
|
-
* Usage (consumer):
|
|
15
|
-
* import createJestRunner from '@zohodesk/unit-testing-framework';
|
|
16
|
-
* await createJestRunner();
|
|
17
|
-
*/
|
|
18
|
-
|
|
19
|
-
/**
|
|
20
|
-
* @typedef {object} RunnerOptions
|
|
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.
|
|
24
|
-
*/
|
|
25
|
-
|
|
26
|
-
/**
|
|
27
|
-
* Create and execute a Jest test run.
|
|
28
|
-
*
|
|
29
|
-
* @param {RunnerOptions} [options={}]
|
|
30
|
-
* @returns {Promise<import('@jest/core').AggregatedResult>} Jest aggregated results.
|
|
31
|
-
*/
|
|
8
|
+
var _defaultConfig = require("../config/default-config.js");
|
|
32
9
|
async function createJestRunner(options = {}) {
|
|
33
10
|
const {
|
|
34
11
|
projectRoot = process.cwd(),
|
|
@@ -37,12 +14,9 @@ async function createJestRunner(options = {}) {
|
|
|
37
14
|
} = options;
|
|
38
15
|
|
|
39
16
|
// ── 1. Build framework-controlled config ───────────────────
|
|
40
|
-
const config = (0,
|
|
41
|
-
|
|
42
|
-
// ── 2. Resolve reporters ───────────────────────────────────
|
|
43
|
-
(0, _runnerBase.resolveConfigReporters)(config, projectRoot);
|
|
17
|
+
const config = (0, _defaultConfig.getDefaultConfig)(projectRoot);
|
|
44
18
|
|
|
45
|
-
// ──
|
|
19
|
+
// ── 2. Build argv & run Jest ───────────────────────────────
|
|
46
20
|
const argv = (0, _runnerBase.buildArgv)(config, {
|
|
47
21
|
testPathPattern,
|
|
48
22
|
watch,
|
|
@@ -4,89 +4,21 @@ 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
|
-
|
|
10
|
-
var _defaultConfig = require("../config/default-config.js");
|
|
11
|
-
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
|
-
* All configuration is framework-controlled — no consumer overrides.
|
|
17
|
-
*/
|
|
18
|
-
/**
|
|
19
|
-
* Create the framework-controlled Jest config.
|
|
20
|
-
*
|
|
21
|
-
* @param {string} projectRoot - Consumer project root directory.
|
|
22
|
-
* @returns {import('@jest/types').Config.InitialOptions}
|
|
23
|
-
*/
|
|
24
|
-
function createBaseConfig(projectRoot) {
|
|
25
|
-
return (0, _defaultConfig.getDefaultConfig)(projectRoot);
|
|
26
|
-
}
|
|
27
|
-
|
|
28
|
-
/**
|
|
29
|
-
* Resolve reporter aliases in the config and return the updated config.
|
|
30
|
-
*
|
|
31
|
-
* @param {object} config - Mutable Jest config.
|
|
32
|
-
* @param {string} projectRoot
|
|
33
|
-
* @returns {object} The same config reference (mutated).
|
|
34
|
-
*/
|
|
35
|
-
function resolveConfigReporters(config, projectRoot) {
|
|
36
|
-
config.reporters = (0, _reporterHandler.resolveReporters)(config.reporters, projectRoot);
|
|
37
|
-
return config;
|
|
38
|
-
}
|
|
39
|
-
|
|
40
|
-
/**
|
|
41
|
-
* Build a yargs-compatible argv object that runCLI understands.
|
|
42
|
-
*
|
|
43
|
-
* @param {object} config - Jest config from the framework.
|
|
44
|
-
* @param {object} params
|
|
45
|
-
* @param {string} [params.testPathPattern] - Regex to filter test files.
|
|
46
|
-
* @param {boolean} [params.watch] - Watch mode flag.
|
|
47
|
-
* @param {string} params.projectRoot - Consumer project root.
|
|
48
|
-
* @returns {object}
|
|
49
|
-
*/
|
|
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); }
|
|
50
9
|
function buildArgv(config, {
|
|
51
10
|
testPathPattern,
|
|
52
|
-
watch = false
|
|
53
|
-
projectRoot
|
|
11
|
+
watch = false
|
|
54
12
|
}) {
|
|
55
13
|
const argv = {
|
|
56
|
-
// Serialise the config so Jest uses our framework config
|
|
57
|
-
// instead of searching for jest.config.* files.
|
|
58
14
|
config: JSON.stringify(config),
|
|
59
|
-
|
|
60
|
-
rootDir: projectRoot,
|
|
61
|
-
// Flags
|
|
62
|
-
watch,
|
|
63
|
-
watchAll: false,
|
|
64
|
-
ci: process.env.CI === 'true',
|
|
65
|
-
// Framework-controlled values
|
|
66
|
-
verbose: config.verbose ?? true,
|
|
67
|
-
passWithNoTests: config.passWithNoTests ?? true,
|
|
68
|
-
maxWorkers: config.maxWorkers ?? '50%',
|
|
69
|
-
silent: config.silent ?? false,
|
|
70
|
-
// Do not search for config files automatically
|
|
71
|
-
_: [],
|
|
72
|
-
$0: 'unit-testing-framework'
|
|
15
|
+
watch
|
|
73
16
|
};
|
|
74
|
-
|
|
75
|
-
// Jest 30 uses `testPathPatterns` (plural, array) instead of
|
|
76
|
-
// the old `testPathPattern` (singular, string) from Jest ≤29.
|
|
77
17
|
if (testPathPattern) {
|
|
78
18
|
argv.testPathPatterns = [testPathPattern];
|
|
79
19
|
}
|
|
80
20
|
return argv;
|
|
81
21
|
}
|
|
82
|
-
|
|
83
|
-
/**
|
|
84
|
-
* Lazy-import @jest/core and execute runCLI.
|
|
85
|
-
*
|
|
86
|
-
* @param {object} argv - yargs-style argv for runCLI.
|
|
87
|
-
* @param {string} projectRoot
|
|
88
|
-
* @returns {Promise<import('@jest/core').AggregatedResult>}
|
|
89
|
-
*/
|
|
90
22
|
async function executeJest(argv, projectRoot) {
|
|
91
23
|
const {
|
|
92
24
|
runCLI
|
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.24-experimental",
|
|
4
4
|
"description": "A modular Jest-based unit testing framework",
|
|
5
5
|
"main": "./build/index.js",
|
|
6
6
|
"exports": {
|
|
@@ -13,7 +13,8 @@
|
|
|
13
13
|
"test": "node --experimental-vm-modules node_modules/.bin/jest",
|
|
14
14
|
"lint": "eslint src/ index.js",
|
|
15
15
|
"build": "babel src -d build/src && babel index.js --out-file build/index.js",
|
|
16
|
-
"prepublishOnly": "npm run build"
|
|
16
|
+
"prepublishOnly": "npm run build",
|
|
17
|
+
"clean": "rm -rf build && npm run build"
|
|
17
18
|
},
|
|
18
19
|
"keywords": [],
|
|
19
20
|
"author": "",
|