@emarketeer/ts-microservice-commons 8.1.1 → 8.2.0
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/dist/lib/em-commons.js +3 -0
- package/dist/lib/jest.config.js +30 -4
- package/package.json +1 -1
package/dist/lib/em-commons.js
CHANGED
|
@@ -677,6 +677,9 @@ if (script === 'cdk-lint') {
|
|
|
677
677
|
result = runCommand('npx eslint -c node_modules/@emarketeer/ts-microservice-commons/dist/cdk/.eslintrc', scriptArgs);
|
|
678
678
|
}
|
|
679
679
|
if (script === 'jest') {
|
|
680
|
+
// --experimental-vm-modules is required so Jest can execute ES-module files
|
|
681
|
+
// in its VM — used by AWS SDK v3's dynamic credential-provider imports and
|
|
682
|
+
// by @mikro-orm/* (and other ESM-only packages) under EM_JEST_ESM_FRIENDLY=true.
|
|
680
683
|
result = runCommand('npx cross-env NODE_OPTIONS="--max_old_space_size=4096 --experimental-vm-modules" jest -w 4 --ci --forceExit --config node_modules/@emarketeer/ts-microservice-commons/dist/lib/jest.config.js', scriptArgs);
|
|
681
684
|
}
|
|
682
685
|
if (!supportedCommands.includes(script)) {
|
package/dist/lib/jest.config.js
CHANGED
|
@@ -5,6 +5,28 @@
|
|
|
5
5
|
}(this, (function () { 'use strict';
|
|
6
6
|
|
|
7
7
|
var esModules = ['@eMarketeerSE/runtime-commons'].join('|');
|
|
8
|
+
// Opt-in mode for services that depend on ESM-only packages (e.g. MikroORM).
|
|
9
|
+
// When EM_JEST_ESM_FRIENDLY=true:
|
|
10
|
+
// - ts-jest compiles .ts as ESM (useESM), targeting es2022.
|
|
11
|
+
// - extensionsToTreatAsEsm lets Jest load .ts through its ESM VM loader,
|
|
12
|
+
// the same realm that handles ESM node_modules like @mikro-orm/*.
|
|
13
|
+
// Opting-in services must import { jest } from '@jest/globals' in test files
|
|
14
|
+
// that use jest.* APIs, since the `jest` global is CJS-only.
|
|
15
|
+
var rawEsmFriendly = process.env.EM_JEST_ESM_FRIENDLY;
|
|
16
|
+
var esmFriendly = (rawEsmFriendly === null || rawEsmFriendly === void 0 ? void 0 : rawEsmFriendly.trim().toLowerCase()) === 'true';
|
|
17
|
+
if (rawEsmFriendly !== undefined && !esmFriendly) {
|
|
18
|
+
// eslint-disable-next-line no-console
|
|
19
|
+
console.warn("[em-commons] EM_JEST_ESM_FRIENDLY=".concat(JSON.stringify(rawEsmFriendly), " ignored;")
|
|
20
|
+
+ ' expected \'true\'. Falling back to default CJS Jest config.');
|
|
21
|
+
}
|
|
22
|
+
var tsJestTsConfig = {
|
|
23
|
+
target: esmFriendly ? 'es2022' : 'es6'
|
|
24
|
+
};
|
|
25
|
+
if (esmFriendly) {
|
|
26
|
+
// useESM needs an ES module output from TS; otherwise ts-jest still emits
|
|
27
|
+
// `exports.foo = ...` which explodes when Jest loads the file as ESM.
|
|
28
|
+
tsJestTsConfig.module = 'esnext';
|
|
29
|
+
}
|
|
8
30
|
var config = {
|
|
9
31
|
verbose: true,
|
|
10
32
|
testEnvironment: 'node',
|
|
@@ -12,10 +34,9 @@
|
|
|
12
34
|
'^.+\\.tsx?$': [
|
|
13
35
|
'ts-jest',
|
|
14
36
|
{
|
|
15
|
-
tsconfig:
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
isolatedModules: true
|
|
37
|
+
tsconfig: tsJestTsConfig,
|
|
38
|
+
isolatedModules: true,
|
|
39
|
+
useESM: esmFriendly
|
|
19
40
|
}
|
|
20
41
|
]
|
|
21
42
|
},
|
|
@@ -26,6 +47,11 @@
|
|
|
26
47
|
moduleFileExtensions: ['ts', 'tsx', 'js', 'jsx', 'json', 'node'],
|
|
27
48
|
transformIgnorePatterns: ["/node_modules/(?!".concat(esModules, ")")]
|
|
28
49
|
};
|
|
50
|
+
if (esmFriendly) {
|
|
51
|
+
// Must match the set of TS extensions transformed above (^.+\.tsx?$), or Jest
|
|
52
|
+
// will load .tsx as CJS while ts-jest emits ESM for it and blow up at import.
|
|
53
|
+
config.extensionsToTreatAsEsm = ['.ts', '.tsx'];
|
|
54
|
+
}
|
|
29
55
|
var shouldAddSetup = !process.argv.includes('unit');
|
|
30
56
|
if (shouldAddSetup) {
|
|
31
57
|
config.globalSetup = '<rootDir>/src/utils/func-test-setup.ts';
|