Skip to content

Commit 751f6d3

Browse files
committed
Add integration tests
Add a test that will export and build using our various flags and check if the command is behaving as expected on all the platforms we support.
1 parent bad3343 commit 751f6d3

File tree

3 files changed

+249
-4
lines changed

3 files changed

+249
-4
lines changed

.github/workflows/main.yml

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,8 @@ on: push
33

44
env:
55
# Keep this in sync with the version used by FlutterFlow.
6-
DART_VERSION: 3.4.3
6+
DART_VERSION: 3.5.2
7+
FLUTTER_VERSION: 3.24.2
78

89
jobs:
910
check:
@@ -44,10 +45,12 @@ jobs:
4445
- name: Clone repository
4546
uses: actions/checkout@v4
4647

47-
- name: Setup Dart
48-
uses: dart-lang/setup-dart@v1
48+
- name: Setup Flutter
49+
uses: subosito/flutter-action@44ac965b96f18d999802d4b807e3256d5a3f9fa1 # v2
4950
with:
50-
sdk: ${{ env.DART_VERSION }}
51+
channel: master
52+
flutter-version: ${{ env.FLUTTER_VERSION }}
53+
cache: true
5154

5255
- name: Install dependencies
5356
run: |
@@ -62,5 +65,7 @@ jobs:
6265
dart run bin/flutterflow_cli.dart -h
6366
6467
- name: Test
68+
env:
69+
FF_TESTER_TOKEN: ${{ secrets.FF_TESTER_TOKEN }}
6570
run: |
6671
dart test

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,3 @@
11
bin/flutterflow
22
.dart_tool/
3+
export/

test/integration_test.dart

Lines changed: 239 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,239 @@
1+
import 'package:flutterflow_cli/src/flutterflow_main.dart';
2+
3+
// See: https://pub.dev/packages/test#timeouts
4+
// ignore: invalid_annotation_target
5+
@Timeout(Duration(seconds: 360))
6+
import 'package:test/test.dart';
7+
import 'package:path/path.dart' as p;
8+
9+
import 'dart:io';
10+
11+
String kProjectId = 'app-with-assets-and-custom-fonts-qxwg6o';
12+
String kToken = Platform.environment['FF_TESTER_TOKEN'] ?? 'not-set';
13+
14+
bool buildProject(String project) {
15+
var result = Process.runSync('flutter', ['build', 'web'],
16+
workingDirectory: p.normalize(project), runInShell: true);
17+
18+
return result.exitCode == 0;
19+
}
20+
21+
bool checkAssets(String project) {
22+
var assets = [
23+
'assets/images/6740bca9ed26c9a34b1ab1ce.png',
24+
'assets/images/6785366c3e83b0072fdc8ef4.png',
25+
'assets/images/6740b4b5cf7b4fdf95795e2c.png',
26+
'assets/images/6740af8ffbd4c3414fcf5728.png',
27+
'assets/images/6740aff03c7e45b220ed9775.png',
28+
'assets/images/6740b3cca8e014dee9325b5d.png',
29+
'assets/images/6740b4b5c0adf773476a5452.png',
30+
'assets/images/67895d616be6f220ee4ec9c3.png',
31+
'assets/images/6740b4b494d7239248fa491e.png',
32+
'assets/images/67895d6177fc072b5e166fd1.png',
33+
'assets/images/6740ae761553efad6aa2a5d4.png',
34+
'assets/images/6740bca9c28f22a68495d368.png',
35+
'assets/images/6744ab4d50d5a3dad758fa39.png',
36+
'assets/images/6785366c77c17f02779e160c.png',
37+
'assets/images/6740aff0d10e0295e5fe33e6.png',
38+
'assets/images/6785366c215b774f00c041a3.png',
39+
'assets/images/67895d61a7af8d11cb9aa957.png',
40+
'assets/images/6740ae76c0adf77347645294.png',
41+
'assets/images/6740b3cc6d3624484183520b.png',
42+
'assets/fonts/JetBrainsMonoNerdFont-Regular.ttf',
43+
'assets/fonts/MartianMonoNerdFont-Medium.ttf',
44+
'assets/fonts/JetBrainsMonoNerdFont-Bold.ttf',
45+
'assets/fonts/ProFontIIxNerdFontMono-Regular.ttf',
46+
'assets/fonts/ProFontIIxNerdFontPropo-Regular.ttf',
47+
'assets/fonts/JetBrainsMonoNerdFont-Italic.ttf',
48+
'assets/fonts/favicon.png',
49+
'assets/fonts/MartianMonoNerdFont-Regular.ttf',
50+
'assets/fonts/MartianMonoNerdFont-Bold.ttf',
51+
'assets/fonts/ProFontIIxNerdFont-Regular.ttf',
52+
];
53+
54+
for (var asset in assets) {
55+
if (fileExists('$project/$asset') == false) {
56+
return false;
57+
}
58+
}
59+
60+
return true;
61+
}
62+
63+
bool fileExists(path) {
64+
return File(p.normalize(path)).existsSync();
65+
}
66+
67+
bool fileContains(path, data) {
68+
return File(p.normalize(path)).readAsStringSync().contains(data);
69+
}
70+
71+
void main() {
72+
test('Default parameters', () async {
73+
final project = 'export/app_with_assets_and_custom_fonts';
74+
75+
await appMain([
76+
'export-code',
77+
'--project',
78+
kProjectId,
79+
'--token',
80+
kToken,
81+
'-d',
82+
'export',
83+
]);
84+
85+
// Missing assets
86+
expect(checkAssets(project), false);
87+
expect(buildProject(project), false);
88+
});
89+
90+
test('Fix code', () async {
91+
final project = 'export/fix_code';
92+
93+
await appMain([
94+
'export-code',
95+
'--no-parent-folder',
96+
'--include-assets',
97+
'--project',
98+
kProjectId,
99+
'--token',
100+
kToken,
101+
'-d',
102+
p.normalize(project),
103+
'--fix',
104+
]);
105+
106+
// Fix will add 'const' to a lot of stuff :-)
107+
expect(
108+
fileContains(
109+
'$project/lib/main.dart', 'localizationsDelegates: const ['),
110+
true);
111+
112+
expect(checkAssets(project), true);
113+
expect(buildProject(project), true);
114+
});
115+
116+
test('Branch', () async {
117+
final project = 'export/branch';
118+
119+
await appMain([
120+
'export-code',
121+
'--no-parent-folder',
122+
'--include-assets',
123+
'--project',
124+
kProjectId,
125+
'--token',
126+
kToken,
127+
'-d',
128+
p.normalize(project),
129+
'--branch-name',
130+
'TestBranch',
131+
]);
132+
133+
expect(
134+
fileExists(
135+
'$project/lib/pages/page_only_on_this_branch/page_only_on_this_branch_widget.dart'),
136+
true);
137+
138+
expect(checkAssets(project), true);
139+
expect(buildProject(project), true);
140+
});
141+
142+
test('Commit', () async {
143+
final project = 'export/commit';
144+
145+
await appMain([
146+
'export-code',
147+
'--no-parent-folder',
148+
'--include-assets',
149+
'--project',
150+
kProjectId,
151+
'--token',
152+
kToken,
153+
'-d',
154+
p.normalize(project),
155+
'--commit-hash',
156+
'0jfsCktnCmIcNp02q3yW',
157+
]);
158+
159+
expect(
160+
fileExists(
161+
'$project/lib/pages/page_only_on_this_commit/page_only_on_this_commit_widget.dart'),
162+
true);
163+
164+
expect(checkAssets(project), true);
165+
expect(buildProject(project), true);
166+
});
167+
168+
test('Debug', () async {
169+
final project = 'export/debug';
170+
171+
await appMain([
172+
'export-code',
173+
'--no-parent-folder',
174+
'--include-assets',
175+
'--project',
176+
kProjectId,
177+
'--token',
178+
kToken,
179+
'-d',
180+
p.normalize(project),
181+
'--as-debug',
182+
]);
183+
184+
// Debug instrumentation added by the flag
185+
expect(
186+
fileContains('$project/lib/main.dart', 'debugLogGlobalProperty'), true);
187+
188+
expect(checkAssets(project), true);
189+
expect(buildProject(project), true);
190+
});
191+
192+
test('Module', () async {
193+
final project = 'export/module';
194+
195+
await appMain([
196+
'export-code',
197+
'--no-parent-folder',
198+
'--include-assets',
199+
'--project',
200+
kProjectId,
201+
'--token',
202+
kToken,
203+
'-d',
204+
p.normalize(project),
205+
'--as-module',
206+
]);
207+
208+
expect(fileContains('$project/pubspec.yaml', 'module:'), true);
209+
210+
expect(checkAssets(project), true);
211+
expect(buildProject(project), true);
212+
});
213+
214+
test('Environment', () async {
215+
final project = 'export/environment';
216+
217+
await appMain([
218+
'export-code',
219+
'--no-parent-folder',
220+
'--include-assets',
221+
'--project',
222+
kProjectId,
223+
'--token',
224+
kToken,
225+
'-d',
226+
p.normalize(project),
227+
'--project-environment',
228+
'Development',
229+
]);
230+
231+
expect(
232+
fileContains('$project/assets/environment_values/environment.json',
233+
'"foobar": "barfoo"'),
234+
true);
235+
236+
expect(checkAssets(project), true);
237+
expect(buildProject(project), true);
238+
});
239+
}

0 commit comments

Comments
 (0)