Skip to content

Commit b7bd4ac

Browse files
committed
feat: add performance mode flag
1 parent 916b13d commit b7bd4ac

File tree

7 files changed

+123
-13
lines changed

7 files changed

+123
-13
lines changed

command-snapshot.json

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,16 +11,16 @@
1111
"alias": [],
1212
"command": "lightning:dev:component",
1313
"flagAliases": [],
14-
"flagChars": ["c", "n", "o"],
15-
"flags": ["client-select", "flags-dir", "json", "name", "target-org"],
14+
"flagChars": ["c", "n", "o", "p"],
15+
"flags": ["client-select", "flags-dir", "json", "name", "performance", "target-org"],
1616
"plugin": "@salesforce/plugin-lightning-dev"
1717
},
1818
{
1919
"alias": [],
2020
"command": "lightning:dev:site",
2121
"flagAliases": [],
2222
"flagChars": ["l", "n", "o"],
23-
"flags": ["flags-dir", "get-latest", "guest", "name", "target-org", "ssr"],
23+
"flags": ["flags-dir", "get-latest", "guest", "name", "ssr", "target-org"],
2424
"plugin": "@salesforce/plugin-lightning-dev"
2525
}
2626
]

messages/lightning.dev.component.md

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,10 @@ Name of a component to preview.
2424

2525
Launch component preview without selecting a component
2626

27+
# flags.performance.summary
28+
29+
Open the component preview in performance mode
30+
2731
# error.directory
2832

2933
Unable to find components
@@ -40,9 +44,15 @@ Failed to parse component metadata at: %s
4044

4145
Unable to find component with name: %s
4246

47+
# error.performance-client-select-conflict
48+
49+
Cannot use --performance flag when --client-select is enabled
50+
4351
# examples
4452

4553
- Select a component and launch the component preview:
4654
<%= config.bin %> <%= command.id %>
4755
- Launch component preview for "myComponent":
4856
<%= config.bin %> <%= command.id %> --name myComponent
57+
- Launch component preview for "myComponent" in performance mode:
58+
<%= config.bin %> <%= command.id %> --name myComponent --performance

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -238,7 +238,7 @@
238238
],
239239
"target": {
240240
"versionNumber": "66.0",
241-
"matchingDevServerVersion": "~13.0.27"
241+
"matchingDevServerVersion": "~13.2.2"
242242
},
243243
"versionToTagMappings": [
244244
{

src/commands/lightning/dev/component.ts

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,11 @@ export default class LightningDevComponent extends SfCommand<void> {
3434
char: 'c',
3535
default: false,
3636
}),
37+
performance: Flags.boolean({
38+
summary: messages.getMessage('flags.performance.summary'),
39+
char: 'p',
40+
default: false,
41+
}),
3742
'target-org': Flags.requiredOrg(),
3843
};
3944

@@ -53,8 +58,13 @@ export default class LightningDevComponent extends SfCommand<void> {
5358

5459
let componentName = flags['name'];
5560
const clientSelect = flags['client-select'];
61+
const performanceMode = flags['performance'];
5662
const targetOrg = flags['target-org'];
5763

64+
if (performanceMode && clientSelect) {
65+
throw new Error(messages.getMessage('error.performance-client-select-conflict'));
66+
}
67+
5868
const { ldpServerId, ldpServerToken } = await PreviewUtils.initializePreviewConnection(targetOrg);
5969

6070
logger.debug('Determining the next available port for Local Dev Server');
@@ -126,7 +136,8 @@ export default class LightningDevComponent extends SfCommand<void> {
126136
ldpServerUrl,
127137
ldpServerId,
128138
componentName,
129-
targetOrgArg
139+
targetOrgArg,
140+
performanceMode
130141
);
131142

132143
// Open the browser and navigate to the right page

src/shared/previewUtils.ts

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -221,13 +221,15 @@ export class PreviewUtils {
221221
* @param ldpServerId Record ID for the identity token
222222
* @param componentName The name of the component to preview
223223
* @param targetOrg An optional org id
224+
* @param performanceMode Whether to enable performance mode
224225
* @returns Array of arguments to be used by Org:Open command for launching the component preview
225226
*/
226227
public static generateComponentPreviewLaunchArguments(
227228
ldpServerUrl: string,
228229
ldpServerId: string,
229230
componentName?: string,
230-
targetOrg?: string
231+
targetOrg?: string,
232+
performanceMode?: boolean
231233
): string[] {
232234
let appPath = `lwr/application/e/devpreview/ai/${encodeURIComponent(
233235
'localdev%2Fpreview'
@@ -236,6 +238,9 @@ export class PreviewUtils {
236238
// TODO: support other namespaces
237239
appPath += `&specifier=c/${componentName}`;
238240
}
241+
if (performanceMode) {
242+
appPath += '&mode=performance';
243+
}
239244

240245
const launchArguments = ['--path', appPath];
241246

test/commands/lightning/dev/component.test.ts

Lines changed: 20 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -4,21 +4,34 @@
44
* Licensed under the BSD 3-Clause license.
55
* For full license text, see LICENSE.txt file in the repo root or https://opensource.org/licenses/BSD-3-Clause
66
*/
7-
import { TestContext } from '@salesforce/core/testSetup';
8-
// import { expect } from 'chai';
9-
// import { stubSfCommandUx } from '@salesforce/sf-plugins-core';
7+
import { Messages } from '@salesforce/core';
8+
import { MockTestOrgData, TestContext } from '@salesforce/core/testSetup';
9+
import { stubUx } from '@salesforce/sf-plugins-core';
10+
import { expect } from 'chai';
11+
import LightningDevComponent from '../../../../src/commands/lightning/dev/component.js';
12+
13+
Messages.importMessagesDirectoryFromMetaUrl(import.meta.url);
1014

1115
describe('lightning single component preview', () => {
16+
const messages = Messages.loadMessages('@salesforce/plugin-lightning-dev', 'lightning.dev.component');
1217
const $$ = new TestContext();
13-
// let sfCommandStubs: ReturnType<typeof stubSfCommandUx>;
18+
const testOrgData = new MockTestOrgData();
1419

15-
beforeEach(() => {
16-
// sfCommandStubs = stubSfCommandUx($$.SANDBOX);
20+
beforeEach(async () => {
21+
stubUx($$.SANDBOX);
22+
await $$.stubAuths(testOrgData);
1723
});
1824

1925
afterEach(() => {
2026
$$.restore();
2127
});
2228

23-
it('todo add unit tests', async () => {});
29+
it('should throw error when both client-select and performance flags are used', async () => {
30+
try {
31+
await LightningDevComponent.run(['--client-select', '--performance', '--target-org', testOrgData.orgId]);
32+
expect.fail('Expected command to throw an error');
33+
} catch (error) {
34+
expect((error as Error).message).to.equal(messages.getMessage('error.performance-client-select-conflict'));
35+
}
36+
});
2437
});

test/shared/previewUtils.test.ts

Lines changed: 71 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -273,6 +273,77 @@ describe('previewUtils', () => {
273273
expect(parsed.values['target-org']).to.be.undefined;
274274
});
275275

276+
it('generateComponentPreviewLaunchArguments with performance mode enabled', async () => {
277+
const result = PreviewUtils.generateComponentPreviewLaunchArguments(
278+
'https://localhost:3333',
279+
testLdpServerId,
280+
'myTestComponent',
281+
'myTargetOrg',
282+
true
283+
);
284+
285+
const parsed = parseArgs({
286+
args: result,
287+
options: {
288+
path: { type: 'string' },
289+
'target-org': { type: 'string' },
290+
},
291+
});
292+
293+
expect(parsed.values.path).to.include('ldpServerUrl=https://localhost:3333');
294+
expect(parsed.values.path).to.include(`ldpServerId=${testLdpServerId}`);
295+
expect(parsed.values.path).to.include('specifier=c/myTestComponent');
296+
expect(parsed.values.path).to.include('mode=performance');
297+
expect(parsed.values['target-org']).to.equal('myTargetOrg');
298+
});
299+
300+
it('generateComponentPreviewLaunchArguments with performance mode disabled', async () => {
301+
const result = PreviewUtils.generateComponentPreviewLaunchArguments(
302+
'https://localhost:3333',
303+
testLdpServerId,
304+
'myTestComponent',
305+
'myTargetOrg',
306+
false
307+
);
308+
309+
const parsed = parseArgs({
310+
args: result,
311+
options: {
312+
path: { type: 'string' },
313+
'target-org': { type: 'string' },
314+
},
315+
});
316+
317+
expect(parsed.values.path).to.include('ldpServerUrl=https://localhost:3333');
318+
expect(parsed.values.path).to.include(`ldpServerId=${testLdpServerId}`);
319+
expect(parsed.values.path).to.include('specifier=c/myTestComponent');
320+
expect(parsed.values.path).to.not.include('mode=performance');
321+
expect(parsed.values['target-org']).to.equal('myTargetOrg');
322+
});
323+
324+
it('generateComponentPreviewLaunchArguments with performance mode undefined (default)', async () => {
325+
const result = PreviewUtils.generateComponentPreviewLaunchArguments(
326+
'https://localhost:3333',
327+
testLdpServerId,
328+
'myTestComponent',
329+
'myTargetOrg'
330+
);
331+
332+
const parsed = parseArgs({
333+
args: result,
334+
options: {
335+
path: { type: 'string' },
336+
'target-org': { type: 'string' },
337+
},
338+
});
339+
340+
expect(parsed.values.path).to.include('ldpServerUrl=https://localhost:3333');
341+
expect(parsed.values.path).to.include(`ldpServerId=${testLdpServerId}`);
342+
expect(parsed.values.path).to.include('specifier=c/myTestComponent');
343+
expect(parsed.values.path).to.not.include('mode=performance');
344+
expect(parsed.values['target-org']).to.equal('myTargetOrg');
345+
});
346+
276347
it('getTargetOrgFromArguments finds -o flag', async () => {
277348
const args = ['command', '-o', 'myOrg', 'otherArg'];
278349
const result = PreviewUtils.getTargetOrgFromArguments(args);

0 commit comments

Comments
 (0)