Skip to content

Commit

Permalink
Merge pull request #865 from Workiva/gold-file-workflow-improvements
Browse files Browse the repository at this point in the history
FED-1956 Gold file workflow improvements
  • Loading branch information
greglittlefield-wf authored Dec 11, 2023
2 parents 97831a1 + 9d29523 commit f4cfcd5
Show file tree
Hide file tree
Showing 14 changed files with 523 additions and 8 deletions.
35 changes: 28 additions & 7 deletions test/vm_tests/builder/over_react_builder_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -112,35 +112,57 @@ main() {
'over_react|test_fixtures/source_files/backwards_compatible/basic_library.over_react.g.dart',
'${p.absolute(p.current)}/test_fixtures/gold_output_files/backwards_compatible/basic_library.over_react.g.dart.goldFile');
});

test('builds for props mixins', () async {
await checkBuildForFile(
'over_react|test_fixtures/source_files/backwards_compatible/props_mixin.dart',
'over_react|test_fixtures/source_files/backwards_compatible/props_mixin.over_react.g.dart',
'${p.absolute(p.current)}/test_fixtures/gold_output_files/backwards_compatible/props_mixin.over_react.g.dart.goldFile');
});

test('builds for state mixins', () async {
await checkBuildForFile(
'over_react|test_fixtures/source_files/backwards_compatible/state_mixin.dart',
'over_react|test_fixtures/source_files/backwards_compatible/state_mixin.over_react.g.dart',
'${p.absolute(p.current)}/test_fixtures/gold_output_files/backwards_compatible/state_mixin.over_react.g.dart.goldFile');
});

test('does not produce a build output for just a part file', () async {
var basicAsset = makeAssetId('over_react|test_fixtures/source_files/backwards_compatible/part_of_basic_library.dart');
await runBuilder(builder, [basicAsset], reader, writerSpy, AnalyzerResolvers(), logger: logger);

expect(writerSpy.assetsWritten, isEmpty);
verifyNoErrorLogs();
});
});

group('for Dart 2 only compatible boilerplate:', () {
test('builds from basic component file', () async {
await checkBuildForFile(
'over_react|test_fixtures/source_files/dart2_only/basic.dart',
'over_react|test_fixtures/source_files/dart2_only/basic.over_react.g.dart',
'${p.absolute(p.current)}/test_fixtures/gold_output_files/basic.over_react.g.dart.goldFile');
'${p.absolute(p.current)}/test_fixtures/gold_output_files/dart2_only/basic.over_react.g.dart.goldFile');
});

test('builds from basic multi-part library', () async {
await checkBuildForFile(
'over_react|test_fixtures/source_files/dart2_only/basic_library.dart',
'over_react|test_fixtures/source_files/dart2_only/basic_library.over_react.g.dart',
'${p.absolute(p.current)}/test_fixtures/gold_output_files/basic_library.over_react.g.dart.goldFile');
'${p.absolute(p.current)}/test_fixtures/gold_output_files/dart2_only/basic_library.over_react.g.dart.goldFile');
});

test('builds for props mixins', () async {
await checkBuildForFile(
'over_react|test_fixtures/source_files/dart2_only/props_mixin.dart',
'over_react|test_fixtures/source_files/dart2_only/props_mixin.over_react.g.dart',
'${p.absolute(p.current)}/test_fixtures/gold_output_files/props_mixin.over_react.g.dart.goldFile');
'${p.absolute(p.current)}/test_fixtures/gold_output_files/dart2_only/props_mixin.over_react.g.dart.goldFile');
});

test('builds for state mixins', () async {
await checkBuildForFile(
'over_react|test_fixtures/source_files/dart2_only/state_mixin.dart',
'over_react|test_fixtures/source_files/dart2_only/state_mixin.over_react.g.dart',
'${p.absolute(p.current)}/test_fixtures/gold_output_files/state_mixin.over_react.g.dart.goldFile');
'${p.absolute(p.current)}/test_fixtures/gold_output_files/dart2_only/state_mixin.over_react.g.dart.goldFile');
});

test('does not produce a build output for just a part file', () async {
Expand All @@ -161,20 +183,19 @@ main() {
reason: 'Expected a SEVERE log for the missing over_react part.');
});


group('for Component2:', () {
test('builds from basic component file', () async {
await checkBuildForFile(
'over_react|test_fixtures/source_files/dart2_only/component2/basic.dart',
'over_react|test_fixtures/source_files/dart2_only/component2/basic.over_react.g.dart',
'${p.absolute(p.current)}/test_fixtures/gold_output_files/component2/basic.over_react.g.dart.goldFile');
'${p.absolute(p.current)}/test_fixtures/gold_output_files/dart2_only/component2/basic.over_react.g.dart.goldFile');
});

test('builds from basic multi-part library', () async {
await checkBuildForFile(
'over_react|test_fixtures/source_files/dart2_only/component2/basic_library.dart',
'over_react|test_fixtures/source_files/dart2_only/component2/basic_library.over_react.g.dart',
'${p.absolute(p.current)}/test_fixtures/gold_output_files/component2/basic_library.over_react.g.dart.goldFile');
'${p.absolute(p.current)}/test_fixtures/gold_output_files/dart2_only/component2/basic_library.over_react.g.dart.goldFile');
});
});
});
Expand Down
11 changes: 11 additions & 0 deletions test_fixtures/gold_output_files/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
## Updating golds

To re-generate the gold files in this directory using the over_react builder, run:
```sh
dart tool/update_gold_output_files.dart
```

If that deletes other generated files throughout over_react (which usually only happens after it prompts you about conflicting outputs), you can restore them by running a build:
```sh
dart run build_runner build
```
Original file line number Diff line number Diff line change
@@ -0,0 +1,78 @@
//@dart=2.11
// GENERATED CODE - DO NOT MODIFY BY HAND

// ignore_for_file: deprecated_member_use_from_same_package, unnecessary_null_in_if_null_operators, prefer_null_aware_operators
part of 'props_mixin.dart';

// **************************************************************************
// OverReactBuilder (package:over_react/src/builder.dart)
// **************************************************************************

abstract class $ExamplePropsMixinClass implements ExamplePropsMixinClass {
@override
Map get props;

static const PropsMeta meta = _$metaForExamplePropsMixinClass;

/// <!-- Generated from [ExamplePropsMixinClass.propMixin1] -->
@override
String get propMixin1 =>
(props[_$key__propMixin1__ExamplePropsMixinClass] ?? null) as String;

/// <!-- Generated from [ExamplePropsMixinClass.propMixin1] -->
@override
set propMixin1(String value) =>
props[_$key__propMixin1__ExamplePropsMixinClass] = value;
/* GENERATED CONSTANTS */
static const PropDescriptor _$prop__propMixin1__ExamplePropsMixinClass =
PropDescriptor(_$key__propMixin1__ExamplePropsMixinClass);
static const String _$key__propMixin1__ExamplePropsMixinClass =
'ExamplePropsMixinClass.propMixin1';

static const List<PropDescriptor> $props = [
_$prop__propMixin1__ExamplePropsMixinClass
];
static const List<String> $propKeys = [
_$key__propMixin1__ExamplePropsMixinClass
];
}

const PropsMeta _$metaForExamplePropsMixinClass = PropsMeta(
fields: $ExamplePropsMixinClass.$props,
keys: $ExamplePropsMixinClass.$propKeys,
);

abstract class $MixesInOtherMixinMixin<T extends Iterable, U>
implements MixesInOtherMixinMixin<T, U> {
@override
Map get props;

static const PropsMeta meta = _$metaForMixesInOtherMixinMixin;

/// <!-- Generated from [MixesInOtherMixinMixin.otherPropMixin] -->
@override
String get otherPropMixin =>
(props[_$key__otherPropMixin__MixesInOtherMixinMixin] ?? null) as String;

/// <!-- Generated from [MixesInOtherMixinMixin.otherPropMixin] -->
@override
set otherPropMixin(String value) =>
props[_$key__otherPropMixin__MixesInOtherMixinMixin] = value;
/* GENERATED CONSTANTS */
static const PropDescriptor _$prop__otherPropMixin__MixesInOtherMixinMixin =
PropDescriptor(_$key__otherPropMixin__MixesInOtherMixinMixin);
static const String _$key__otherPropMixin__MixesInOtherMixinMixin =
'MixesInOtherMixinMixin.otherPropMixin';

static const List<PropDescriptor> $props = [
_$prop__otherPropMixin__MixesInOtherMixinMixin
];
static const List<String> $propKeys = [
_$key__otherPropMixin__MixesInOtherMixinMixin
];
}

const PropsMeta _$metaForMixesInOtherMixinMixin = PropsMeta(
fields: $MixesInOtherMixinMixin.$props,
keys: $MixesInOtherMixinMixin.$propKeys,
);
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
//@dart=2.11
// GENERATED CODE - DO NOT MODIFY BY HAND

// ignore_for_file: deprecated_member_use_from_same_package, unnecessary_null_in_if_null_operators, prefer_null_aware_operators
part of 'state_mixin.dart';

// **************************************************************************
// OverReactBuilder (package:over_react/src/builder.dart)
// **************************************************************************

abstract class $ExampleStateMixinClass implements ExampleStateMixinClass {
@override
Map get state;

static const StateMeta meta = _$metaForExampleStateMixinClass;

/// <!-- Generated from [ExampleStateMixinClass.stateMixin1] -->
@override
String get stateMixin1 =>
(state[_$key__stateMixin1__ExampleStateMixinClass] ?? null) as String;

/// <!-- Generated from [ExampleStateMixinClass.stateMixin1] -->
@override
set stateMixin1(String value) =>
state[_$key__stateMixin1__ExampleStateMixinClass] = value;
/* GENERATED CONSTANTS */
static const StateDescriptor _$prop__stateMixin1__ExampleStateMixinClass =
StateDescriptor(_$key__stateMixin1__ExampleStateMixinClass);
static const String _$key__stateMixin1__ExampleStateMixinClass =
'ExampleStateMixinClass.stateMixin1';

static const List<StateDescriptor> $state = [
_$prop__stateMixin1__ExampleStateMixinClass
];
static const List<String> $stateKeys = [
_$key__stateMixin1__ExampleStateMixinClass
];
}

const StateMeta _$metaForExampleStateMixinClass = StateMeta(
fields: $ExampleStateMixinClass.$state,
keys: $ExampleStateMixinClass.$stateKeys,
);
Original file line number Diff line number Diff line change
@@ -0,0 +1,116 @@
//@dart=2.11
// GENERATED CODE - DO NOT MODIFY BY HAND

// ignore_for_file: deprecated_member_use_from_same_package, unnecessary_null_in_if_null_operators, prefer_null_aware_operators
part of 'library.dart';

// **************************************************************************
// OverReactBuilder (package:over_react/src/builder.dart)
// **************************************************************************

// React component factory implementation.
//
// Registers component implementation and links type meta to builder factory.
final $BasicPartOfLibComponentFactory = registerComponent(
() => _$BasicPartOfLibComponent(),
builderFactory: _$BasicPartOfLib,
componentClass: BasicPartOfLibComponent,
isWrapper: false,
parentType: null,
);

abstract class _$BasicPartOfLibPropsAccessorsMixin
implements _$BasicPartOfLibProps {
@override
Map get props;

/// <!-- Generated from [_$BasicPartOfLibProps.basicProp] -->
@override
String get basicProp =>
(props[_$key__basicProp___$BasicPartOfLibProps] ?? null) as String;

/// <!-- Generated from [_$BasicPartOfLibProps.basicProp] -->
@override
set basicProp(String value) =>
props[_$key__basicProp___$BasicPartOfLibProps] = value;
/* GENERATED CONSTANTS */
static const PropDescriptor _$prop__basicProp___$BasicPartOfLibProps =
PropDescriptor(_$key__basicProp___$BasicPartOfLibProps);
static const String _$key__basicProp___$BasicPartOfLibProps =
'BasicPartOfLibProps.basicProp';

static const List<PropDescriptor> $props = [
_$prop__basicProp___$BasicPartOfLibProps
];
static const List<String> $propKeys = [
_$key__basicProp___$BasicPartOfLibProps
];
}

const PropsMeta _$metaForBasicPartOfLibProps = PropsMeta(
fields: _$BasicPartOfLibPropsAccessorsMixin.$props,
keys: _$BasicPartOfLibPropsAccessorsMixin.$propKeys,
);

class BasicPartOfLibProps extends _$BasicPartOfLibProps
with _$BasicPartOfLibPropsAccessorsMixin {
static const PropsMeta meta = _$metaForBasicPartOfLibProps;
}

_$$BasicPartOfLibProps _$BasicPartOfLib([Map backingProps]) =>
_$$BasicPartOfLibProps(backingProps);

// Concrete props implementation.
//
// Implements constructor and backing map, and links up to generated component factory.
class _$$BasicPartOfLibProps extends _$BasicPartOfLibProps
with _$BasicPartOfLibPropsAccessorsMixin
implements BasicPartOfLibProps {
// This initializer of `_props` to an empty map, as well as the reassignment
// of `_props` in the constructor body is necessary to work around a DDC bug: https://github.com/dart-lang/sdk/issues/36217
_$$BasicPartOfLibProps(Map backingMap) : this._props = {} {
this._props = backingMap ?? {};
}

/// The backing props map proxied by this class.
@override
Map get props => _props;
Map _props;

/// Let `UiProps` internals know that this class has been generated.
@override
bool get $isClassGenerated => true;

/// The `ReactComponentFactory` associated with the component built by this class.
@override
ReactComponentFactoryProxy get componentFactory =>
super.componentFactory ?? $BasicPartOfLibComponentFactory;

/// The default namespace for the prop getters/setters generated for this class.
@override
String get propKeyNamespace => 'BasicPartOfLibProps.';
}

// Concrete component implementation mixin.
//
// Implements typed props/state factories, defaults `consumedPropKeys` to the keys
// generated for the associated props class.
class _$BasicPartOfLibComponent extends BasicPartOfLibComponent {
@override
_$$BasicPartOfLibProps typedPropsFactory(Map backingMap) =>
_$$BasicPartOfLibProps(backingMap);

/// Let `UiComponent` internals know that this class has been generated.
@override
bool get $isClassGenerated => true;

@override
String get displayName => 'BasicPartOfLib';

/// The default consumed props, taken from _$BasicPartOfLibProps.
/// Used in `*ConsumedProps` methods if [consumedProps] is not overridden.
@override
final List<ConsumedProps> $defaultConsumedProps = const [
_$metaForBasicPartOfLibProps
];
}
Loading

0 comments on commit f4cfcd5

Please sign in to comment.