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

#73: Inject namespace using string replacements. #78

Open
wants to merge 31 commits into
base: main
Choose a base branch
from

Conversation

zenibako
Copy link
Contributor

Avoid code duplication of ApexMockeryOverview and StubBuilderImpl by using Salesforce CLI's string replacement functionality to replace namespace. with the value of the SF_NAMESPACE_DOT environment variable.

Description

I replaced mockery. with namespace. where it was hard-coded into Apex, and added the string replacements to the sfdx-project.json config file. This format for the replacement string should be more friendly to linters than alternatives like %%%NAMESPACE_DOT%%% (which is what CumulusCI uses).

Because I set the allowUnsetEnvVariable property to true, namespace. will be cleared if the SF_NAMESPACE_DOT environment variable isn't set, which allows the variable to effectively act as a toggle for namespace/non-namespace testing. This should enable a less-invasive developer experience overall while still allowing for namespace testing.

Motivation and Context

#73

How Has This Been Tested?

I had some issues actually testing this in a namespace (scratch org wasn't able to be created even after adding my own namespace to the config). Apologies for not testing this in more depth prior to committing...perhaps it's fine since it will need the main repo's secrets to properly test packaging anyways. Please feel free to push back or suggest fixes; I might try again later.

I was able to text the conversion process itself by following the Test String Replacements process specified in the docs, which verified that the string replacements themselves are successful.

zenibako and others added 30 commits May 13, 2024 18:00
{
"glob": "force-app/recipes/**/*.cls",
"stringToReplace": "namespace.",
"replaceWithEnv": "SF_NAMESPACE_DOT",
Copy link
Contributor

Choose a reason for hiding this comment

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

question: SF_NAMESPACE_DOT should be used then in the github actions right ?

We should remove then this githubaction
And only use this one:

  • It should take a parameter a boolean "namespace". When namespace is true it should set the SF_NAMESPACE_DOT with the value mockery., else it should set it with empty string
  • this github action should be modified to call the only one action twice with the "namespace" boolean true for validate-namespace-compatibility step and false for validate-package-version

Something like that ?

Copy link
Contributor Author

@zenibako zenibako Dec 12, 2024

Choose a reason for hiding this comment

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

That's exactly it. It should also give people the opportunity to use their own namespace if they want to fork the package (since tests in their repository will fail if it is locked to mockery).

Copy link
Contributor

Choose a reason for hiding this comment

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

I'll try to contribute here soon (don't know when yet) !

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

Successfully merging this pull request may close these issues.

3 participants