Skip to content

Commit 441e1b7

Browse files
Malargalexeyinkin
authored andcommitted
disable examples check (apache#27126)
* disable examples check * Clean up (apache#27125) * Fix a Gradle task (apache#27125) * Fix a SCIO example descriptor (apache#27125) * Test local code instead of fetching from GitHub (apache#27125) * Fix tests (apache#27125) * Fix tests (apache#27125) * Update README (apache#27125) * Re-run tests (apache#27125) --------- Co-authored-by: Alexey Inkin <alexey.inkin@akvelon.com>
1 parent 458ed5d commit 441e1b7

16 files changed

+377
-97
lines changed

playground/frontend/README.md

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -178,6 +178,18 @@ flutter test
178178
./gradlew :playground:frontend:integrationTest -PdeviceId=web-server
179179
```
180180

181+
By default, tests do not expect specific code and output from most examples.
182+
This is because we get the expected example files from GitHub itself at runtime.
183+
Examples in the default GitHub branch may differ from the deployed ones,
184+
and this will break the tests.
185+
186+
To expect specific code and output, run tests like this using any repository owner/name
187+
and commit reference to load the examples from:
188+
189+
```bash
190+
./gradlew :playground:frontend:integrationTest -PexamplesRepository=apache/beam -PexamplesRef=master
191+
```
192+
181193
## Localization
182194

183195
The project is in the process of migrating from

playground/frontend/build.gradle

Lines changed: 20 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -263,20 +263,33 @@ tasks.register("integrationTest_standalone_share_code") {
263263

264264
void runIntegrationTest(String path, String url) {
265265
// Run with -PdeviceId=web-server for headless tests.
266+
// Run with -PexamplesRepository=apache/beam -PexamplesRef=master to verify that deployed examples match the given branch or commit.
266267
String deviceId = project.hasProperty("deviceId") ? project.deviceId : "chrome"
268+
String examplesRepository = project.hasProperty("examplesRepository") ? project.examplesRepository : null
269+
String examplesRef = project.hasProperty("examplesRef") ? project.examplesRef : null
270+
271+
List<String> flutterArgs = [
272+
"drive",
273+
"--driver=test_driver/integration_test.dart",
274+
"--target=integration_test/${path}_test.dart",
275+
"--web-launch-url='$url'",
276+
"--device-id=$deviceId",
277+
]
278+
279+
if (examplesRepository != null) {
280+
flutterArgs.add("--dart-define=examples-repository=$examplesRepository")
281+
}
282+
if (examplesRef != null) {
283+
flutterArgs.add("--dart-define=examples-ref=$examplesRef")
284+
}
267285

268286
exec {
269287
executable("flutter")
270-
args(
271-
"drive",
272-
"--driver=test_driver/integration_test.dart",
273-
"--target=integration_test/${path}_test.dart",
274-
"--web-launch-url='$url'",
275-
"--device-id=$deviceId",
276-
)
288+
args(flutterArgs)
277289
}
278290
}
279291

292+
280293
task copyDockerfileDependencies(type: Copy) {
281294
group = "build"
282295
description = "Copy files that required to build docker container"

playground/frontend/integration_test/initial_urls_test.dart

Lines changed: 48 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ void main() {
4949
await _testCatalogDefaultExampleLoader(wt);
5050
await _testContentExampleLoader(wt);
5151
await _testEmptyExampleLoader(wt);
52-
await _testHttpExampleLoader(wt);
52+
await _testHttpExampleLoaderIfDeployed(wt);
5353
await _testStandardExampleLoader(wt);
5454
await _testUserSharedExampleLoader(wt);
5555

@@ -76,7 +76,7 @@ final _croppedViewOptions = _mapToQueryString(_croppedViewOptionsMap);
7676
Future<void> _testEmbeddedRoot(WidgetTester wt) async {
7777
await wt.navigateAndSettle(_embeddedPath);
7878
expectSdk(Sdk.java, wt);
79-
expectVisibleText('', wt);
79+
expectVisibleTextIfDeployed('', wt);
8080
expectLastAnalyticsEvent(
8181
const LoadedAnalyticsEvent(
8282
sdk: Sdk.java,
@@ -90,7 +90,7 @@ Future<void> _testStandaloneRoot(WidgetTester wt) async {
9090
await wt.navigateAndSettle(_standalonePath);
9191

9292
expectSdk(Sdk.java, wt);
93-
expectVisibleText(visibleText, wt);
93+
expectVisibleTextIfDeployed(visibleText, wt);
9494
expectLastAnalyticsEvent(
9595
const LoadedAnalyticsEvent(
9696
sdk: Sdk.java,
@@ -102,7 +102,7 @@ Future<void> _testStandaloneRoot(WidgetTester wt) async {
102102
Future<void> _testEmbeddedSdkOnly(WidgetTester wt) async {
103103
await wt.navigateAndSettle('$_embeddedPath?sdk=go');
104104
expectSdk(Sdk.go, wt);
105-
expectVisibleText('', wt);
105+
expectVisibleTextIfDeployed('', wt);
106106
expectLastAnalyticsEvent(
107107
const LoadedAnalyticsEvent(
108108
sdk: Sdk.go,
@@ -116,7 +116,7 @@ Future<void> _testStandaloneSdkOnly(WidgetTester wt) async {
116116
await wt.navigateAndSettle('$_standalonePath?sdk=go');
117117

118118
expectSdk(Sdk.go, wt);
119-
expectVisibleText(visibleText, wt);
119+
expectVisibleTextIfDeployed(visibleText, wt);
120120
expectLastAnalyticsEvent(
121121
const LoadedAnalyticsEvent(
122122
sdk: Sdk.go,
@@ -130,7 +130,7 @@ Future<void> _testCatalogDefaultExampleLoader(WidgetTester wt) async {
130130
await wt.navigateAndSettle('$_standalonePath?sdk=go&default=true');
131131

132132
expectSdk(Sdk.go, wt);
133-
expectVisibleText(visibleText, wt);
133+
expectVisibleTextIfDeployed(visibleText, wt);
134134
expectLastAnalyticsEvent(
135135
const LoadedAnalyticsEvent(
136136
sdk: Sdk.go,
@@ -150,7 +150,7 @@ Future<void> _testContentExampleLoader(WidgetTester wt) async {
150150
'$path?sdk=go&files=${Uri.encodeComponent(files)}&$_fullViewOptions',
151151
);
152152
expectSdk(Sdk.go, wt);
153-
expectVisibleText(goExample.foldedVisibleText, wt);
153+
expectVisibleTextIfDeployed(goExample.foldedVisibleText, wt);
154154
expectLastAnalyticsEvent(
155155
const LoadedAnalyticsEvent(
156156
sdk: Sdk.go,
@@ -163,7 +163,7 @@ Future<void> _testContentExampleLoader(WidgetTester wt) async {
163163
'$path?sdk=go&files=${Uri.encodeComponent(files)}&$_croppedViewOptions',
164164
);
165165
expectSdk(Sdk.go, wt);
166-
expectVisibleText(goExample.croppedFoldedVisibleText, wt);
166+
expectVisibleTextIfDeployed(goExample.croppedFoldedVisibleText, wt);
167167
_expectReadOnly(wt);
168168
}
169169
}
@@ -172,7 +172,7 @@ Future<void> _testEmptyExampleLoader(WidgetTester wt) async {
172172
for (final path in _paths) {
173173
await wt.navigateAndSettle('$path?sdk=go&empty=true');
174174
expectSdk(Sdk.go, wt);
175-
expectVisibleText('', wt);
175+
expectVisibleTextIfDeployed('', wt);
176176
expectLastAnalyticsEvent(
177177
const LoadedAnalyticsEvent(
178178
sdk: Sdk.go,
@@ -182,13 +182,17 @@ Future<void> _testEmptyExampleLoader(WidgetTester wt) async {
182182
}
183183
}
184184

185-
Future<void> _testHttpExampleLoader(WidgetTester wt) async {
185+
Future<void> _testHttpExampleLoaderIfDeployed(WidgetTester wt) async {
186+
if (!areExamplesDeployed) {
187+
return;
188+
}
189+
186190
for (final path in _paths) {
187191
await wt.navigateAndSettle(
188192
'$path?sdk=go&url=${goExample.rawUrl}&$_fullViewOptions',
189193
);
190194
expectSdk(Sdk.go, wt);
191-
expectVisibleText(goExample.foldedVisibleText, wt);
195+
expectVisibleTextIfDeployed(goExample.foldedVisibleText, wt);
192196
expectLastAnalyticsEvent(
193197
LoadedAnalyticsEvent(
194198
sdk: Sdk.go,
@@ -201,7 +205,7 @@ Future<void> _testHttpExampleLoader(WidgetTester wt) async {
201205
'$path?sdk=go&url=${goExample.rawUrl}&$_croppedViewOptions',
202206
);
203207
expectSdk(Sdk.go, wt);
204-
expectVisibleText(goExample.croppedFoldedVisibleText, wt);
208+
expectVisibleTextIfDeployed(goExample.croppedFoldedVisibleText, wt);
205209
expectLastAnalyticsEvent(
206210
LoadedAnalyticsEvent(
207211
sdk: Sdk.go,
@@ -220,7 +224,7 @@ Future<void> _testStandardExampleLoader(WidgetTester wt) async {
220224
'$path?sdk=go&path=${goWordCount.dbPath}',
221225
);
222226
expectSdk(Sdk.go, wt);
223-
expectVisibleText(visibleText, wt);
227+
expectVisibleTextIfDeployed(visibleText, wt);
224228
expectLastAnalyticsEvent(
225229
LoadedAnalyticsEvent(
226230
sdk: Sdk.go,
@@ -234,22 +238,14 @@ Future<void> _testUserSharedExampleLoader(WidgetTester wt) async {
234238
final template = await goExample.getFullText();
235239
final tail = '\n//${DateTime.now().millisecondsSinceEpoch}';
236240
final content = '$template$tail';
237-
238-
final exampleCache = wt.findPlaygroundController().exampleCache;
239-
final snippetId = await exampleCache.saveSnippet(
240-
files: [SnippetFile(content: content, isMain: false, name: 'name')],
241-
sdk: Sdk.go,
242-
pipelineOptions: '--name=value',
243-
);
244-
245-
print('Created user-shared example ID: $snippetId');
241+
final snippetId = await _getSnippetId(wt, content, Sdk.go);
246242

247243
for (final path in _paths) {
248244
await wt.navigateAndSettle(
249245
'$path?sdk=go&shared=$snippetId&$_fullViewOptions',
250246
);
251247
expectSdk(Sdk.go, wt);
252-
expectVisibleText('${goExample.foldedVisibleText}$tail', wt);
248+
expectVisibleTextIfDeployed('${goExample.foldedVisibleText}$tail', wt);
253249
expectLastAnalyticsEvent(
254250
LoadedAnalyticsEvent(
255251
sdk: Sdk.go,
@@ -262,7 +258,7 @@ Future<void> _testUserSharedExampleLoader(WidgetTester wt) async {
262258
'$path?sdk=go&shared=$snippetId&$_croppedViewOptions',
263259
);
264260
expectSdk(Sdk.go, wt);
265-
expectVisibleText(goExample.croppedFoldedVisibleText, wt);
261+
expectVisibleTextIfDeployed(goExample.croppedFoldedVisibleText, wt);
266262
expectLastAnalyticsEvent(
267263
LoadedAnalyticsEvent(
268264
sdk: Sdk.go,
@@ -273,18 +269,38 @@ Future<void> _testUserSharedExampleLoader(WidgetTester wt) async {
273269
}
274270
}
275271

272+
Future<String> _getSnippetId(WidgetTester wt, String content, Sdk sdk) async {
273+
final exampleCache = wt.findPlaygroundController().exampleCache;
274+
final snippetId = await exampleCache.saveSnippet(
275+
files: [SnippetFile(content: content, isMain: false, name: 'name')],
276+
sdk: sdk,
277+
pipelineOptions: '--name=value',
278+
);
279+
280+
print('Created user-shared example ID: $snippetId');
281+
282+
return snippetId;
283+
}
284+
276285
Future<void> _testMultipleExamples(WidgetTester wt) async {
277-
final javaVisibleText = await javaAggregationMax.getVisibleText();
278-
final goVisibleText = goExample.foldedVisibleText;
286+
final javaTemplate = await javaExample.getFullText();
287+
final goTemplate= await goExample.getFullText();
288+
final tail = '\n//${DateTime.now().millisecondsSinceEpoch}';
289+
final javaSnippetId = await _getSnippetId(wt, '$javaTemplate$tail', Sdk.java);
290+
final goSnippetId = await _getSnippetId(wt, '$goTemplate$tail', Sdk.go);
291+
292+
final javaVisibleText = '${javaExample.foldedVisibleText}$tail';
293+
final goVisibleText = '${goExample.foldedVisibleText}$tail';
279294

280295
final examplesList = [
281296
{
282297
'sdk': Sdk.java.id,
283-
'path': javaAggregationMax.dbPath,
298+
'shared': javaSnippetId,
299+
..._fullViewOptionsMap,
284300
},
285301
{
286302
'sdk': Sdk.go.id,
287-
'url': goExample.rawUrl,
303+
'shared': goSnippetId,
288304
..._fullViewOptionsMap,
289305
},
290306
];
@@ -293,11 +309,11 @@ Future<void> _testMultipleExamples(WidgetTester wt) async {
293309
for (final path in _paths) {
294310
await wt.navigateAndSettle('$path?sdk=go&examples=$examples');
295311
expectSdk(Sdk.go, wt);
296-
expectVisibleText(goVisibleText, wt);
312+
expectVisibleText(goVisibleText, wt, reason: 'go, $path');
297313
expectLastAnalyticsEvent(
298314
LoadedAnalyticsEvent(
299315
sdk: Sdk.go,
300-
snippet: goExample.rawUrl,
316+
snippet: goSnippetId,
301317
),
302318
);
303319
await _expectEditableAndReadOnly(wt);
@@ -307,7 +323,8 @@ Future<void> _testMultipleExamples(WidgetTester wt) async {
307323
await wt.pumpAndSettle();
308324

309325
expectSdk(Sdk.java, wt);
310-
expectVisibleText(javaVisibleText, wt);
326+
expectVisibleText(javaVisibleText, wt, reason: 'java, $path');
327+
await _expectEditableAndReadOnly(wt);
311328
}
312329
}
313330

playground/frontend/integration_test/miscellaneous_ui/external_url_navigation.dart

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -90,6 +90,9 @@ Future<void> _checkMenuItems(WidgetTester wt) async {
9090
}
9191

9292
Future<void> _checkExampleDescription(WidgetTester wt) async {
93+
final url = wt.findPlaygroundController().selectedExample?.urlVcs;
94+
expect(url, isNotNull);
95+
9396
await _tapAndExpectNavigationEvent(
9497
wt,
9598
[
@@ -99,7 +102,7 @@ Future<void> _checkExampleDescription(WidgetTester wt) async {
99102
matching: find.byType(GithubButton),
100103
),
101104
],
102-
javaMinimalWordCount.url,
105+
url!,
103106
);
104107
}
105108

playground/frontend/integration_test/standalone_change_example_sdk_run_test.dart

Lines changed: 26 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -35,12 +35,17 @@ void main() {
3535
await wt.tapAndSettle(find.exampleSelector());
3636
await wt.tapAndSettle(find.exampleItemInDropdown(javaAggregationMax.name));
3737

38-
expect(
39-
wt.findOneCodeController().lastTextSpan!.toPlainText().isAsIfCutFrom(
40-
await javaAggregationMax.getVisibleText(),
41-
),
42-
true,
43-
);
38+
if (areExamplesDeployed) {
39+
final visibleText = await javaAggregationMax.getVisibleText();
40+
final lastSpanText =
41+
wt.findOneCodeController().lastTextSpan!.toPlainText();
42+
43+
expect(
44+
lastSpanText.isAsIfCutFrom(visibleText),
45+
true,
46+
reason: '$lastSpanText is not as if cut from $visibleText',
47+
);
48+
}
4449

4550
expectLastAnalyticsEvent(
4651
SnippetSelectedAnalyticsEvent(
@@ -65,18 +70,25 @@ public class MyClass {
6570

6671
await wt.tapAndSettle(find.runOrCancelButton());
6772

68-
expectOutputEquals('$_outputPrefix$text', wt);
73+
expectOutputEqualsIfDeployed('$_outputPrefix$text', wt);
6974
}
7075

7176
Future<void> switchToPython(WidgetTester wt) async {
7277
await wt.changeSdk(Sdk.python);
7378

74-
expect(
75-
wt.findOneCodeController().lastTextSpan!.toPlainText().isAsIfCutFrom(
76-
await pythonWordCountWithMetrics.getVisibleText(),
77-
),
78-
true,
79-
);
79+
if (areExamplesDeployed) {
80+
final visibleText = await pythonWordCountWithMetrics.getVisibleText();
81+
final lastSpanText = wt
82+
.findOneCodeController()
83+
.lastTextSpan!
84+
.toPlainText();
85+
86+
expect(
87+
lastSpanText.isAsIfCutFrom(visibleText),
88+
true,
89+
reason: '$lastSpanText is not as if cut from $visibleText',
90+
);
91+
}
8092

8193
expectLastAnalyticsEvent(const SdkSelectedAnalyticsEvent(sdk: Sdk.python));
8294
}
@@ -108,7 +120,7 @@ public class MyClass {
108120

109121
await wt.tapAndSettle(find.runOrCancelButton());
110122

111-
expectOutputEquals('$_outputPrefix$text', wt);
123+
expectOutputEqualsIfDeployed('$_outputPrefix$text', wt);
112124
}
113125

114126
testWidgets('Change example, change SDK, run', (WidgetTester wt) async {

playground/frontend/integration_test/standalone_default_examples_test.dart

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ Future<void> _expectExample(ExampleDescriptor example, WidgetTester wt) async {
5353
final visibleText = await example.getVisibleText();
5454

5555
expectSdk(example.sdk, wt);
56-
expectVisibleText(visibleText, wt);
56+
expectVisibleTextIfDeployed(visibleText, wt);
5757

5858
if (example.hasGraphTab) {
5959
expect(find.graphTab(), findsOneWidget);

0 commit comments

Comments
 (0)