-
Notifications
You must be signed in to change notification settings - Fork 12
feat: added UT for site #279
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Closed
Closed
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -4,39 +4,62 @@ | |
* Licensed under the BSD 3-Clause license. | ||
* For full license text, see LICENSE.txt file in the repo root or https://opensource.org/licenses/BSD-3-Clause | ||
*/ | ||
|
||
import { strictEqual } from 'node:assert'; | ||
import { TestContext } from '@salesforce/core/testSetup'; | ||
// import { expect } from 'chai'; | ||
// import { stubSfCommandUx } from '@salesforce/sf-plugins-core'; | ||
// import LightningDevSite from '../../../../src/commands/lightning/dev/site.js'; | ||
import { expect } from 'chai'; | ||
import { Org } from '@salesforce/core'; | ||
import { LocalDevOptions } from '@lwrjs/api'; | ||
import LightningDevSite from '../../../../src/commands/lightning/dev/site.js'; | ||
import { OrgUtils } from '../../../../src/shared/orgUtils.js'; | ||
|
||
// TODO fix me once we have a fully working command | ||
describe('lightning dev site', () => { | ||
const $$ = new TestContext(); | ||
// let sfCommandStubs: ReturnType<typeof stubSfCommandUx>; | ||
|
||
beforeEach(() => { | ||
// sfCommandStubs = stubSfCommandUx($$.SANDBOX); | ||
$$.SANDBOX.stub(OrgUtils, 'isLocalDevEnabled').resolves(true); | ||
$$.SANDBOX.stub(OrgUtils, 'ensureMatchingAPIVersion').returns(); | ||
}); | ||
|
||
afterEach(() => { | ||
$$.restore(); | ||
}); | ||
|
||
it('runs hello', async () => { | ||
// await LightningDevSite.run([]); | ||
// const output = sfCommandStubs.log | ||
// .getCalls() | ||
// .flatMap((c) => c.args) | ||
// .join('\n'); | ||
// expect(output).to.include('hello world'); | ||
it('should have summary, description, and examples defined', () => { | ||
strictEqual(typeof LightningDevSite.summary, 'string', 'Summary should be a string'); | ||
strictEqual(typeof LightningDevSite.description, 'string', 'Description should be a string'); | ||
strictEqual(typeof LightningDevSite.examples, 'object', 'Examples should be an array'); | ||
}); | ||
|
||
it('result should be undefined if local development is not enabled', async () => { | ||
$$.SANDBOX.restore(); | ||
$$.SANDBOX.stub(OrgUtils, 'isLocalDevEnabled').resolves(false); | ||
const result = await LightningDevSite.run(['--name', 'Astro', '--target-org', '00Dxx0000001gEH']); | ||
expect(result).to.be.undefined; | ||
}); | ||
|
||
it('runs hello world --name Astro', async () => { | ||
// await LightningDevSite.run(['--name', 'Astro']); | ||
// const output = sfCommandStubs.log | ||
// .getCalls() | ||
// .flatMap((c) => c.args) | ||
// .join('\n'); | ||
// expect(output).to.include('hello Astro'); | ||
it('should have valid startupParams', async () => { | ||
// eslint-disable-next-line @typescript-eslint/no-unsafe-argument, @typescript-eslint/no-explicit-any | ||
const org = new Org({ id: '00Dxx0000001gEH', connection: {} } as any); | ||
$$.SANDBOX.stub(Org, 'create').returns(Promise.resolve(org)); | ||
|
||
const startupParams: LocalDevOptions = { | ||
sfCLI: true, | ||
authToken: 'test-auth-token', | ||
open: true, | ||
port: 3000, | ||
logLevel: 'error', | ||
mode: 'dev', | ||
siteZip: 'test-site-zip', | ||
siteDir: 'test-site-dir', | ||
}; | ||
|
||
$$.SANDBOX.stub(LightningDevSite, 'run').resolves(Promise.resolve(startupParams)); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This test isn't testing anything. You are mocking the entire run method and having it always return startupParams. So you are just testing if(startupParams === startupParams). |
||
process.env.SETUP_ONLY = 'true'; | ||
|
||
const result = await LightningDevSite.run(['--name', 'Astro', '--target-org', '00Dxx0000001gEH']); | ||
delete process.env.SETUP_ONLY; | ||
|
||
expect(result).to.deep.equal(startupParams); | ||
}); | ||
}); |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We probably should do something similar to LWC here:

There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
if you look at the beforeEach method, they are mocking org data, auth, etc. Thats what you need to get the unit tests running: