|
| 1 | +// Copyright (c) 2024, the Dart project authors. Please see the AUTHORS file |
| 2 | +// for details. All rights reserved. Use of this source code is governed by a |
| 3 | +// BSD-style license that can be found in the LICENSE file. |
| 4 | + |
| 5 | +@Tags(['daily']) |
| 6 | +@TestOn('vm') |
| 7 | +@Timeout(Duration(minutes: 5)) |
| 8 | +import 'package:dwds/dwds.dart'; |
| 9 | +import 'package:test/test.dart'; |
| 10 | +import 'package:test_common/logging.dart'; |
| 11 | +import 'package:test_common/test_sdk_configuration.dart'; |
| 12 | +import 'package:test_common/utilities.dart'; |
| 13 | +import 'package:vm_service/vm_service.dart'; |
| 14 | + |
| 15 | +import 'fixtures/context.dart'; |
| 16 | +import 'fixtures/project.dart'; |
| 17 | +import 'fixtures/utilities.dart'; |
| 18 | + |
| 19 | +const originalString = 'variableToModifyToForceRecompile = 23'; |
| 20 | +const newString = 'variableToModifyToForceRecompile = 45'; |
| 21 | + |
| 22 | +const constantSuccessString = 'ConstantEqualitySuccess'; |
| 23 | +const constantFailureString = 'ConstantEqualityFailure'; |
| 24 | + |
| 25 | +void main() { |
| 26 | + // set to true for debug logging. |
| 27 | + final debug = false; |
| 28 | + |
| 29 | + final provider = TestSdkConfigurationProvider(verbose: debug); |
| 30 | + tearDownAll(provider.dispose); |
| 31 | + |
| 32 | + final testHotRestart2 = TestProject.testHotRestart2; |
| 33 | + final context = TestContext(testHotRestart2, provider); |
| 34 | + |
| 35 | + Future<void> makeEditAndWaitForRebuild() async { |
| 36 | + context.makeEditToDartLibFile( |
| 37 | + libFileName: 'library2.dart', |
| 38 | + toReplace: originalString, |
| 39 | + replaceWith: newString, |
| 40 | + ); |
| 41 | + await context.waitForSuccessfulBuild(propagateToBrowser: true); |
| 42 | + } |
| 43 | + |
| 44 | + void undoEdit() { |
| 45 | + context.makeEditToDartLibFile( |
| 46 | + libFileName: 'library2.dart', |
| 47 | + toReplace: newString, |
| 48 | + replaceWith: originalString, |
| 49 | + ); |
| 50 | + } |
| 51 | + |
| 52 | + group( |
| 53 | + 'Injected client', |
| 54 | + () { |
| 55 | + setUp(() async { |
| 56 | + setCurrentLogWriter(debug: debug); |
| 57 | + await context.setUp( |
| 58 | + testSettings: TestSettings( |
| 59 | + enableExpressionEvaluation: true, |
| 60 | + ), |
| 61 | + ); |
| 62 | + }); |
| 63 | + |
| 64 | + tearDown(() async { |
| 65 | + await context.tearDown(); |
| 66 | + undoEdit(); |
| 67 | + }); |
| 68 | + |
| 69 | + test( |
| 70 | + 'properly compares constants after hot restart via the service extension', |
| 71 | + () async { |
| 72 | + final client = context.debugConnection.vmService; |
| 73 | + await client.streamListen('Isolate'); |
| 74 | + |
| 75 | + var source = await context.webDriver.pageSource; |
| 76 | + expect( |
| 77 | + source, |
| 78 | + contains( |
| 79 | + 'ConstObject(reloadVariable: 23, ConstantEqualitySuccess)', |
| 80 | + ), |
| 81 | + ); |
| 82 | + |
| 83 | + await makeEditAndWaitForRebuild(); |
| 84 | + |
| 85 | + final eventsDone = expectLater( |
| 86 | + client.onIsolateEvent, |
| 87 | + emitsThrough( |
| 88 | + emitsInOrder([ |
| 89 | + _hasKind(EventKind.kIsolateExit), |
| 90 | + _hasKind(EventKind.kIsolateStart), |
| 91 | + _hasKind(EventKind.kIsolateRunnable), |
| 92 | + ]), |
| 93 | + ), |
| 94 | + ); |
| 95 | + |
| 96 | + expect( |
| 97 | + await client.callServiceExtension('hotRestart'), |
| 98 | + const TypeMatcher<Success>(), |
| 99 | + ); |
| 100 | + |
| 101 | + await eventsDone; |
| 102 | + |
| 103 | + source = await context.webDriver.pageSource; |
| 104 | + if (dartSdkIsAtLeast('3.4.0-61.0.dev')) { |
| 105 | + expect( |
| 106 | + source, |
| 107 | + contains( |
| 108 | + 'ConstObject(reloadVariable: 45, ConstantEqualitySuccess)', |
| 109 | + ), |
| 110 | + ); |
| 111 | + } |
| 112 | + }); |
| 113 | + }, |
| 114 | + timeout: Timeout.factor(2), |
| 115 | + ); |
| 116 | + |
| 117 | + group( |
| 118 | + 'Injected client with hot restart', |
| 119 | + () { |
| 120 | + group('and with debugging', () { |
| 121 | + setUp(() async { |
| 122 | + setCurrentLogWriter(debug: debug); |
| 123 | + await context.setUp( |
| 124 | + testSettings: TestSettings( |
| 125 | + reloadConfiguration: ReloadConfiguration.hotRestart, |
| 126 | + ), |
| 127 | + ); |
| 128 | + }); |
| 129 | + |
| 130 | + tearDown(() async { |
| 131 | + await context.tearDown(); |
| 132 | + undoEdit(); |
| 133 | + }); |
| 134 | + |
| 135 | + test('properly compares constants after hot restart', () async { |
| 136 | + var source = await context.webDriver.pageSource; |
| 137 | + expect( |
| 138 | + source, |
| 139 | + contains( |
| 140 | + 'ConstObject(reloadVariable: 23, ConstantEqualitySuccess)', |
| 141 | + ), |
| 142 | + ); |
| 143 | + |
| 144 | + await makeEditAndWaitForRebuild(); |
| 145 | + |
| 146 | + source = await context.webDriver.pageSource; |
| 147 | + if (dartSdkIsAtLeast('3.4.0-61.0.dev')) { |
| 148 | + expect( |
| 149 | + source, |
| 150 | + contains( |
| 151 | + 'ConstObject(reloadVariable: 45, ConstantEqualitySuccess)', |
| 152 | + ), |
| 153 | + ); |
| 154 | + } |
| 155 | + }); |
| 156 | + }); |
| 157 | + |
| 158 | + group('and without debugging', () { |
| 159 | + setUp(() async { |
| 160 | + setCurrentLogWriter(debug: debug); |
| 161 | + await context.setUp( |
| 162 | + testSettings: TestSettings( |
| 163 | + reloadConfiguration: ReloadConfiguration.hotRestart, |
| 164 | + ), |
| 165 | + debugSettings: |
| 166 | + TestDebugSettings.noDevTools().copyWith(enableDebugging: false), |
| 167 | + ); |
| 168 | + }); |
| 169 | + |
| 170 | + tearDown(() async { |
| 171 | + await context.tearDown(); |
| 172 | + undoEdit(); |
| 173 | + }); |
| 174 | + |
| 175 | + test('properly compares constants after hot restart', () async { |
| 176 | + var source = await context.webDriver.pageSource; |
| 177 | + expect( |
| 178 | + source, |
| 179 | + contains( |
| 180 | + 'ConstObject(reloadVariable: 23, ConstantEqualitySuccess)', |
| 181 | + ), |
| 182 | + ); |
| 183 | + |
| 184 | + await makeEditAndWaitForRebuild(); |
| 185 | + |
| 186 | + source = await context.webDriver.pageSource; |
| 187 | + if (dartSdkIsAtLeast('3.4.0-61.0.dev')) { |
| 188 | + expect( |
| 189 | + source, |
| 190 | + contains( |
| 191 | + 'ConstObject(reloadVariable: 45, ConstantEqualitySuccess)', |
| 192 | + ), |
| 193 | + ); |
| 194 | + } |
| 195 | + }); |
| 196 | + }); |
| 197 | + }, |
| 198 | + timeout: Timeout.factor(2), |
| 199 | + ); |
| 200 | +} |
| 201 | + |
| 202 | +TypeMatcher<Event> _hasKind(String kind) => |
| 203 | + isA<Event>().having((e) => e.kind, 'kind', kind); |
0 commit comments