-
Notifications
You must be signed in to change notification settings - Fork 7
AF-2152: add more tests to cover additions made in AF-1928 #4
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
Changes from all commits
053e3a7
1829643
a9ab06d
35cd60a
b700267
c266120
ae03264
d305667
4b7e8b4
db2480c
7d81ebb
639dcd3
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
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 | ||
RUN echo "Install codemod" && \ | ||
pip install git+https://github.com/georgelesica-wf/codemod@dart-convert && \ | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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 There was a problem hiding this comment. Choose a reason for hiding this commentThe 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 |
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 |
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)); | ||
} |
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()(); | ||
} |
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 {} |
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 {} |
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 |
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()(); | ||
} |
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 {} |
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 {} |
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 |
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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.