Skip to content

Commit f48e9cb

Browse files
committed
fix(ci): 测试改用 TDESIGN_COMPONENT_ROOT,先 clone 再跑单测
CI 上 8 个测试失败因硬编码本地绝对路径;统一通过环境变量解析 tdesign-component 路径。
1 parent 400734f commit f48e9cb

7 files changed

Lines changed: 61 additions & 25 deletions

File tree

.github/workflows/api-compliance.yml

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,14 @@ jobs:
4343
- name: 静态分析 tools
4444
run: dart analyze --fatal-infos
4545

46+
- name: 克隆 tdesign-flutter(测试与 validate 共用)
47+
run: |
48+
git clone --depth 1 --branch "${FLUTTER_BRANCH}" \
49+
https://github.com/Tencent/tdesign-flutter.git "${FLUTTER_REPO}"
50+
4651
- name: 单元测试(完备性相关)
52+
env:
53+
TDESIGN_COMPONENT_ROOT: ${{ github.workspace }}/${{ env.FLUTTER_REPO }}/tdesign-component
4754
run: |
4855
dart test test/aux_types_test.dart \
4956
test/ctor_defaults_test.dart \
@@ -52,11 +59,6 @@ jobs:
5259
test/enum_members_test.dart \
5360
test/positional_ctor_test.dart
5461
55-
- name: 克隆 tdesign-flutter(只读,用于读取已提交的 *_api.md)
56-
run: |
57-
git clone --depth 1 --branch "${FLUTTER_BRANCH}" \
58-
https://github.com/Tencent/tdesign-flutter.git "${FLUTTER_REPO}"
59-
6062
- name: 运行 AST 完备性检测(非零 exit code 即失败)
6163
run: |
6264
dart run bin/main.dart validate \

test/aux_types_test.dart

Lines changed: 13 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,10 @@ import 'package:analyzer/file_system/physical_file_system.dart';
44
import 'package:tdesign_flutter_tools/component_rule.dart';
55
import 'package:test/test.dart';
66

7-
List<dynamic> _analyse(List<String> names, String path) {
7+
import 'support/component_paths.dart';
8+
9+
List<dynamic> _analyse(List<String> names, String relPath) {
10+
final String path = componentSourcePath(relPath);
811
final col = AnalysisContextCollection(
912
includedPaths: [path],
1013
resourceProvider: PhysicalResourceProvider.INSTANCE,
@@ -16,15 +19,16 @@ List<dynamic> _analyse(List<String> names, String path) {
1619
isGrammarParser: false,
1720
nameList: names,
1821
folderName: 'popup',
19-
sourceFileName: path.split('/').last,
22+
sourceFileName: relPath.split('/').last,
2023
).analyse();
2124
}
2225

2326
void main() {
2427
test('auto includes SlideTransitionFrom when parsing TSlidePopupRoute file', () {
25-
final path =
26-
'/Users/rs/Documents/cursor/tdesign-flutter/tdesign-component/lib/src/components/popup/t_popup_route.dart';
27-
final list = _analyse(['TSlidePopupRoute'], path);
28+
final list = _analyse(
29+
['TSlidePopupRoute'],
30+
'lib/src/components/popup/t_popup_route.dart',
31+
);
2832
final names = list.map((e) => e.componentInfo!.name).toList();
2933
expect(names, contains('SlideTransitionFrom'));
3034
final enumInfo =
@@ -35,9 +39,10 @@ void main() {
3539
});
3640

3741
test('auto includes PopupClick when parsing popup panel file', () {
38-
final path =
39-
'/Users/rs/Documents/cursor/tdesign-flutter/tdesign-component/lib/src/components/popup/t_popup_panel.dart';
40-
final list = _analyse(['TPopupBottomDisplayPanel'], path);
42+
final list = _analyse(
43+
['TPopupBottomDisplayPanel'],
44+
'lib/src/components/popup/t_popup_panel.dart',
45+
);
4146
final names = list.map((e) => e.componentInfo!.name).toList();
4247
expect(names, contains('PopupClick'));
4348
final typedefInfo =

test/ctor_defaults_test.dart

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,11 @@ import 'package:analyzer/file_system/physical_file_system.dart';
44
import 'package:tdesign_flutter_tools/component_rule.dart';
55
import 'package:test/test.dart';
66

7+
import 'support/component_paths.dart';
8+
79
List<dynamic> _analyse(List<String> names) {
8-
final path =
9-
'/Users/rs/Documents/cursor/tdesign-flutter/tdesign-component/lib/src/components/popup/t_popup_panel.dart';
10+
const String relPath = 'lib/src/components/popup/t_popup_panel.dart';
11+
final String path = componentSourcePath(relPath);
1012
final col = AnalysisContextCollection(
1113
includedPaths: [path],
1214
resourceProvider: PhysicalResourceProvider.INSTANCE,

test/enum_members_test.dart

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,11 +5,10 @@ import 'package:tdesign_flutter_tools/component_rule.dart';
55
import 'package:tdesign_flutter_tools/model.dart';
66
import 'package:test/test.dart';
77

8-
const String _componentRoot =
9-
'/Users/rs/Documents/cursor/tdesign-flutter/tdesign-component';
8+
import 'support/component_paths.dart';
109

1110
List<ParsedComponentInfoInfo> _analyse(List<String> names, String relPath) {
12-
final path = '$_componentRoot/$relPath';
11+
final String path = componentSourcePath(relPath);
1312
final col = AnalysisContextCollection(
1413
includedPaths: [path],
1514
resourceProvider: PhysicalResourceProvider.INSTANCE,

test/factory_ctor_test.dart

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,11 +5,10 @@ import 'package:tdesign_flutter_tools/component_rule.dart';
55
import 'package:tdesign_flutter_tools/model.dart';
66
import 'package:test/test.dart';
77

8-
const String _componentRoot =
9-
'/Users/rs/Documents/cursor/tdesign-flutter/tdesign-component';
8+
import 'support/component_paths.dart';
109

1110
List<ParsedComponentInfoInfo> _analyse(List<String> names, String relPath) {
12-
final path = '$_componentRoot/$relPath';
11+
final String path = componentSourcePath(relPath);
1312
final col = AnalysisContextCollection(
1413
includedPaths: [path],
1514
resourceProvider: PhysicalResourceProvider.INSTANCE,

test/positional_ctor_test.dart

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,11 +5,10 @@ import 'package:tdesign_flutter_tools/component_rule.dart';
55
import 'package:tdesign_flutter_tools/model.dart';
66
import 'package:test/test.dart';
77

8-
const String _componentRoot =
9-
'/Users/rs/Documents/cursor/tdesign-flutter/tdesign-component';
8+
import 'support/component_paths.dart';
109

1110
List<ParsedComponentInfoInfo> _analyse(List<String> names, String relPath) {
12-
final path = '$_componentRoot/$relPath';
11+
final String path = componentSourcePath(relPath);
1312
final col = AnalysisContextCollection(
1413
includedPaths: [path],
1514
resourceProvider: PhysicalResourceProvider.INSTANCE,
@@ -38,7 +37,6 @@ void main() {
3837
expect(contextParam.isNamed, isFalse);
3938
expect(contextParam.type, 'BuildContext');
4039

41-
// positional 参数排在命名参数之前
4240
final firstParam = info.propertyList.first;
4341
expect(firstParam.name, 'context');
4442
expect(firstParam.isNamed, isFalse);

test/support/component_paths.dart

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
import 'dart:io';
2+
3+
import 'package:path/path.dart' as p;
4+
5+
/// tdesign-component 根目录。
6+
/// CI 通过环境变量 `TDESIGN_COMPONENT_ROOT` 注入;本地默认可用 ../tdesign-flutter/tdesign-component。
7+
String get tdesignComponentRoot {
8+
final String? fromEnv = Platform.environment['TDESIGN_COMPONENT_ROOT'];
9+
if (fromEnv != null && fromEnv.isNotEmpty) {
10+
return p.normalize(fromEnv);
11+
}
12+
13+
final List<String> candidates = <String>[
14+
p.normalize(
15+
p.join(Directory.current.path, '../tdesign-flutter/tdesign-component'),
16+
),
17+
];
18+
for (final String candidate in candidates) {
19+
if (Directory(candidate).existsSync()) {
20+
return candidate;
21+
}
22+
}
23+
24+
throw StateError(
25+
'未找到 tdesign-component。请 clone tdesign-flutter 或设置 TDESIGN_COMPONENT_ROOT。',
26+
);
27+
}
28+
29+
String componentSourcePath(String relativePath) {
30+
return p.join(tdesignComponentRoot, relativePath);
31+
}

0 commit comments

Comments
 (0)