@ds-sfdc/sfparty 1.4.15 → 1.4.17
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/package.json +4 -4
- package/src/lib/gitUtils.js +17 -1
- package/test/lib/git/updateLastCommit.spec.js +20 -25
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@ds-sfdc/sfparty",
|
|
3
|
-
"version": "1.4.
|
|
3
|
+
"version": "1.4.17",
|
|
4
4
|
"description": "Salesforce metadata XML splitter for CI/CD",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"repository": {
|
|
@@ -37,6 +37,7 @@
|
|
|
37
37
|
"semver": "^7.3.8",
|
|
38
38
|
"util": "^0.10.3",
|
|
39
39
|
"winston": "^3.8.2",
|
|
40
|
+
"xml2js": "^0.6.2",
|
|
40
41
|
"yargs": "^17.6.2"
|
|
41
42
|
},
|
|
42
43
|
"devDependencies": {
|
|
@@ -47,9 +48,8 @@
|
|
|
47
48
|
"babel-jest": "^29.3.1",
|
|
48
49
|
"husky": "^8.0.3",
|
|
49
50
|
"jest": "^29.3.1",
|
|
50
|
-
"nodemon": "^
|
|
51
|
-
"prettier": "^2.8.3"
|
|
52
|
-
"xml2js": "^0.5.0"
|
|
51
|
+
"nodemon": "^3.0.3",
|
|
52
|
+
"prettier": "^2.8.3"
|
|
53
53
|
},
|
|
54
54
|
"engines": {
|
|
55
55
|
"node": ">=0.11"
|
package/src/lib/gitUtils.js
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import path from 'path'
|
|
2
2
|
import * as os from 'node:os'
|
|
3
|
+
import { execSync } from 'child_process'
|
|
3
4
|
|
|
4
5
|
const defaultDefinition = {
|
|
5
6
|
git: {
|
|
@@ -187,10 +188,12 @@ export function updateLastCommit({ dir, latest, fileUtils, fs }) {
|
|
|
187
188
|
throw new Error(
|
|
188
189
|
`updateLastCommit received a ${typeof latest} instead of string`,
|
|
189
190
|
)
|
|
191
|
+
|
|
190
192
|
if (latest !== undefined) {
|
|
191
193
|
const folder = path.join(dir, '.sfdx', 'sfparty')
|
|
192
194
|
const fileName = path.join(folder, 'index.yaml')
|
|
193
195
|
let data = undefined
|
|
196
|
+
|
|
194
197
|
if (fileUtils.fileExists({ filePath: fileName, fs })) {
|
|
195
198
|
data = fileUtils.readFile(fileName)
|
|
196
199
|
}
|
|
@@ -199,7 +202,20 @@ export function updateLastCommit({ dir, latest, fileUtils, fs }) {
|
|
|
199
202
|
data = defaultDefinition
|
|
200
203
|
}
|
|
201
204
|
|
|
202
|
-
|
|
205
|
+
// Determine the current branch name
|
|
206
|
+
const currentBranch = execSync(`git rev-parse --abbrev-ref HEAD`, {
|
|
207
|
+
cwd: dir,
|
|
208
|
+
encoding: 'utf-8',
|
|
209
|
+
}).trim()
|
|
210
|
+
|
|
211
|
+
// Initialize branches object if not exist
|
|
212
|
+
if (!data.git.branches) {
|
|
213
|
+
data.git.branches = {}
|
|
214
|
+
}
|
|
215
|
+
|
|
216
|
+
// Update the last commit for the current branch
|
|
217
|
+
data.git.branches[currentBranch] = latest
|
|
218
|
+
|
|
203
219
|
fileUtils.saveFile(data, fileName)
|
|
204
220
|
}
|
|
205
221
|
}
|
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import path from 'path'
|
|
2
1
|
import * as fileUtils from '../../../src/lib/fileUtils.js'
|
|
3
2
|
import { updateLastCommit } from '../../../src/lib/gitUtils.js'
|
|
3
|
+
import { execSync } from 'child_process'
|
|
4
4
|
|
|
5
5
|
let dir, latest
|
|
6
6
|
|
|
@@ -33,41 +33,37 @@ it('should not update lastCommit property if latest is undefined', () => {
|
|
|
33
33
|
expect(fileUtils.saveFile).not.toHaveBeenCalled()
|
|
34
34
|
})
|
|
35
35
|
|
|
36
|
-
|
|
37
|
-
//
|
|
36
|
+
jest.mock('child_process', () => ({
|
|
37
|
+
...jest.requireActual('child_process'), // This line ensures that other child_process methods are still available as normal
|
|
38
|
+
execSync: jest.fn().mockReturnValue('mock-branch'),
|
|
39
|
+
}))
|
|
40
|
+
|
|
41
|
+
// Then in your test:
|
|
42
|
+
it('should update lastCommit property in index.yaml for the current branch', () => {
|
|
38
43
|
fileUtils.fileExists = jest.fn(() => true)
|
|
39
|
-
// mock the readFile method of fileUtils
|
|
40
44
|
fileUtils.readFile = jest.fn(() => ({
|
|
41
|
-
git: {
|
|
45
|
+
git: { branches: { 'mock-branch': '1111111111abcdef' } },
|
|
42
46
|
}))
|
|
43
|
-
// mock the saveFile method of fileUtils
|
|
44
47
|
fileUtils.saveFile = jest.fn()
|
|
48
|
+
|
|
45
49
|
updateLastCommit({ dir, latest, fileUtils })
|
|
46
|
-
|
|
50
|
+
|
|
47
51
|
expect(fileUtils.saveFile).toHaveBeenCalledWith(
|
|
48
|
-
{ git: {
|
|
52
|
+
{ git: { branches: { 'mock-branch': latest } } },
|
|
49
53
|
'/test/directory/.sfdx/sfparty/index.yaml',
|
|
50
54
|
)
|
|
51
55
|
})
|
|
52
56
|
|
|
53
|
-
it('should
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
updateLastCommit({ dir, latest, fileUtils })
|
|
58
|
-
expect(fileUtils.fileExists).toHaveBeenCalled()
|
|
59
|
-
expect(fileUtils.readFile).not.toHaveBeenCalled()
|
|
60
|
-
expect(fileUtils.saveFile).toHaveBeenCalled()
|
|
61
|
-
})
|
|
62
|
-
|
|
63
|
-
it('should save the default definition if file does not exist', () => {
|
|
57
|
+
it('should save the default definition with branches object if file does not exist', () => {
|
|
58
|
+
jest.mock('child_process', () => ({
|
|
59
|
+
execSync: jest.fn().mockReturnValue('mock-branch'),
|
|
60
|
+
}))
|
|
64
61
|
fileUtils.fileExists = jest.fn(() => false)
|
|
65
|
-
fileUtils.readFile = jest.fn()
|
|
66
62
|
fileUtils.saveFile = jest.fn()
|
|
67
63
|
|
|
68
|
-
const
|
|
64
|
+
const defaultDefinitionWithBranches = {
|
|
69
65
|
git: {
|
|
70
|
-
|
|
66
|
+
branches: { 'mock-branch': latest },
|
|
71
67
|
},
|
|
72
68
|
local: {
|
|
73
69
|
lastDate: undefined,
|
|
@@ -75,10 +71,9 @@ it('should save the default definition if file does not exist', () => {
|
|
|
75
71
|
}
|
|
76
72
|
|
|
77
73
|
updateLastCommit({ dir, latest, fileUtils })
|
|
78
|
-
|
|
79
|
-
expect(fileUtils.readFile).not.toHaveBeenCalled()
|
|
74
|
+
|
|
80
75
|
expect(fileUtils.saveFile).toHaveBeenCalledWith(
|
|
81
|
-
|
|
76
|
+
defaultDefinitionWithBranches,
|
|
82
77
|
'/test/directory/.sfdx/sfparty/index.yaml',
|
|
83
78
|
)
|
|
84
79
|
})
|