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

fix: Reset pixel ratio and textScaleFactor values on tearDown #72

Open
1 task done
jamesblasco opened this issue Aug 2, 2022 · 1 comment
Open
1 task done
Labels
bug Something isn't working

Comments

@jamesblasco
Copy link

Is there an existing issue for this?

  • I have searched the existing issues.

Version

0.4.1

Description

The method FlutterGoldenTestAdapter.pumpGoldenTest sets a new pixelRatio and textScalorFactor test values that are not reset to the original values on tear down. This makes the test that run after a golden test to have modified properties that can alter the result of the test.

tester.binding.window.devicePixelRatioTestValue = 1.0;
tester.binding.window.platformDispatcher.textScaleFactorTestValue =
textScaleFactor;

We should clear values on tearDown:

addTearDown(() {
   tester.binding.window.clearDevicePixelRatioTestValue();
   tester.binding.platformDispatcher.clearTextScaleFactorTestValue();
});

Steps to reproduce

When running the following code, goldenTest sets up a new devicePixelRatio and the test after it fail.

import 'package:alchemist/alchemist.dart';
import 'package:flutter/widgets.dart';
import 'package:flutter_test/flutter_test.dart';

void main() {
  testWidgets('before golden devicePixelRatio', (tester) async {
    expect(tester.binding.window.devicePixelRatio, 3);
  });

  goldenTest(
    'A',
    fileName: 'a',
    builder: () => Container(height: 300),
  );

  testWidgets('after golden devicePixelRatio', (tester) async {
    expect(tester.binding.window.devicePixelRatio, 3);  // Fails with actual value 1
  });
}

Expected behavior

When clearing devicePixelRatio on tearDown, the test work as expected

import 'package:alchemist/alchemist.dart';
import 'package:flutter/widgets.dart';
import 'package:flutter_test/flutter_test.dart';

void main() {
  testWidgets('before golden devicePixelRatio', (tester) async {
    expect(tester.binding.window.devicePixelRatio, 3);
  });

  goldenTest(
    'A',
    fileName: 'a',
    builder: () => Container(height: 300),
    whilePerforming: (tester) async {
      addTearDown(() {
        tester.binding.window.clearDevicePixelRatioTestValue();
      });
      return;
    },
  );

  testWidgets('after golden devicePixelRatio', (tester) async {
    expect(tester.binding.window.devicePixelRatio, 3);
  });
}

Screenshots

Screenshot 2022-08-02 at 10 42 10

Additional context and comments

No response

@jamesblasco jamesblasco added the bug Something isn't working label Aug 2, 2022
@Kirpal
Copy link
Collaborator

Kirpal commented Sep 9, 2022

Can you try this again? I just ran your expected behavior example on the latest version of Alchemist and it all passes.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants