Skip to content

Commit 288d44d

Browse files
committed
Modify currentDirectoryUri when currentDirectory is updated and fix up some tests
1 parent 8592053 commit 288d44d

File tree

4 files changed

+44
-27
lines changed

4 files changed

+44
-27
lines changed

dwds/lib/src/utilities/dart_uri.dart

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -161,15 +161,24 @@ class DartUri {
161161
/// Returns resolved path for a package, app, or dart uri.
162162
static String? toResolvedUri(String uri) => _uriToResolvedUri[uri];
163163

164+
static String _currentDirectory = p.current;
165+
164166
/// The directory in which we're running.
165167
///
166168
/// We store this here because for tests we may want to act as if we're
167169
/// running in the directory of a target package, even if the current
168170
/// directory of the tests is actually the main dwds directory.
169-
static String currentDirectory = p.current;
171+
static String get currentDirectory => _currentDirectory;
172+
173+
static set currentDirectory(String newDir) {
174+
_currentDirectory = newDir;
175+
_currentDirectoryUri = '${p.toUri(newDir)}';
176+
}
177+
178+
static String _currentDirectoryUri = '${p.toUri(currentDirectory)}';
170179

171180
/// The current directory as a file: Uri, saved here to avoid re-computing.
172-
static final String currentDirectoryUri = '${p.toUri(currentDirectory)}';
181+
static String get currentDirectoryUri => _currentDirectoryUri;
173182

174183
/// Record library and script uris to enable resolving library and script paths.
175184
static Future<void> initialize() async {

dwds/test/dart_uri_file_uri_test.dart

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -65,8 +65,8 @@ void main() {
6565
test('file path to org-dartlang-app', () {
6666
final webMain = Uri.file(
6767
p.join(
68-
// The directory for the _testPackage package (contained within
69-
// dwds), which imports _test.
68+
// The directory for the _testPackage package which imports
69+
// _test.
7070
testPackageProject.absolutePackageDirectory,
7171
'web',
7272
'main.dart',
@@ -91,7 +91,8 @@ void main() {
9191
test('file path to another package', () {
9292
final testLib = Uri.file(
9393
p.join(
94-
// The directory for the general _test package.
94+
// The directory for the general _test package. This is going to
95+
// be relative to the project in the `TestContext`.
9596
testPackageProject.absolutePackageDirectory,
9697
'..',
9798
testProject.packageDirectory,

dwds/test/fixtures/project.dart

Lines changed: 17 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -169,13 +169,14 @@ class TestProject {
169169
required this.htmlEntryFileName,
170170
});
171171

172-
static void _copyPackageAndPathDependenciesIntoTempDirectory(
172+
static Future<void> _copyPackageAndPathDependenciesIntoTempDirectory(
173173
Directory tempDirectory,
174-
String packageDirectory,
174+
String absolutePackageDirectory,
175175
Set<String> copiedPackageDirectories,
176-
) {
176+
) async {
177177
// There may be cycles in dependencies, so check that we already copied this
178178
// package.
179+
final packageDirectory = p.basename(absolutePackageDirectory);
179180
if (copiedPackageDirectories.contains(packageDirectory)) return;
180181
final currentPath = absolutePath(pathFromFixtures: packageDirectory);
181182
final newPath = p.join(tempDirectory.absolute.path, packageDirectory);
@@ -199,13 +200,22 @@ class TestProject {
199200
'${dependencyDirectory.path} is not an immediate directory in '
200201
'`fixtures`.',
201202
);
202-
_copyPackageAndPathDependenciesIntoTempDirectory(
203+
await _copyPackageAndPathDependenciesIntoTempDirectory(
203204
tempDirectory,
204-
p.basename(dependencyDirectory.path),
205+
dependencyDirectory.path,
205206
copiedPackageDirectories,
206207
);
207208
}
208209
}
210+
211+
// Clean up the project.
212+
// Called when we need to rebuild sdk and the app from previous test
213+
// configurations.
214+
await Process.run('dart', [
215+
'run',
216+
'build_runner',
217+
'clean',
218+
], workingDirectory: absolutePackageDirectory);
209219
}
210220

211221
Future<void> setUp() async {
@@ -219,20 +229,11 @@ class TestProject {
219229
Directory.systemTemp.resolveSymbolicLinksSync(),
220230
);
221231
_fixturesCopy = systemTempDir.createTempSync();
222-
_copyPackageAndPathDependenciesIntoTempDirectory(
232+
await _copyPackageAndPathDependenciesIntoTempDirectory(
223233
_fixturesCopy,
224-
packageDirectory,
234+
absolutePackageDirectory,
225235
{},
226236
);
227-
228-
// Clean up the project.
229-
// Called when we need to rebuild sdk and the app from previous test
230-
// configurations.
231-
await Process.run('dart', [
232-
'run',
233-
'build_runner',
234-
'clean',
235-
], workingDirectory: absolutePackageDirectory);
236237
}
237238

238239
/// Delete the copy of the project.

dwds/test/package_uri_mapper_test.dart

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -35,19 +35,23 @@ void main() {
3535

3636
final resolvedPath = '${project.packageDirectory}/lib/test_library.dart';
3737

38-
final testPackageSoundPath = project.absolutePackageDirectory;
39-
final packageConfigFile = Uri.file(
40-
p.join(testPackageSoundPath, '.dart_tool', 'package_config.json'),
41-
);
42-
4338
late final PackageUriMapper packageUriMapper;
4439
setUpAll(() async {
40+
await project.setUp();
4541
// Note: Run `dart pub upgrade` before the test cases to fix
4642
// https://github.com/dart-lang/webdev/issues/1834:
4743
await Process.run('dart', [
4844
'pub',
4945
'upgrade',
50-
], workingDirectory: testPackageSoundPath);
46+
], workingDirectory: project.absolutePackageDirectory);
47+
48+
final packageConfigFile = Uri.file(
49+
p.join(
50+
project.absolutePackageDirectory,
51+
'.dart_tool',
52+
'package_config.json',
53+
),
54+
);
5155

5256
packageUriMapper = await PackageUriMapper.create(
5357
fileSystem,
@@ -56,6 +60,8 @@ void main() {
5660
);
5761
});
5862

63+
tearDownAll(project.tearDown);
64+
5965
test('Can convert package urls to server paths', () {
6066
expect(packageUriMapper.packageUriToServerPath(packageUri), serverPath);
6167
});

0 commit comments

Comments
 (0)