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

update usage of '.sfdx' dir in isvdebugging #4521

Merged
merged 13 commits into from
Nov 4, 2022

Conversation

RitamAgrawal
Copy link
Member

What does this PR do?

This PR adds relativeToolsFolder function in projectPaths which updates the usage of string '.sfdx' and 'tools'

What issues does this PR fix or reference?

@W-11633488@

Functionality Before

.sfdx/tools dir was referenced as string

Functionality After

.sfdx/tools dir is referenced using dynamic functions from salesforcedx-utils-vscode

@RitamAgrawal RitamAgrawal requested a review from a team as a code owner October 28, 2022 16:50
'isvdebuggermdapitmp'
);
public readonly relativeApexPackageXmlPath = path.join(
this.relativeMetdataTempPath,
'package.xml'
);
public readonly relativeInstalledPackagesPath = path.join(
'.sfdx',
'tools',
projectPaths.relativeToolsFolder(),
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I realize adding a full blown jest unit test suite for this file is probably more lift then is worthwhile for the work being addressed, but you would add a test(s) to verify the relativeInstalledPackagesPath and relativeMetdataTempPath readonly values are set appropriately.

Copy link
Contributor

@gbockus-sf gbockus-sf left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

couple of testing suggestions 👍


it('should return a path to the relative tools folder', () => {
const relativeToolsFolder = projectPaths.relativeToolsFolder();
expect(relativeToolsFolder).toEqual(FAKE_TOOLS_FOLDER);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

So for this test you should be verifying that the value returned is the combo of the relative state folder and the tools constant. I'd probably be ok with something like

expect(relativeToolsFolder).toEqual(
        path.join(FAKE_STATE_FOLDER, TOOLS) // TOOLS exported from paths.ts
      );

But even better would be to mock the projectPaths.relativeStateFolder() response for this test and have something like

     relativeStateFolderMock.resolves(FAKE_STATE_FOLDER);
     const relativeToolsFolder = projectPaths.relativeToolsFolder();
      expect(relativeToolsFolder).toEqual(
        path.join(FAKE_STATE_FOLDER, TOOLS) // TOOLS exported from paths.ts
      );

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks like your test is failing with

    Expected: ".sfdx/tools"     Received: ".sfdx\\tools"```

another good reason to update to the above suggested method for the assertion.

@@ -13,6 +13,7 @@ jest.mock('@salesforce/core', () => {
describe('test project paths', () => {
const FAKE_WORKSPACE = '/here/is/a/fake/path/to/';
const FAKE_STATE_FOLDER = '.sfdx';
const FAKE_TOOLS_FOLDER = 'tools';
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@gbockus-sf Is this okay or Should I import the const TOOLS from projectPaths here?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Importing the tools constant from the single location would def be better

@@ -26,7 +26,6 @@ import {
} from '@salesforce/source-deploy-retrieve/lib/src/client/types';
import { join } from 'path';
import * as vscode from 'vscode';
import { BaseDeployExecutor } from '.';
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

So doing an import like this results in scanning all things exported from the index.ts file. Which can lead to complications in unit testing. Updated to pull directly from the file where exported instead.

@@ -23,7 +18,7 @@ import { SfdxPackageDirectories } from '../sfdxProject';
import { telemetryService } from '../telemetry';
import { workspaceUtils } from '../util';
import { DeployExecutor } from './baseDeployRetrieve';
import { FilePathGatherer, SfdxCommandlet, SfdxWorkspaceChecker } from './util';
import { ConflictDetectionMessages, FilePathGatherer, SfdxCommandlet, SfdxWorkspaceChecker } from './util';
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ran an organize imports. quite a few unused here.

* 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
*/

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

So for these two exports they were originally in postconditionCheckers.ts with a ton of other stuff. This lead to always importing this metadata caching checker that had a ton of dependancies and eventually had issues. Simplified by moving these out to their own files and re-exporting from there for index.ts.

import { channelService } from '../../channels';
import { notificationService, ProgressNotification } from '../../notifications';
import { sfdxCoreSettings } from '../../settings';
import { taskViewService } from '../../statuses';
import { telemetryService } from '../../telemetry';
import { workspaceUtils } from '../../util';
import { EmptyPostChecker } from './emptyPostChecker';
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

organize imports.

});

it('should be defined', () => {
isvDebugBootstrapExecutorInst = new IsvDebugBootstrapExecutor();
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

So this wasn't required, but when testing an instance of a class it's always good to create the instance for each test.

onDidChange: jest.fn(),
onDidCreate: jest.fn(),
onDidDelete: jest.fn()
}),
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

new vscode mock setup to get things working for core. Note that b/c the src/context/index.ts creates an instance of WorkspaceContext on initialization
export const workspaceContext = WorkspaceContext.getInstance();
We need to mock the file watcher results prior to loading any test dependancies.
This is an anti-pattern we should avoid for singletons.

@@ -26,7 +26,6 @@ import {
} from '@salesforce/source-deploy-retrieve/lib/src/client/types';
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Some touches to get jest unit tests working in core.

@@ -53,19 +54,21 @@ export interface InstalledPackageInfo {
versionNumber: string;
}

export const ISVDEBUGGER = 'isvdebuggermdapitmp';
export const INSTALLED_PACKAGES = 'installed-packages';
export const PACKAGE_XML = 'package.xml';
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

we should update the below paths to use these constants.

relativeStateFolder
relativeStateFolder,
relativeToolsFolder,
TOOLS
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: I'd just export the TOOLS constant on line 17 vs including constants and functions here.

Copy link
Contributor

@gbockus-sf gbockus-sf left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Couple of simple polish suggestions and you're good to go 👍

  • Verified unit test execution and pass in circle ✅
  • Verified unit test execution local ✅
  • Not sure how to execute the ISV debugger but verified as best I could ✅

@RitamAgrawal RitamAgrawal merged commit d575ba8 into develop Nov 4, 2022
@RitamAgrawal RitamAgrawal deleted the ra/update_usage_of_sfdx_dir_in_isvdebugging branch November 4, 2022 18:27
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