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
33 changes: 33 additions & 0 deletions docs/api/methods.md
Original file line number Diff line number Diff line change
Expand Up @@ -235,3 +235,36 @@ describe('App.tsx', () => {
});
});
```

### reload()

Terminates the app in the emulator/simulator, and restarts it.

This is useful when you want to complete a set of tests and nove onto a new set of tests.

Depending on your use-case, you could call `reload` in a `beforeAll`, or `beforeEach` callback, or within a test case, to get the app into a clean state before each set of tests for example.


#### Example


```js title="__tests__/App.owl.tsx"
import { reload } from 'react-native-owl';

describe('App.tsx', () => {
describe('the checkout flow', () => {
beforeAll(async () => {
// highlight-next-line
await reload();
}),

it('adds product to cart', async () => {
...
});

it('starts checkout flow', async () => {
...
});
});
});
```
Binary file added example/.owl/baseline/android/after-reload.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added example/.owl/baseline/ios/after-reload.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
71 changes: 43 additions & 28 deletions example/__tests__/App.owl.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,56 +6,71 @@ import {
scrollTo,
scrollToEnd,
longPress,
reload,
} from 'react-native-owl';

jest.setTimeout(30000);

describe('App.tsx', () => {
it('takes a screenshot of the initial screen', async () => {
const screen = await takeScreenshot('initial');
describe('Basic navigation', () => {
it('takes a screenshot of the initial screen', async () => {
const screen = await takeScreenshot('initial');

expect(screen).toMatchBaseline();
});
expect(screen).toMatchBaseline();
});

it('longPress a Pressable, then takes a screenshot', async () => {
await longPress('Pressable');
it('longPress a Pressable, then takes a screenshot', async () => {
await longPress('Pressable');

const screen = await takeScreenshot('long-press');
const screen = await takeScreenshot('long-press');

expect(screen).toMatchBaseline();
});
expect(screen).toMatchBaseline();
});

it('press a Pressable, waits for an element then takes a screenshot', async () => {
await press('Pressable');
it('press a Pressable, waits for an element then takes a screenshot', async () => {
await press('Pressable');

await toExist('TextInput');
await toExist('TextInput');

const screen = await takeScreenshot('test-input');
const screen = await takeScreenshot('test-input');

expect(screen).toMatchBaseline();
});
expect(screen).toMatchBaseline();
});

it('enters some text and takes a screenshot', async () => {
await changeText('TextInput', 'Entered text');
it('enters some text and takes a screenshot', async () => {
await changeText('TextInput', 'Entered text');

const screen = await takeScreenshot('entered-text');
const screen = await takeScreenshot('entered-text');

expect(screen).toMatchBaseline();
});
expect(screen).toMatchBaseline();
});

it('scrolls a bit and takes a screenshot', async () => {
await scrollTo('ScrollView', { y: 50 });

const screen = await takeScreenshot('scroll-to');

expect(screen).toMatchBaseline();
});

it('scrolls a bit and takes a screenshot', async () => {
await scrollTo('ScrollView', { y: 50 });
it('scrolls to end and takes a screenshot', async () => {
await scrollToEnd('ScrollView');

const screen = await takeScreenshot('scroll-to');
const screen = await takeScreenshot('scroll-to-end');

expect(screen).toMatchBaseline();
expect(screen).toMatchBaseline();
});
});

it('scrolls to end and takes a screenshot', async () => {
await scrollToEnd('ScrollView');
describe('Reload example', () => {
beforeAll(async () => {
await reload();
});

const screen = await takeScreenshot('scroll-to-end');
it('takes a screenshot of the welcome screen', async () => {
const screen = await takeScreenshot('after-reload');

expect(screen).toMatchBaseline();
expect(screen).toMatchBaseline();
});
});
});
2 changes: 1 addition & 1 deletion example/ios/Podfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -523,4 +523,4 @@ SPEC CHECKSUMS:

PODFILE CHECKSUM: 3190b6d7739c1a0f98e11d88f08dd49936f770e0

COCOAPODS: 1.11.2
COCOAPODS: 1.11.3
2 changes: 1 addition & 1 deletion example/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
"dependencies": {
"react": "17.0.2",
"react-native": "0.66.0",
"react-native-owl": "link:../"
"react-native-owl": "link:.."
},
"devDependencies": {
"@babel/core": "^7.12.9",
Expand Down
65 changes: 65 additions & 0 deletions lib/actions.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,10 @@
import { getConfig } from './cli/config';

import { Logger } from './logger';
import { CliRunOptions } from './types';
import { adbLaunch, adbTerminate } from './utils/adb';
import { waitFor } from './utils/wait-for';
import { xcrunLaunch, xcrunTerminate, xcrunUi } from './utils/xcrun';
import { createWebSocketClient } from './websocket';
import {
SOCKET_TEST_REQUEST,
Expand Down Expand Up @@ -57,3 +63,62 @@ export const scrollToEnd = (testID: string) =>

export const toExist = (testID: string) =>
sendEvent({ type: 'LAYOUT', action: 'EXISTS', testID });

export const reload = async () => {
const args = (global as any).OWL_CLI_ARGS as CliRunOptions;

if (!args) {
return;
}

const config = await getConfig(args.config);

if (args.platform === 'ios') {
if (!config.ios?.device) {
return Promise.reject('Missing device name');
}

await xcrunTerminate({
debug: config.debug,
binaryPath: config.ios?.binaryPath,
device: config.ios.device,
scheme: config.ios?.scheme,
configuration: config.ios?.configuration,
});

await xcrunLaunch({
debug: config.debug,
binaryPath: config.ios?.binaryPath,
device: config.ios.device,
scheme: config.ios?.scheme,
configuration: config.ios?.configuration,
});

await waitFor(1000);

await xcrunUi({
debug: config.debug,
device: config.ios.device,
configuration: config.ios.configuration,
binaryPath: config.ios.binaryPath,
});
}

if (args.platform === 'android') {
if (!config.android?.packageName) {
return Promise.reject('Missing package name');
}

await adbTerminate({
debug: config.debug,
packageName: config.android.packageName,
});

await adbLaunch({
debug: config.debug,
packageName: config.android.packageName,
});

await waitFor(500);
}
};
Loading