Skip to content
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

feat: added UT for site #279

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open

feat: added UT for site #279

wants to merge 1 commit into from

Conversation

pulkit0555
Copy link
Contributor

What does this PR do?

Added UT for site

What issues does this PR fix or reference?

@W-15440486@

@pulkit0555 pulkit0555 self-assigned this Dec 2, 2024
@pulkit0555 pulkit0555 requested a review from a team as a code owner December 2, 2024 09:13
strictEqual(typeof LightningDevSite.examples, 'object', 'Examples should be an array');
});

it('result should be undefined if local development is not enabled', async () => {
Copy link
Collaborator

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:
image

Copy link
Collaborator

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:

beforeEach(async () => {
    stubUx($$.SANDBOX);
    stubSpinner($$.SANDBOX);
    await $$.stubAuths(testOrgData);

    $$.SANDBOX.stub(SfConfig, 'create').withArgs($$.SANDBOX.match.any).resolves(SfConfig.prototype);
    $$.SANDBOX.stub(SfConfig, 'addAllowedProperties').withArgs($$.SANDBOX.match.any);
    $$.SANDBOX.stub(SfConfig.prototype, 'get').returns(undefined);
    $$.SANDBOX.stub(SfConfig.prototype, 'set');
    $$.SANDBOX.stub(SfConfig.prototype, 'write').resolves();
    $$.SANDBOX.stub(Connection.prototype, 'getUsername').returns(testUsername);
    $$.SANDBOX.stub(PreviewUtils, 'getOrCreateAppServerIdentity').resolves(testIdentityData);
    $$.SANDBOX.stub(OrgUtils, 'isLocalDevEnabled').resolves(true);
    $$.SANDBOX.stub(OrgUtils, 'ensureMatchingAPIVersion').returns();

    MockedLightningPreviewApp = await esmock<typeof LightningDevApp>('../../../../src/commands/lightning/dev/app.js', {
      '../../../../src/lwc-dev-server/index.js': {
        startLWCServer: async () => ({ stopServer: () => {} }),
      },
    });
  });

siteDir: 'test-site-dir',
};

$$.SANDBOX.stub(LightningDevSite, 'run').resolves(Promise.resolve(startupParams));
Copy link
Collaborator

Choose a reason for hiding this comment

The 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).

@pulkit0555
Copy link
Contributor Author

These tests are written solely for the purpose of beginning with UT for the site and for proper testing need to have a mocked implementation of org data, auth, etc.
Since we are deliberating on the usage of CodeGenie for writing UT for complete repository, can we merge this meanwhile and start afresh when we have an answer on same?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants