Skip to content

Commit

Permalink
feat(config): drop support for the all-in-one configuration format
Browse files Browse the repository at this point in the history
BREAKING: please migrate to the new { apps, devices, configurations }
schema that Detox has been already using for more than a year.
  • Loading branch information
noomorph committed May 12, 2022
1 parent 750f318 commit 319566b
Show file tree
Hide file tree
Showing 25 changed files with 614 additions and 575 deletions.
4 changes: 4 additions & 0 deletions .editorconfig
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,10 @@ trim_trailing_whitespace = true
indent_size = 2
tab_width = 2

[detox/index.d.ts]
indent_size = 4
tab_width = 4

[{*.cjs,*.js}]
indent_size = 2
tab_width = 2
Expand Down
125 changes: 60 additions & 65 deletions detox/index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ declare global {
namespace Detox {
// region DetoxConfig

interface DetoxConfig {
interface DetoxConfig extends DetoxConfigurationCommon {
/**
* @example extends: './relative/detox.config'
* @example extends: '@my-org/detox-preset'
Expand All @@ -51,15 +51,18 @@ declare global {
* @example specs: 'detoxE2E'
*/
specs?: string;
artifacts?: DetoxArtifactsConfig;
behavior?: DetoxBehaviorConfig;
session?: DetoxSessionConfig;
apps?: Record<string, DetoxAppConfig>;
devices?: Record<string, DetoxDeviceConfig>;
selectedConfiguration?: string;
configurations: Record<string, DetoxConfiguration>;
}

type DetoxConfigurationCommon = {
artifacts?: false | DetoxArtifactsConfig;
behavior?: DetoxBehaviorConfig;
session?: DetoxSessionConfig;
};

interface DetoxArtifactsConfig {
rootDir?: string;
pathBuilder?: string;
Expand Down Expand Up @@ -107,7 +110,7 @@ declare global {
sessionId?: string;
}

type DetoxAppConfig = (DetoxIosAppConfig | DetoxAndroidAppConfig) & {
type DetoxAppConfig = (DetoxBuiltInAppConfig | DetoxCustomAppConfig) & {
/**
* App name to use with device.selectApp(appName) calls.
* Can be omitted if you have a single app under the test.
Expand All @@ -119,8 +122,6 @@ declare global {

type DetoxDeviceConfig = DetoxBuiltInDeviceConfig | DetoxCustomDriverConfig;

type DetoxConfiguration = DetoxPlainConfiguration | DetoxAliasedConfiguration;

interface DetoxLogArtifactsPluginConfig {
enabled?: boolean;
keepOnlyFailedTestsArtifacts?: boolean;
Expand Down Expand Up @@ -164,6 +165,8 @@ declare global {
enabled?: boolean;
}

type DetoxBuiltInAppConfig = (DetoxIosAppConfig | DetoxAndroidAppConfig);

interface DetoxIosAppConfig {
type: 'ios.app';
binaryPath: string;
Expand All @@ -181,27 +184,17 @@ declare global {
launchArgs?: Record<string, any>;
}

interface _DetoxAppConfigFragment {
binaryPath: string;
bundleId?: string;
build?: string;
testBinaryPath?: string;
launchArgs?: Record<string, any>;
interface DetoxCustomAppConfig {
type: string;

[prop: string]: unknown;
}

type DetoxBuiltInDeviceConfig =
| DetoxIosSimulatorDriverConfig
| DetoxAttachedAndroidDriverConfig
| DetoxAndroidEmulatorDriverConfig
| DetoxGenymotionCloudDriverConfig;

type DetoxPlainConfiguration = DetoxConfigurationOverrides & (
| (DetoxIosSimulatorDriverConfig & _DetoxAppConfigFragment)
| (DetoxAttachedAndroidDriverConfig & _DetoxAppConfigFragment)
| (DetoxAndroidEmulatorDriverConfig & _DetoxAppConfigFragment)
| (DetoxGenymotionCloudDriverConfig & _DetoxAppConfigFragment)
| (DetoxCustomDriverConfig)
);
| DetoxIosSimulatorDriverConfig
| DetoxAttachedAndroidDriverConfig
| DetoxAndroidEmulatorDriverConfig
| DetoxGenymotionCloudDriverConfig;

interface DetoxIosSimulatorDriverConfig {
type: 'ios.simulator';
Expand Down Expand Up @@ -251,30 +244,25 @@ declare global {

type DetoxKnownDeviceType = DetoxBuiltInDeviceConfig['type'];

type DetoxConfigurationOverrides = {
artifacts?: false | DetoxArtifactsConfig;
behavior?: DetoxBehaviorConfig;
session?: DetoxSessionConfig;
};

type DetoxAliasedConfiguration =
| DetoxAliasedConfigurationSingleApp
| DetoxAliasedConfigurationMultiApps;
type DetoxConfiguration = DetoxConfigurationCommon & (
| DetoxConfigurationSingleApp
| DetoxConfigurationMultiApps
);

interface DetoxAliasedConfigurationSingleApp {
type?: never;
interface DetoxConfigurationSingleApp {
device: DetoxAliasedDevice;
app: string | DetoxAppConfig;
app: DetoxAliasedApp;
}

interface DetoxAliasedConfigurationMultiApps {
type?: never;
interface DetoxConfigurationMultiApps {
device: DetoxAliasedDevice;
apps: string[];
apps: DetoxAliasedApp[];
}

type DetoxAliasedDevice = string | DetoxDeviceConfig;

type DetoxAliasedApp = string | DetoxAppConfig;

// endregion DetoxConfig

// Detox exports all methods from detox global and all of the global constants.
Expand Down Expand Up @@ -458,13 +446,13 @@ declare global {
*/
launchApp(config?: DeviceLaunchAppConfig): Promise<void>;

/**
* Relaunch the app. Convenience method that calls {@link Device#launchApp}
* with { newInstance: true } override.
*
* @param config
* @see Device#launchApp
*/
/**
* Relaunch the app. Convenience method that calls {@link Device#launchApp}
* with { newInstance: true } override.
*
* @param config
* @see Device#launchApp
*/
relaunchApp(config?: Omit<DeviceLaunchAppConfig, 'newInstance'>): Promise<void>;

/**
Expand Down Expand Up @@ -492,6 +480,7 @@ declare global {
* @see AppLaunchArgs
*/
appLaunchArgs: AppLaunchArgs;

/**
* Terminate the app.
*
Expand Down Expand Up @@ -856,11 +845,13 @@ declare global {
* @example await element(by.text('Product').and(by.id('product_name'));
*/
and(by: NativeMatcher): NativeMatcher;

/**
* Find an element by a matcher with a parent matcher
* @example await element(by.id('Grandson883').withAncestor(by.id('Son883')));
*/
withAncestor(parentBy: NativeMatcher): NativeMatcher;

/**
* Find an element by a matcher with a child matcher
* @example await element(by.id('Son883').withDescendant(by.id('Grandson883')));
Expand All @@ -874,6 +865,7 @@ declare global {

interface ExpectFacade {
(element: NativeElement): Expect;

(webElement: WebElement): WebExpect;
}

Expand Down Expand Up @@ -968,6 +960,7 @@ declare global {
* @example await expect(element(by.id('switch'))).toHaveToggleValue(true);
*/
toHaveToggleValue(value: boolean): R;

/**
* Expect components like a Switch to have a value ('0' for off, '1' for on).
* @example await expect(element(by.id('UniqueId533'))).toHaveValue('0');
Expand Down Expand Up @@ -1004,6 +997,7 @@ declare global {
* @example await waitFor(element(by.text('Text5'))).toBeVisible().whileElement(by.id('ScrollView630')).scroll(50, 'down');
*/
whileElement(by: NativeMatcher): NativeElement & WaitFor;

// TODO: not sure about & WaitFor - check if we can chain whileElement multiple times
}

Expand All @@ -1029,6 +1023,7 @@ declare global {
*/
longPressAndDrag(duration: number, normalizedPositionX: number, normalizedPositionY: number, targetElement: NativeElement,
normalizedTargetPositionX: number, normalizedTargetPositionY: number, speed: Speed, holdDuration: number): Promise<void>;

/**
* Simulate multiple taps on an element.
* @param times number of times to tap
Expand Down Expand Up @@ -1084,18 +1079,18 @@ declare global {
* @example await element(by.id('scrollView')).scroll(100, 'up');
*/
scroll(
pixels: number,
direction: Direction,
startPositionX?: number,
startPositionY?: number,
pixels: number,
direction: Direction,
startPositionX?: number,
startPositionY?: number
): Promise<void>;

/**
* Scroll to index.
* @example await element(by.id('scrollView')).scrollToIndex(10);
*/
scrollToIndex(
index: Number
index: Number
): Promise<void>;

/**
Expand Down Expand Up @@ -1184,7 +1179,7 @@ declare global {
* // * on failure, to: <artifacts-location>/✗ Menu items should have Logout/tap on menu.png
* });
*/
takeScreenshot(name: string): Promise<string>;
takeScreenshot(name: string): Promise<string>;

/**
* Gets the native (OS-dependent) attributes of the element.
Expand All @@ -1202,7 +1197,7 @@ declare global {
* jestExpect(attributes.width).toHaveValue(100);
* })
*/
getAttributes(): Promise<IosElementAttributes | AndroidElementAttributes | { elements: IosElementAttributes[]; }>;
getAttributes(): Promise<IosElementAttributes | AndroidElementAttributes | { elements: IosElementAttributes[]; }>;
}

interface WebExpect<R = Promise<void>> {
Expand All @@ -1218,7 +1213,7 @@ declare global {
* @example
* await expect(web.element(by.web.id('UniqueId205'))).toHaveText('ExactText');
*/
toHaveText(text: string): R
toHaveText(text: string): R;

/**
* Expect the view to exist in the webview DOM tree.
Expand All @@ -1239,56 +1234,56 @@ declare global {
}

interface WebElementActions {
tap(): Promise<void>
tap(): Promise<void>;

/**
* @param text to type
* @param isContentEditable whether its a ContentEditable element, default is false.
*/
typeText(text: string, isContentEditable: boolean): Promise<void>
typeText(text: string, isContentEditable: boolean): Promise<void>;

/**
* At the moment not working on content-editable
* @param text to replace with the old content.
*/
replaceText(text: string): Promise<void>
replaceText(text: string): Promise<void>;

/**
* At the moment not working on content-editable
*/
clearText(): Promise<void>
clearText(): Promise<void>;

/**
* scrolling to the view, the element top position will be at the top of the screen.
*/
scrollToView(): Promise<void>
scrollToView(): Promise<void>;

/**
* Gets the input content
*/
getText(): Promise<string>
getText(): Promise<string>;

/**
* Calls the focus function on the element
*/
focus(): Promise<void>
focus(): Promise<void>;

/**
* Selects all the input content, works on ContentEditable at the moment.
*/
selectAllText(): Promise<void>
selectAllText(): Promise<void>;

/**
* Moves the input cursor / caret to the end of the content, works on ContentEditable at the moment.
*/
moveCursorToEnd(): Promise<void>
moveCursorToEnd(): Promise<void>;

/**
* Running a script on the element
* @param script a method that accept the element as its first arg
* @example function foo(element) { console.log(element); }
*/
runScript(script: string): Promise<any>
runScript(script: string): Promise<any>;

/**
* Running a script on the element that accept args
Expand Down
Loading

0 comments on commit 319566b

Please sign in to comment.