|
4 | 4 | * Licensed under the BSD 3-Clause license. |
5 | 5 | * For full license text, see LICENSE.txt file in the repo root or https://opensource.org/licenses/BSD-3-Clause |
6 | 6 | */ |
| 7 | + |
| 8 | +import { strictEqual } from 'node:assert'; |
7 | 9 | import { TestContext } from '@salesforce/core/testSetup'; |
8 | | -// import { expect } from 'chai'; |
9 | | -// import { stubSfCommandUx } from '@salesforce/sf-plugins-core'; |
10 | | -// import LightningDevSite from '../../../../src/commands/lightning/dev/site.js'; |
| 10 | +import { expect } from 'chai'; |
| 11 | +import { Org } from '@salesforce/core'; |
| 12 | +import { LocalDevOptions } from '@lwrjs/api'; |
| 13 | +import LightningDevSite from '../../../../src/commands/lightning/dev/site.js'; |
| 14 | +import { OrgUtils } from '../../../../src/shared/orgUtils.js'; |
11 | 15 |
|
12 | | -// TODO fix me once we have a fully working command |
13 | 16 | describe('lightning dev site', () => { |
14 | 17 | const $$ = new TestContext(); |
15 | | - // let sfCommandStubs: ReturnType<typeof stubSfCommandUx>; |
16 | 18 |
|
17 | 19 | beforeEach(() => { |
18 | | - // sfCommandStubs = stubSfCommandUx($$.SANDBOX); |
| 20 | + $$.SANDBOX.stub(OrgUtils, 'isLocalDevEnabled').resolves(true); |
| 21 | + $$.SANDBOX.stub(OrgUtils, 'ensureMatchingAPIVersion').returns(); |
19 | 22 | }); |
20 | 23 |
|
21 | 24 | afterEach(() => { |
22 | 25 | $$.restore(); |
23 | 26 | }); |
24 | 27 |
|
25 | | - it('runs hello', async () => { |
26 | | - // await LightningDevSite.run([]); |
27 | | - // const output = sfCommandStubs.log |
28 | | - // .getCalls() |
29 | | - // .flatMap((c) => c.args) |
30 | | - // .join('\n'); |
31 | | - // expect(output).to.include('hello world'); |
| 28 | + it('should have summary, description, and examples defined', () => { |
| 29 | + strictEqual(typeof LightningDevSite.summary, 'string', 'Summary should be a string'); |
| 30 | + strictEqual(typeof LightningDevSite.description, 'string', 'Description should be a string'); |
| 31 | + strictEqual(typeof LightningDevSite.examples, 'object', 'Examples should be an array'); |
| 32 | + }); |
| 33 | + |
| 34 | + it('result should be undefined if local development is not enabled', async () => { |
| 35 | + $$.SANDBOX.restore(); |
| 36 | + $$.SANDBOX.stub(OrgUtils, 'isLocalDevEnabled').resolves(false); |
| 37 | + const result = await LightningDevSite.run(['--name', 'Astro', '--target-org', '00Dxx0000001gEH']); |
| 38 | + expect(result).to.be.undefined; |
32 | 39 | }); |
33 | 40 |
|
34 | | - it('runs hello world --name Astro', async () => { |
35 | | - // await LightningDevSite.run(['--name', 'Astro']); |
36 | | - // const output = sfCommandStubs.log |
37 | | - // .getCalls() |
38 | | - // .flatMap((c) => c.args) |
39 | | - // .join('\n'); |
40 | | - // expect(output).to.include('hello Astro'); |
| 41 | + it('should have valid startupParams', async () => { |
| 42 | + // eslint-disable-next-line @typescript-eslint/no-unsafe-argument, @typescript-eslint/no-explicit-any |
| 43 | + const org = new Org({ id: '00Dxx0000001gEH', connection: {} } as any); |
| 44 | + $$.SANDBOX.stub(Org, 'create').returns(Promise.resolve(org)); |
| 45 | + |
| 46 | + const startupParams: LocalDevOptions = { |
| 47 | + sfCLI: true, |
| 48 | + authToken: 'test-auth-token', |
| 49 | + open: true, |
| 50 | + port: 3000, |
| 51 | + logLevel: 'error', |
| 52 | + mode: 'dev', |
| 53 | + siteZip: 'test-site-zip', |
| 54 | + siteDir: 'test-site-dir', |
| 55 | + }; |
| 56 | + |
| 57 | + $$.SANDBOX.stub(LightningDevSite, 'run').resolves(Promise.resolve(startupParams)); |
| 58 | + process.env.SETUP_ONLY = 'true'; |
| 59 | + |
| 60 | + const result = await LightningDevSite.run(['--name', 'Astro', '--target-org', '00Dxx0000001gEH']); |
| 61 | + delete process.env.SETUP_ONLY; |
| 62 | + |
| 63 | + expect(result).to.deep.equal(startupParams); |
41 | 64 | }); |
42 | 65 | }); |
0 commit comments