Skip to content

Commit

Permalink
fix: fixed failing tests
Browse files Browse the repository at this point in the history
  • Loading branch information
gibahjoe committed Nov 4, 2024
1 parent 79c9ce7 commit f1c0a1c
Show file tree
Hide file tree
Showing 4 changed files with 79 additions and 46 deletions.
38 changes: 11 additions & 27 deletions .github/workflows/code_quality.yml
Original file line number Diff line number Diff line change
Expand Up @@ -44,8 +44,8 @@ jobs:
- name: Install Dependencies
run: melos exec -- "dart pub get"

- name: Build runner
run: melos exec --depends-on="build_runner" -- bash -c "cd \$MELOS_PACKAGE_PATH && dart run build_runner build --delete-conflicting-outputs"
# - name: Build runner
# run: melos exec --depends-on="build_runner" -- bash -c "cd \$MELOS_PACKAGE_PATH && dart run build_runner build --delete-conflicting-outputs"
- name: Validate formatting
run: melos format --set-exit-if-changed
- name: Run analyzer
Expand All @@ -65,38 +65,22 @@ jobs:
run: dart pub global activate coverage

- name: Install Coverage Tools
run: dart pub global activate coverage combine_coverage
run: dart pub global activate combine_coverage

- name: Format Coverage for Each Package
run: |
# Find each package's coverage directory and format to lcov
for dir in $(find . -name "coverage" -type d); do
$HOME/.pub-cache/bin/format_coverage \
--lcov \
--in=$dir \
--out=$dir/coverage.lcov \
--packages=$dir/../.packages \
--report-on=lib
done
- name: format coverage
run: melos exec -- bash "$HOME/.pub-cache/bin/format_coverage --lcov --in=\$MELOS_PACKAGE_PATH/coverage/test --out=\$MELOS_PACKAGE_PATH/coverage/lcov.info --report-on=lib"

- name: Combine Coverage Reports
run: |
mkdir -p coverage # Create a root coverage folder if it doesn't exist
dart pub global run combine_coverage \
--repo-path="." \
--output=coverage/combined.lcov # Combines all into a single lcov file
run: dart pub global run combine_coverage --repo-path="."

- name: Upload Combined Coverage to Codecov
- name: Upload coverage reports to Codecov
uses: codecov/codecov-action@v3
with:
files: ./coverage/combined.lcov
flags: combined_coverage
name: Combined Code Coverage
fail_ci_if_error: true
env:
CODECOV_TOKEN: ${{ secrets.CODECOV_TOKEN }} # Required only for private repositories
files: ./coverage/lcov.info
verbose: true

- name: Stop Docker Container
run: docker-compose -f "docker-compose.yaml" down
run: melos exec --scope="openapi_generator" -- bash -c "cd \$MELOS_PACKAGE_PATH && docker-compose -f "docker-compose.yaml" down"

build:
name: Build example project 🛠️
Expand Down
35 changes: 17 additions & 18 deletions openapi-generator/test/builder_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -263,26 +263,25 @@ class TestClassConfig extends OpenapiGeneratorConfig {}
copy.deleteSync();
expect(hasOutput, isTrue);
});

test('skip updating annotated file', () async {
final annotatedFile = File(
'.${Platform.pathSeparator}test${Platform.pathSeparator}specs${Platform.pathSeparator}output-nextgen${Platform.pathSeparator}annotated_file.dart');
final annotetedFileContent = '\n';
await annotatedFile.writeAsString(annotetedFileContent, flush: true);
// create the cached spec
f.writeAsStringSync(jsonEncode({'someKey': 'someValue'}));
// Read the contents of the annotation we want to test
var annotatedFile =
File('$testSpecPath/skip_update_annotated_file_test_config.dart');
final contents = annotatedFile.readAsStringSync();
final copy = File(
'./test/specs/skip_update_annotated_file_test_config_copy.dart');
copy.writeAsStringSync(contents, flush: true);

generatedOutput = await generate('''
@Openapi(
inputSpecFile: '$specPath',
inputSpec: RemoteSpec(path: '$specPath'),
useNextGen: true,
cachePath: '${f.path}',
updateAnnotatedFile: false,
)
''', path: annotatedFile.path);
expect(
generatedOutput,
contains(
'Skipped updating annotated file step because flag was set.'));
expect(annotatedFile.readAsStringSync(), equals(annotetedFileContent));
generatedOutput = await generateForSource(copy.path, path: copy.path);

var hasOutput = copy.readAsStringSync().contains(lastRunPlaceHolder);
copy.deleteSync();
expect(generatedOutput,
isNot(contains('Creating generated timestamp with ')));
expect(hasOutput, isFalse);
});
group('source gen', () {
group('uses Flutter', () {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
import 'package:openapi_generator_annotations/openapi_generator_annotations.dart';

@Openapi(
inputSpec: RemoteSpec(
path:
'https://raw.githubusercontent.com/Nexushunter/tagmine-api/main/openapi.yaml',
),
generatorName: Generator.dio,
updateAnnotatedFile: false,
cachePath: './test/specs/output-nextgen/expected-args/cache.json',
outputDirectory: './test/specs/output-nextgen/expected-args')
class TestClassConfig {}
40 changes: 39 additions & 1 deletion openapi-generator/test/utils.dart
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import 'package:openapi_generator/src/process_runner.dart';
import 'package:source_gen/source_gen.dart';
import 'package:test_process/test_process.dart';

final String pkgName = 'pkg';
final String pkgName = 'openapi_generator';

final Builder builder = LibraryBuilder(
OpenapiGenerator(ProcessRunnerForTests()),
Expand All @@ -20,6 +20,44 @@ final testSpecPath =
///
/// [path] available so an override for the adds generated comment test can
/// compare the output.
Future<String> generateForSource(String annotatedFilePath,
{String path = 'lib/myapp.dart'}) async {
final spec = File('${testSpecPath}openapi.test.yaml').readAsStringSync();
final annotatedContent = File(annotatedFilePath).readAsStringSync();
var srcs = <String, String>{
'openapi_generator|$path': annotatedContent,
'openapi_generator|openapi-spec.yaml': spec
};

// Capture any message from generation; if there is one, return that instead of
// the generated output.
String? logMessage;
void captureLog(dynamic logRecord) {
if (logRecord is OutputMessage) {
logMessage =
'${logMessage ?? ''}\n${logRecord.level} ${logRecord.message} \n ${logRecord.additionalContext} \n ${logRecord.stackTrace}';
} else {
logMessage =
'${logMessage ?? ''}\n${logRecord.message ?? ''}\n${logRecord.error ?? ''}\n${logRecord.stackTrace ?? ''}';
}
}

var writer = InMemoryAssetWriter();
await testBuilder(builder, srcs,
reader: await PackageAssetReader.currentIsolate(),
rootPackage: pkgName,
writer: writer,
onLog: captureLog);
return logMessage ??
String.fromCharCodes(
writer.assets[AssetId(pkgName, 'lib/value.g.dart')] ?? []);
}

/// Runs an in memory test variant of the generator with the given [source].
///
/// [path] available so an override for the adds generated comment test can
/// compare the output.
@Deprecated('Use generateForSource instead')
Future<String> generate(String source, {String path = 'lib/myapp.dart'}) async {
final spec = File('${testSpecPath}openapi.test.yaml').readAsStringSync();
var srcs = <String, String>{
Expand Down

0 comments on commit f1c0a1c

Please sign in to comment.