Skip to content

Commit

Permalink
feature: integration tests
Browse files Browse the repository at this point in the history
  • Loading branch information
efraespada committed Oct 5, 2024
1 parent fdde738 commit c3d1513
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 15 deletions.
32 changes: 19 additions & 13 deletions lib/src/bin/preview_builder/preview_builder.dart
Original file line number Diff line number Diff line change
Expand Up @@ -252,7 +252,7 @@ class ${clazz}Test {
);
}

Future<TestBuilderInfo> generateInstrumentedTest(
Future<TestBuilderInfo> generateIntegrationTest(
dynamic config,
String srcPath,
String className,
Expand All @@ -264,25 +264,25 @@ Future<TestBuilderInfo> generateInstrumentedTest(
String fileName = srcPath.split('/').last;
String name = fileName.split('.').first;
String dirPath = srcPath.replaceAll(fileName, '');
String testPath = '${dirPath}catalog/instrumented_test/';
String testPath = '${dirPath}catalog/integration_test/';

await Directory(testPath).create(recursive: true);

String testFile = '$testPath${name}_instrumented_test.dart';
String testFile = '$testPath${name}_integration_test.dart';
File file = File(testFile);

var importParts = classImport.split('/');
importParts.removeAt(importParts.length - 1);
importParts.add(config['output']);
importParts.add('instrumented_test');
importParts.add('${name}_instrumented_test.dart');
importParts.add('integration_test');
importParts.add('${name}_integration_test.dart');

if (await file.exists()) {
print(
'🧪 👌 Test file already exist for $clazz - ${clazz}InstrumentedTest ($testFile)');
'🧪 👌 Test file already exist for $clazz - ${clazz}IntegrationTest ($testFile)');
return TestBuilderInfo(
alias: buildTestAlias(4),
clazzName: '${clazz}InstrumentedTest',
clazzName: '${clazz}IntegrationTest',
import: importParts.join('/'),
);
}
Expand All @@ -300,10 +300,10 @@ import 'package:catalog/catalog.dart';
import '../dummy/$name.dummy.dart';
import '../preview/$name.$prefix.dart';
class ${clazz}InstrumentedTestTest {
class ${clazz}IntegrationTestTest {
void main() {
group(
'$clazz - InstrumentedTest Tests',
'$clazz - IntegrationTest Tests',
() {
testWidgets(
'Lorem text not found',
Expand Down Expand Up @@ -337,7 +337,7 @@ class ${clazz}InstrumentedTestTest {

return TestBuilderInfo(
alias: buildTestAlias(4),
clazzName: '${clazz}InstrumentedTest',
clazzName: '${clazz}IntegrationTest',
import: importParts.join('/'),
);
}
Expand Down Expand Up @@ -368,13 +368,19 @@ void main() {
await file.writeAsString(content);
}

Future<void> generateMainInstrumentedTest(
Future<void> generateMainIntegrationTest(
String basePath,
List<TestBuilderInfo> tests,
) async {
File file = File('./${basePath}instrumented_test/catalog_widget_instrumented_test.dart');

print('🧪 Updating catalog instrumented test collector (${file.path})');
String testPath = './${basePath}integration_test/';

await Directory(testPath).create(recursive: true);


File file = File('./${basePath}integration_test/catalog_widget_integration_test.dart');

print('🧪 Updating catalog integration test collector (${file.path})');

var content = '''
/// AUTOGENERATED FILE. DO NOT EDIT
Expand Down
4 changes: 2 additions & 2 deletions lib/src/bin/tasks/tasks/instrumented_test_task.dart
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ class InstrumentedTestTask extends BaseTask {
if (className == null) continue;
if (preview == null) continue;

final testFile = await generateInstrumentedTest(
final testFile = await generateIntegrationTest(
config,
file.path,
className,
Expand All @@ -66,6 +66,6 @@ class InstrumentedTestTask extends BaseTask {
test.add(testFile);
}

await generateMainInstrumentedTest(base, test);
await generateMainIntegrationTest(base, test);
}
}

0 comments on commit c3d1513

Please sign in to comment.