Skip to content
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

[Detox 20] feat: new global lifecycle for Detox #3333

Merged
merged 88 commits into from
Sep 5, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
88 commits
Select commit Hold shift + click to select a range
c04e9b8
wip: move to global lifecycle
noomorph May 17, 2022
0c0f356
wip: implement new testRunner section
noomorph May 25, 2022
1379f6a
wip: revive worker context
noomorph May 27, 2022
e50198a
wip: fix tests and hanging workers
noomorph Jun 6, 2022
35a9f02
wip: refine Detox facade
noomorph Jun 7, 2022
e114d05
wip: fix naming
noomorph Jun 7, 2022
e6dc82b
wip: reuse primary <-> seconary contexts
noomorph Jun 7, 2022
789bba1
wip: restore loggers
noomorph Jun 7, 2022
d758314
fix: init/cleanup signature and child logging
noomorph Jun 8, 2022
933ed02
wip: move to Bunyan-only and implement logger config
noomorph Jun 10, 2022
dcdb1b6
wip: fix IPC session state management
noomorph Jun 21, 2022
e04113a
test: fix mocks
noomorph Jun 21, 2022
536779b
wip: finalize log artifacts
noomorph Jun 21, 2022
93c7f57
test: fix missing logs
noomorph Jun 21, 2022
8b01c24
wip: add jest.reportSpecs section
noomorph Jun 21, 2022
5034ece
wip: unite logs
noomorph Jun 23, 2022
b956139
wip: prepare log stream to splitting
noomorph Jun 23, 2022
5ce4644
wip: add logger debug stream
noomorph Jun 23, 2022
cad0ce9
wip: pass Detox state in file for instant boot
noomorph Jun 23, 2022
09b677c
wip: restore platformSpecificFilter
noomorph Jun 24, 2022
ddb411a
wip: almost fixed spawn except for rare DETOX_ARGV_OVERRIDE cases
noomorph Jun 24, 2022
7b6cb2d
wip: rewrite local-cli/test integration tests
noomorph Jun 24, 2022
046a031
fix escaping issue
noomorph Jun 24, 2022
f4fe8f8
wip: write trace events to log
noomorph Jul 1, 2022
0da5fe8
wip: finish trace implementation
noomorph Jul 3, 2022
735c6bc
wip: poc of trace timeline
noomorph Jul 3, 2022
e3dda13
wip: Win32 fixes
noomorph Jul 4, 2022
9d7832d
temp: disable coverage
noomorph Jul 4, 2022
00a6c8a
improve tracing and streams
noomorph Jul 4, 2022
c29c5e0
fix: duplicate logs
noomorph Jul 4, 2022
3a1638d
temp: disable timeline integration test
noomorph Jul 4, 2022
971d294
ci: fix build
noomorph Jul 4, 2022
0fdcfca
wip: implement internal status check
noomorph Jul 7, 2022
b4f3cd1
test: fix unit tests
noomorph Jul 7, 2022
4974687
test: fix integration test
noomorph Jul 8, 2022
8e4f947
fix: rework init/cleanup
noomorph Jul 9, 2022
c536b9f
remove tight dependencies on env vars
noomorph Jul 9, 2022
2bc179a
ci: simplify scripts via config
noomorph Jul 9, 2022
41603b6
fix: restore DetoxConstants in facade
noomorph Jul 11, 2022
754fa8c
fix(ios): headless mode
noomorph Jul 11, 2022
f6102ec
ci: fix config
noomorph Jul 11, 2022
cf667c0
fix: cli, e2e-unhappy and etc
noomorph Jul 11, 2022
ff0e417
fix: override console, hang up for --listTests in Jest, and test file…
noomorph Jul 11, 2022
2107fec
fix: logger file cleanup
noomorph Jul 11, 2022
54236d6
fix: logger leakage
noomorph Jul 11, 2022
7a2d075
fix: test pattern
noomorph Jul 11, 2022
7e4aab2
test: fix eventemitter leakage
noomorph Jul 11, 2022
cf97f67
ci: guarantee artifacts recording
noomorph Jul 12, 2022
5ba0329
ci: remove upload artifacts
noomorph Jul 12, 2022
9ffb7d7
fix: eventemitter leakage
noomorph Jul 12, 2022
3340bec
ci: fix artifact uploading for android
noomorph Jul 12, 2022
e96a378
more fixes
noomorph Jul 12, 2022
e342b34
wip: reworking facade again
noomorph Jul 13, 2022
548f199
ci: fix upload artifacts script
noomorph Jul 13, 2022
5430be7
docs: add UML sequence diagrams
noomorph Jul 14, 2022
0591c58
rewrite facade again
noomorph Jul 17, 2022
bbafe03
fix: retries JSON behavior and CI
noomorph Jul 17, 2022
f6f9279
testEnvironment path change, testRunner section fixes
noomorph Jul 18, 2022
ca6f13d
fix: logger
noomorph Jul 18, 2022
f2d5a1e
test: fix unhappy scenario
noomorph Jul 18, 2022
416effe
fix: retries cli and example project
noomorph Jul 18, 2022
f17d45b
temp: debugging ci
noomorph Jul 18, 2022
e89c826
Publish 20.0.0-breaking.new-global-lifecycle.0 [ci skip]
mobile1-internal Jul 19, 2022
841fd4e
test: add typing tests
noomorph Jul 18, 2022
43f2eab
fix: reporting failed tests
noomorph Aug 9, 2022
1f07f14
fix: multiapp installation bug
noomorph Aug 9, 2022
e2c5a03
Merge branch 'next' into breaking/new-global-lifecycle
noomorph Aug 10, 2022
b057924
Publish 20.0.1-breaking.new-global-lifecycle.0 [ci skip]
mobile1-internal Aug 10, 2022
7c4fb9f
fix(cli): --retries <N> + jest.retryTimes() cooperation
noomorph Aug 11, 2022
cda5a55
Publish 20.0.2-breaking.new-global-lifecycle.0 [ci skip]
mobile1-internal Aug 12, 2022
fbaf0f3
fix(config): add legacy handling for test-runner
noomorph Aug 12, 2022
6eb5c15
Merge branch 'next' into breaking/new-global-lifecycle
noomorph Aug 12, 2022
b0d1f2e
fix: make Detox runtime config key names identical to Detox static co…
noomorph Aug 12, 2022
1e9a8a5
Publish 20.0.3-breaking.new-global-lifecycle.0 [ci skip]
mobile1-internal Aug 15, 2022
214e447
fix: solve global lifecycle issue
noomorph Aug 15, 2022
5a4d2fa
Publish 20.0.4-breaking.new-global-lifecycle.0 [ci skip]
mobile1-internal Aug 15, 2022
ba14549
ci: bump
noomorph Aug 15, 2022
5001e8c
rename workerId -> workerIndex, minor fixes
noomorph Aug 17, 2022
ed4ea43
remove dead code
noomorph Aug 17, 2022
69e14c1
fix: kill signal handling
noomorph Aug 17, 2022
e7acceb
refactor: rename facade
noomorph Aug 17, 2022
eb11a9b
fix: test lifecycle
noomorph Aug 24, 2022
88eb9ce
refactor: logger and tracer (#3569)
noomorph Sep 4, 2022
e299576
Publish 20.0.5-breaking.new-global-lifecycle.0 [ci skip]
mobile1-internal Sep 4, 2022
0e5a6e9
fix: logger
noomorph Sep 5, 2022
5ba8a75
fix: 50 char limitation in BI ecosystem
noomorph Sep 5, 2022
29baf7c
Publish 20.0.6-breaking.new-global-lifecycle.0 [ci skip]
mobile1-internal Sep 5, 2022
c35671f
fix: test env resolution
noomorph Sep 5, 2022
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
4 changes: 3 additions & 1 deletion detox/__tests__/setupJest.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
jest.mock('proper-lockfile');
jest.mock('signal-exit');
jest.mock('../src/logger/DetoxLogger');

const path = require('path');

Expand Down Expand Up @@ -36,5 +38,5 @@ function callCli(modulePath, cmd) {
});
}

// @ts-ignore
global.callCli = callCli;
global.IS_RUNNING_DETOX_UNIT_TESTS = true;
219 changes: 161 additions & 58 deletions detox/index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@
// * Max Komarychev <https://github.com/maxkomarychev>
// * Dor Ben Baruch <https://github.com/Dor256>

import { BunyanDebugStreamOptions } from 'bunyan-debug-stream';

declare global {
const device: Detox.DetoxExportWrapper['device'];
const element: Detox.DetoxExportWrapper['element'];
Expand Down Expand Up @@ -36,21 +38,7 @@ declare global {
* @example extends: '@my-org/detox-preset'
*/
extends?: string;
/**
* Override test runner binary command.
* @default 'jest'
*/
testRunner?: string;
/**
* @example runnerConfig: 'e2e/config.js'
*/
runnerConfig?: string;
/**
* Optional. A default glob pattern for a test runner to use when no test files are specified.
*
* @example specs: 'detoxE2E'
*/
specs?: string;

apps?: Record<string, DetoxAppConfig>;
devices?: Record<string, DetoxDeviceConfig>;
selectedConfiguration?: string;
Expand All @@ -60,7 +48,9 @@ declare global {
type DetoxConfigurationCommon = {
artifacts?: false | DetoxArtifactsConfig;
behavior?: DetoxBehaviorConfig;
logger?: DetoxLoggerConfig;
session?: DetoxSessionConfig;
testRunner?: DetoxTestRunnerConfig;
};

interface DetoxArtifactsConfig {
Expand All @@ -71,7 +61,6 @@ declare global {
screenshot?: 'none' | 'manual' | 'failing' | 'all' | DetoxScreenshotArtifactsPluginConfig;
video?: 'none' | 'failing' | 'all' | DetoxVideoArtifactsPluginConfig;
instruments?: 'none' | 'all' | DetoxInstrumentsArtifactsPluginConfig;
timeline?: 'none' | 'all' | DetoxTimelineArtifactsPluginConfig;
uiHierarchy?: 'disabled' | 'enabled' | DetoxUIHierarchyArtifactsPluginConfig;

[pluginId: string]: unknown;
Expand All @@ -91,25 +80,85 @@ declare global {
*/
exposeGlobals?: boolean;
/**
* By default, `await detox.init()` will uninstall and install the app.
* By default, Detox will uninstall and install the app upon the initialization.
* If you wish to reuse the existing app for a faster run, set the property to
* `false`.
*/
reinstallApp?: boolean;
/**
* If you wish to run multiple "detox test" commands in parallel,
* make sure they don't delete the shared lock file – only the
* first command should reset the lock file.
*
* @default false
*/
keepLockFile?: boolean;
};
launchApp?: 'auto' | 'manual';
cleanup?: {
shutdownDevice?: boolean;
};
}

interface DetoxLoggerConfig {
level?: DetoxLogLevel;
/**
* @default 'sandbox'
*/
overrideConsole?: 'all' | 'sandbox' | 'none';
options?: BunyanDebugStreamOptions | ((config: Partial<DetoxLoggerConfig>) => BunyanDebugStreamOptions);
}

interface DetoxSessionConfig {
autoStart?: boolean;
debugSynchronization?: number;
server?: string;
sessionId?: string;
}

interface DetoxTestRunnerConfig {
args?: {
/**
* The command to use for runner: 'jest', 'nyc jest',
*/
$0: string;
/**
* The positional arguments to pass to the runner.
*/
_?: string[];
/**
* Any other properties recognized by test runner
*/
[prop: string]: unknown;
};
/**
* Configuration of custom integration features
* between Detox and Jest
*/
jest?: {
/**
* Device init timeout
*/
initTimeout?: number | undefined;
/**
* Insist on CLI-based retry mechanism even when the failed tests have been handled
* by jest.retryTimes(n) mechanism from Jest Circus.
*/
retryAfterCircusRetries?: boolean;
reportSpecs?: boolean | undefined;
reportWorkerAssign?: boolean | undefined;
};
/**
* Retries count. Zero means a single attempt to run tests.
*/
retries?: number;
/**
* Custom handler to process --inspect-brk CLI flag.
* Use it when you rely on another test runner than Jest.
*/
inspectBrk?: boolean | ((config: DetoxTestRunnerConfig) => void);
}

type DetoxAppConfig = (DetoxBuiltInAppConfig | DetoxCustomAppConfig) & {
/**
* App name to use with device.selectApp(appName) calls.
Expand Down Expand Up @@ -161,10 +210,6 @@ declare global {
enabled?: boolean;
}

interface DetoxTimelineArtifactsPluginConfig {
enabled?: boolean;
}

type DetoxBuiltInAppConfig = (DetoxIosAppConfig | DetoxAndroidAppConfig);

interface DetoxIosAppConfig {
Expand Down Expand Up @@ -216,7 +261,7 @@ declare global {
type: 'android.emulator';
device: string | { avdName: string };
bootArgs?: string;
gpuMode?: 'auto' | 'host' | 'swiftshader_indirect' | 'angle_indirect' | 'guest';
gpuMode?: 'auto' | 'host' | 'swiftshader_indirect' | 'angle_indirect' | 'guest' | 'off';
headless?: boolean;
/**
* @default true
Expand Down Expand Up @@ -265,51 +310,111 @@ declare global {

// endregion DetoxConfig

// Detox exports all methods from detox global and all of the global constants.
interface DetoxInstance {
device: Device;
element: ElementFacade;
waitFor: WaitForFacade;
expect: ExpectFacade;
by: ByFacade;
web: WebFacade;
}
interface DetoxExportWrapper {
readonly device: Device;

interface DetoxExportWrapper extends DetoxInstance {
/**
* The setup phase happens inside detox.init(). This is the phase where detox reads its configuration, starts a server, loads its expection library and starts a simulator
*
* @param configOverride - this object is deep-merged with the selected Detox configuration from .detoxrc
* @example
* beforeAll(async () => {
* await detox.init();
* });
*/
init(configOverride?: Partial<DetoxConfig>): Promise<void>;
readonly element: ElementFacade;

readonly waitFor: WaitForFacade;

readonly expect: ExpectFacade;

readonly by: ByFacade;

beforeEach(...args: any[]): Promise<void>;
readonly web: WebFacade;

afterEach(...args: any[]): Promise<void>;
readonly DetoxConstants: {
userNotificationTriggers: {
push: 'push';
calendar: 'calendar';
timeInterval: 'timeInterval';
location: 'location';
};
userActivityTypes: {
searchableItem: string;
browsingWeb: string;
},
searchableItemActivityIdentifier: string;
};

/**
* The cleanup phase should happen after all the tests have finished.
* This is the phase where the Detox server shuts down.
*
* @example
* after(async () => {
* await detox.cleanup();
* });
* Detox logger instance. Can be used for saving user logs to the general log file.
*/
cleanup(): Promise<void>;
readonly log: Logger;

/**
* Unstable. API to access an assembled detox config before it gets passed to testRunner
* or detox.init(). Use it only if you don't have another option.
* @internal
* @deprecated
*
* Deprecated - use {@link Detox.Logger#trace}
* Detox tracer instance. Can be used for building timelines in Google Event Tracing format.
*/
readonly trace: {
/** @deprecated */
readonly startSection: (name: string) => void;
/** @deprecated */
readonly endSection: (name: string) => void;
};

/**
* @deprecated
*/
hook(event: 'UNSAFE_configReady', listener: (config: unknown) => void): void;
readonly traceCall: <T>(event: string, action: () => Promise<T>) => Promise<T>;
}

interface Logger {
readonly level: DetoxLogLevel;

readonly fatal: _LogMethod;
readonly error: _LogMethod;
readonly warn: _LogMethod;
readonly info: _LogMethod;
readonly debug: _LogMethod;
readonly trace: _LogMethod;

child(context?: Partial<LogEvent>): Logger;
}

/** @internal */
interface _LogMethod extends _LogMethodSignature {
readonly begin: _LogMethodSignature;
readonly complete: _CompleteMethodSignature;
readonly end: _LogMethodSignature;
}

/** @internal */
interface _LogMethodSignature {
(...args: unknown[]): void
(event: LogEvent, ...args: unknown[]): void;
}

/** @internal */
interface _CompleteMethodSignature {
<T>(message: string, action: T | (() => T)): T;
<T>(event: LogEvent, message: string, action: T | (() => T)): T;
}

type LogEvent = {
/** Use when there's a risk of logging several parallel duration events. */
id?: string | number;
/** Optional. Event categories (tags) to facilitate filtering. */
cat?: string | string[];
/** Optional. Color name (applicable in Google Chrome Trace Format) */
cname?: string;

/** Reserved property. Process ID. */
pid?: never;
/** Reserved property. Thread ID. */
tid?: never;
/** Reserved property. Timestamp. */
ts?: never;
/** Reserved property. Event phase. */
ph?: never;

[customProperty: string]: unknown;
};

type DetoxLogLevel = 'fatal' | 'error' | 'warn' | 'info' | 'debug' | 'trace';

type Point2D = {
x: number,
y: number,
Expand Down Expand Up @@ -396,12 +501,10 @@ declare global {
* Holds the environment-unique ID of the device - namely, the adb ID on Android (e.g. emulator-5554) and the Mac-global simulator UDID on iOS,
* as used by simctl (e.g. AAAAAAAA-BBBB-CCCC-DDDD-EEEEEEEEEEEE).
*
* The value will be undefined until the device is properly prepared (i.e. in detox.init())
*/
id: string;
/**
* Holds a descriptive name of the device. Example: emulator-5554 (Pixel_API_29)
* The value will be undefined until the device is properly prepared (i.e. in detox.init()).
*/
name: string;

Expand Down
1 change: 1 addition & 0 deletions detox/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
module.exports = require('./src/realms');
Loading