Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Starting each analysis from scratch in end2end tests. #1347

Merged
merged 1 commit into from
Apr 11, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
64 changes: 36 additions & 28 deletions test/end2end_light_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -9,35 +9,43 @@ import 'package:path/path.dart' as p;
import 'package:test/test.dart';

void main() {
late String tempDir;
late PackageAnalyzer analyzer;

setUpAll(() async {
tempDir = Directory.systemTemp
.createTempSync('pana-test')
.resolveSymbolicLinksSync();
final pubCacheDir = p.join(tempDir, 'pub-cache');
Directory(pubCacheDir).createSync();
analyzer = PackageAnalyzer(await ToolEnvironment.create(
pubCacheDir: pubCacheDir,
dartdocVersion: 'any',
));
});

tearDownAll(() async {
Directory(tempDir).deleteSync(recursive: true);
});

void verifyPackage(String package) {
test('end2end light: $package', () async {
final summary = await analyzer.inspectPackage(package);
expect(summary.report, isNotNull);
expect(summary.allDependencies!, isNotEmpty);
expect(summary.tags!, isNotEmpty);
expect(summary.tags, contains('is:dart3-compatible'));
expect(summary.report!.grantedPoints,
greaterThanOrEqualTo(summary.report!.maxPoints - 20));
}, timeout: const Timeout.factor(2));
group('end2end light: $package', () {
late String tempDir;
late PackageAnalyzer analyzer;

setUpAll(() async {
tempDir = Directory.systemTemp
.createTempSync('pana-test')
.resolveSymbolicLinksSync();
final pubCacheDir = p.join(tempDir, 'pub-cache');
final dartConfigDir = p.join(tempDir, 'config', 'dart');
final flutterConfigDir = p.join(tempDir, 'config', 'flutter');
Directory(pubCacheDir).createSync();
Directory(dartConfigDir).createSync(recursive: true);
Directory(flutterConfigDir).createSync(recursive: true);
analyzer = PackageAnalyzer(await ToolEnvironment.create(
dartSdkConfig: SdkConfig(configHomePath: dartConfigDir),
flutterSdkConfig: SdkConfig(configHomePath: flutterConfigDir),
pubCacheDir: pubCacheDir,
dartdocVersion: 'any',
));
});

tearDownAll(() async {
Directory(tempDir).deleteSync(recursive: true);
});

test('analysis', () async {
final summary = await analyzer.inspectPackage(package);
expect(summary.report, isNotNull);
expect(summary.allDependencies!, isNotEmpty);
expect(summary.tags!, isNotEmpty);
expect(summary.tags, contains('is:dart3-compatible'));
expect(summary.report!.grantedPoints,
greaterThanOrEqualTo(summary.report!.maxPoints - 20));
}, timeout: const Timeout.factor(4));
});
}

// generic, cross-platform package
Expand Down
77 changes: 37 additions & 40 deletions test/end2end_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -18,56 +18,47 @@ final _goldenDir = p.join('test', 'goldens', 'end2end');
final _pubDevUri = Uri.parse('https://pub.dartlang.org/');

void main() {
late String tempDir;
late PackageAnalyzer analyzer;
http.Client? httpClient;
late HttpServer httpServer;

setUpAll(() async {
tempDir = Directory.systemTemp
.createTempSync('pana-test')
.resolveSymbolicLinksSync();
final pubCacheDir = p.join(tempDir, 'pub-cache');
final panaCacheDir = p.join(tempDir, 'pana-cache');
final dartConfigDir = p.join(tempDir, 'config', 'dart');
final flutterConfigDir = p.join(tempDir, 'config', 'flutter');
final goldenDirLastModified = await _detectGoldenLastModified();
Directory(pubCacheDir).createSync();
Directory(panaCacheDir).createSync();
Directory(dartConfigDir).createSync(recursive: true);
Directory(flutterConfigDir).createSync(recursive: true);
httpClient = http.Client();
httpServer = await _startLocalProxy(
httpClient: httpClient,
blockPublishAfter: goldenDirLastModified,
);
analyzer = PackageAnalyzer(await ToolEnvironment.create(
dartSdkConfig: SdkConfig(configHomePath: dartConfigDir),
flutterSdkConfig: SdkConfig(configHomePath: flutterConfigDir),
pubCacheDir: pubCacheDir,
panaCacheDir: panaCacheDir,
pubHostedUrl: 'http://127.0.0.1:${httpServer.port}',
dartdocVersion: 'any',
));
});

tearDownAll(() async {
await httpServer.close(force: true);
httpClient!.close();
Directory(tempDir).deleteSync(recursive: true);
});

void verifyPackage(
String package,
String version, {
bool skipDartdoc = false,
}) {
final filename = '$package-$version.json';
group('end2end: $package $version', () {
late String tempDir;
late PackageAnalyzer analyzer;
http.Client? httpClient;
late HttpServer httpServer;
late final Map<String, Object?> actualMap;

setUpAll(() async {
final dartdocOutputDir = p.join(tempDir, 'doc', '$package-version');
tempDir = Directory.systemTemp
.createTempSync('pana-test')
.resolveSymbolicLinksSync();
final pubCacheDir = p.join(tempDir, 'pub-cache');
final panaCacheDir = p.join(tempDir, 'pana-cache');
final dartConfigDir = p.join(tempDir, 'config', 'dart');
final flutterConfigDir = p.join(tempDir, 'config', 'flutter');
final goldenDirLastModified = await _detectGoldenLastModified();
Directory(pubCacheDir).createSync();
Directory(panaCacheDir).createSync();
Directory(dartConfigDir).createSync(recursive: true);
Directory(flutterConfigDir).createSync(recursive: true);
httpClient = http.Client();
httpServer = await _startLocalProxy(
httpClient: httpClient,
blockPublishAfter: goldenDirLastModified,
);
analyzer = PackageAnalyzer(await ToolEnvironment.create(
dartSdkConfig: SdkConfig(configHomePath: dartConfigDir),
flutterSdkConfig: SdkConfig(configHomePath: flutterConfigDir),
pubCacheDir: pubCacheDir,
panaCacheDir: panaCacheDir,
pubHostedUrl: 'http://127.0.0.1:${httpServer.port}',
dartdocVersion: 'any',
));

final dartdocOutputDir = p.join(tempDir, 'doc', '$package-$version');
await Directory(dartdocOutputDir).create(recursive: true);

var summary = await analyzer.inspectPackage(
Expand Down Expand Up @@ -111,6 +102,12 @@ void main() {
actualMap = json.decode(updated) as Map<String, Object?>;
});

tearDownAll(() async {
await httpServer.close(force: true);
httpClient!.close();
Directory(tempDir).deleteSync(recursive: true);
});

test('matches known good', () {
void removeDependencyDetails(Map<String, dynamic> map) {
if (map.containsKey('pkgResolution') &&
Expand Down