Skip to content

Commit

Permalink
Add integration tests
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
tmpsantos committed Jan 30, 2025
1 parent bad3343 commit f873242
Show file tree
Hide file tree
Showing 3 changed files with 241 additions and 4 deletions.
11 changes: 7 additions & 4 deletions .github/workflows/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,8 @@ on: push

env:
# Keep this in sync with the version used by FlutterFlow.
DART_VERSION: 3.4.3
DART_VERSION: 3.5.2
FLUTTER_VERSION: 3.24.2

jobs:
check:
Expand Down Expand Up @@ -44,10 +45,12 @@ jobs:
- name: Clone repository
uses: actions/checkout@v4

- name: Setup Dart
uses: dart-lang/setup-dart@v1
- name: Setup Flutter
uses: subosito/flutter-action@44ac965b96f18d999802d4b807e3256d5a3f9fa1 # v2
with:
sdk: ${{ env.DART_VERSION }}
channel: master
flutter-version: ${{ env.FLUTTER_VERSION }}
cache: true

- name: Install dependencies
run: |
Expand Down
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
bin/flutterflow
.dart_tool/
export/
233 changes: 233 additions & 0 deletions test/integration_test.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,233 @@
import 'package:flutterflow_cli/src/flutterflow_main.dart';

import 'package:test/test.dart';

import 'dart:io';

String kProjectId = 'app-with-assets-and-custom-fonts-qxwg6o';
String kToken = Platform.environment['FF_TESTER_TOKEN'] ?? 'not-set';

bool buildProject(String project) {
var result =
Process.runSync('flutter', ['build', 'web'], workingDirectory: project);

return result.exitCode == 0;
}

bool checkAssets(String project) {
var assets = [
'assets/images/6740bca9ed26c9a34b1ab1ce.png',
'assets/images/6785366c3e83b0072fdc8ef4.png',
'assets/images/6740b4b5cf7b4fdf95795e2c.png',
'assets/images/6740af8ffbd4c3414fcf5728.png',
'assets/images/6740aff03c7e45b220ed9775.png',
'assets/images/6740b3cca8e014dee9325b5d.png',
'assets/images/6740b4b5c0adf773476a5452.png',
'assets/images/67895d616be6f220ee4ec9c3.png',
'assets/images/6740b4b494d7239248fa491e.png',
'assets/images/67895d6177fc072b5e166fd1.png',
'assets/images/6740ae761553efad6aa2a5d4.png',
'assets/images/6740bca9c28f22a68495d368.png',
'assets/images/6744ab4d50d5a3dad758fa39.png',
'assets/images/6785366c77c17f02779e160c.png',
'assets/images/6740aff0d10e0295e5fe33e6.png',
'assets/images/6785366c215b774f00c041a3.png',
'assets/images/67895d61a7af8d11cb9aa957.png',
'assets/images/6740ae76c0adf77347645294.png',
'assets/images/6740b3cc6d3624484183520b.png',
'assets/fonts/JetBrainsMonoNerdFont-Regular.ttf',
'assets/fonts/MartianMonoNerdFont-Medium.ttf',
'assets/fonts/JetBrainsMonoNerdFont-Bold.ttf',
'assets/fonts/ProFontIIxNerdFontMono-Regular.ttf',
'assets/fonts/ProFontIIxNerdFontPropo-Regular.ttf',
'assets/fonts/JetBrainsMonoNerdFont-Italic.ttf',
'assets/fonts/favicon.png',
'assets/fonts/MartianMonoNerdFont-Regular.ttf',
'assets/fonts/MartianMonoNerdFont-Bold.ttf',
'assets/fonts/ProFontIIxNerdFont-Regular.ttf',
];

for (var asset in assets) {
if (File('$project/$asset').existsSync() == false) {
return false;
}
}

return true;
}

void main() {
test('Default parameters', () async {
final project = 'export/app_with_assets_and_custom_fonts';

await appMain([
'export-code',
'--project',
kProjectId,
'--token',
kToken,
'-d',
'export',
]);

// Missing assets
expect(checkAssets(project), false);
expect(buildProject(project), false);
});

test('Fix code', () async {
final project = 'export/fix_code';

await appMain([
'export-code',
'--no-parent-folder',
'--include-assets',
'--project',
kProjectId,
'--token',
kToken,
'-d',
project,
'--fix',
]);

// Fix will add 'const' to a lot of stuff :-)
expect(
File('$project/lib/main.dart')
.readAsStringSync()
.contains('localizationsDelegates: const ['),
true);

expect(checkAssets(project), true);
expect(buildProject(project), true);
});

test('Branch', () async {
final project = 'export/branch';

await appMain([
'export-code',
'--no-parent-folder',
'--include-assets',
'--project',
kProjectId,
'--token',
kToken,
'-d',
project,
'--branch-name',
'TestBranch',
]);

expect(
File('$project/lib/pages/page_only_on_this_branch/page_only_on_this_branch_widget.dart')
.existsSync(),
true);

expect(checkAssets(project), true);
expect(buildProject(project), true);
});

test('Commit', () async {
final project = 'export/commit';

await appMain([
'export-code',
'--no-parent-folder',
'--include-assets',
'--project',
kProjectId,
'--token',
kToken,
'-d',
project,
'--commit-hash',
'0jfsCktnCmIcNp02q3yW',
]);

expect(
File('$project/lib/pages/page_only_on_this_commit/page_only_on_this_commit_widget.dart')
.existsSync(),
true);

expect(checkAssets(project), true);
expect(buildProject(project), true);
});

test('Debug', () async {
final project = 'export/debug';

await appMain([
'export-code',
'--no-parent-folder',
'--include-assets',
'--project',
kProjectId,
'--token',
kToken,
'-d',
project,
'--as-debug',
]);

// Debug instrumentation added by the flag
expect(
File('$project/lib/main.dart')
.readAsStringSync()
.contains('debugLogGlobalProperty'),
true);

expect(checkAssets(project), true);
expect(buildProject(project), true);
});

test('Module', () async {
final project = 'export/module';

await appMain([
'export-code',
'--no-parent-folder',
'--include-assets',
'--project',
kProjectId,
'--token',
kToken,
'-d',
project,
'--as-module',
]);

expect(File('$project/pubspec.yaml').readAsStringSync().contains('module:'),
true);

expect(checkAssets(project), true);
expect(buildProject(project), true);
});

test('Environment', () async {
final project = 'export/environment';

await appMain([
'export-code',
'--no-parent-folder',
'--include-assets',
'--project',
kProjectId,
'--token',
kToken,
'-d',
project,
'--project-environment',
'Development',
]);

expect(
File('$project/assets/environment_values/environment.json')
.readAsStringSync()
.contains('"foobar": "barfoo"'),
true);

expect(checkAssets(project), true);
expect(buildProject(project), true);
});
}

0 comments on commit f873242

Please sign in to comment.