diff --git a/.github/workflows/integration_tests.yaml b/.github/workflows/integration_tests.yaml index 9a5937d8..4f69e16f 100644 --- a/.github/workflows/integration_tests.yaml +++ b/.github/workflows/integration_tests.yaml @@ -32,4 +32,6 @@ jobs: - name: 🧪 Run Integration Tests env: FIGMA_FREE_TOKEN: ${{ secrets.FIGMA_FREE_TOKEN }} - run: dart test integration_test/generation_notifier_integration_test.dart \ No newline at end of file + run: | + dart test integration_test/generation_notifier_integration_test.dart + dart test integration_test/full_integration_test.dart \ No newline at end of file diff --git a/.github/workflows/tag_release.yaml b/.github/workflows/tag_release.yaml index 57e44b4b..5642928a 100644 --- a/.github/workflows/tag_release.yaml +++ b/.github/workflows/tag_release.yaml @@ -12,6 +12,8 @@ jobs: if: contains(github.event.head_commit.message, 'chore(release)') steps: - uses: actions/checkout@v4 + with: + fetch-depth: 0 - uses: dart-lang/setup-dart@v1.6.5 - uses: bluefireteam/melos-action@c7dcb921b23cc520cace360b95d02b37bf09cdaa with: diff --git a/.github/workflows/version.yaml b/.github/workflows/version.yaml index ba43945e..e9cb99ae 100644 --- a/.github/workflows/version.yaml +++ b/.github/workflows/version.yaml @@ -19,7 +19,7 @@ jobs: steps: - uses: actions/checkout@v4 with: - fetch-tags: true + fetch-depth: 0 - uses: dart-lang/setup-dart@v1.6.5 - uses: bluefireteam/melos-action@c7dcb921b23cc520cace360b95d02b37bf09cdaa with: diff --git a/integration_test/full_integration_test.dart b/integration_test/full_integration_test.dart new file mode 100644 index 00000000..72a8adba --- /dev/null +++ b/integration_test/full_integration_test.dart @@ -0,0 +1,86 @@ +import 'dart:convert'; +import 'dart:io'; + +import 'package:test/test.dart'; + +void main() { + group('Full integration test', () { + setUp(() {}); + + test('prints help to console', () async { + final process = await Process.start( + 'dart', + ['run', 'bin/figmage.dart', 'forge', '--help'], + ); + final exitCode = await process.exitCode; + expect(exitCode, 0); + + const helpText = ''' +This command forges a new package from your figma file. + + Usage: figmage forge [arguments] + -h, --help Print this usage information. + -t, --token (mandatory) Your figma API token + -p, --path The ouptut path for the generated package, if not provided, the current directory will be used. + -f, --fileId Your figma file ID, needs to be either given here, or in the figmage.yaml + + Run "figmage help" to see global options. + '''; + + await expectLater( + process.stdout.transform(const Utf8Decoder()), + emits(equalsIgnoringWhitespace(helpText)), + ); + }); + + test('generates default package from command', () async { + final dir = Directory('./full_test_package')..createSync(); + addTearDown(() => dir.deleteSync(recursive: true)); + final process = await Process.start( + 'dart', + [ + 'run', + '../bin/figmage.dart', + 'forge', + '-f', + 'HHUVTJ7lsjhG24SQB5h0zX', + '-t', + Platform.environment['FIGMA_FREE_TOKEN']!, + ], + workingDirectory: dir.path, + ); + final exitCode = await process.exitCode; + expect(exitCode, 0); + + final pubspec = File("${dir.path}/pubspec.yaml"); + final pubspecContent = pubspec.readAsStringSync(); + expect( + pubspecContent, + contains("name: full_test_package"), + reason: 'Package name was not generated from directory', + ); + + final files = [ + File("${dir.path}/lib/src/colors.dart"), + File("${dir.path}/lib/src/typography.dart"), + ]; + expect( + files.every((f) => f.existsSync()), + true, + reason: 'Token files were not generated', + ); + + final analyzeProcess = await Process.start( + 'dart', + ['analyze', '--fatal-infos', '--fatal-warnings'], + workingDirectory: dir.path, + ); + final analyzeExitCode = await analyzeProcess.exitCode; + expect( + analyzeExitCode, + 0, + reason: 'Generated package has analysis issues', + ); + }); + }); +} diff --git a/lib/src/commands/forge/forge_command.dart b/lib/src/commands/forge/forge_command.dart index d086598a..45867fab 100644 --- a/lib/src/commands/forge/forge_command.dart +++ b/lib/src/commands/forge/forge_command.dart @@ -13,18 +13,18 @@ class ForgeCommand extends Command { /// {@macro forge_command} ForgeCommand(this._container) { argParser - ..addOption( - "path", - defaultsTo: ".", - help: "The ouptut path for the generated package, if not provided, " - "the current directory will be used.", - ) ..addOption( "token", abbr: "t", help: "Your figma API token", mandatory: true, ) + ..addOption( + "path", + abbr: "p", + help: "The ouptut path for the generated package, if not provided, " + "the current directory will be used.", + ) ..addOption( "fileId", abbr: "f", diff --git a/lib/src/commands/shared/forge_settings_providers.dart b/lib/src/commands/shared/forge_settings_providers.dart index bfef4f17..90c37540 100644 --- a/lib/src/commands/shared/forge_settings_providers.dart +++ b/lib/src/commands/shared/forge_settings_providers.dart @@ -12,8 +12,9 @@ import 'package:riverpod/riverpod.dart'; final settingsProvider = FutureProvider.autoDispose .family((ref, args) async { final dir = switch (args['path']) { + null => Directory.current, final String dir => Directory(dir), - _ => throw ArgumentError.notNull('path'), + _ => throw ArgumentError.value(args['path'], 'path'), }; final configPath = join(dir.path, 'figmage.yaml'); diff --git a/test/src/commands/forge/forge_command_test.dart b/test/src/commands/forge/forge_command_test.dart index 3c4eed3c..5003be43 100644 --- a/test/src/commands/forge/forge_command_test.dart +++ b/test/src/commands/forge/forge_command_test.dart @@ -106,9 +106,9 @@ void main() { test('tells user how to use command when wrong arguments provided', () async { - final exitCode = await commandRunner.run(['forge', '-p']); + final exitCode = await commandRunner.run(['forge', '-x']); verify( - () => logger.err('Could not find an option or flag "-p".'), + () => logger.err('Could not find an option or flag "-x".'), ).called(1); verify(() => logger.info('')).called(1); final infoLog = verify(() => logger.info(captureAny())).captured.first; @@ -121,7 +121,7 @@ void main() { final args = command.argParser.parse(['-t', 'token', '-f', 'fileId']); expect(args['token'], 'token'); expect(args['fileId'], 'fileId'); - expect(args['path'], '.', reason: 'defaults to "."'); + expect(args['path'], isNull); }); }); } @@ -129,9 +129,8 @@ void main() { const usage = ''' Usage: figmage forge [arguments] -h, --help Print this usage information. - --path The ouptut path for the generated package, if not provided, the current directory will be used. - (defaults to ".") -t, --token (mandatory) Your figma API token +-p, --path The ouptut path for the generated package, if not provided, the current directory will be used. -f, --fileId Your figma file ID, needs to be either given here, or in the figmage.yaml Run "figmage help" to see global options.'''; diff --git a/test/src/commands/shared/forge_settings_providers_test.dart b/test/src/commands/shared/forge_settings_providers_test.dart index 47c4956c..20c472c3 100644 --- a/test/src/commands/shared/forge_settings_providers_test.dart +++ b/test/src/commands/shared/forge_settings_providers_test.dart @@ -56,8 +56,8 @@ void main() { expect(result.path, "arg_path"); }); - test('throws an ArgumentError if path is not in the args', () async { - when(() => argResults['path']).thenReturn(null); + test('throws an ArgumentError if path is not a string or null', () async { + when(() => argResults['path']).thenReturn(0); await expectLater( () => container.read(settingsProvider(argResults).future), throwsA(