@mojaloop/ml-testing-toolkit-shared-lib 14.2.0 → 14.3.1
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/.grype.yaml +4 -1
- package/CHANGELOG.md +14 -0
- package/__mocks__/@faker-js/faker.js +128 -0
- package/jest.config.js +5 -1
- package/package.json +7 -7
package/.grype.yaml
CHANGED
package/CHANGELOG.md
CHANGED
|
@@ -1,4 +1,18 @@
|
|
|
1
1
|
# Changelog: [mojaloop/als-consent-oracle](https://github.com/mojaloop/als-consent-oracle)
|
|
2
|
+
### [14.3.1](https://github.com/mojaloop/ml-testing-toolkit-shared-lib/compare/v14.3.0...v14.3.1) (2025-11-06)
|
|
3
|
+
|
|
4
|
+
|
|
5
|
+
### Chore
|
|
6
|
+
|
|
7
|
+
* update dependencies ([#27](https://github.com/mojaloop/ml-testing-toolkit-shared-lib/issues/27)) ([126c67e](https://github.com/mojaloop/ml-testing-toolkit-shared-lib/commit/126c67eb0f0bd495f6b5acc507e9b23d640617a3))
|
|
8
|
+
|
|
9
|
+
## [14.3.0](https://github.com/mojaloop/ml-testing-toolkit-shared-lib/compare/v14.2.0...v14.3.0) (2025-09-26)
|
|
10
|
+
|
|
11
|
+
|
|
12
|
+
### Features
|
|
13
|
+
|
|
14
|
+
* add grype src scan, up deps plus jest conf ([#25](https://github.com/mojaloop/ml-testing-toolkit-shared-lib/issues/25)) ([8e9ee15](https://github.com/mojaloop/ml-testing-toolkit-shared-lib/commit/8e9ee15cd3292e27ac443d42bdc1dffd22364aa2))
|
|
15
|
+
|
|
2
16
|
## [14.2.0](https://github.com/mojaloop/ml-testing-toolkit-shared-lib/compare/v14.1.0...v14.2.0) (2025-07-15)
|
|
3
17
|
|
|
4
18
|
|
|
@@ -0,0 +1,128 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Mock for @faker-js/faker to handle ESM compatibility issues in Jest
|
|
3
|
+
*
|
|
4
|
+
* RATIONALE:
|
|
5
|
+
* @faker-js/faker v10.0.0+ uses ESM (ECMAScript Modules) format which Jest
|
|
6
|
+
* cannot handle natively in a CommonJS environment. This mock provides a
|
|
7
|
+
* CommonJS-compatible replacement that:
|
|
8
|
+
*
|
|
9
|
+
* 1. ONLY affects Jest unit tests (via moduleNameMapper in jest.config.js)
|
|
10
|
+
* 2. Does NOT affect production runtime - real faker is used in production
|
|
11
|
+
* 3. Provides predictable but somewhat dynamic test data
|
|
12
|
+
* 4. Maintains the same API structure as the real faker library
|
|
13
|
+
*
|
|
14
|
+
* FUTURE UPGRADE PATH:
|
|
15
|
+
* When Jest adds full native ESM support (expected in v30+), this mock can be
|
|
16
|
+
* removed and tests will work with the real @faker-js/faker package without changes.
|
|
17
|
+
*
|
|
18
|
+
* ALTERNATIVES CONSIDERED:
|
|
19
|
+
* - Downgrading to faker v7.x (last CommonJS version): Not future-proof
|
|
20
|
+
* - Using experimental ESM in Jest: Still unstable and may cause issues
|
|
21
|
+
* - Babel transformation: Adds complexity and slows down tests
|
|
22
|
+
*
|
|
23
|
+
* This approach is the simplest and most maintainable solution for now.
|
|
24
|
+
*/
|
|
25
|
+
|
|
26
|
+
// Counter for generating unique but predictable values
|
|
27
|
+
let counter = 0
|
|
28
|
+
|
|
29
|
+
// Reset function for test isolation (can be called in beforeEach)
|
|
30
|
+
const resetCounter = () => {
|
|
31
|
+
counter = 0
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
module.exports = {
|
|
35
|
+
resetCounter,
|
|
36
|
+
faker: {
|
|
37
|
+
string: {
|
|
38
|
+
// Generate semi-dynamic but predictable UUIDs for tests
|
|
39
|
+
uuid: () => {
|
|
40
|
+
counter++
|
|
41
|
+
return `${counter.toString().padStart(8, '0')}-0000-4000-8000-${Date.now().toString().slice(-12).padStart(12, '0')}`
|
|
42
|
+
},
|
|
43
|
+
// Generate alphanumeric strings with optional length
|
|
44
|
+
alphanumeric: (length = 10) => {
|
|
45
|
+
const chars = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789'
|
|
46
|
+
return Array.from({ length }, (_, i) => chars[i % chars.length]).join('')
|
|
47
|
+
},
|
|
48
|
+
sample: () => `sample_${counter++}`
|
|
49
|
+
},
|
|
50
|
+
number: {
|
|
51
|
+
// Generate predictable but varying integers
|
|
52
|
+
int: (options = {}) => {
|
|
53
|
+
const min = options.min || 0
|
|
54
|
+
const max = options.max || 1000
|
|
55
|
+
counter++
|
|
56
|
+
return min + (counter % (max - min + 1))
|
|
57
|
+
},
|
|
58
|
+
// Generate predictable but varying floats
|
|
59
|
+
float: (options = {}) => {
|
|
60
|
+
const min = options.min || 0
|
|
61
|
+
const max = options.max || 100
|
|
62
|
+
counter++
|
|
63
|
+
return min + ((counter * 1.23) % (max - min))
|
|
64
|
+
}
|
|
65
|
+
},
|
|
66
|
+
datatype: {
|
|
67
|
+
// Alternate between true and false
|
|
68
|
+
boolean: () => (counter++ % 2) === 0
|
|
69
|
+
},
|
|
70
|
+
date: {
|
|
71
|
+
// Generate dates that increment by day
|
|
72
|
+
recent: (days = 10) => {
|
|
73
|
+
const date = new Date('2023-01-01T00:00:00.000Z')
|
|
74
|
+
date.setDate(date.getDate() + (counter++ % days))
|
|
75
|
+
return date
|
|
76
|
+
}
|
|
77
|
+
},
|
|
78
|
+
lorem: {
|
|
79
|
+
word: () => ['lorem', 'ipsum', 'dolor', 'sit', 'amet'][counter++ % 5],
|
|
80
|
+
words: (count = 3) => {
|
|
81
|
+
const wordList = ['lorem', 'ipsum', 'dolor', 'sit', 'amet', 'consectetur', 'adipiscing', 'elit']
|
|
82
|
+
return Array.from({ length: count }, (_, i) => wordList[(counter + i) % wordList.length]).join(' ')
|
|
83
|
+
},
|
|
84
|
+
sentence: () => {
|
|
85
|
+
const sentences = [
|
|
86
|
+
'Lorem ipsum dolor sit amet.',
|
|
87
|
+
'Consectetur adipiscing elit.',
|
|
88
|
+
'Sed do eiusmod tempor incididunt.',
|
|
89
|
+
'Ut labore et dolore magna aliqua.'
|
|
90
|
+
]
|
|
91
|
+
return sentences[counter++ % sentences.length]
|
|
92
|
+
}
|
|
93
|
+
},
|
|
94
|
+
person: {
|
|
95
|
+
firstName: () => ['John', 'Jane', 'Bob', 'Alice', 'Charlie'][counter++ % 5],
|
|
96
|
+
lastName: () => ['Doe', 'Smith', 'Johnson', 'Williams', 'Brown'][counter++ % 5],
|
|
97
|
+
fullName: () => {
|
|
98
|
+
const firstNames = ['John', 'Jane', 'Bob', 'Alice', 'Charlie']
|
|
99
|
+
const lastNames = ['Doe', 'Smith', 'Johnson', 'Williams', 'Brown']
|
|
100
|
+
const idx = counter++ % 5
|
|
101
|
+
return `${firstNames[idx]} ${lastNames[idx]}`
|
|
102
|
+
}
|
|
103
|
+
},
|
|
104
|
+
internet: {
|
|
105
|
+
email: () => {
|
|
106
|
+
const names = ['john', 'jane', 'bob', 'alice', 'charlie']
|
|
107
|
+
const domains = ['example.com', 'test.org', 'demo.net', 'sample.io', 'mock.dev']
|
|
108
|
+
const idx = counter++ % 5
|
|
109
|
+
return `${names[idx]}@${domains[idx]}`
|
|
110
|
+
},
|
|
111
|
+
url: () => {
|
|
112
|
+
const paths = ['home', 'about', 'contact', 'products', 'services']
|
|
113
|
+
return `https://example.com/${paths[counter++ % 5]}`
|
|
114
|
+
}
|
|
115
|
+
},
|
|
116
|
+
helpers: {
|
|
117
|
+
arrayElement: (arr) => {
|
|
118
|
+
if (!arr || arr.length === 0) return null
|
|
119
|
+
return arr[counter++ % arr.length]
|
|
120
|
+
},
|
|
121
|
+
arrayElements: (arr, count) => {
|
|
122
|
+
if (!arr || arr.length === 0) return []
|
|
123
|
+
const num = count || Math.min(3, arr.length)
|
|
124
|
+
return Array.from({ length: num }, (_, i) => arr[(counter + i) % arr.length])
|
|
125
|
+
}
|
|
126
|
+
}
|
|
127
|
+
}
|
|
128
|
+
}
|
package/jest.config.js
CHANGED
|
@@ -12,5 +12,9 @@ module.exports = {
|
|
|
12
12
|
}
|
|
13
13
|
},
|
|
14
14
|
modulePathIgnorePatterns: [],
|
|
15
|
-
testEnvironment: 'node'
|
|
15
|
+
testEnvironment: 'node',
|
|
16
|
+
// Mock ESM modules that Jest can't handle
|
|
17
|
+
moduleNameMapper: {
|
|
18
|
+
'^@faker-js/faker$': '<rootDir>/__mocks__/@faker-js/faker.js'
|
|
19
|
+
}
|
|
16
20
|
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@mojaloop/ml-testing-toolkit-shared-lib",
|
|
3
|
-
"version": "14.
|
|
3
|
+
"version": "14.3.1",
|
|
4
4
|
"description": "Shared library for ml-testing-toolkit re-usable functions",
|
|
5
5
|
"main": "src/index.js",
|
|
6
6
|
"contributors": [
|
|
@@ -48,21 +48,21 @@
|
|
|
48
48
|
"snapshot": "npx standard-version --no-verify --skip.changelog --prerelease snapshot --releaseCommitMessageFormat 'chore(snapshot): {{currentTag}}'"
|
|
49
49
|
},
|
|
50
50
|
"dependencies": {
|
|
51
|
-
"@apidevtools/json-schema-ref-parser": "14.1
|
|
52
|
-
"@faker-js/faker": "
|
|
51
|
+
"@apidevtools/json-schema-ref-parser": "14.2.1",
|
|
52
|
+
"@faker-js/faker": "10.1.0",
|
|
53
53
|
"ajv": "8.17.1",
|
|
54
54
|
"json-schema-faker": "0.5.9",
|
|
55
55
|
"lodash": "4.17.21",
|
|
56
56
|
"node-dir": "0.1.17"
|
|
57
57
|
},
|
|
58
58
|
"devDependencies": {
|
|
59
|
-
"@commitlint/cli": "^
|
|
60
|
-
"@commitlint/config-conventional": "^
|
|
59
|
+
"@commitlint/cli": "^20.1.0",
|
|
60
|
+
"@commitlint/config-conventional": "^20.0.0",
|
|
61
61
|
"@types/jest": "30.0.0",
|
|
62
62
|
"audit-ci": "^7.1.0",
|
|
63
|
-
"jest": "30.0
|
|
63
|
+
"jest": "30.2.0",
|
|
64
64
|
"jest-junit": "16.0.0",
|
|
65
|
-
"npm-check-updates": "
|
|
65
|
+
"npm-check-updates": "19.1.2",
|
|
66
66
|
"pre-commit": "^1.2.2",
|
|
67
67
|
"replace": "^1.2.2",
|
|
68
68
|
"standard": "^17.1.2",
|