Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 28 additions & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
FROM drydock-prod.workiva.net/workiva/smithy-runner-generator:355624 as build

# Build Environment Vars
ARG BUILD_ID
ARG BUILD_NUMBER
ARG BUILD_URL
ARG GIT_COMMIT
ARG GIT_BRANCH
ARG GIT_TAG
ARG GIT_COMMIT_RANGE
ARG GIT_HEAD_URL
ARG GIT_MERGE_HEAD
ARG GIT_MERGE_BRANCH
WORKDIR /build/
ADD . /build/
ENV TERM=linux
ENV TERMINFO=/etc/terminfo
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I remember you explaining this to me before, but could you remind me why this is needed?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

These are need to run 'migrater.py' within CI so the tests run properly.

RUN echo "Install codemod" && \
pip install git+https://github.com/georgelesica-wf/codemod@dart-convert && \
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

George's PR to codemod was accepted, so I believe we can install the official facebook version of codemod now

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We still need George's branch because they haven't released the changes he made.

echo "done"
RUN echo "Starting the script sections" && \
dart --version && \
pub get && \
pub run dart_dev test && \
echo "Script sections completed"
ARG BUILD_ARTIFACTS_DART-DEPENDENCIES=/build/pubspec.lock
ARG BUILD_ARTIFACTS_BUILD=/build/pubspec.lock
FROM scratch
2 changes: 1 addition & 1 deletion migrater.py
Original file line number Diff line number Diff line change
Expand Up @@ -242,7 +242,7 @@ def props_metas_suggest(lines, path):
if class_body_is_empty:
last_class_def_line = last_class_def_line.replace('{}\n', '{\n')

ignore_line = ' // ignore: undefined_identifier, const_initialized_with_non_constant_value\n'
ignore_line = ' // ignore: undefined_identifier, undefined_class, const_initialized_with_non_constant_value\n'
meta_line = ' static const PropsMeta meta = $metaFor%s;\n' % props_class_name
# debug_line = 'line endings: %s' % line_endings

Expand Down
16 changes: 16 additions & 0 deletions pubspec.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
name: over_react_codemod
description: A tool to convert Over React components from Dart 1 to Dart 2 using Codemod.
version: 0.0.1

environment:
sdk: '>=1.22.1 <3.0.0'

dependencies:
over_react: ^1.25.0

dev_dependencies:
dart_dev: ^1.7.7
dart_style: ^1.0.6
meta: ^1.0.0
mockito: ^2.0.0
test: ^0.12.32+1
64 changes: 64 additions & 0 deletions test/migrater_test.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
import 'dart:async';
import 'dart:io';

import 'package:path/path.dart' as p;
import 'package:test/test.dart';

final pathToMigrater = p.absolute('migrater.py');
final pathToBeforeCodeModTestFixtures = p.absolute('test/test_fixtures/before_codemod/');
final pathToAfterCodeModTestFixtures = p.absolute('test/test_fixtures/after_codemod/');

void main() {
group('Migrater', () {
Directory tempDir;

setUp(() {
tempDir = Directory.systemTemp.createTempSync('over_react_codemod_test_');
});

tearDown(() {
tempDir.deleteSync(recursive: true);
});

test('correctly converts components in parts', () async {
await codeModAndCompare(tempDir, 'component_in_part.dart');
});

test('correctly converts components in a library', () async {
await codeModAndCompare(tempDir, 'component_in_library.dart');
});

test('correctly adds part directive to the generated file in the library file', () async {
await codeModAndCompare(tempDir, 'test_component_library.dart');
});

test('correctly coverts \$PropKeys references', () async {
await codeModAndCompare(tempDir, 'dollar_prop_keys_usages.dart');
});

test('correctly coverts \$Prop references', () async {
await codeModAndCompare(tempDir, 'component_with_multiple_consumed_props.dart');
});
});
}

Future<Null> codeModAndCompare(Directory tempDir, String fileToCodemod) async {
final tempDirPath = tempDir.absolute.path;

/// Copy the file to codemod to the temporary directory.
await Process.run('/bin/bash',
['-c', 'cp -r $fileToCodemod /$tempDirPath'], workingDirectory: pathToBeforeCodeModTestFixtures);

/// Codemod the file within the temporary directory
await Process.start('python', [pathToMigrater], workingDirectory: tempDirPath).then((Process process) async {
await process.stdin.write('A\nA\n');
await process.stdin.close();
await process.exitCode;
});

/// Compare expected results against codemod file in temp directory.
String expectedResults = new File(pathToAfterCodeModTestFixtures + fileToCodemod).readAsStringSync();
String testFile = new File('$tempDirPath/$fileToCodemod').readAsStringSync();

expect(testFile, equals(expectedResults));
}
20 changes: 20 additions & 0 deletions test/test_fixtures/after_codemod/component_in_library.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
import 'package:over_react/over_react.dart';

// ignore: uri_does_not_exist
part 'component_in_library.generated.dart';

@Factory()
// ignore: undefined_identifier
UiFactory<ComponentInLibraryProps> ComponentInLibrary = $ComponentInLibrary;

@Props()
class ComponentInLibraryProps extends UiProps {
// ignore: undefined_identifier, undefined_class, const_initialized_with_non_constant_value
static const PropsMeta meta = $metaForComponentInLibraryProps;
}

@Component()
class ComponentInLibraryComponent extends UiComponent<ComponentInLibraryProps> {
@override
render() => Dom.div()();
}
17 changes: 17 additions & 0 deletions test/test_fixtures/after_codemod/component_in_part.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
part of test_component_library;

@Factory()
// ignore: undefined_identifier
UiFactory<ComponentInPartProps> ComponentInPart = $ComponentInPart;

@Props()
class ComponentInPartProps extends UiProps {
// ignore: undefined_identifier, undefined_class, const_initialized_with_non_constant_value
static const PropsMeta meta = $metaForComponentInPartProps;
}

@Component()
class ComponentInPartComponent extends UiComponent<ComponentInPartProps> {
@override
render() => Dom.div()();
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
import 'package:over_react/over_react.dart';

// ignore: uri_does_not_exist
part 'component_with_multiple_consumed_props.generated.dart';

@Factory()
// ignore: undefined_identifier
UiFactory<ComponentWithMultipleConsumedPropsProps> ComponentWithMultipleConsumedProps = $ComponentWithMultipleConsumedProps;

@Props()
class ComponentWithMultipleConsumedPropsProps extends UiProps {
// ignore: undefined_identifier, undefined_class, const_initialized_with_non_constant_value
static const PropsMeta meta = $metaForComponentWithMultipleConsumedPropsProps;

@requiredProp
var required;

@nullableRequiredProp
var nullable;
}

@Component()
class ComponentWithMultipleConsumedPropsComponent extends UiComponent<ComponentWithMultipleConsumedPropsProps> {
@override
get consumedProps => const [
AbstractToggleInputGroupProps.meta,
ToggleButtonGroupProps.meta,
];

@override
render() => Dom.div()();
}

/// Add these class as a placeholder to eliminate analyzer errors.
/// This will not affect how migrater.py performs.
class AbstractToggleInputGroupProps {}
class ToggleButtonGroupProps {}
27 changes: 27 additions & 0 deletions test/test_fixtures/after_codemod/dollar_prop_keys_usages.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
import 'package:over_react/over_react.dart';
import 'package:test/test.dart';

main() {
group('MockTestCaseComponent', () {
// ignore: undefined_identifier, undefined_function
abstractColorPickerTriggerTests(ColorPickerButton,
primitiveComponentTestId: 'wsd.MockTestCaseComponent.MockTestCaseComponentPrimitve'
);

group('common component functionality:', () {
// ignore: undefined_function
commonComponentTests(
// ignore: undefined_identifier
MockTestCaseComponent,
unconsumedPropKeys: []
..addAll(ButtonPropsMixin.meta.keys)
..addAll(ButtonDisplayPropsMixin.meta.keys)
);
});
});
}

/// Add this class as a placeholder to eliminate analyzer errors.
/// This will not affect how migrater.py performs.
class ButtonPropsMixin {}
class ButtonDisplayPropsMixin {}
6 changes: 6 additions & 0 deletions test/test_fixtures/after_codemod/test_component_library.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
library test_component_library;

import 'package:over_react/over_react.dart';

part 'component_in_part.dart';
part 'component_in_part.generated.dart'; // ignore: uri_does_not_exist
13 changes: 13 additions & 0 deletions test/test_fixtures/before_codemod/component_in_library.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
import 'package:over_react/over_react.dart';

@Factory()
UiFactory<ComponentInLibraryProps> ComponentInLibrary;

@Props()
class ComponentInLibraryProps extends UiProps {}

@Component()
class ComponentInLibraryComponent extends UiComponent<ComponentInLibraryProps> {
@override
render() => Dom.div()();
}
13 changes: 13 additions & 0 deletions test/test_fixtures/before_codemod/component_in_part.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
part of test_component_library;

@Factory()
UiFactory<ComponentInPartProps> ComponentInPart;

@Props()
class ComponentInPartProps extends UiProps {}

@Component()
class ComponentInPartComponent extends UiComponent<ComponentInPartProps> {
@override
render() => Dom.div()();
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
import 'package:over_react/over_react.dart';

@Factory()
UiFactory<ComponentWithMultipleConsumedPropsProps> ComponentWithMultipleConsumedProps;

@Props()
class ComponentWithMultipleConsumedPropsProps extends UiProps {
@requiredProp
var required;

@nullableRequiredProp
var nullable;
}

@Component()
class ComponentWithMultipleConsumedPropsComponent extends UiComponent<ComponentWithMultipleConsumedPropsProps> {
@override
get consumedProps => const [
const $Props(AbstractToggleInputGroupProps),
const $Props(ToggleButtonGroupProps),
];

@override
render() => Dom.div()();
}

/// Add these class as a placeholder to eliminate analyzer errors.
/// This will not affect how migrater.py performs.
class AbstractToggleInputGroupProps {}
class ToggleButtonGroupProps {}
27 changes: 27 additions & 0 deletions test/test_fixtures/before_codemod/dollar_prop_keys_usages.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
import 'package:over_react/over_react.dart';
import 'package:test/test.dart';

main() {
group('MockTestCaseComponent', () {
// ignore: undefined_identifier, undefined_function
abstractColorPickerTriggerTests(ColorPickerButton,
primitiveComponentTestId: 'wsd.MockTestCaseComponent.MockTestCaseComponentPrimitve'
);

group('common component functionality:', () {
// ignore: undefined_function
commonComponentTests(
// ignore: undefined_identifier
MockTestCaseComponent,
unconsumedPropKeys: []
..addAll(const $PropKeys(ButtonPropsMixin))
..addAll(const $PropKeys(ButtonDisplayPropsMixin))
);
});
});
}

/// Add this class as a placeholder to eliminate analyzer errors.
/// This will not affect how migrater.py performs.
class ButtonPropsMixin {}
class ButtonDisplayPropsMixin {}
6 changes: 6 additions & 0 deletions test/test_fixtures/before_codemod/test_component_library.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
library test_component_library;

import 'package:over_react/over_react.dart';

part 'component_in_part.dart';
part 'component_in_part.generated.dart'; // ignore: uri_does_not_exist