Skip to content

Commit 4c2fce8

Browse files
committed
Copy fixtures when edits are needed
1 parent fa4ca71 commit 4c2fce8

10 files changed

+127
-160
lines changed

dwds/pubspec.yaml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,7 @@ dev_dependencies:
5353
graphs: ^2.1.0
5454
frontend_server_common:
5555
path: ../frontend_server_common
56+
io: ^1.0.5
5657
js: '>=0.6.4 <0.8.0'
5758
pubspec_parse: ^1.2.0
5859
puppeteer: ^3.1.1

dwds/test/common/hot_restart_common.dart

Lines changed: 0 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -54,13 +54,6 @@ void runTests({
5454
await recompile(hasEdits: true);
5555
}
5656

57-
void undoEdit() {
58-
context.makeEditToDartEntryFile(
59-
toReplace: newString,
60-
replaceWith: originalString,
61-
);
62-
}
63-
6457
/// Wait for main to finish executing before checking expectations by checking
6558
/// for a log output.
6659
///
@@ -98,7 +91,6 @@ void runTests({
9891
});
9992

10093
tearDown(() async {
101-
undoEdit();
10294
await context.tearDown();
10395
});
10496

@@ -131,7 +123,6 @@ void runTests({
131123
});
132124

133125
tearDown(() async {
134-
undoEdit();
135126
await context.tearDown();
136127
});
137128

@@ -166,7 +157,6 @@ void runTests({
166157

167158
tearDown(() async {
168159
await context.tearDown();
169-
undoEdit();
170160
});
171161

172162
test('can live reload changes ', () async {
@@ -204,7 +194,6 @@ void runTests({
204194

205195
tearDown(() async {
206196
await context.tearDown();
207-
undoEdit();
208197
});
209198

210199
test('destroys and recreates the isolate during a hot restart', () async {
@@ -501,7 +490,6 @@ void runTests({
501490

502491
tearDown(() async {
503492
await context.tearDown();
504-
undoEdit();
505493
});
506494

507495
test('can hot restart changes ', () async {
@@ -562,7 +550,6 @@ void runTests({
562550

563551
tearDown(() async {
564552
await context.tearDown();
565-
undoEdit();
566553
});
567554

568555
test('can hot restart changes ', () async {
@@ -609,7 +596,6 @@ void runTests({
609596

610597
tearDown(() async {
611598
await context.tearDown();
612-
undoEdit();
613599
});
614600

615601
test(

dwds/test/common/hot_restart_correctness_common.dart

Lines changed: 0 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -51,14 +51,6 @@ void runTests({
5151
}
5252
}
5353

54-
void undoEdit() {
55-
context.makeEditToDartLibFile(
56-
libFileName: 'library2.dart',
57-
toReplace: newString,
58-
replaceWith: originalString,
59-
);
60-
}
61-
6254
group('Injected client', () {
6355
VmService? fakeClient;
6456

@@ -78,7 +70,6 @@ void runTests({
7870

7971
tearDown(() async {
8072
await context.tearDown();
81-
undoEdit();
8273
});
8374

8475
test(
@@ -145,7 +136,6 @@ void runTests({
145136

146137
tearDown(() async {
147138
await context.tearDown();
148-
undoEdit();
149139
});
150140

151141
test('properly compares constants after hot restart', () async {
@@ -189,7 +179,6 @@ void runTests({
189179

190180
tearDown(() async {
191181
await context.tearDown();
192-
undoEdit();
193182
});
194183

195184
test('properly compares constants after hot restart', () async {

dwds/test/devtools_test.dart

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -132,11 +132,6 @@ void main() {
132132
await context.webDriver.driver.refresh();
133133

134134
await eventsDone;
135-
// Re-set the edited file:
136-
context.makeEditToDartEntryFile(
137-
toReplace: 'Bonjour le monde!',
138-
replaceWith: 'Hello World!',
139-
);
140135
},
141136
skip: 'https://github.com/dart-lang/webdev/issues/1888',
142137
);

dwds/test/fixtures/context.dart

Lines changed: 22 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -129,18 +129,7 @@ class TestContext {
129129
/// External VM service.
130130
VmService get vmService => debugConnection.vmService;
131131

132-
TestContext(this.project, this.sdkConfigurationProvider) {
133-
DartUri.currentDirectory = project.absolutePackageDirectory;
134-
135-
project.validate();
136-
137-
_logger.info(
138-
'Serving: ${project.directoryToServe}/${project.filePathToServe}',
139-
);
140-
_logger.info('Project: ${project.absolutePackageDirectory}');
141-
_logger.info('Packages: ${project.packageConfigFile}');
142-
_logger.info('Entry: ${project.dartEntryFilePath}');
143-
}
132+
TestContext(this.project, this.sdkConfigurationProvider);
144133

145134
Future<void> setUp({
146135
TestSettings testSettings = const TestSettings(),
@@ -160,10 +149,17 @@ class TestContext {
160149
final sdkLayout = sdkConfigurationProvider.sdkLayout;
161150
final configuration = await sdkConfigurationProvider.configuration;
162151
configuration.validate();
163-
await project.cleanUp();
152+
await project.setUp();
164153

165154
DartUri.currentDirectory = project.absolutePackageDirectory;
166155

156+
_logger.info(
157+
'Serving: ${project.directoryToServe}/${project.filePathToServe}',
158+
);
159+
_logger.info('Project: ${project.absolutePackageDirectory}');
160+
_logger.info('Packages: ${project.packageConfigFile}');
161+
_logger.info('Entry: ${project.dartEntryFilePath}');
162+
167163
configureLogWriter();
168164

169165
_client = IOClient(
@@ -552,6 +548,7 @@ class TestContext {
552548
_client?.close();
553549
await _outputDir?.delete(recursive: true);
554550
stopLogWriter();
551+
project.tearDown();
555552

556553
// clear the state for next setup
557554
_webDriver = null;
@@ -568,6 +565,10 @@ class TestContext {
568565
required String toReplace,
569566
required String replaceWith,
570567
}) {
568+
assert(
569+
project.editable,
570+
'Project ${project.packageName} is not marked as editable',
571+
);
571572
final file = File(project.dartEntryFilePath);
572573
final fileContents = file.readAsStringSync();
573574
file.writeAsStringSync(fileContents.replaceAll(toReplace, replaceWith));
@@ -578,23 +579,26 @@ class TestContext {
578579
required String toReplace,
579580
required String replaceWith,
580581
}) {
582+
assert(
583+
project.editable,
584+
'Project ${project.packageName} is not marked as editable',
585+
);
581586
final file = File(project.dartLibFilePath(libFileName));
582587
final fileContents = file.readAsStringSync();
583588
file.writeAsStringSync(fileContents.replaceAll(toReplace, replaceWith));
584589
}
585590

586591
void addLibraryFile({required String libFileName, required String contents}) {
592+
assert(
593+
project.editable,
594+
'Project ${project.packageName} is not marked as editable',
595+
);
587596
final file = File(project.dartLibFilePath(libFileName));
588597
// Library folder may not exist yet, so create it.
589598
file.createSync(recursive: true);
590599
file.writeAsStringSync(contents);
591600
}
592601

593-
void removeLibraryFile({required String libFileName}) {
594-
final file = File(project.dartLibFilePath(libFileName));
595-
file.deleteSync();
596-
}
597-
598602
Future<void> recompile({required bool fullRestart}) async {
599603
await webRunner.run(
600604
frontendServerFileSystem,

0 commit comments

Comments
 (0)