Betterment / alchemist

A Flutter tool that makes golden testing easy.
MIT License
268 stars 36 forks source link

Question regarding target platforms #93

Closed CillianMyles closed 1 year ago

CillianMyles commented 1 year ago

Say I have a component that is re-used across mobile and desktop e.g. a button.

Hypothetically on desktop the button should be 32x32 and on mobile it should be 40x40, among other differences.

Assuming I make the distinction between platforms based on the foundation.dart property: defaultTargetPlatform in the button -- is there a way for me to run my golden tests/scenarios against both platforms?

I've looked into AlchemistConfig but can find any way to specific these type of variation.

I also tried to hack it manually but it didn't work (I have the same golden images for both):

import 'package:alchemist/alchemist.dart';
import 'package:flutter/foundation.dart';
import 'package:flutter/material.dart';
import 'package:flutter_test/flutter_test.dart';

void main() {
  group('Golden Tests', () async {
    Future<void> runTests(String variant) async {
      await goldenTest(
        'should render correctly',
        fileName: 'component_$variant',
        constraints: const BoxConstraints(maxWidth: 800),
        builder: () {
          return GoldenTestGroup(
            columnWidthBuilder: (_) => const FlexColumnWidth(),
            children: [
              GoldenTestScenario(
                name: 'scenario 1',
                child: ...,
              ),
              GoldenTestScenario(
                name: 'scenario w',
                child: ...,
              ),
            ],
          );
        },
      );
    }

    // Desktop
    debugDefaultTargetPlatformOverride = TargetPlatform.macOS;
    await runTests('desktop');
    debugDefaultTargetPlatformOverride = null;

    // Mobile
    debugDefaultTargetPlatformOverride = TargetPlatform.iOS;
    await runTests('mobile');
    debugDefaultTargetPlatformOverride = null;
  });
}

Any advice on how to test goldens agains multiple target platforms in a nice way?

Or any idea why even my hack solution does not work?

Thanks in advance, Cillian.

jigar-f commented 1 month ago

Any update on this? Ware you able to do it @CillianMyles