devtools_shared: Use the file package for a file system abstraction for testing#9872
Open
srawlins wants to merge 4 commits into
Open
devtools_shared: Use the file package for a file system abstraction for testing#9872srawlins wants to merge 4 commits into
srawlins wants to merge 4 commits into
Conversation
Contributor
There was a problem hiding this comment.
Code Review
This pull request refactors LocalFileSystem and IOPersistentProperties in packages/devtools_shared to use package:file instead of dart:io, enabling file system mocking in tests. Feedback on the changes includes a recommendation to allow passing a custom FileSystem to DevToolsUsage to prevent real disk writes during tests, a suggestion to defensively check the decoded JSON type in devToolsFileAsJson to avoid runtime type errors, and a minor correction for a typo in the changelog.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Mainly, the
extension LocalFileSystem on Neveris ripped out for an extension on the 'file' package'sFileSystem. Production code can use a top-levelfileSystemconstant, which is the local file system. Test code can use aMemoryFileSystem. This avoids reading and writing files on devs' machines and CI machines. Better isolation. From the CHANGELOG:LocalFileSystem, an extension which provided some handyhelpers, has been refactored into an extension on the
filepackage'sFileSystemabstraction. In detail:fileSystemis a new top-level constant which represents the local (real)file system.
LocalFileSystem.devToolsDir()is now a static getter,FileSystemExtension.devToolsDir.LocalFileSystem.maybeMoveLegacyDevToolsStore()is now an instance method,FileSystemExtension.maybeMoveLegacyDevToolsStore().LocalFileSystem.devToolsStoreLocation()is now a static getter,FileSystemExtension.devToolsStoreLocation.LocalFileSystem.ensureDevToolsDirectory()is now private.LocalFileSystem.devToolsFileFromPath()is now an instance method,FileSystemExtension.devToolsFileFromPath().LocalFileSystem.devToolsFileAsJson()is now an instance method,FileSystemExtension.devToolsFileAsJson().LocalFileSystem.flutterStoreExists()is now an instance getter,FileSystemExtension.flutterStoreExists.IOPersistentProperties.newaccepts a new optionalFileSystem fsargument.
LocalFileSystemandIOPersistentPropertiesto usepackage:fileinstead of
dart:ioto allow mocking the file system.