-
Notifications
You must be signed in to change notification settings - Fork 25
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: handle namespaces when running tests #126
Conversation
export class TestService { | ||
public readonly connection: Connection; | ||
|
||
constructor(connection: Connection) { | ||
this.connection = connection; | ||
} | ||
|
||
// utils to build test run payloads that may contain namespaces | ||
public async buildSyncPayload( |
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.
Moved this functionality over to the library- we'll need these utils for the plugin and in VS Code. Consumers can still build their own payloads when calling runTestsAsync/Sync
but these utils are helpful if there's a chance that namespace info may be present.
} as TestItem; | ||
} | ||
|
||
const namespaces = await this.queryNamespaces(); |
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.
Running the queries adds time to the operation so want to avoid querying unless absolutely necessary. Only query for namespaces if the test field is specified and it's a two part argument - myNamespace.myClass
or myClass.myTest
.
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.
This is going to be very inefficient because the query can potentially run on every item of the array. There's two ways in which I think we can address this.
The first, to split this into two different loops on the testNameArray. The first one to build the payload as complete as possible and split those items that might have a namespace into a separate structure. The second loop would consume the data structure generated for potential namespaces, run the namespace query once, continue processing the data structure and merge it with the one from the first loop.
The second, look at caching the results of queryNamespace during runtime so we only run the query once but we would still need to tweak when to run it.
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.
That's a good point, I'll change this so we only query for the namespaces once during a test run rather than for each test/class in the test run
detailed_code_cov_header: 'Apex Code Coverage for Test Run %s', | ||
syncClassErr: | ||
'Synchronous test runs can include test methods from only one Apex class. Omit the --synchronous flag or include tests from only one class' |
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.
When are keys underscore vs camelcase?
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.
hmmm good question, looking through right now and looks like we've got a bit of everything : - ) I'll update the ones in the library package for now
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.
Actually I'll open a follow up for everything, it's going to get messy in this PR
namespaces = await this.queryNamespaces(); | ||
} | ||
|
||
if (namespaces.has(testParts[0])) { |
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.
I think this will error out if we run a namespaced tests against an org that returns no namespaces.
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.
Nevermind it does work correctly. Can we add a test for that scenario ?
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.
Done - tests that the argument we build will treat the namespace as a classname & the class as a test method so eventually the test run would error out.
What does this PR do?
This PR adds support for namespaces when running tests - it addresses specifying a namespace ie. when working with a namespaced scratch org
What issues does this PR fix or reference?
@W-8725635@