From 74a253972e5c2242626f3d06e654aa79f06ad7c7 Mon Sep 17 00:00:00 2001 From: Kody Peterson Date: Tue, 20 Feb 2024 15:17:35 -0800 Subject: [PATCH 1/2] Resolves an issue where test bundler would generate invalid code if the file path included dashes --- packages/patrol_cli/lib/src/test_bundler.dart | 3 +- .../patrol_cli/test/test_bundler_test.dart | 29 +++++++++++++++---- 2 files changed, 25 insertions(+), 7 deletions(-) diff --git a/packages/patrol_cli/lib/src/test_bundler.dart b/packages/patrol_cli/lib/src/test_bundler.dart index bc8674c7a..3c7849725 100644 --- a/packages/patrol_cli/lib/src/test_bundler.dart +++ b/packages/patrol_cli/lib/src/test_bundler.dart @@ -245,7 +245,8 @@ ${generateGroupsCode([testFilePath]).split('\n').map((e) => ' $e').join('\n')} String _createTestName(String relativeTestFilePath) { var testName = relativeTestFilePath .replaceFirst('integration_test${_fs.path.separator}', '') - .replaceAll('/', '__'); + .replaceAll('/', '__') + .replaceAll('-', '___'); testName = testName.substring(0, testName.length - 5); return testName; diff --git a/packages/patrol_cli/test/test_bundler_test.dart b/packages/patrol_cli/test/test_bundler_test.dart index 8033e393e..158c0569c 100644 --- a/packages/patrol_cli/test/test_bundler_test.dart +++ b/packages/patrol_cli/test/test_bundler_test.dart @@ -13,8 +13,7 @@ Directory _initFakeFs(FileSystem fs, Platform platform) { fs.directory(fs.path.join(platform.home)).createSync(recursive: true); fs.currentDirectory = platform.home; - final projectRootDir = - fs.directory(fs.path.join(platform.home, 'awesome_app'))..createSync(); + final projectRootDir = fs.directory(fs.path.join(platform.home, 'awesome_app'))..createSync(); fs.currentDirectory = projectRootDir; fs.directory('integration_test').createSync(); return projectRootDir; @@ -48,6 +47,7 @@ void _test(Platform platform) { final tests = [ fs.path.join('integration_test', 'example_test.dart'), fs.path.join('integration_test', 'example', 'example_test.dart'), + fs.path.join('integration_test', 'example-dash-test', 'example_test.dart'), ]; // when @@ -56,7 +56,8 @@ void _test(Platform platform) { /// then expect(imports, ''' import 'example_test.dart' as example_test; -import 'example/example_test.dart' as example__example_test;'''); +import 'example/example_test.dart' as example__example_test; +import 'example-dash-test/example_test.dart' as example___dash___test__example_test;'''); }); test('generates imports from absolute paths', () { @@ -74,6 +75,12 @@ import 'example/example_test.dart' as example__example_test;'''); 'integration_test', 'example/example_test.dart', ), + fs.path.join( + platform.home, + 'awesome_app', + 'integration_test', + 'example-dash-test/example_test.dart', + ), ]; // when @@ -82,7 +89,8 @@ import 'example/example_test.dart' as example__example_test;'''); /// then expect(imports, ''' import 'example_test.dart' as example_test; -import 'example/example_test.dart' as example__example_test;'''); +import 'example/example_test.dart' as example__example_test; +import 'example-dash-test/example_test.dart' as example___dash___test__example_test;'''); }); test('generates groups from relative paths', () { @@ -90,6 +98,7 @@ import 'example/example_test.dart' as example__example_test;'''); final tests = [ fs.path.join('integration_test', 'example_test.dart'), fs.path.join('integration_test', 'example/example_test.dart'), + fs.path.join('integration_test', 'example-dash-test/example_test.dart'), ]; // when @@ -98,7 +107,8 @@ import 'example/example_test.dart' as example__example_test;'''); /// then expect(groupsCode, ''' group('example_test', example_test.main); -group('example.example_test', example__example_test.main);'''); +group('example.example_test', example__example_test.main); +group('example._dash._test.example_test', example___dash___test__example_test.main);'''); }); test('generates groups from absolute paths', () { @@ -116,6 +126,12 @@ group('example.example_test', example__example_test.main);'''); 'integration_test', 'example/example_test.dart', ), + fs.path.join( + platform.home, + 'awesome_app', + 'integration_test', + 'example-dash-test/example_test.dart', + ), ]; // when @@ -124,7 +140,8 @@ group('example.example_test', example__example_test.main);'''); /// then expect(groupsCode, ''' group('example_test', example_test.main); -group('example.example_test', example__example_test.main);'''); +group('example.example_test', example__example_test.main); +group('example._dash._test.example_test', example___dash___test__example_test.main);'''); }); }); } From bfc718e87deaa33357f5700288716ac3340a0175 Mon Sep 17 00:00:00 2001 From: Kody Peterson Date: Tue, 20 Feb 2024 15:24:48 -0800 Subject: [PATCH 2/2] Correct formatting --- packages/patrol_cli/test/test_bundler_test.dart | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/packages/patrol_cli/test/test_bundler_test.dart b/packages/patrol_cli/test/test_bundler_test.dart index 158c0569c..969eb18c8 100644 --- a/packages/patrol_cli/test/test_bundler_test.dart +++ b/packages/patrol_cli/test/test_bundler_test.dart @@ -13,7 +13,8 @@ Directory _initFakeFs(FileSystem fs, Platform platform) { fs.directory(fs.path.join(platform.home)).createSync(recursive: true); fs.currentDirectory = platform.home; - final projectRootDir = fs.directory(fs.path.join(platform.home, 'awesome_app'))..createSync(); + final projectRootDir = + fs.directory(fs.path.join(platform.home, 'awesome_app'))..createSync(); fs.currentDirectory = projectRootDir; fs.directory('integration_test').createSync(); return projectRootDir; @@ -47,7 +48,8 @@ void _test(Platform platform) { final tests = [ fs.path.join('integration_test', 'example_test.dart'), fs.path.join('integration_test', 'example', 'example_test.dart'), - fs.path.join('integration_test', 'example-dash-test', 'example_test.dart'), + fs.path + .join('integration_test', 'example-dash-test', 'example_test.dart'), ]; // when