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

FEDX-522 Add APIs to help test suggestors with resolved AST #74

Merged

Conversation

evanweible-wf
Copy link
Contributor

Motivation

AstVisitingSuggestor makes it easy to write suggestors that resolve the AST by overriding shouldResolveAst(), but we don't make it very easy to test those suggestors, especially on files that have imports.

Changes

Add PackageContextForTest to help with this use case. See readme for details.

@aviary-wf
Copy link

Security Insights

No security relevant content was detected by automated scans.

Action Items

  • Review PR for security impact; comment "security review required" if needed or unsure
  • Verify aviary.yaml coverage of security relevant code

Questions or Comments? Reach out on Slack: #support-infosec.

robbecker-wf
robbecker-wf previously approved these changes Nov 10, 2023
Copy link
Member

@robbecker-wf robbecker-wf left a comment

Choose a reason for hiding this comment

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

This will be very helpful!

Copy link
Contributor

@greglittlefield-wf greglittlefield-wf left a comment

Choose a reason for hiding this comment

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

Changes look good to me! Just a couple comments / optional suggestions

.toList()
.then((patches) => applyPatches(context.sourceFile, patches)),
completion(resultMatcher));
class PackageContextForTest {
Copy link
Contributor

Choose a reason for hiding this comment

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

This looks like a slimmed down version of a similar utility in over_react_codemod; I like it! https://github.com/Workiva/over_react_codemod/blob/bb73b48f65e0e4fa4ee53f21549a74f0f45351c7/test/resolved_file_context.dart#L46

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I knew I should have looked harder in that package 😆

lib/test.dart Outdated
/// that require the resolved AST.
///
/// See [PackageContextForTest] for an example.
Future<FileContext> addFile(String path, String sourceText) async {
Copy link
Contributor

Choose a reason for hiding this comment

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

In over_react_codemod, we ended up having to share contexts across tests, since it would take too long to spin up a new analysis context for each test.

With that setup, it's a bit annoying to have to come up with unique file names for each test case, so being able to auto-generate them is nice (and what we ended up doing in over_react_codemod).

Copy link
Contributor Author

@evanweible-wf evanweible-wf Nov 10, 2023

Choose a reason for hiding this comment

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

Yeah I was wondering about that.. I was about to type something out about how it's unfortunate that the test_descriptor package uses addTearDown by default since that effectively scopes everything it creates to a single test, but then I found this issue in that repo for that exact case:
https://github.com/dart-lang/test_descriptor/issues/11

And it turns out they solved it by updating how addTearDown from the test package works so that it knows when is called from setUpAll, which is awesome! TIL! So that means consumers could create a PackageContextForTest in a setUpAll to share it across tests without any other changes here. With that in mind, I agree, auto-generating a file name would be convenient. I had wondered about auto-generating a name for the directory as well, so I think I'll do that, too.

Copy link
Contributor

Choose a reason for hiding this comment

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

Awesome, thanks for adding that!

Oh nice, I was wondering how if the sharing might not be possible test_descriptor; glad that works with setUpAll!

@robbecker-wf robbecker-wf changed the title Add APIs to help test suggestors with resolved AST FEDX-522 Add APIs to help test suggestors with resolved AST Nov 13, 2023
@evanweible-wf
Copy link
Contributor Author

@evanweible-wf
Copy link
Contributor Author

@Workiva/release-management-p

Copy link

@rmconsole-wf rmconsole-wf left a comment

Choose a reason for hiding this comment

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

+1 from RM

@rmconsole4-wk rmconsole4-wk merged commit eef2fd0 into master Nov 20, 2023
3 checks passed
@rmconsole4-wk rmconsole4-wk deleted the add-test-apis-for-testing-resolved-ast-suggestors branch November 20, 2023 17:34
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.

7 participants