Skip to content

Commit

Permalink
Starting each analysis from scratch in end2end tests. (#1347)
Browse files Browse the repository at this point in the history
  • Loading branch information
isoos authored Apr 11, 2024
1 parent f9635fc commit 7559322
Show file tree
Hide file tree
Showing 2 changed files with 73 additions and 68 deletions.
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

0 comments on commit 7559322

Please sign in to comment.