@ds-sfdc/sfparty 1.3.9 → 1.3.11
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/.husky/pre-push +4 -0
- package/README.md +5 -0
- package/package.json +1 -1
- package/src/index.js +89 -57
- package/src/lib/checkVersion.js +1 -1
- package/src/lib/fileUtils.js +14 -14
- package/src/lib/gitUtils.js +110 -70
- package/src/lib/packageUtil.js +5 -1
- package/src/party/combine.js +647 -632
- package/src/party/split.js +5 -3
- package/test/lib/file/directoryExists.spec.js +43 -0
- package/test/lib/file/fileExists.spec.js +36 -0
- package/test/lib/git/diff.spec.js +208 -33
- package/test/lib/git/lastCommit.spec.js +119 -52
- package/test/lib/git/updateLastCommit.spec.js +64 -45
- package/test/lib/package/getPackageXML.spec.js +146 -124
- package/test_mocha/lib/fileUtils.js +0 -374
- package/test_mocha/lib/git.js +0 -82
- package/test_mocha/lib/gitUtils.js +0 -54
- package/test_mocha/lib/versionCheck.js +0 -43
- package/test_mocha/root.js +0 -14
|
@@ -2,64 +2,83 @@ import path from 'path'
|
|
|
2
2
|
import * as fileUtils from '../../../src/lib/fileUtils.js'
|
|
3
3
|
import { updateLastCommit } from '../../../src/lib/gitUtils.js'
|
|
4
4
|
|
|
5
|
-
|
|
6
|
-
return {
|
|
7
|
-
fileExists: jest.fn(),
|
|
8
|
-
readFile: jest.fn(),
|
|
9
|
-
saveFile: jest.fn()
|
|
10
|
-
}
|
|
11
|
-
})
|
|
5
|
+
let dir, latest
|
|
12
6
|
|
|
13
7
|
beforeEach(() => {
|
|
14
|
-
|
|
8
|
+
dir = '/test/directory'
|
|
9
|
+
latest = '1234567890abcdef'
|
|
15
10
|
})
|
|
16
11
|
|
|
17
12
|
afterEach(() => {
|
|
18
|
-
|
|
13
|
+
jest.resetModules()
|
|
19
14
|
})
|
|
20
15
|
|
|
21
|
-
it('
|
|
22
|
-
|
|
16
|
+
it('should throw an error if latest is not a string', () => {
|
|
17
|
+
latest = {}
|
|
18
|
+
expect(() => updateLastCommit({ dir, latest, fileUtils })).toThrowError(
|
|
19
|
+
'updateLastCommit received a object instead of string',
|
|
20
|
+
)
|
|
23
21
|
})
|
|
24
22
|
|
|
25
|
-
it('
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
23
|
+
it('should not update lastCommit property if latest is undefined', () => {
|
|
24
|
+
latest = undefined
|
|
25
|
+
fileUtils.fileExists = jest.fn(() => true)
|
|
26
|
+
fileUtils.readFile = jest.fn(() => ({
|
|
27
|
+
git: { lastCommit: '1111111111abcdef' },
|
|
28
|
+
}))
|
|
29
|
+
fileUtils.saveFile = jest.fn()
|
|
30
|
+
updateLastCommit(dir, latest, fileUtils)
|
|
31
|
+
expect(fileUtils.fileExists).not.toHaveBeenCalled()
|
|
32
|
+
expect(fileUtils.readFile).not.toHaveBeenCalled()
|
|
33
|
+
expect(fileUtils.saveFile).not.toHaveBeenCalled()
|
|
34
|
+
})
|
|
36
35
|
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
36
|
+
it('should update lastCommit property in index.yaml file', () => {
|
|
37
|
+
// mock the fileExists method of fileUtils
|
|
38
|
+
fileUtils.fileExists = jest.fn(() => true)
|
|
39
|
+
// mock the readFile method of fileUtils
|
|
40
|
+
fileUtils.readFile = jest.fn(() => ({
|
|
41
|
+
git: { lastCommit: '1111111111abcdef' },
|
|
42
|
+
}))
|
|
43
|
+
// mock the saveFile method of fileUtils
|
|
44
|
+
fileUtils.saveFile = jest.fn()
|
|
45
|
+
updateLastCommit({ dir, latest, fileUtils })
|
|
46
|
+
expect(fileUtils.readFile).toHaveBeenCalled()
|
|
47
|
+
expect(fileUtils.saveFile).toHaveBeenCalledWith(
|
|
48
|
+
{ git: { lastCommit: latest } },
|
|
49
|
+
'/test/directory/.sfdx/sfparty/index.yaml',
|
|
50
|
+
)
|
|
40
51
|
})
|
|
41
52
|
|
|
42
|
-
it('
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
},
|
|
52
|
-
local: {
|
|
53
|
-
lastDate: undefined,
|
|
54
|
-
}
|
|
55
|
-
}
|
|
53
|
+
it('should use existing index.yaml if it exists', () => {
|
|
54
|
+
fileUtils.fileExists = jest.fn(() => false)
|
|
55
|
+
fileUtils.readFile = jest.fn()
|
|
56
|
+
fileUtils.saveFile = jest.fn()
|
|
57
|
+
updateLastCommit({ dir, latest, fileUtils })
|
|
58
|
+
expect(fileUtils.fileExists).toHaveBeenCalled()
|
|
59
|
+
expect(fileUtils.readFile).not.toHaveBeenCalled()
|
|
60
|
+
expect(fileUtils.saveFile).toHaveBeenCalled()
|
|
61
|
+
})
|
|
56
62
|
|
|
57
|
-
|
|
58
|
-
|
|
63
|
+
it('should save the default definition if file does not exist', () => {
|
|
64
|
+
fileUtils.fileExists = jest.fn(() => false)
|
|
65
|
+
fileUtils.readFile = jest.fn()
|
|
66
|
+
fileUtils.saveFile = jest.fn()
|
|
59
67
|
|
|
60
|
-
|
|
68
|
+
const defaultDefinition = {
|
|
69
|
+
git: {
|
|
70
|
+
lastCommit: latest,
|
|
71
|
+
},
|
|
72
|
+
local: {
|
|
73
|
+
lastDate: undefined,
|
|
74
|
+
},
|
|
75
|
+
}
|
|
61
76
|
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
77
|
+
updateLastCommit({ dir, latest, fileUtils })
|
|
78
|
+
expect(fileUtils.fileExists).toHaveBeenCalled()
|
|
79
|
+
expect(fileUtils.readFile).not.toHaveBeenCalled()
|
|
80
|
+
expect(fileUtils.saveFile).toHaveBeenCalledWith(
|
|
81
|
+
defaultDefinition,
|
|
82
|
+
'/test/directory/.sfdx/sfparty/index.yaml',
|
|
83
|
+
)
|
|
65
84
|
})
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
|
|
1
|
+
import fs from 'fs'
|
|
2
2
|
import * as packageDefinition from '../../../src/meta/Package.js'
|
|
3
3
|
import { Package } from '../../../src/lib/packageUtil.js'
|
|
4
4
|
import * as labelDefinition from '../../../src/meta/CustomLabels.js'
|
|
@@ -9,163 +9,185 @@ import * as workflowDefinition from '../../../src/meta/Workflows.js'
|
|
|
9
9
|
global.__basedir = '.'
|
|
10
10
|
global.format = 'yaml'
|
|
11
11
|
global.metaTypes = {
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
12
|
+
label: {
|
|
13
|
+
type: labelDefinition.metadataDefinition.filetype,
|
|
14
|
+
definition: labelDefinition.metadataDefinition,
|
|
15
|
+
add: { files: [], directories: [] },
|
|
16
|
+
remove: { files: [], directories: [] },
|
|
17
|
+
},
|
|
18
|
+
profile: {
|
|
19
|
+
type: profileDefinition.metadataDefinition.filetype,
|
|
20
|
+
definition: profileDefinition.metadataDefinition,
|
|
21
|
+
add: { files: [], directories: [] },
|
|
22
|
+
remove: { files: [], directories: [] },
|
|
23
|
+
},
|
|
24
|
+
permset: {
|
|
25
|
+
type: permsetDefinition.metadataDefinition.filetype,
|
|
26
|
+
definition: permsetDefinition.metadataDefinition,
|
|
27
|
+
add: { files: [], directories: [] },
|
|
28
|
+
remove: { files: [], directories: [] },
|
|
29
|
+
},
|
|
30
|
+
workflow: {
|
|
31
|
+
type: workflowDefinition.metadataDefinition.filetype,
|
|
32
|
+
definition: workflowDefinition.metadataDefinition,
|
|
33
|
+
add: { files: [], directories: [] },
|
|
34
|
+
remove: { files: [], directories: [] },
|
|
35
|
+
},
|
|
36
36
|
}
|
|
37
37
|
|
|
38
38
|
let pkg
|
|
39
39
|
const fileUtils = {
|
|
40
|
-
|
|
41
|
-
|
|
40
|
+
fileExists: jest.fn(),
|
|
41
|
+
readFile: jest.fn(),
|
|
42
42
|
}
|
|
43
43
|
beforeEach(() => {
|
|
44
|
-
|
|
44
|
+
pkg = new Package('xmlPath')
|
|
45
45
|
})
|
|
46
46
|
|
|
47
|
-
|
|
48
47
|
afterEach(() => {
|
|
49
|
-
|
|
48
|
+
jest.clearAllMocks()
|
|
50
49
|
})
|
|
51
50
|
|
|
52
51
|
it('should default the package if the json is empty', async () => {
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
52
|
+
fileUtils.fileExists.mockReturnValue(true)
|
|
53
|
+
fileUtils.readFile.mockResolvedValue({})
|
|
54
|
+
global.git = { append: true }
|
|
55
|
+
const result = await pkg.getPackageXML(fileUtils)
|
|
56
|
+
expect(result).toBe('existing')
|
|
57
|
+
expect(fileUtils.fileExists).toHaveBeenCalled()
|
|
58
|
+
expect(fileUtils.readFile).toHaveBeenCalled()
|
|
59
|
+
expect(pkg.packageJSON).toEqual(
|
|
60
|
+
packageDefinition.metadataDefinition.emptyPackage,
|
|
61
|
+
)
|
|
61
62
|
})
|
|
62
63
|
|
|
63
64
|
it('should read an existing file and call processJSON', async () => {
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
65
|
+
fileUtils.fileExists.mockReturnValue(true)
|
|
66
|
+
fileUtils.readFile.mockResolvedValue(
|
|
67
|
+
packageDefinition.metadataDefinition.emptyPackage,
|
|
68
|
+
)
|
|
69
|
+
global.git = { append: true }
|
|
70
|
+
const result = await pkg.getPackageXML(fileUtils)
|
|
71
|
+
expect(result).toBe('existing')
|
|
72
|
+
expect(fileUtils.fileExists).toHaveBeenCalled()
|
|
73
|
+
expect(fileUtils.readFile).toHaveBeenCalled()
|
|
71
74
|
})
|
|
72
75
|
|
|
73
76
|
it('should create an empty pkg JSON and call processJSON', async () => {
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
77
|
+
fileUtils.fileExists.mockReturnValue(false)
|
|
78
|
+
const finalJSON = JSON.parse(
|
|
79
|
+
JSON.stringify(packageDefinition.metadataDefinition.emptyPackage),
|
|
80
|
+
)
|
|
81
|
+
finalJSON.Package.version =
|
|
82
|
+
packageDefinition.metadataDefinition.fallbackVersion
|
|
83
|
+
const result = await pkg.getPackageXML(fileUtils)
|
|
84
|
+
expect(result).toBe('not found')
|
|
85
|
+
expect(fileUtils.fileExists).toHaveBeenCalled()
|
|
86
|
+
expect(pkg.packageJSON).toEqual(finalJSON)
|
|
81
87
|
})
|
|
82
88
|
|
|
83
89
|
it('should throw an error if xmlPath is undefined', async () => {
|
|
84
|
-
|
|
85
|
-
|
|
90
|
+
pkg.xmlPath = undefined
|
|
91
|
+
await expect(pkg.getPackageXML(fileUtils)).rejects.toThrowError(
|
|
92
|
+
'Package not initialized',
|
|
93
|
+
)
|
|
86
94
|
})
|
|
87
95
|
|
|
88
96
|
it('should throw an error if error occurs during processing', async () => {
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
97
|
+
fileUtils.fileExists.mockReturnValue(true)
|
|
98
|
+
fileUtils.readFile.mockRejectedValue(new Error('Error'))
|
|
99
|
+
await expect(pkg.getPackageXML(fileUtils)).rejects.toThrowError('Error')
|
|
92
100
|
})
|
|
93
101
|
|
|
94
102
|
it('should catch errors and reject the promise', async () => {
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
+
fileUtils.fileExists.mockReturnValue(true)
|
|
104
|
+
fileUtils.readFile.mockRejectedValue(new Error('Test Error'))
|
|
105
|
+
global.git = { append: true }
|
|
106
|
+
try {
|
|
107
|
+
await pkg.getPackageXML(fileUtils)
|
|
108
|
+
} catch (error) {
|
|
109
|
+
expect(error.message).toEqual('Test Error')
|
|
110
|
+
}
|
|
103
111
|
})
|
|
104
112
|
|
|
105
113
|
it('should default to an empty package if the read file is empty', async () => {
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
+
fileUtils.fileExists.mockReturnValue(true)
|
|
115
|
+
fileUtils.readFile.mockResolvedValue('')
|
|
116
|
+
global.git = { append: true }
|
|
117
|
+
const result = await pkg.getPackageXML(fileUtils)
|
|
118
|
+
expect(result).toBe('existing')
|
|
119
|
+
expect(pkg.packageJSON).toEqual(
|
|
120
|
+
packageDefinition.metadataDefinition.emptyPackage,
|
|
121
|
+
)
|
|
122
|
+
expect(fileUtils.fileExists).toHaveBeenCalled()
|
|
123
|
+
expect(fileUtils.readFile).toHaveBeenCalled()
|
|
114
124
|
})
|
|
115
125
|
|
|
116
126
|
it('should throw an error if fileUtils.readFile() returns a rejected promise', async () => {
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
127
|
+
fileUtils.fileExists.mockReturnValue(true)
|
|
128
|
+
fileUtils.readFile.mockRejectedValue(new Error('Test Error'))
|
|
129
|
+
global.git = { append: true }
|
|
130
|
+
await expect(pkg.getPackageXML(fileUtils)).rejects.toThrowError(
|
|
131
|
+
'Test Error',
|
|
132
|
+
)
|
|
133
|
+
expect(fileUtils.fileExists).toHaveBeenCalled()
|
|
134
|
+
expect(fileUtils.readFile).toHaveBeenCalled()
|
|
123
135
|
})
|
|
124
136
|
|
|
125
137
|
it('should correctly process the json object returned from the XML file', async () => {
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
138
|
+
fileUtils.fileExists.mockReturnValue(true)
|
|
139
|
+
fileUtils.readFile.mockResolvedValueOnce({
|
|
140
|
+
Package: {
|
|
141
|
+
types: [
|
|
142
|
+
{
|
|
143
|
+
members: ['Test', 'Test.yaml'],
|
|
144
|
+
name: 'CustomLabels',
|
|
145
|
+
},
|
|
146
|
+
{
|
|
147
|
+
members: ['Test', 'Test.yaml'],
|
|
148
|
+
name: 'Profile',
|
|
149
|
+
},
|
|
150
|
+
{
|
|
151
|
+
members: ['Test', 'Test.yaml'],
|
|
152
|
+
name: 'PermissionSet',
|
|
153
|
+
},
|
|
154
|
+
{
|
|
155
|
+
members: ['Test', 'Test.yaml'],
|
|
156
|
+
name: 'Workflow',
|
|
157
|
+
},
|
|
158
|
+
],
|
|
159
|
+
version: '56.0',
|
|
160
|
+
},
|
|
161
|
+
})
|
|
162
|
+
fileUtils.readFile.mockImplementationOnce(() => {
|
|
163
|
+
return { sourceApiVersion: '56.0' }
|
|
164
|
+
})
|
|
165
|
+
global.git = { append: true }
|
|
166
|
+
const result = await pkg.getPackageXML(fileUtils)
|
|
167
|
+
expect(result).toBe('existing')
|
|
168
|
+
expect(fileUtils.fileExists).toHaveBeenCalled()
|
|
169
|
+
expect(fileUtils.readFile).toHaveBeenCalled()
|
|
170
|
+
expect(pkg.packageJSON).toEqual({
|
|
171
|
+
Package: {
|
|
172
|
+
types: [
|
|
173
|
+
{
|
|
174
|
+
members: ['Test'],
|
|
175
|
+
name: 'CustomLabels',
|
|
176
|
+
},
|
|
177
|
+
{
|
|
178
|
+
members: ['Test'],
|
|
179
|
+
name: 'Profile',
|
|
180
|
+
},
|
|
181
|
+
{
|
|
182
|
+
members: ['Test'],
|
|
183
|
+
name: 'PermissionSet',
|
|
184
|
+
},
|
|
185
|
+
{
|
|
186
|
+
members: ['Test'],
|
|
187
|
+
name: 'Workflow',
|
|
188
|
+
},
|
|
189
|
+
],
|
|
190
|
+
version: '56.0',
|
|
191
|
+
},
|
|
192
|
+
})
|
|
171
193
|
})
|