|
| 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 | + group('export-code', () { |
| 73 | + test('Default parameters', () async { |
| 74 | + final project = 'export/app_with_assets_and_custom_fonts'; |
| 75 | + |
| 76 | + await appMain([ |
| 77 | + 'export-code', |
| 78 | + '--project', |
| 79 | + kProjectId, |
| 80 | + '--token', |
| 81 | + kToken, |
| 82 | + '-d', |
| 83 | + 'export', |
| 84 | + ]); |
| 85 | + |
| 86 | + // Missing assets |
| 87 | + expect(checkAssets(project), false); |
| 88 | + expect(buildProject(project), false); |
| 89 | + }); |
| 90 | + |
| 91 | + test('Fix code', () async { |
| 92 | + final project = 'export/fix_code'; |
| 93 | + |
| 94 | + await appMain([ |
| 95 | + 'export-code', |
| 96 | + '--no-parent-folder', |
| 97 | + '--include-assets', |
| 98 | + '--project', |
| 99 | + kProjectId, |
| 100 | + '--token', |
| 101 | + kToken, |
| 102 | + '-d', |
| 103 | + p.normalize(project), |
| 104 | + '--fix', |
| 105 | + ]); |
| 106 | + |
| 107 | + // Fix will add 'const' to a lot of stuff :-) |
| 108 | + expect( |
| 109 | + fileContains( |
| 110 | + '$project/lib/main.dart', 'localizationsDelegates: const ['), |
| 111 | + true); |
| 112 | + |
| 113 | + expect(checkAssets(project), true); |
| 114 | + expect(buildProject(project), true); |
| 115 | + }); |
| 116 | + |
| 117 | + test('Branch', () async { |
| 118 | + final project = 'export/branch'; |
| 119 | + |
| 120 | + await appMain([ |
| 121 | + 'export-code', |
| 122 | + '--no-parent-folder', |
| 123 | + '--include-assets', |
| 124 | + '--project', |
| 125 | + kProjectId, |
| 126 | + '--token', |
| 127 | + kToken, |
| 128 | + '-d', |
| 129 | + p.normalize(project), |
| 130 | + '--branch-name', |
| 131 | + 'TestBranch', |
| 132 | + ]); |
| 133 | + |
| 134 | + expect( |
| 135 | + fileExists( |
| 136 | + '$project/lib/pages/page_only_on_this_branch/page_only_on_this_branch_widget.dart'), |
| 137 | + true); |
| 138 | + |
| 139 | + expect(checkAssets(project), true); |
| 140 | + expect(buildProject(project), true); |
| 141 | + }); |
| 142 | + |
| 143 | + test('Commit', () async { |
| 144 | + final project = 'export/commit'; |
| 145 | + |
| 146 | + await appMain([ |
| 147 | + 'export-code', |
| 148 | + '--no-parent-folder', |
| 149 | + '--include-assets', |
| 150 | + '--project', |
| 151 | + kProjectId, |
| 152 | + '--token', |
| 153 | + kToken, |
| 154 | + '-d', |
| 155 | + p.normalize(project), |
| 156 | + '--commit-hash', |
| 157 | + '0jfsCktnCmIcNp02q3yW', |
| 158 | + ]); |
| 159 | + |
| 160 | + expect( |
| 161 | + fileExists( |
| 162 | + '$project/lib/pages/page_only_on_this_commit/page_only_on_this_commit_widget.dart'), |
| 163 | + true); |
| 164 | + |
| 165 | + expect(checkAssets(project), true); |
| 166 | + expect(buildProject(project), true); |
| 167 | + }); |
| 168 | + |
| 169 | + test('Debug', () async { |
| 170 | + final project = 'export/debug'; |
| 171 | + |
| 172 | + await appMain([ |
| 173 | + 'export-code', |
| 174 | + '--no-parent-folder', |
| 175 | + '--include-assets', |
| 176 | + '--project', |
| 177 | + kProjectId, |
| 178 | + '--token', |
| 179 | + kToken, |
| 180 | + '-d', |
| 181 | + p.normalize(project), |
| 182 | + '--as-debug', |
| 183 | + ]); |
| 184 | + |
| 185 | + // Debug instrumentation added by the flag |
| 186 | + expect(fileContains('$project/lib/main.dart', 'debugLogGlobalProperty'), |
| 187 | + true); |
| 188 | + |
| 189 | + expect(checkAssets(project), true); |
| 190 | + expect(buildProject(project), true); |
| 191 | + }); |
| 192 | + |
| 193 | + test('Module', () async { |
| 194 | + final project = 'export/module'; |
| 195 | + |
| 196 | + await appMain([ |
| 197 | + 'export-code', |
| 198 | + '--no-parent-folder', |
| 199 | + '--include-assets', |
| 200 | + '--project', |
| 201 | + kProjectId, |
| 202 | + '--token', |
| 203 | + kToken, |
| 204 | + '-d', |
| 205 | + p.normalize(project), |
| 206 | + '--as-module', |
| 207 | + ]); |
| 208 | + |
| 209 | + expect(fileContains('$project/pubspec.yaml', 'module:'), true); |
| 210 | + |
| 211 | + expect(checkAssets(project), true); |
| 212 | + expect(buildProject(project), true); |
| 213 | + }); |
| 214 | + |
| 215 | + test('Environment', () async { |
| 216 | + final project = 'export/environment'; |
| 217 | + |
| 218 | + await appMain([ |
| 219 | + 'export-code', |
| 220 | + '--no-parent-folder', |
| 221 | + '--include-assets', |
| 222 | + '--project', |
| 223 | + kProjectId, |
| 224 | + '--token', |
| 225 | + kToken, |
| 226 | + '-d', |
| 227 | + p.normalize(project), |
| 228 | + '--project-environment', |
| 229 | + 'Development', |
| 230 | + ]); |
| 231 | + |
| 232 | + expect( |
| 233 | + fileContains('$project/assets/environment_values/environment.json', |
| 234 | + '"foobar": "barfoo"'), |
| 235 | + true); |
| 236 | + |
| 237 | + expect(checkAssets(project), true); |
| 238 | + expect(buildProject(project), true); |
| 239 | + }); |
| 240 | + }, timeout: Timeout(Duration(minutes: 30))); |
| 241 | +} |
0 commit comments