From 20047d0aad57475f658744d83afb3c1f54f5227b Mon Sep 17 00:00:00 2001 From: devmil Date: Wed, 27 Sep 2023 07:24:04 +0200 Subject: [PATCH] chore: adds an integration test for the recent relative path issue --- .../cli/extract_command_test.dart | 41 +++++++++++++++++++ 1 file changed, 41 insertions(+) diff --git a/test/integration_tests/cli/extract_command_test.dart b/test/integration_tests/cli/extract_command_test.dart index e17849d..3835005 100644 --- a/test/integration_tests/cli/extract_command_test.dart +++ b/test/integration_tests/cli/extract_command_test.dart @@ -1,3 +1,6 @@ +import 'dart:convert'; +import 'dart:io'; + import 'package:args/command_runner.dart'; import 'package:dart_apitool/api_tool_cli.dart'; import 'package:test/test.dart'; @@ -34,6 +37,44 @@ void main() { timeout: integrationTestTimeout, ); + test( + 'packages with path dependencies don\'t yield unresolvable types', + () async { + final tempDir = await Directory.systemTemp.createTemp(); + final tempFilePath = path.join(tempDir.path, 'extract_paths_test.json'); + final exitCode = await runner.run([ + 'extract', + '--input', + path.join( + 'test', + 'test_packages', + 'path_references', + 'cluster_a', + 'package_a', + ), + '--output', + tempFilePath, + ]); + expect(exitCode, 0); + + final jsonReportFile = File(tempFilePath); + expect(await jsonReportFile.exists(), isTrue); + + final jsonReport = jsonDecode(await jsonReportFile.readAsString()); + await tempDir.delete(recursive: true); + + // check if the ClassB field in ClassA has resolved its type + final interfaceDeclarations = + jsonReport['packageApi']['interfaceDeclarations'] as List; + final classADeclaration = + interfaceDeclarations.singleWhere((id) => id['name'] == 'ClassA'); + final classBField = (classADeclaration['fieldDeclarations'] as List) + .singleWhere((fd) => fd['name'] == 'classB'); + expect(classBField['typeName'], 'ClassB'); + }, + timeout: integrationTestTimeout, + ); + test( 'Can handle pub ref', () async {