Skip to content

Commit ad39f38

Browse files
authored
Convert the Playground app to Typescript (wix#6325)
* Convert the playground app to TypeScript * Switch to eslint from tslint * introduce Prettier with basic config
1 parent 22444b1 commit ad39f38

File tree

131 files changed

+4058
-3601
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

131 files changed

+4058
-3601
lines changed

.eslintignore

+6
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
node_modules/
2+
lib/dist/
3+
website/
4+
autolink/
5+
scripts/
6+
e2e/

.eslintrc.js

+6
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
module.exports = {
2+
root: true,
3+
extends: ['@react-native-community', 'prettier', 'prettier/@typescript-eslint', 'prettier/react'],
4+
parser: '@typescript-eslint/parser',
5+
plugins: ['@typescript-eslint'],
6+
};

.prettierrc

+6
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
{
2+
"semi": true,
3+
"singleQuote": true,
4+
"trailingComma": "es5",
5+
"printWidth": 100
6+
}

babel.config.js

+5-7
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,10 @@
11
module.exports = function (api) {
22
api && api.cache(false);
33
return {
4-
presets: [
5-
"module:metro-react-native-babel-preset"
6-
],
4+
presets: ['module:metro-react-native-babel-preset'],
75
plugins: [
8-
"@babel/plugin-proposal-export-namespace-from",
9-
"@babel/plugin-proposal-export-default-from"
10-
]
6+
'@babel/plugin-proposal-export-namespace-from',
7+
'@babel/plugin-proposal-export-default-from',
8+
],
119
};
12-
}
10+
};

e2e/AndroidUtils.js

+9-3
Original file line numberDiff line numberDiff line change
@@ -3,11 +3,17 @@ const utils = {
33
pressBack: () => utils.pressKeyCode(4),
44
pressMenu: () => utils.pressKeyCode(82),
55
pressKeyCode: (keyCode) => utils.executeShellCommand(`input keyevent ${keyCode}`),
6-
grantPermission: () => utils.executeShellCommand('pm grant com.reactnativenavigation.playground android.permission.READ_PHONE_STATE'),
7-
revokePermission: () => utils.executeShellCommand('pm revoke com.reactnativenavigation.playground android.permission.READ_PHONE_STATE'),
6+
grantPermission: () =>
7+
utils.executeShellCommand(
8+
'pm grant com.reactnativenavigation.playground android.permission.READ_PHONE_STATE'
9+
),
10+
revokePermission: () =>
11+
utils.executeShellCommand(
12+
'pm revoke com.reactnativenavigation.playground android.permission.READ_PHONE_STATE'
13+
),
814
executeShellCommand: (command) => {
915
exec.execSync(`adb -s ${device.id} shell ${command}`);
1016
},
1117
};
1218

13-
module.exports = utils;
19+
export default utils;

e2e/ApplicationLifecycleTest.test.js

+8-8
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,15 @@
1-
const Utils = require('./Utils');
2-
const Android = require('./AndroidUtils');
3-
const TestIDs = require('../playground/src/testIDs');
4-
const includes = require('lodash/includes');
1+
import Utils from './Utils';
2+
import Android from './AndroidUtils';
3+
import TestIDs from '../playground/src/testIDs';
4+
import includes from 'lodash/includes';
55

66
const { elementByLabel, elementById, sleep } = Utils;
77
const IS_RELEASE = includes(process.argv, '--release');
88
const KEY_CODE_R = 46;
99

1010
describe('application lifecycle test', () => {
1111
beforeEach(async () => {
12-
await device.relaunchApp();
12+
await device.launchApp({ newInstance: true });
1313
});
1414

1515
it('push a screen to ensure its not there after reload', async () => {
@@ -26,7 +26,7 @@ describe('application lifecycle test', () => {
2626
await expect(elementByLabel('Pushed Screen')).toBeVisible();
2727

2828
await device.sendToHome();
29-
await device.launchApp();
29+
await device.launchApp({ newInstance: false });
3030

3131
await expect(elementByLabel('Pushed Screen')).toBeVisible();
3232
});
@@ -38,7 +38,7 @@ describe('application lifecycle test', () => {
3838

3939
Android.pressBack();
4040

41-
await device.launchApp();
41+
await device.launchApp({ newInstance: false });
4242
await expect(elementByLabel('Pushed Screen')).toBeNotVisible();
4343
});
4444

@@ -60,7 +60,7 @@ describe('application lifecycle test', () => {
6060

6161
await togglePhonePermission();
6262
await sleep(1000);
63-
await device.launchApp();
63+
await device.launchApp({ newInstance: false });
6464

6565
await expect(elementByLabel('Pushed Screen')).toBeNotVisible();
6666
await expect(elementById(TestIDs.WELCOME_SCREEN_HEADER)).toBeVisible();

e2e/BottomTabs.test.js

+6-5
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,11 @@
1-
const Utils = require('./Utils');
2-
const TestIDs = require('../playground/src/testIDs');
3-
const Android = require('./AndroidUtils');
4-
const { elementByLabel, elementById, sleep } = Utils;
1+
import Utils from './Utils';
2+
import TestIDs from '../playground/src/testIDs';
3+
4+
const { elementByLabel, elementById } = Utils;
5+
56
describe('BottomTabs', () => {
67
beforeEach(async () => {
7-
await device.relaunchApp();
8+
await device.launchApp({ newInstance: true });
89
await elementById(TestIDs.BOTTOM_TABS_BTN).tap();
910
await expect(elementByLabel('First Tab')).toBeVisible();
1011
});

e2e/Buttons.test.js

+3-3
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
1-
const Utils = require('./Utils');
2-
const TestIDs = require('../playground/src/testIDs');
1+
import Utils from './Utils';
2+
import TestIDs from '../playground/src/testIDs';
33

44
const { elementById, elementByLabel } = Utils;
55

66
describe('Buttons', () => {
77
beforeEach(async () => {
8-
await device.relaunchApp();
8+
await device.launchApp({ newInstance: true });
99
await elementById(TestIDs.OPTIONS_TAB).tap();
1010
await elementById(TestIDs.GOTO_BUTTONS_SCREEN).tap();
1111
});

e2e/CustomTransition.js

+4-5
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,11 @@
1+
import Utils from './Utils';
2+
import testIDs from '../playground/src/testIDs';
13

2-
const Utils = require('./Utils');
3-
const testIDs = require('../playground/src/testIDs');
4-
5-
const elementById = Utils.elementById;
4+
const { elementById } = Utils;
65

76
describe(':ios: custom transition', () => {
87
beforeEach(async () => {
9-
await device.relaunchApp();
8+
await device.launchApp({ newInstance: true });
109
});
1110

1211
test('sanity', async () => {

e2e/ExternalComponent.test.js

+3-4
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,11 @@
1-
const Utils = require('./Utils');
2-
const TestIDs = require('../playground/src/testIDs');
3-
const Android = require('./AndroidUtils');
1+
import Utils from './Utils';
2+
import TestIDs from '../playground/src/testIDs';
43

54
const { elementByLabel, elementById } = Utils;
65

76
describe('External Component', () => {
87
beforeEach(async () => {
9-
await device.relaunchApp();
8+
await device.launchApp({ newInstance: true });
109
await elementById(TestIDs.NAVIGATION_TAB).tap();
1110
await elementById(TestIDs.EXTERNAL_COMP_BTN).tap();
1211
});

e2e/Modals.test.js

+5-6
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,12 @@
1-
const Utils = require('./Utils');
2-
const TestIDs = require('../playground/src/testIDs');
3-
const Android = require('./AndroidUtils');
1+
import Utils from './Utils';
2+
import TestIDs from '../playground/src/testIDs';
3+
import Android from './AndroidUtils';
44

55
const { elementByLabel, elementById, sleep } = Utils;
66

77
describe('modal', () => {
88
beforeEach(async () => {
9-
await device.relaunchApp();
9+
await device.launchApp({ newInstance: true });
1010
await elementById(TestIDs.NAVIGATION_TAB).tap();
1111
await elementById(TestIDs.MODAL_BTN).tap();
1212
});
@@ -72,8 +72,7 @@ describe('modal', () => {
7272

7373
await elementById(TestIDs.DISMISS_MODAL_BTN).tap();
7474
await expect(elementById(TestIDs.NAVIGATION_TAB)).toBeVisible();
75-
}
76-
);
75+
});
7776

7877
it('dismiss some modal by id deep in the stack', async () => {
7978
await expect(elementByLabel('Modal Stack Position: 1')).toBeVisible();

e2e/Options.test.js

+3-4
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,11 @@
1-
const Utils = require('./Utils');
2-
const Android = require('./AndroidUtils');
3-
const TestIDs = require('../playground/src/testIDs');
1+
import Utils from './Utils';
2+
import TestIDs from '../playground/src/testIDs';
43

54
const { elementById, elementByLabel } = Utils;
65

76
describe('Options', () => {
87
beforeEach(async () => {
9-
await device.relaunchApp();
8+
await device.launchApp({ newInstance: true });
109
await elementById(TestIDs.OPTIONS_TAB).tap();
1110
});
1211

e2e/Orientation.test.js

+5-19
Original file line numberDiff line numberDiff line change
@@ -1,31 +1,17 @@
1-
2-
const Utils = require('./Utils');
3-
const TestIDs = require('../playground/src/testIDs');
1+
import Utils from './Utils';
2+
import TestIDs from '../playground/src/testIDs';
43

54
const { elementById } = Utils;
65

76
describe(':ios: orientation', () => {
8-
97
beforeEach(async () => {
10-
await device.relaunchApp();
11-
waitForDeviceToSettleAfterOrientationChangeAndroid = ms => new Promise(res => setTimeout(res, device.getPlatform() === 'ios' ? 0 : 400));
8+
await device.launchApp({ newInstance: true });
9+
waitForDeviceToSettleAfterOrientationChangeAndroid = (ms) =>
10+
new Promise((res) => setTimeout(res, device.getPlatform() === 'ios' ? 0 : 400));
1211
await elementById(TestIDs.NAVIGATION_TAB).tap();
1312
await elementById(TestIDs.SHOW_ORIENTATION_SCREEN).tap();
1413
});
1514

16-
it('default allows all', async () => {
17-
await elementById(TestIDs.DEFAULT_ORIENTATION_BTN).tap();
18-
waitForDeviceToSettleAfterOrientationChangeAndroid();
19-
await expect(elementById(TestIDs.PORTRAIT_ELEMENT)).toBeVisible();
20-
await device.setOrientation('landscape');
21-
waitForDeviceToSettleAfterOrientationChangeAndroid();
22-
await expect(elementById(TestIDs.LANDSCAPE_ELEMENT)).toBeVisible();
23-
await device.setOrientation('portrait');
24-
waitForDeviceToSettleAfterOrientationChangeAndroid();
25-
await expect(elementById(TestIDs.PORTRAIT_ELEMENT)).toBeVisible();
26-
await elementById(TestIDs.DISMISS_BTN).tap();
27-
});
28-
2915
it('landscape and portrait array', async () => {
3016
await elementById(TestIDs.LANDSCAPE_PORTRAIT_ORIENTATION_BTN).tap();
3117
await expect(element(by.id(TestIDs.PORTRAIT_ELEMENT))).toBeVisible();

e2e/Overlay.test.js

+4-3
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,11 @@
1-
const Utils = require('./Utils');
2-
const TestIDs = require('../playground/src/testIDs');
1+
import Utils from './Utils';
2+
import TestIDs from '../playground/src/testIDs';
3+
34
const { elementByLabel, elementById } = Utils;
45

56
describe('Overlay', () => {
67
beforeEach(async () => {
7-
await device.relaunchApp();
8+
await device.launchApp({ newInstance: true });
89
await elementById(TestIDs.NAVIGATION_TAB).tap();
910
await elementById(TestIDs.OVERLAY_BTN).tap();
1011
});

e2e/SetRoot.test.js

+4-3
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,11 @@
1-
const Utils = require('./Utils');
2-
const TestIDs = require('../playground/src/testIDs');
1+
import Utils from './Utils';
2+
import TestIDs from '../playground/src/testIDs';
3+
34
const { elementById } = Utils;
45

56
describe('SetRoot', () => {
67
beforeEach(async () => {
7-
await device.relaunchApp();
8+
await device.launchApp({ newInstance: true });
89
await elementById(TestIDs.NAVIGATION_TAB).tap();
910
await elementById(TestIDs.SET_ROOT_BTN).tap();
1011
});

e2e/SideMenu.test.js

+4-3
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,11 @@
1-
const Utils = require('./Utils');
2-
const TestIDs = require('../playground/src/testIDs');
1+
import Utils from './Utils';
2+
import TestIDs from '../playground/src/testIDs';
3+
34
const { elementByLabel, elementById } = Utils;
45

56
describe('SideMenu', () => {
67
beforeEach(async () => {
7-
await device.relaunchApp();
8+
await device.launchApp({ newInstance: true });
89
await elementById(TestIDs.SIDE_MENU_BTN).tap();
910
});
1011

e2e/SplitView.test.js

+4-3
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,12 @@
1-
const Utils = require('./Utils');
2-
const TestIDs = require('../playground/src/testIDs');
1+
import Utils from './Utils';
2+
import TestIDs from '../playground/src/testIDs';
3+
34
const cocktailsList = require('../playground/src/assets/cocktails').default;
45
const { elementByLabel, elementById } = Utils;
56

67
describe(':ios: SplitView', () => {
78
beforeEach(async () => {
8-
await device.relaunchApp();
9+
await device.launchApp({ newInstance: true });
910
await elementById(TestIDs.SPLIT_VIEW_BUTTON).tap();
1011
});
1112

e2e/Stack.test.js

+7-5
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,12 @@
1-
const Utils = require('./Utils');
2-
const TestIDs = require('../playground/src/testIDs');
1+
import Utils from './Utils';
2+
import TestIDs from '../playground/src/testIDs';
3+
import Android from './AndroidUtils';
4+
35
const { elementByLabel, elementById, sleep } = Utils;
4-
const Android = require('./AndroidUtils');
56

67
describe('Stack', () => {
78
beforeEach(async () => {
8-
await device.relaunchApp();
9+
await device.launchApp({ newInstance: true });
910
await elementById(TestIDs.STACK_BTN).tap();
1011
});
1112

@@ -100,7 +101,8 @@ describe('Stack', () => {
100101
await expect(elementByLabel('Stack Position: 2')).toBeVisible();
101102
});
102103

103-
xit(':ios: set searchBar and handle onSearchUpdated event', async () => { // Broken on iOS 13
104+
xit(':ios: set searchBar and handle onSearchUpdated event', async () => {
105+
// Broken on iOS 13
104106
await elementById(TestIDs.SEARCH_BTN).tap();
105107
await expect(elementByLabel('Start Typing')).toBeVisible();
106108
await elementByLabel('Start Typing').tap();

e2e/StaticLifecycleEvents.test.js

+13-6
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,11 @@
1-
const Utils = require('./Utils');
2-
const TestIDs = require('../playground/src/testIDs');
1+
import Utils from './Utils';
2+
import TestIDs from '../playground/src/testIDs';
3+
34
const { elementByLabel, elementById } = Utils;
45

56
describe('static lifecycle events', () => {
67
beforeEach(async () => {
7-
await device.relaunchApp();
8+
await device.launchApp({ newInstance: true });
89
await elementById(TestIDs.NAVIGATION_TAB).tap();
910
await elementById(TestIDs.SHOW_STATIC_EVENTS_SCREEN).tap();
1011
await elementById(TestIDs.STATIC_EVENTS_OVERLAY_BTN).tap();
@@ -46,9 +47,13 @@ describe('static lifecycle events', () => {
4647
await elementById(TestIDs.PUSH_OPTIONS_BUTTON).tap();
4748
await elementById(TestIDs.CLEAR_OVERLAY_EVENTS_BTN).tap();
4849
await elementById(TestIDs.GOTO_BUTTONS_SCREEN).tap();
49-
await expect(elementByLabel('componentDidAppear | CustomRoundedButton | TopBarButton')).toBeVisible();
50+
await expect(
51+
elementByLabel('componentDidAppear | CustomRoundedButton | TopBarButton')
52+
).toBeVisible();
5053
await elementById(TestIDs.RESET_BUTTONS).tap();
51-
await expect(elementByLabel('componentDidDisappear | CustomRoundedButton | TopBarButton')).toBeVisible();
54+
await expect(
55+
elementByLabel('componentDidDisappear | CustomRoundedButton | TopBarButton')
56+
).toBeVisible();
5257
});
5358

5459
it('top bar title didAppear didDisappear', async () => {
@@ -58,7 +63,9 @@ describe('static lifecycle events', () => {
5863
await elementById(TestIDs.SET_REACT_TITLE_VIEW).tap();
5964
await expect(elementByLabel('componentDidAppear | ReactTitleView | TopBarTitle')).toBeVisible();
6065
await elementById(TestIDs.PUSH_BTN).tap();
61-
await expect(elementByLabel('componentDidDisappear | ReactTitleView | TopBarTitle')).toBeVisible();
66+
await expect(
67+
elementByLabel('componentDidDisappear | ReactTitleView | TopBarTitle')
68+
).toBeVisible();
6269
});
6370

6471
it('unmounts previous root before resolving setRoot promise', async () => {

0 commit comments

Comments
 (0)