@elliemae/ds-monorepo-devops 3.49.0-beta.2 → 3.49.0-beta.3

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.
@@ -1,14 +1,70 @@
1
1
  import { jestConfig } from '@elliemae/pui-cli';
2
+ import path from 'path';
3
+ import { fileURLToPath } from 'url';
4
+ const __filename = fileURLToPath(import.meta.url); // get the resolved path to the file
5
+ const __dirname = path.dirname(__filename); // get the name of the directory
6
+ const getFileFromCurrentFolder = (fileName) => path.normalize(path.resolve(__dirname, fileName));
7
+ /**
8
+ * Generates an array of setup files for Jest based on provided flags.
9
+ *
10
+ * @param {Object} options - The options object.
11
+ * @param {boolean} [options.silenceConsole=false] - Flag to determine if console output should be silenced.
12
+ * @returns {string[]} An array of setup files for Jest.
13
+ */
14
+ const getSetupFilesAfterEnvBasedOnFlags = ({ silenceConsole = false }) => {
15
+ const setupFilesAfterEnv = [];
2
16
 
3
- export const config = (specificFile = undefined, specialRules = {}) => ({
4
- ...jestConfig,
5
- collectCoverage: false,
6
- collectCoverageFrom: [],
7
- coverageDirectory: undefined,
8
- coverageReporters: undefined,
9
- ...specialRules,
10
- // testRegex: 'tests/.*\\.test\\.[jt]sx?$',
11
- testRegex: specificFile ? `.*/tests/${specificFile}$` : 'tests/.*\\.test\\.[jt]sx?$',
12
- testTimeout: 120000,
13
- });
17
+ if (silenceConsole) {
18
+ setupFilesAfterEnv.push(getFileFromCurrentFolder('noConsoleMode.mjs'));
19
+ }
20
+
21
+ return setupFilesAfterEnv;
22
+ };
23
+
24
+ /**
25
+ * Generates a Jest configuration object.
26
+ *
27
+ * @param {Object} options - Configuration options.
28
+ * @param {string} [options.relativePathAfterTestsFolder] - Relative path after the tests folder to match test files.
29
+ * @param {Object} [options.firstLevelSpread] - Configuration options to override defaults.
30
+ * @param {Object} options.flags - Flags for configuration.
31
+ * @param {boolean} [options.flags.silenceConsole=false] - Flag to silence the console during tests.
32
+ * @returns {import('jest').Config} Jest configuration object.
33
+ *
34
+ * @example
35
+ * config({
36
+ * // matches tests/GlobalHeader.keyboard.test.js
37
+ * relativePathAfterTestsFolder: 'GlobalHeader.keyboard.test.js',
38
+ * // overrides the default configuration for jest config 'verbose' to true
39
+ * firstLevelSpread: { verbose: true },
40
+ * // silences the console during tests via custom setup file
41
+ * flags: { silenceConsole: true }
42
+ * });
43
+ *
44
+ * @example
45
+ * // matches tests/GlobalHeader/a11y/test.keys.js
46
+ * config({
47
+ * relativePathAfterTestsFolder: 'GlobalHeader/a11y/test.keys.js',
48
+ * flags: { silenceConsole: true }
49
+ * });
50
+ */
51
+ export const config = ({ relativePathAfterTestsFolder = undefined, firstLevelSpread = {}, flags = {} } = {}) => {
52
+ const silenceConsole = flags.silenceConsole ?? process.env.JEST_FORCE_SILENT_CONSOLE ?? false;
53
+
54
+ /** @type {import('jest').Config} */
55
+ return {
56
+ ...jestConfig,
57
+ collectCoverage: false,
58
+ collectCoverageFrom: [],
59
+ coverageDirectory: undefined,
60
+ coverageReporters: undefined,
61
+ // testRegex: 'tests/.*\\.test\\.[jt]sx?$',
62
+ testRegex: relativePathAfterTestsFolder
63
+ ? `.*/tests/${relativePathAfterTestsFolder}$`
64
+ : 'tests/.*\\.test\\.[jt]sx?$',
65
+ testTimeout: 120000,
66
+ setupFilesAfterEnv: [...jestConfig.setupFilesAfterEnv, ...getSetupFilesAfterEnvBasedOnFlags({ silenceConsole })],
67
+ ...firstLevelSpread,
68
+ };
69
+ };
14
70
  export default config;
@@ -0,0 +1 @@
1
+ global.console = { jestLog: console.log, error: jest.fn(), warn: jest.fn(), log: jest.fn() };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@elliemae/ds-monorepo-devops",
3
- "version": "3.49.0-beta.2",
3
+ "version": "3.49.0-beta.3",
4
4
  "license": "MIT",
5
5
  "description": "ICE MT - Dimsum - Monorepo Devops",
6
6
  "files": [
@@ -19,7 +19,7 @@
19
19
  },
20
20
  "engines": {
21
21
  "pnpm": ">=8",
22
- "node": ">=18"
22
+ "node": ">=22"
23
23
  },
24
24
  "author": "ICE MT",
25
25
  "jestSonar": {