Skip to content

Commit 79c9ce7

Browse files
committed
fix: fixes some tests
1 parent fe64d7a commit 79c9ce7

File tree

5 files changed

+42
-24
lines changed

5 files changed

+42
-24
lines changed

openapi-generator/example/example.dart

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
// Openapi Generator last run: : 2024-11-04T10:28:15.653697
12
import 'package:openapi_generator_annotations/openapi_generator_annotations.dart';
23

34
@Openapi(

openapi-generator/example/pubspec.yaml

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -21,10 +21,10 @@ dependency_overrides:
2121
# meta: ^1.2.2
2222
openapi_generator_annotations:
2323
path: ../../openapi-generator-annotations
24-
openapi_generator:
25-
path: ../../openapi-generator
26-
openapi_generator_cli:
27-
path: ../../openapi-generator-cli
24+
# openapi_generator:
25+
# path: ../../openapi-generator
26+
# openapi_generator_cli:
27+
# path: ../../openapi-generator-cli
2828

2929
dependencies:
3030
# flutter:
@@ -35,8 +35,8 @@ dependencies:
3535
dev_dependencies:
3636
# flutter_test:
3737
# sdk: flutter
38-
build_runner:
39-
openapi_generator: ^4.10.0
38+
# build_runner:
39+
# openapi_generator: ^4.10.0
4040

4141

4242
# For information on the generic Dart part of this file, see the

openapi-generator/pubspec.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,13 +15,13 @@ dependencies:
1515
openapi_generator_cli: '>5.0.2 <7.0.0'
1616
yaml: ^3.1.2
1717
http: '>=0.13.1 <=2.0.0'
18-
build_runner: '>=1.0.0 <3.0.0'
1918
logging: '>=1.0.0 <=2.0.0'
2019

2120
dev_dependencies:
2221
test: ^1.24.2
2322
mockito: ^5.4.4
2423
build_test: '>=1.2.0 <3.0.0'
2524
source_gen_test:
25+
test_process:
2626
pedantic:
2727
coverage: ^1.6.3

openapi-generator/test/builder_test.dart

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -297,17 +297,20 @@ class TestClassConfig extends OpenapiGeneratorConfig {}
297297
useNextGen: true,
298298
cachePath: '${f.path}',
299299
outputDirectory: '${f.parent.path}/fvm',
300+
updateAnnotatedFile: false,
300301
additionalProperties: AdditionalProperties(
301302
wrapper: Wrapper.fvm,
302303
),
303304
)
304305
''');
305-
expect(
306-
generatedOutput, contains('Running source code generation.'));
307306
expect(
308307
generatedOutput,
309308
contains(
310-
'fvm pub run build_runner build --delete-conflicting-outputs'));
309+
'Installing dependencies with generated source. fvm pub get'));
310+
// expect(
311+
// generatedOutput,
312+
// contains(
313+
// 'fvm pub run build_runner build --delete-conflicting-outputs'));
311314
});
312315
test('flutterw', () async {
313316
generatedOutput = await generate('''
@@ -324,12 +327,14 @@ class TestClassConfig extends OpenapiGeneratorConfig {}
324327
),
325328
)
326329
''');
327-
expect(
328-
generatedOutput, contains('Running source code generation.'));
329330
expect(
330331
generatedOutput,
331332
contains(
332-
'./flutterw pub run build_runner build --delete-conflicting-outputs'));
333+
'Installing dependencies with generated source. ./flutterw pub get'));
334+
// expect(
335+
// generatedOutput,
336+
// contains(
337+
// './flutterw pub run build_runner build --delete-conflicting-outputs'));
333338
});
334339
});
335340
test('without wrapper', () async {

openapi-generator/test/utils.dart

Lines changed: 23 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -2,19 +2,16 @@ import 'dart:io';
22

33
import 'package:build/build.dart';
44
import 'package:build_test/build_test.dart';
5-
import 'package:mockito/annotations.dart';
6-
import 'package:mockito/mockito.dart';
75
import 'package:openapi_generator/src/models/output_message.dart';
86
import 'package:openapi_generator/src/openapi_generator_runner.dart';
97
import 'package:openapi_generator/src/process_runner.dart';
108
import 'package:source_gen/source_gen.dart';
11-
12-
@GenerateNiceMocks([MockSpec<ProcessRunner>()])
13-
import 'utils.mocks.dart';
9+
import 'package:test_process/test_process.dart';
1410

1511
final String pkgName = 'pkg';
16-
var _mockProcessRunner = MockProcessRunner();
17-
final Builder builder = LibraryBuilder(OpenapiGenerator(_mockProcessRunner),
12+
13+
final Builder builder = LibraryBuilder(
14+
OpenapiGenerator(ProcessRunnerForTests()),
1815
generatedExtension: '.openapi_generator');
1916
final testSpecPath =
2017
'${Directory.current.path}${Platform.pathSeparator}test${Platform.pathSeparator}specs${Platform.pathSeparator}';
@@ -24,9 +21,6 @@ final testSpecPath =
2421
/// [path] available so an override for the adds generated comment test can
2522
/// compare the output.
2623
Future<String> generate(String source, {String path = 'lib/myapp.dart'}) async {
27-
when(_mockProcessRunner.run(any, any, environment: anyNamed('environment')))
28-
.thenAnswer((_) async => ProcessResult(0, 0, 'Output', ''));
29-
3024
final spec = File('${testSpecPath}openapi.test.yaml').readAsStringSync();
3125
var srcs = <String, String>{
3226
'openapi_generator_annotations|lib/src/openapi_generator_annotations_base.dart':
@@ -35,7 +29,8 @@ Future<String> generate(String source, {String path = 'lib/myapp.dart'}) async {
3529
'openapi_generator|$path': '''
3630
import 'package:openapi_generator_annotations/src/openapi_generator_annotations_base.dart';
3731
$source
38-
class MyApp {}
32+
class MyApp {
33+
}
3934
''',
4035
'openapi_generator|openapi-spec.yaml': spec
4136
};
@@ -60,3 +55,20 @@ Future<String> generate(String source, {String path = 'lib/myapp.dart'}) async {
6055
String.fromCharCodes(
6156
writer.assets[AssetId(pkgName, 'lib/value.g.dart')] ?? []);
6257
}
58+
59+
class ProcessRunnerForTests extends ProcessRunner {
60+
@override
61+
Future<ProcessResult> run(String executable, List<String> arguments,
62+
{Map<String, String>? environment,
63+
String? workingDirectory,
64+
bool runInShell = false}) {
65+
return TestProcess.start(executable, arguments,
66+
environment: environment,
67+
workingDirectory: workingDirectory,
68+
runInShell: runInShell)
69+
.then(
70+
(value) async => ProcessResult(
71+
value.pid, await value.exitCode, value.stdout, value.stderr),
72+
);
73+
}
74+
}

0 commit comments

Comments
 (0)