Skip to content

Commit 36fa973

Browse files
authored
Refactor TestContext constructor for clarity (#1844)
1 parent 57776a0 commit 36fa973

34 files changed

+257
-223
lines changed

dwds/test/build_daemon_breakpoint_test.dart

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -8,18 +8,18 @@ import 'dart:async';
88

99
import 'package:dwds/src/connections/debug_connection.dart';
1010
import 'package:dwds/src/services/chrome_proxy_service.dart';
11-
import 'package:path/path.dart' as p;
1211
import 'package:test/test.dart';
1312
import 'package:vm_service/vm_service.dart';
1413
import 'package:webkit_inspection_protocol/webkit_inspection_protocol.dart';
1514

1615
import 'fixtures/context.dart';
1716

18-
final context = TestContext(
19-
directory: p.join('..', 'fixtures', '_testPackageSound'),
20-
entry: p.join('..', 'fixtures', '_testPackageSound', 'web', 'main.dart'),
21-
path: 'index.html',
22-
pathToServe: 'web');
17+
final context = TestContext.withSoundNullSafety(
18+
packageName: '_testPackageSound',
19+
webAssetsPath: 'web',
20+
dartEntryFileName: 'main.dart',
21+
htmlEntryFileName: 'index.html',
22+
);
2323

2424
ChromeProxyService get service =>
2525
fetchChromeProxyService(context.debugConnection);

dwds/test/build_daemon_callstack_test.dart

Lines changed: 10 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,6 @@ import 'dart:async';
88

99
import 'package:dwds/src/connections/debug_connection.dart';
1010
import 'package:dwds/src/services/chrome_proxy_service.dart';
11-
import 'package:path/path.dart' as p;
1211
import 'package:test/test.dart';
1312
import 'package:vm_service/vm_service.dart';
1413
import 'package:webkit_inspection_protocol/webkit_inspection_protocol.dart';
@@ -18,20 +17,18 @@ import 'fixtures/logging.dart';
1817
import 'utils/version_compatibility.dart';
1918

2019
class TestSetup {
21-
static final contextUnsound = TestContext(
22-
directory: p.join('..', 'fixtures', '_testPackage'),
23-
entry: p.join('..', 'fixtures', '_testPackage', 'web', 'main.dart'),
24-
path: 'index.html',
25-
pathToServe: 'web',
26-
nullSafety: NullSafety.weak,
20+
static final contextUnsound = TestContext.withWeakNullSafety(
21+
packageName: '_testPackage',
22+
webAssetsPath: 'web',
23+
dartEntryFileName: 'main.dart',
24+
htmlEntryFileName: 'index.html',
2725
);
2826

29-
static final contextSound = TestContext(
30-
directory: p.join('..', 'fixtures', '_testPackageSound'),
31-
entry: p.join('..', 'fixtures', '_testPackageSound', 'web', 'main.dart'),
32-
path: 'index.html',
33-
pathToServe: 'web',
34-
nullSafety: NullSafety.sound,
27+
static final contextSound = TestContext.withSoundNullSafety(
28+
packageName: '_testPackageSound',
29+
webAssetsPath: 'web',
30+
dartEntryFileName: 'main.dart',
31+
htmlEntryFileName: 'index.html',
3532
);
3633

3734
TestContext context;

dwds/test/chrome_proxy_service_test.dart

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ import 'package:webkit_inspection_protocol/webkit_inspection_protocol.dart';
2121
import 'fixtures/context.dart';
2222
import 'fixtures/logging.dart';
2323

24-
final context = TestContext();
24+
final context = TestContext.withSoundNullSafety();
2525

2626
ChromeProxyService get service =>
2727
fetchChromeProxyService(context.debugConnection);

dwds/test/dart_uri_file_uri_test.dart

Lines changed: 7 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -13,21 +13,19 @@ import 'fixtures/context.dart';
1313
import 'fixtures/utilities.dart';
1414
import 'utils/version_compatibility.dart';
1515

16-
final context = TestContext(
17-
directory: p.join('..', 'fixtures', '_testPackage'),
18-
entry: p.join('..', 'fixtures', '_testPackage', 'web', 'main.dart'),
19-
path: 'index.html',
20-
pathToServe: 'web',
21-
nullSafety: NullSafety.weak,
16+
final context = TestContext.withWeakNullSafety(
17+
packageName: '_testPackage',
18+
webAssetsPath: 'web',
19+
dartEntryFileName: 'main.dart',
20+
htmlEntryFileName: 'index.html',
2221
);
2322

2423
/// The directory for the general _test package.
25-
final testDir = absolutePath(pathFromDwds: p.join('..', 'fixtures', '_test'));
24+
final testDir = absolutePath(pathFromFixtures: p.join('_test'));
2625

2726
/// The directory for the _testPackage package (contained within dwds), which
2827
/// imports _test.
29-
final testPackageDir =
30-
absolutePath(pathFromDwds: p.join('..', 'fixtures', '_testPackage'));
28+
final testPackageDir = absolutePath(pathFromFixtures: p.join('_testPackage'));
3129

3230
// This tests converting file Uris into our internal paths.
3331
//

dwds/test/debug_extension_test.dart

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ import 'fixtures/utilities.dart';
2929
// Remove the key before pushing code to GitHub.
3030
// See go/extension-identification.
3131

32-
final context = TestContext();
32+
final context = TestContext.withSoundNullSafety();
3333

3434
void main() async {
3535
Future<void> waitForDartDevToolsWithRetry({
@@ -203,7 +203,7 @@ void main() async {
203203
}
204204

205205
group('With encoding', () {
206-
final context = TestContext();
206+
final context = TestContext.withSoundNullSafety();
207207
setUp(() async {
208208
await context.setUp(
209209
enableDebugExtension: true,
@@ -224,7 +224,7 @@ void main() async {
224224
});
225225

226226
group('With "any" hostname', () {
227-
final context = TestContext();
227+
final context = TestContext.withSoundNullSafety();
228228
final uriPattern = RegExp(r'dartExtensionUri = "([^"]+)";');
229229

230230
setUp(() async {

dwds/test/debug_service_test.dart

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ import 'package:test/test.dart';
1212

1313
import 'fixtures/context.dart';
1414

15-
final context = TestContext();
15+
final context = TestContext.withSoundNullSafety();
1616

1717
void main() {
1818
setUpAll(() async {

dwds/test/debugger_test.dart

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ import 'fixtures/context.dart';
2222
import 'fixtures/debugger_data.dart';
2323
import 'fixtures/fakes.dart';
2424

25-
final context = TestContext();
25+
final context = TestContext.withSoundNullSafety();
2626
late AppInspector inspector;
2727
late Debugger debugger;
2828
late FakeWebkitDebugger webkitDebugger;

dwds/test/devtools_test.dart

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -13,9 +13,7 @@ import 'package:webdriver/io.dart';
1313

1414
import 'fixtures/context.dart';
1515

16-
final context = TestContext(
17-
path: 'append_body/index.html',
18-
);
16+
final context = TestContext.withSoundNullSafety();
1917

2018
Future<void> _waitForPageReady(TestContext context) async {
2119
var attempt = 100;

dwds/test/evaluate_circular_common.dart

Lines changed: 12 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,6 @@ import 'dart:async';
88

99
import 'package:dwds/src/connections/debug_connection.dart';
1010
import 'package:dwds/src/services/chrome_proxy_service.dart';
11-
import 'package:path/path.dart' as p;
1211
import 'package:test/test.dart';
1312
import 'package:vm_service/vm_service.dart';
1413
import 'package:webkit_inspection_protocol/webkit_inspection_protocol.dart';
@@ -17,21 +16,21 @@ import 'fixtures/context.dart';
1716
import 'fixtures/logging.dart';
1817

1918
class TestSetup {
20-
static TestContext createContext(
21-
String index, String packageRoot, NullSafety nullSafety) =>
22-
TestContext(
23-
directory: p.join('..', 'fixtures', packageRoot),
24-
entry: p.join('..', 'fixtures', packageRoot, 'web', 'main.dart'),
25-
path: index,
26-
pathToServe: 'web',
27-
nullSafety: nullSafety,
28-
);
29-
3019
static TestContext contextUnsound(String index) =>
31-
createContext(index, '_testCircular2', NullSafety.weak);
20+
TestContext.withWeakNullSafety(
21+
packageName: '_testCircular2',
22+
webAssetsPath: 'web',
23+
dartEntryFileName: 'main.dart',
24+
htmlEntryFileName: index,
25+
);
3226

3327
static TestContext contextSound(String index) =>
34-
createContext(index, '_testCircular2Sound', NullSafety.sound);
28+
TestContext.withSoundNullSafety(
29+
packageName: '_testCircular2Sound',
30+
webAssetsPath: 'web',
31+
dartEntryFileName: 'main.dart',
32+
htmlEntryFileName: index,
33+
);
3534

3635
TestContext context;
3736

dwds/test/evaluate_common.dart

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,6 @@ import 'dart:async';
88

99
import 'package:dwds/src/connections/debug_connection.dart';
1010
import 'package:dwds/src/services/chrome_proxy_service.dart';
11-
import 'package:path/path.dart' as p;
1211
import 'package:test/test.dart';
1312
import 'package:vm_service/vm_service.dart';
1413
import 'package:webkit_inspection_protocol/webkit_inspection_protocol.dart';
@@ -17,20 +16,21 @@ import 'fixtures/context.dart';
1716
import 'fixtures/logging.dart';
1817

1918
class TestSetup {
20-
static TestContext createContext(
21-
String index, String packageRoot, NullSafety nullSafety) =>
22-
TestContext(
23-
directory: p.join('..', 'fixtures', packageRoot),
24-
entry: p.join('..', 'fixtures', packageRoot, 'web', 'main.dart'),
25-
path: index,
26-
pathToServe: 'web',
27-
nullSafety: nullSafety);
28-
2919
static TestContext contextUnsound(String index) =>
30-
createContext(index, '_testPackage', NullSafety.weak);
20+
TestContext.withWeakNullSafety(
21+
packageName: '_testPackage',
22+
webAssetsPath: 'web',
23+
dartEntryFileName: 'main.dart',
24+
htmlEntryFileName: index,
25+
);
3126

3227
static TestContext contextSound(String index) =>
33-
createContext(index, '_testPackageSound', NullSafety.sound);
28+
TestContext.withSoundNullSafety(
29+
packageName: '_testPackageSound',
30+
webAssetsPath: 'web',
31+
dartEntryFileName: 'main.dart',
32+
htmlEntryFileName: index,
33+
);
3434

3535
TestContext context;
3636

0 commit comments

Comments
 (0)