@salesforce/core 3.30.14 → 3.31.7

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.
Files changed (153) hide show
  1. package/LICENSE.txt +11 -11
  2. package/README.md +222 -227
  3. package/lib/config/aliasesConfig.d.ts +12 -12
  4. package/lib/config/aliasesConfig.js +27 -27
  5. package/lib/config/authInfoConfig.d.ts +19 -19
  6. package/lib/config/authInfoConfig.js +34 -34
  7. package/lib/config/config.d.ts +311 -311
  8. package/lib/config/config.js +574 -574
  9. package/lib/config/configAggregator.d.ts +232 -232
  10. package/lib/config/configAggregator.js +379 -379
  11. package/lib/config/configFile.d.ts +199 -199
  12. package/lib/config/configFile.js +340 -340
  13. package/lib/config/configGroup.d.ts +141 -141
  14. package/lib/config/configGroup.js +224 -224
  15. package/lib/config/configStore.d.ts +241 -241
  16. package/lib/config/configStore.js +352 -352
  17. package/lib/config/envVars.d.ts +101 -101
  18. package/lib/config/envVars.js +456 -456
  19. package/lib/config/orgUsersConfig.d.ts +31 -31
  20. package/lib/config/orgUsersConfig.js +41 -41
  21. package/lib/config/sandboxOrgConfig.d.ts +37 -37
  22. package/lib/config/sandboxOrgConfig.js +50 -50
  23. package/lib/config/sandboxProcessCache.d.ts +16 -16
  24. package/lib/config/sandboxProcessCache.js +37 -37
  25. package/lib/config/tokensConfig.d.ts +10 -10
  26. package/lib/config/tokensConfig.js +28 -28
  27. package/lib/config/ttlConfig.d.ts +34 -34
  28. package/lib/config/ttlConfig.js +54 -54
  29. package/lib/crypto/crypto.d.ts +54 -54
  30. package/lib/crypto/crypto.js +220 -220
  31. package/lib/crypto/keyChain.d.ts +8 -8
  32. package/lib/crypto/keyChain.js +61 -61
  33. package/lib/crypto/keyChainImpl.d.ts +116 -116
  34. package/lib/crypto/keyChainImpl.js +486 -486
  35. package/lib/crypto/secureBuffer.d.ts +46 -46
  36. package/lib/crypto/secureBuffer.js +82 -82
  37. package/lib/deviceOauthService.d.ts +71 -71
  38. package/lib/deviceOauthService.js +191 -191
  39. package/lib/exported.d.ts +38 -38
  40. package/lib/exported.js +118 -118
  41. package/lib/global.d.ts +70 -70
  42. package/lib/global.js +109 -109
  43. package/lib/lifecycleEvents.d.ts +93 -93
  44. package/lib/lifecycleEvents.js +188 -188
  45. package/lib/logger.d.ts +381 -381
  46. package/lib/logger.js +734 -734
  47. package/lib/messages.d.ts +291 -291
  48. package/lib/messages.js +543 -543
  49. package/lib/org/authInfo.d.ts +344 -344
  50. package/lib/org/authInfo.js +892 -892
  51. package/lib/org/authRemover.d.ts +88 -88
  52. package/lib/org/authRemover.js +182 -182
  53. package/lib/org/connection.d.ts +197 -197
  54. package/lib/org/connection.js +395 -395
  55. package/lib/org/index.d.ts +6 -6
  56. package/lib/org/index.js +28 -28
  57. package/lib/org/org.d.ts +558 -558
  58. package/lib/org/org.js +1267 -1267
  59. package/lib/org/orgConfigProperties.d.ts +69 -69
  60. package/lib/org/orgConfigProperties.js +136 -136
  61. package/lib/org/permissionSetAssignment.d.ts +35 -35
  62. package/lib/org/permissionSetAssignment.js +125 -125
  63. package/lib/org/scratchOrgCache.d.ts +20 -20
  64. package/lib/org/scratchOrgCache.js +32 -32
  65. package/lib/org/scratchOrgCreate.d.ts +54 -54
  66. package/lib/org/scratchOrgCreate.js +216 -216
  67. package/lib/org/scratchOrgErrorCodes.d.ts +10 -10
  68. package/lib/org/scratchOrgErrorCodes.js +88 -88
  69. package/lib/org/scratchOrgFeatureDeprecation.d.ts +26 -26
  70. package/lib/org/scratchOrgFeatureDeprecation.js +109 -109
  71. package/lib/org/scratchOrgInfoApi.d.ts +68 -68
  72. package/lib/org/scratchOrgInfoApi.js +413 -413
  73. package/lib/org/scratchOrgInfoGenerator.d.ts +64 -64
  74. package/lib/org/scratchOrgInfoGenerator.js +241 -241
  75. package/lib/org/scratchOrgLifecycleEvents.d.ts +10 -10
  76. package/lib/org/scratchOrgLifecycleEvents.js +40 -40
  77. package/lib/org/scratchOrgSettingsGenerator.d.ts +78 -78
  78. package/lib/org/scratchOrgSettingsGenerator.js +276 -276
  79. package/lib/org/scratchOrgTypes.d.ts +43 -43
  80. package/lib/org/scratchOrgTypes.js +8 -8
  81. package/lib/org/user.d.ts +187 -187
  82. package/lib/org/user.js +448 -448
  83. package/lib/schema/printer.d.ts +79 -79
  84. package/lib/schema/printer.js +260 -260
  85. package/lib/schema/validator.d.ts +70 -70
  86. package/lib/schema/validator.js +169 -169
  87. package/lib/sfError.d.ts +73 -73
  88. package/lib/sfError.js +136 -136
  89. package/lib/sfProject.d.ts +357 -357
  90. package/lib/sfProject.js +671 -671
  91. package/lib/stateAggregator/accessors/aliasAccessor.d.ts +98 -98
  92. package/lib/stateAggregator/accessors/aliasAccessor.js +145 -145
  93. package/lib/stateAggregator/accessors/orgAccessor.d.ts +101 -101
  94. package/lib/stateAggregator/accessors/orgAccessor.js +240 -240
  95. package/lib/stateAggregator/accessors/sandboxAccessor.d.ts +8 -8
  96. package/lib/stateAggregator/accessors/sandboxAccessor.js +27 -27
  97. package/lib/stateAggregator/accessors/tokenAccessor.d.ts +63 -63
  98. package/lib/stateAggregator/accessors/tokenAccessor.js +79 -79
  99. package/lib/stateAggregator/index.d.ts +4 -4
  100. package/lib/stateAggregator/index.js +26 -26
  101. package/lib/stateAggregator/stateAggregator.d.ts +25 -25
  102. package/lib/stateAggregator/stateAggregator.js +45 -45
  103. package/lib/status/myDomainResolver.d.ts +66 -66
  104. package/lib/status/myDomainResolver.js +124 -124
  105. package/lib/status/pollingClient.d.ts +85 -85
  106. package/lib/status/pollingClient.js +115 -115
  107. package/lib/status/streamingClient.d.ts +244 -244
  108. package/lib/status/streamingClient.js +436 -436
  109. package/lib/status/types.d.ts +89 -89
  110. package/lib/status/types.js +17 -17
  111. package/lib/testSetup.d.ts +553 -530
  112. package/lib/testSetup.js +871 -727
  113. package/lib/util/cache.d.ts +11 -11
  114. package/lib/util/cache.js +69 -69
  115. package/lib/util/checkLightningDomain.d.ts +1 -1
  116. package/lib/util/checkLightningDomain.js +28 -28
  117. package/lib/util/directoryWriter.d.ts +12 -12
  118. package/lib/util/directoryWriter.js +53 -53
  119. package/lib/util/getJwtAudienceUrl.d.ts +4 -4
  120. package/lib/util/getJwtAudienceUrl.js +18 -18
  121. package/lib/util/internal.d.ts +58 -58
  122. package/lib/util/internal.js +118 -118
  123. package/lib/util/jsonXmlTools.d.ts +14 -14
  124. package/lib/util/jsonXmlTools.js +38 -38
  125. package/lib/util/mapKeys.d.ts +14 -14
  126. package/lib/util/mapKeys.js +51 -51
  127. package/lib/util/sfdc.d.ts +52 -52
  128. package/lib/util/sfdc.js +85 -85
  129. package/lib/util/sfdcUrl.d.ts +72 -72
  130. package/lib/util/sfdcUrl.js +215 -215
  131. package/lib/util/structuredWriter.d.ts +9 -9
  132. package/lib/util/structuredWriter.js +2 -2
  133. package/lib/util/zipWriter.d.ts +16 -16
  134. package/lib/util/zipWriter.js +67 -67
  135. package/lib/webOAuthServer.d.ts +156 -156
  136. package/lib/webOAuthServer.js +388 -388
  137. package/messages/auth.md +37 -37
  138. package/messages/config.md +156 -156
  139. package/messages/connection.md +30 -30
  140. package/messages/core.json +20 -20
  141. package/messages/core.md +67 -67
  142. package/messages/encryption.md +85 -85
  143. package/messages/envVars.md +303 -303
  144. package/messages/org.md +63 -63
  145. package/messages/permissionSetAssignment.md +31 -31
  146. package/messages/scratchOrgCreate.md +23 -23
  147. package/messages/scratchOrgErrorCodes.md +115 -115
  148. package/messages/scratchOrgFeatureDeprecation.md +11 -11
  149. package/messages/scratchOrgInfoApi.md +15 -15
  150. package/messages/scratchOrgInfoGenerator.md +23 -23
  151. package/messages/streaming.md +23 -23
  152. package/messages/user.md +35 -35
  153. package/package.json +97 -97
package/LICENSE.txt CHANGED
@@ -1,12 +1,12 @@
1
- Copyright (c) 2022, Salesforce.com, Inc.
2
- All rights reserved.
3
-
4
- Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met:
5
-
6
- * Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer.
7
-
8
- * Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution.
9
-
10
- * Neither the name of Salesforce.com nor the names of its contributors may be used to endorse or promote products derived from this software without specific prior written permission.
11
-
1
+ Copyright (c) 2022, Salesforce.com, Inc.
2
+ All rights reserved.
3
+
4
+ Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met:
5
+
6
+ * Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer.
7
+
8
+ * Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution.
9
+
10
+ * Neither the name of Salesforce.com nor the names of its contributors may be used to endorse or promote products derived from this software without specific prior written permission.
11
+
12
12
  THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
package/README.md CHANGED
@@ -1,227 +1,222 @@
1
- [![NPM](https://img.shields.io/npm/v/@salesforce/core.svg)](https://www.npmjs.com/package/@salesforce/core)
2
- [![CircleCI](https://circleci.com/gh/forcedotcom/sfdx-core.svg?style=svg&circle-token=2377ca31221869e9d13448313620486da80e595f)](https://circleci.com/gh/forcedotcom/sfdx-core)
3
-
4
- - [Description](#description)
5
- - [Usage](#usage)
6
- - [Contributing](#contributing)
7
- - [Using TestSetup](#using-testsetup)
8
- - [Mocking Authorizations](#mocking-authorizations)
9
- - [Mocking Config Files](#mocking-config-files)
10
- - [Using the Built-in Sinon Sandboxes](#using-the-built-in-sinon-sandboxes)
11
- - [Testing Expected Failures](#testing-expected-failures)
12
- - [Testing Log Lines](#testing-log-lines)
13
-
14
- # Description
15
-
16
- The @salesforce/core library provides client-side management of Salesforce DX projects, org authentication, connections to Salesforce APIs, and other utilities. Much of the core functionality that powers the Salesforce CLI plugins comes from this library. You can use this functionality in your plugins too.
17
-
18
- # Usage
19
-
20
- See the [API documentation](https://forcedotcom.github.io/sfdx-core/).
21
-
22
- ## Contributing
23
-
24
- If you are interested in contributing, please take a look at the [CONTRIBUTING](CONTRIBUTING.md) guide.
25
-
26
- # Using TestSetup
27
-
28
- The Salesforce DX Core Library provides a unit testing utility to help with mocking and sand-boxing core components. This feature allows unit tests to execute without needing to make API calls to salesforce.com.
29
-
30
- ## Mocking Authorizations
31
-
32
- Here you can mock authorization for a Salesforce scratch org.
33
-
34
- ```typescript
35
- import { strictEqual } from 'assert';
36
- import { MockTestOrgData, testSetup } from '@salesforce/core/lib/testSetup';
37
- import { AuthInfo } from '@salesforce/core';
38
-
39
- const $$ = testSetup();
40
-
41
- describe('Mocking Auth data', () => {
42
- it('example', async () => {
43
- const testData = new MockTestOrgData();
44
- await $$.stubAuths(testData);
45
- const auth = await AuthInfo.create({ username: testData.username });
46
- strictEqual(auth.getUsername(), testData.username);
47
- });
48
- });
49
- ```
50
-
51
- After having a valid AuthInfo object you can then create fake connections to a Salesforce.com scratch org. This allows for writing tests that can validate result responses for SOQL queries and REST endpoints.
52
-
53
- ```typescript
54
- import { AuthInfo, Connection, SfError } from '@salesforce/core';
55
- import { MockTestOrgData, testSetup } from '@salesforce/core/lib/testSetup';
56
- import { AnyJson, ensureJsonMap, JsonMap } from '@salesforce/ts-types';
57
- import { ensureString } from '@salesforce/ts-types';
58
- import { deepStrictEqual } from 'assert';
59
- import { QueryResult } from 'jsforce';
60
-
61
- const $$ = testSetup();
62
-
63
- describe('Mocking a force server call', () => {
64
- it('example', async () => {
65
- const records: AnyJson = { records: ['123456', '234567'] };
66
- const testData = new MockTestOrgData();
67
- await $$.stubAuths(testData);
68
- $$.fakeConnectionRequest = (request: AnyJson): Promise<AnyJson> => {
69
- const _request = ensureJsonMap(request);
70
- if (request && ensureString(_request.url).includes('Account')) {
71
- return Promise.resolve(records);
72
- } else {
73
- return Promise.reject(new SfError(`Unexpected request: ${_request.url}`));
74
- }
75
- };
76
- const connection = await Connection.create({
77
- authInfo: await AuthInfo.create({ username: testData.username }),
78
- });
79
- const result = await connection.query('select Id From Account');
80
- deepStrictEqual(result, records);
81
- });
82
- });
83
- ```
84
-
85
- ## Mocking Config Files
86
-
87
- You can mock the contents of various config files
88
-
89
- ```typescript
90
- import { strictEqual } from 'assert';
91
- import { MockTestOrgData, testSetup } from '@salesforce/core/lib/testSetup';
92
- import { StateAggregator, OrgConfigProperties } from '@salesforce/core';
93
-
94
- const $$ = testSetup();
95
-
96
- describe('Mocking Aliases', () => {
97
- it('example', async () => {
98
- const testData = new MockTestOrgData();
99
- await $$.stubAliases({ myAlias: testData.username });
100
- const alias = (await StateAggregator.getInstance()).aliases.get(testData.username);
101
- strictEqual(alias, 'myAlais');
102
- });
103
- });
104
-
105
- describe('Mocking Config', () => {
106
- it('example', async () => {
107
- const testData = new MockTestOrgData();
108
- await $$.stubConfig({ [OrgConfigProperties.TARGET_ORG]: testData.username });
109
- const { value } = (await ConfigAggregator.create()).getInfo(OrgConfigProperties.TARGET_ORG);
110
- strictEqual(value, testData.username);
111
- });
112
- });
113
-
114
- describe('Mocking Arbitrary Config Files', () => {
115
- it('example', async () => {
116
- // MyConfigFile must extend the ConfigFile class in order for this to work properly.
117
- $$.setConfigStubContents('MyConfigFile', { contents: { foo: 'bar' } });
118
- });
119
- });
120
- ```
121
-
122
- ## Using the Built-in Sinon Sandboxes
123
-
124
- sfdx-core uses Sinon as its underlying mocking system. If you're unfamiliar with Sinon and its sandboxing concept you can find more information here:
125
- https://sinonjs.org/
126
- Sinon `stub`s and `spy`s must be cleaned up after test invocations. To ease the use of Sinon with sfdx core we've exposed our sandbox in TestSetup. After adding your own `stub`s and/or `spy`s they will automatically be cleaned up after each test using mocha's afterEach method.
127
-
128
- ```typescript
129
- import { strictEqual } from 'assert';
130
-
131
- import { testSetup } from '@salesforce/core/lib/testSetup';
132
- import * as os from 'os';
133
-
134
- const $$ = testSetup();
135
-
136
- describe('Using the built in Sinon sandbox.', () => {
137
- it('example', async () => {
138
- const unsupportedOS = 'LEO';
139
- $$.SANDBOX.stub(os, 'platform').returns(unsupportedOS);
140
- strictEqual(os.platform(), unsupportedOS);
141
- });
142
- });
143
- ```
144
-
145
- ## Testing Expected Failures
146
-
147
- It's important to have negative tests that ensure proper error handling. With `shouldThrow` it's easy to test for expected async rejections.
148
-
149
- ```typescript
150
- import { SfError } from '@salesforce/core';
151
- import { shouldThrow } from '@salesforce/core/lib/testSetup';
152
- import { strictEqual } from 'assert';
153
-
154
- class TestObject {
155
- public static async method() {
156
- throw new SfError('Error', 'ExpectedError');
157
- }
158
- }
159
-
160
- describe('Testing for expected errors', () => {
161
- it('example', async () => {
162
- try {
163
- await shouldThrow(TestObject.method());
164
- } catch (e) {
165
- strictEqual(e.name, 'ExpectedError');
166
- }
167
- });
168
- });
169
- ```
170
-
171
- You can also use `shouldThrowSync` for syncrhonous functions you expect to fail
172
-
173
- ```typescript
174
- import { SfError } from '@salesforce/core';
175
- import { shouldThrowSync } from '@salesforce/core/lib/testSetup';
176
- import { strictEqual } from 'assert';
177
-
178
- class TestObject {
179
- public static method() {
180
- throw new SfError('Error', 'ExpectedError');
181
- }
182
- }
183
-
184
- describe('Testing for expected errors', () => {
185
- it('example', async () => {
186
- try {
187
- shouldThrowSync(() => TestObject.method());
188
- } catch (e) {
189
- strictEqual(e.name, 'ExpectedError');
190
- }
191
- });
192
- });
193
- ```
194
-
195
- ## Testing Log Lines
196
-
197
- It's also useful to check expected values and content from log lines. TestSetup configures the sfdx-core logger to use an in memory LogLine storage structure. These can be easily accessed from tests.
198
-
199
- ```typescript
200
- import { Logger, LogLine } from '@salesforce/core';
201
- import { testSetup } from '@salesforce/core/lib/testSetup';
202
- import { strictEqual } from 'assert';
203
-
204
- const $$ = testSetup();
205
-
206
- const TEST_STRING = 'foo was here';
207
-
208
- class TestObject {
209
- constructor(private logger: Logger) {
210
- this.logger = logger.child('TestObject');
211
- }
212
-
213
- public method() {
214
- this.logger.error(TEST_STRING);
215
- }
216
- }
217
-
218
- describe('Testing log lines', () => {
219
- it('example', async () => {
220
- const obj = new TestObject($$.TEST_LOGGER);
221
- obj.method();
222
- const records = $$.TEST_LOGGER.getBufferedRecords();
223
- strictEqual(records.length, 1);
224
- strictEqual(records[0].msg, TEST_STRING);
225
- });
226
- });
227
- ```
1
+ [![NPM](https://img.shields.io/npm/v/@salesforce/core.svg)](https://www.npmjs.com/package/@salesforce/core)
2
+ [![CircleCI](https://circleci.com/gh/forcedotcom/sfdx-core.svg?style=svg&circle-token=2377ca31221869e9d13448313620486da80e595f)](https://circleci.com/gh/forcedotcom/sfdx-core)
3
+
4
+ - [Description](#description)
5
+ - [Usage](#usage)
6
+ - [Contributing](#contributing)
7
+ - [Using TestSetup](#using-testsetup)
8
+ - [Mocking Authorizations](#mocking-authorizations)
9
+ - [Mocking Config Files](#mocking-config-files)
10
+ - [Using the Built-in Sinon Sandboxes](#using-the-built-in-sinon-sandboxes)
11
+ - [Testing Expected Failures](#testing-expected-failures)
12
+ - [Testing Log Lines](#testing-log-lines)
13
+
14
+ # Description
15
+
16
+ The @salesforce/core library provides client-side management of Salesforce DX projects, org authentication, connections to Salesforce APIs, and other utilities. Much of the core functionality that powers the Salesforce CLI plugins comes from this library. You can use this functionality in your plugins too.
17
+
18
+ # Usage
19
+
20
+ See the [API documentation](https://forcedotcom.github.io/sfdx-core/).
21
+
22
+ ## Contributing
23
+
24
+ If you are interested in contributing, please take a look at the [CONTRIBUTING](CONTRIBUTING.md) guide.
25
+
26
+ # Using TestSetup
27
+
28
+ The Salesforce DX Core Library provides a unit testing utility to help with mocking and sand-boxing core components. This feature allows unit tests to execute without needing to make API calls to salesforce.com.
29
+
30
+ ## Mocking Authorizations
31
+
32
+ Here you can mock authorization for a Salesforce scratch org.
33
+
34
+ ```typescript
35
+ import { strictEqual } from 'assert';
36
+ import { MockTestOrgData, TestContext } from '@salesforce/core/lib/testSetup';
37
+ import { AuthInfo } from '@salesforce/core';
38
+
39
+ describe('Mocking Auth data', () => {
40
+ const $$ = new TestContext();
41
+ it('example', async () => {
42
+ const testData = new MockTestOrgData();
43
+ await $$.stubAuths(testData);
44
+ const auth = await AuthInfo.create({ username: testData.username });
45
+ strictEqual(auth.getUsername(), testData.username);
46
+ });
47
+ });
48
+ ```
49
+
50
+ After having a valid AuthInfo object you can then create fake connections to a Salesforce.com scratch org. This allows for writing tests that can validate result responses for SOQL queries and REST endpoints.
51
+
52
+ ```typescript
53
+ import { AuthInfo, Connection, SfError } from '@salesforce/core';
54
+ import { MockTestOrgData, TestContext } from '@salesforce/core/lib/testSetup';
55
+ import { AnyJson, ensureJsonMap, JsonMap } from '@salesforce/ts-types';
56
+ import { ensureString } from '@salesforce/ts-types';
57
+ import { deepStrictEqual } from 'assert';
58
+ import { QueryResult } from 'jsforce';
59
+
60
+ describe('Mocking a force server call', () => {
61
+ const $$ = new TestContext();
62
+ it('example', async () => {
63
+ const records: AnyJson = { records: ['123456', '234567'] };
64
+ const testData = new MockTestOrgData();
65
+ await $$.stubAuths(testData);
66
+ $$.fakeConnectionRequest = (request: AnyJson): Promise<AnyJson> => {
67
+ const _request = ensureJsonMap(request);
68
+ if (request && ensureString(_request.url).includes('Account')) {
69
+ return Promise.resolve(records);
70
+ } else {
71
+ return Promise.reject(new SfError(`Unexpected request: ${_request.url}`));
72
+ }
73
+ };
74
+ const connection = await Connection.create({
75
+ authInfo: await AuthInfo.create({ username: testData.username }),
76
+ });
77
+ const result = await connection.query('select Id From Account');
78
+ deepStrictEqual(result, records);
79
+ });
80
+ });
81
+ ```
82
+
83
+ ## Mocking Config Files
84
+
85
+ You can mock the contents of various config files
86
+
87
+ ```typescript
88
+ import { strictEqual } from 'assert';
89
+ import { MockTestOrgData, TestContext } from '@salesforce/core/lib/testSetup';
90
+ import { StateAggregator, OrgConfigProperties } from '@salesforce/core';
91
+
92
+ describe('Mocking Aliases', () => {
93
+ const $$ = new TestContext();
94
+ it('example', async () => {
95
+ const testData = new MockTestOrgData();
96
+ await $$.stubAliases({ myAlias: testData.username });
97
+ const alias = (await StateAggregator.getInstance()).aliases.get(testData.username);
98
+ strictEqual(alias, 'myAlais');
99
+ });
100
+ });
101
+
102
+ describe('Mocking Config', () => {
103
+ it('example', async () => {
104
+ const testData = new MockTestOrgData();
105
+ await $$.stubConfig({ [OrgConfigProperties.TARGET_ORG]: testData.username });
106
+ const { value } = (await ConfigAggregator.create()).getInfo(OrgConfigProperties.TARGET_ORG);
107
+ strictEqual(value, testData.username);
108
+ });
109
+ });
110
+
111
+ describe('Mocking Arbitrary Config Files', () => {
112
+ it('example', async () => {
113
+ // MyConfigFile must extend the ConfigFile class in order for this to work properly.
114
+ $$.setConfigStubContents('MyConfigFile', { contents: { foo: 'bar' } });
115
+ });
116
+ });
117
+ ```
118
+
119
+ ## Using the Built-in Sinon Sandboxes
120
+
121
+ sfdx-core uses Sinon as its underlying mocking system. If you're unfamiliar with Sinon and its sandboxing concept you can find more information here:
122
+ https://sinonjs.org/
123
+ Sinon `stub`s and `spy`s must be cleaned up after test invocations. To ease the use of Sinon with sfdx core we've exposed our sandbox in TestSetup. After adding your own `stub`s and/or `spy`s they will automatically be cleaned up after each test using mocha's afterEach method.
124
+
125
+ ```typescript
126
+ import { strictEqual } from 'assert';
127
+
128
+ import { TestContext } from '@salesforce/core/lib/testSetup';
129
+ import * as os from 'os';
130
+
131
+ describe('Using the built in Sinon sandbox.', () => {
132
+ const $$ = new TestContext();
133
+ it('example', async () => {
134
+ const unsupportedOS = 'LEO';
135
+ $$.SANDBOX.stub(os, 'platform').returns(unsupportedOS);
136
+ strictEqual(os.platform(), unsupportedOS);
137
+ });
138
+ });
139
+ ```
140
+
141
+ ## Testing Expected Failures
142
+
143
+ It's important to have negative tests that ensure proper error handling. With `shouldThrow` it's easy to test for expected async rejections.
144
+
145
+ ```typescript
146
+ import { SfError } from '@salesforce/core';
147
+ import { shouldThrow } from '@salesforce/core/lib/testSetup';
148
+ import { strictEqual } from 'assert';
149
+
150
+ class TestObject {
151
+ public static async method() {
152
+ throw new SfError('Error', 'ExpectedError');
153
+ }
154
+ }
155
+
156
+ describe('Testing for expected errors', () => {
157
+ it('example', async () => {
158
+ try {
159
+ await shouldThrow(TestObject.method());
160
+ } catch (e) {
161
+ strictEqual(e.name, 'ExpectedError');
162
+ }
163
+ });
164
+ });
165
+ ```
166
+
167
+ You can also use `shouldThrowSync` for syncrhonous functions you expect to fail
168
+
169
+ ```typescript
170
+ import { SfError } from '@salesforce/core';
171
+ import { shouldThrowSync } from '@salesforce/core/lib/testSetup';
172
+ import { strictEqual } from 'assert';
173
+
174
+ class TestObject {
175
+ public static method() {
176
+ throw new SfError('Error', 'ExpectedError');
177
+ }
178
+ }
179
+
180
+ describe('Testing for expected errors', () => {
181
+ it('example', async () => {
182
+ try {
183
+ shouldThrowSync(() => TestObject.method());
184
+ } catch (e) {
185
+ strictEqual(e.name, 'ExpectedError');
186
+ }
187
+ });
188
+ });
189
+ ```
190
+
191
+ ## Testing Log Lines
192
+
193
+ It's also useful to check expected values and content from log lines. TestSetup configures the sfdx-core logger to use an in memory LogLine storage structure. These can be easily accessed from tests.
194
+
195
+ ```typescript
196
+ import { Logger, LogLine } from '@salesforce/core';
197
+ import { TestContext } from '@salesforce/core/lib/testSetup';
198
+ import { strictEqual } from 'assert';
199
+
200
+ const TEST_STRING = 'foo was here';
201
+
202
+ class TestObject {
203
+ constructor(private logger: Logger) {
204
+ this.logger = logger.child('TestObject');
205
+ }
206
+
207
+ public method() {
208
+ this.logger.error(TEST_STRING);
209
+ }
210
+ }
211
+
212
+ describe('Testing log lines', () => {
213
+ const $$ = new TestContext();
214
+ it('example', async () => {
215
+ const obj = new TestObject($$.TEST_LOGGER);
216
+ obj.method();
217
+ const records = $$.TEST_LOGGER.getBufferedRecords();
218
+ strictEqual(records.length, 1);
219
+ strictEqual(records[0].msg, TEST_STRING);
220
+ });
221
+ });
222
+ ```
@@ -1,12 +1,12 @@
1
- import { ConfigGroup } from './configGroup';
2
- import { ConfigContents, ConfigValue } from './configStore';
3
- /**
4
- * Different groups of aliases. Currently only support orgs.
5
- */
6
- export declare enum AliasGroup {
7
- ORGS = "orgs"
8
- }
9
- export declare class AliasesConfig extends ConfigGroup<ConfigGroup.Options> {
10
- static getDefaultOptions(): ConfigGroup.Options;
11
- protected setMethod(contents: ConfigContents, key: string, value?: ConfigValue): void;
12
- }
1
+ import { ConfigGroup } from './configGroup';
2
+ import { ConfigContents, ConfigValue } from './configStore';
3
+ /**
4
+ * Different groups of aliases. Currently only support orgs.
5
+ */
6
+ export declare enum AliasGroup {
7
+ ORGS = "orgs"
8
+ }
9
+ export declare class AliasesConfig extends ConfigGroup<ConfigGroup.Options> {
10
+ static getDefaultOptions(): ConfigGroup.Options;
11
+ protected setMethod(contents: ConfigContents, key: string, value?: ConfigValue): void;
12
+ }
@@ -1,28 +1,28 @@
1
- "use strict";
2
- /*
3
- * Copyright (c) 2022, salesforce.com, inc.
4
- * All rights reserved.
5
- * Licensed under the BSD 3-Clause license.
6
- * For full license text, see LICENSE.txt file in the repo root or https://opensource.org/licenses/BSD-3-Clause
7
- */
8
- Object.defineProperty(exports, "__esModule", { value: true });
9
- exports.AliasesConfig = exports.AliasGroup = void 0;
10
- const configGroup_1 = require("./configGroup");
11
- /**
12
- * Different groups of aliases. Currently only support orgs.
13
- */
14
- var AliasGroup;
15
- (function (AliasGroup) {
16
- AliasGroup["ORGS"] = "orgs";
17
- })(AliasGroup = exports.AliasGroup || (exports.AliasGroup = {}));
18
- class AliasesConfig extends configGroup_1.ConfigGroup {
19
- static getDefaultOptions() {
20
- return { ...configGroup_1.ConfigGroup.getOptions(AliasGroup.ORGS, 'alias.json'), isGlobal: true, isState: true };
21
- }
22
- // eslint-disable-next-line class-methods-use-this
23
- setMethod(contents, key, value) {
24
- contents[key] = value;
25
- }
26
- }
27
- exports.AliasesConfig = AliasesConfig;
1
+ "use strict";
2
+ /*
3
+ * Copyright (c) 2022, salesforce.com, inc.
4
+ * All rights reserved.
5
+ * Licensed under the BSD 3-Clause license.
6
+ * For full license text, see LICENSE.txt file in the repo root or https://opensource.org/licenses/BSD-3-Clause
7
+ */
8
+ Object.defineProperty(exports, "__esModule", { value: true });
9
+ exports.AliasesConfig = exports.AliasGroup = void 0;
10
+ const configGroup_1 = require("./configGroup");
11
+ /**
12
+ * Different groups of aliases. Currently only support orgs.
13
+ */
14
+ var AliasGroup;
15
+ (function (AliasGroup) {
16
+ AliasGroup["ORGS"] = "orgs";
17
+ })(AliasGroup = exports.AliasGroup || (exports.AliasGroup = {}));
18
+ class AliasesConfig extends configGroup_1.ConfigGroup {
19
+ static getDefaultOptions() {
20
+ return { ...configGroup_1.ConfigGroup.getOptions(AliasGroup.ORGS, 'alias.json'), isGlobal: true, isState: true };
21
+ }
22
+ // eslint-disable-next-line class-methods-use-this
23
+ setMethod(contents, key, value) {
24
+ contents[key] = value;
25
+ }
26
+ }
27
+ exports.AliasesConfig = AliasesConfig;
28
28
  //# sourceMappingURL=aliasesConfig.js.map
@@ -1,19 +1,19 @@
1
- import { AuthFields } from '../org';
2
- import { ConfigFile } from './configFile';
3
- /**
4
- * An auth config file that stores information such as access tokens, usernames, etc.,
5
- * in the global sfdx directory (~/.sfdx).
6
- *
7
- * ```
8
- * const authInfo = await AuthInfoConfig.create(AuthInfoConfig.getOptions(username));
9
- * ```
10
- */
11
- export declare class AuthInfoConfig extends ConfigFile<ConfigFile.Options, AuthFields> {
12
- protected static encryptedKeys: RegExp[];
13
- /**
14
- * Gets the config options for a given org ID.
15
- *
16
- * @param username The username for the org.
17
- */
18
- static getOptions(username: string): ConfigFile.Options;
19
- }
1
+ import { AuthFields } from '../org';
2
+ import { ConfigFile } from './configFile';
3
+ /**
4
+ * An auth config file that stores information such as access tokens, usernames, etc.,
5
+ * in the global sfdx directory (~/.sfdx).
6
+ *
7
+ * ```
8
+ * const authInfo = await AuthInfoConfig.create(AuthInfoConfig.getOptions(username));
9
+ * ```
10
+ */
11
+ export declare class AuthInfoConfig extends ConfigFile<ConfigFile.Options, AuthFields> {
12
+ protected static encryptedKeys: RegExp[];
13
+ /**
14
+ * Gets the config options for a given org ID.
15
+ *
16
+ * @param username The username for the org.
17
+ */
18
+ static getOptions(username: string): ConfigFile.Options;
19
+ }