AlchemistConfig class

A configuration object that contains settings used by Alchemist for customizing the behavior of all golden tests.

Alchemist uses this configuration object to determine when and how to run any given test. The default configuration is used when no custom configuration is provided. The current instance can be retrieved using AlchemistConfig.current.

To override the current configuration, use AlchemistConfig.runWithConfig. The function passed to this method will receive the provided config whenever AlchemistConfig.current is called. See AlchemistConfig.runWithConfig for more details.

Set forceUpdateGoldenFiles to true to force all tests to update their golden files. Otherwise, the golden tests will only update the golden file if the --update-goldens flag is passed when running flutter test. This defaults to false.

If a theme is provided, it will be assigned to the MaterialApp created by Alchemist that wraps the golden test groups and scenarios when a test is run. If no theme is provided, the default ThemeData.light will be used, unless platformGoldensConfig or ciGoldensConfig provide their own themes.

A platformGoldensConfig and ciGoldensConfig can be provided to configure the behavior of platform and CI golden tests respectively. Each of these also contains a theme property that can be used to override the theme used for each type of golden test.

Platform tests vs. CI tests

Alchemist can perform two kinds of golden tests. One is platform tests, which generate golden files with human readable text. These can be considered regular golden tests. The other is CI tests, which look and function the same as readable text, except that the text blocks are replaced with colored squares. The reason for this distinction is that the output of platform tests is dependent on the platform the test is running on. For example, macOS is known to render text differently than other platforms. This causes readable golden files generated on macOS to be ever so slightly off from the golden files generated on other platforms, causing CI systems to fail the test. CI tests, on the other hand, were made to circumvent this, and will always have the same output regardless of the platform.

By default, CI tests will always be generated and compared, whereas platform tests will be generated but are never compared.

Note that by default, CI tests are in the "Ahem" font family to ensure consistent results across platforms. In other words, the font family of the theme (and ciGoldensConfig theme) will be ignored.

Constructors

AlchemistConfig.new({bool? forceUpdateGoldenFiles, GoldenTestTheme? goldenTestTheme, ThemeData? theme, PlatformGoldensConfig? platformGoldensConfig, CiGoldensConfig? ciGoldensConfig})
A configuration object that contains settings used by Alchemist for customizing the behavior of all golden tests.
const
AlchemistConfig.current()
The instance of the AlchemistConfig in the current zone used by the alchemist package.
factory

Properties

ciGoldensConfig CiGoldensConfig
The configuration for golden tests intended to be run in CI.
no setter
forceUpdateGoldenFiles bool
Whether to force the golden tests to update the golden file.
no setter
goldenTestTheme GoldenTestTheme?
The GoldenTestTheme to use when generating golden tests.
no setter
hashCode int
The hash code for this object.
no setterinherited
platformGoldensConfig PlatformGoldensConfig
The configuration for human-readable golden tests running in non-CI environments.
no setter
props List<Object?>
The list of properties that will be used to determine whether two instances are equal.
no setter
runtimeType Type
A representation of the runtime type of the object.
no setterinherited
stringify bool?
If set to true, the toString method will be overridden to output this instance's props.
no setterinherited
theme ThemeData?
The ThemeData to use when generating golden tests.
no setter

Methods

copyWith({bool? forceUpdateGoldenFiles, ThemeData? theme, GoldenTestTheme? goldenTestTheme, PlatformGoldensConfig? platformGoldensConfig, CiGoldensConfig? ciGoldensConfig}) AlchemistConfig
Creates a copy of this AlchemistConfig and replaces the given fields.
merge(AlchemistConfig? other) AlchemistConfig
Creates a copy and merges this AlchemistConfig with the given config, replacing all set fields of the copy with the given config's fields.
noSuchMethod(Invocation invocation) → dynamic
Invoked when a nonexistent method or property is accessed.
inherited
toString() String
A string representation of this object.
inherited

Operators

operator ==(Object other) bool
The equality operator.
inherited

Static Methods

runWithConfig<T>({required AlchemistConfig config, required T run()}) → T
Runs the given function run in a Zone where the default AlchemistConfig is set to config.

Constants

currentConfigKey → const Symbol
The Symbol used to look up and assign the default AlchemistConfig in a Zone.