Skip to content

Refactor TestContext constructor for clarity #1844

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

Merged
merged 32 commits into from
Jan 5, 2023

Conversation

elliette
Copy link
Contributor

@elliette elliette commented Dec 20, 2022

Work towards #1818:

  • "Make nullsafety mode a required option in test context set up"

And work towards #1845:

  • "Make it clearer what parameters should be passed to TestContext (eg, it is unclear the difference between path vs pathToServe). Also the default Dart entry file is in append_body, but the default HTML entry file is in hello_world."

Note: Core of the change is in context.dart and utilities.dart, all other changes are to test files to use the new TestContext constructors.

Refactors the TestContext constructor so that there are 2 named constructors:

  • TestContext.withSoundNullSafety()
  • TestContext.withWeakNullSafety()

Also changes the parameters to the TestContext constructors from:

  • String directory eg "../fixtures/_testPackageSound"
  • String pathToServe eg "web"
  • String entry eg "../fixtures/_testPackageSound/web"
  • String path eg "index.html"

to:

  • String packageName eg "_testPackageSound"
  • String webAssetsPath eg "web/hello_world"
  • String dartEntryFileName eg "main.dart"
  • String htmlEntryFileName eg "index.html"

This way all the parameters are self-consistent (no way to pass "../fixtures/_testPackageSound" and "../fixtures/_testPackage/web" for example).

Moves the fields being initialized in the constructor into getters.

Finally, makes the absolutePath function in utilities.dart more flexible by allowing clients to specify pathFromWebdev or pathFromFixtures along with pathFromDwds.

@elliette elliette changed the title [WIP] Refactor testcontext Refactor TestContext constructors for clarity Dec 20, 2022
@elliette elliette changed the title Refactor TestContext constructors for clarity Refactor TestContext constructor for clarity Dec 20, 2022
@elliette elliette marked this pull request as ready for review December 20, 2022 20:21
Copy link
Contributor

@annagrin annagrin left a comment

Choose a reason for hiding this comment

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

Thanks Elliott! Generally LGTM with some comments where I am not sure it will work on windows, but the tests would catch them I believe.

this.pathToServe = 'example',
TestContext.withSoundNullSafety({
String packageName = '_testSound',
String webAssetsPath = 'example/hello_world',
Copy link
Contributor

Choose a reason for hiding this comment

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

Is this only used in a uri? there are more places like this.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

It is only a web uri. I've added a helper webCompatiblePath for other places, though not here since this is a default param and therefore needs to be const.

/// The URI for the package_config.json is located in:
/// <project directory>/.dart_tool/package_config
Uri get _packageConfigFile =>
p.toUri(p.join(workingDirectory, '.dart_tool/package_config.json'));
Copy link
Contributor

Choose a reason for hiding this comment

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

should we use p.join(workingDirectory, '.dart_tool', 'package_config.json') so the separators are consistent?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Done!

@elliette elliette merged commit 36fa973 into dart-lang:master Jan 5, 2023
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