Skip to content

Commit

Permalink
fix: fixes some tests
Browse files Browse the repository at this point in the history
  • Loading branch information
gibahjoe committed Nov 4, 2024
1 parent f587789 commit 4fe6701
Show file tree
Hide file tree
Showing 5 changed files with 42 additions and 24 deletions.
1 change: 1 addition & 0 deletions openapi-generator/example/example.dart
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
// Openapi Generator last run: : 2024-11-04T10:28:15.653697
import 'package:openapi_generator_annotations/openapi_generator_annotations.dart';

@Openapi(
Expand Down
12 changes: 6 additions & 6 deletions openapi-generator/example/pubspec.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -21,10 +21,10 @@ dependency_overrides:
# meta: ^1.2.2
openapi_generator_annotations:
path: ../../openapi-generator-annotations
openapi_generator:
path: ../../openapi-generator
openapi_generator_cli:
path: ../../openapi-generator-cli
# openapi_generator:
# path: ../../openapi-generator
# openapi_generator_cli:
# path: ../../openapi-generator-cli

dependencies:
# flutter:
Expand All @@ -35,8 +35,8 @@ dependencies:
dev_dependencies:
# flutter_test:
# sdk: flutter
build_runner:
openapi_generator: ^4.10.0
# build_runner:
# openapi_generator: ^4.10.0


# For information on the generic Dart part of this file, see the
Expand Down
2 changes: 1 addition & 1 deletion openapi-generator/pubspec.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -15,13 +15,13 @@ dependencies:
openapi_generator_cli: '>5.0.2 <7.0.0'
yaml: ^3.1.2
http: '>=0.13.1 <=2.0.0'
build_runner: '>=1.0.0 <3.0.0'
logging: '>=1.0.0 <=2.0.0'

dev_dependencies:
test: ^1.24.2
mockito: ^5.4.4
build_test: '>=1.2.0 <3.0.0'
source_gen_test:
test_process:
pedantic:
coverage: ^1.6.3
17 changes: 11 additions & 6 deletions openapi-generator/test/builder_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -297,17 +297,20 @@ class TestClassConfig extends OpenapiGeneratorConfig {}
useNextGen: true,
cachePath: '${f.path}',
outputDirectory: '${f.parent.path}/fvm',
updateAnnotatedFile: false,
additionalProperties: AdditionalProperties(
wrapper: Wrapper.fvm,
),
)
''');
expect(
generatedOutput, contains('Running source code generation.'));
expect(
generatedOutput,
contains(
'fvm pub run build_runner build --delete-conflicting-outputs'));
'Installing dependencies with generated source. fvm pub get'));
// expect(
// generatedOutput,
// contains(
// 'fvm pub run build_runner build --delete-conflicting-outputs'));
});
test('flutterw', () async {
generatedOutput = await generate('''
Expand All @@ -324,12 +327,14 @@ class TestClassConfig extends OpenapiGeneratorConfig {}
),
)
''');
expect(
generatedOutput, contains('Running source code generation.'));
expect(
generatedOutput,
contains(
'./flutterw pub run build_runner build --delete-conflicting-outputs'));
'Installing dependencies with generated source. ./flutterw pub get'));
// expect(
// generatedOutput,
// contains(
// './flutterw pub run build_runner build --delete-conflicting-outputs'));
});
});
test('without wrapper', () async {
Expand Down
34 changes: 23 additions & 11 deletions openapi-generator/test/utils.dart
Original file line number Diff line number Diff line change
Expand Up @@ -2,19 +2,16 @@ import 'dart:io';

import 'package:build/build.dart';
import 'package:build_test/build_test.dart';
import 'package:mockito/annotations.dart';
import 'package:mockito/mockito.dart';
import 'package:openapi_generator/src/models/output_message.dart';
import 'package:openapi_generator/src/openapi_generator_runner.dart';
import 'package:openapi_generator/src/process_runner.dart';
import 'package:source_gen/source_gen.dart';

@GenerateNiceMocks([MockSpec<ProcessRunner>()])
import 'utils.mocks.dart';
import 'package:test_process/test_process.dart';

final String pkgName = 'pkg';
var _mockProcessRunner = MockProcessRunner();
final Builder builder = LibraryBuilder(OpenapiGenerator(_mockProcessRunner),

final Builder builder = LibraryBuilder(
OpenapiGenerator(ProcessRunnerForTests()),
generatedExtension: '.openapi_generator');
final testSpecPath =
'${Directory.current.path}${Platform.pathSeparator}test${Platform.pathSeparator}specs${Platform.pathSeparator}';
Expand All @@ -24,9 +21,6 @@ final testSpecPath =
/// [path] available so an override for the adds generated comment test can
/// compare the output.
Future<String> generate(String source, {String path = 'lib/myapp.dart'}) async {
when(_mockProcessRunner.run(any, any, environment: anyNamed('environment')))
.thenAnswer((_) async => ProcessResult(0, 0, 'Output', ''));

final spec = File('${testSpecPath}openapi.test.yaml').readAsStringSync();
var srcs = <String, String>{
'openapi_generator_annotations|lib/src/openapi_generator_annotations_base.dart':
Expand All @@ -35,7 +29,8 @@ Future<String> generate(String source, {String path = 'lib/myapp.dart'}) async {
'openapi_generator|$path': '''
import 'package:openapi_generator_annotations/src/openapi_generator_annotations_base.dart';
$source
class MyApp {}
class MyApp {
}
''',
'openapi_generator|openapi-spec.yaml': spec
};
Expand All @@ -60,3 +55,20 @@ Future<String> generate(String source, {String path = 'lib/myapp.dart'}) async {
String.fromCharCodes(
writer.assets[AssetId(pkgName, 'lib/value.g.dart')] ?? []);
}

class ProcessRunnerForTests extends ProcessRunner {
@override
Future<ProcessResult> run(String executable, List<String> arguments,
{Map<String, String>? environment,
String? workingDirectory,
bool runInShell = false}) {
return TestProcess.start(executable, arguments,
environment: environment,
workingDirectory: workingDirectory,
runInShell: runInShell)
.then(
(value) async => ProcessResult(
value.pid, await value.exitCode, value.stdout, value.stderr),
);
}
}

0 comments on commit 4fe6701

Please sign in to comment.