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
21 changes: 21 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -144,6 +144,27 @@ The npm package also ships `dcd-mcp`, an older server with the same `dcd_*` tool

`--package` matters: the package's default bin is `dcd`, so `npx @devicecloud.dev/dcd dcd-mcp` would run `dcd dcd-mcp` (an unknown command) instead of the server. It signs in like `dcd mcp`, and takes `--read-only` and `DCD_MCP_READONLY=1` the same way.

## e2e tests on DeviceCloud devices (early access)

`@devicecloud.dev/dcd/e2e` is a device provider for [e2e](https://github.com/e2e-inc/e2e). Each e2e worker gets its own DeviceCloud device session, and e2e drives the device directly. The session shows in the console, is recorded, and is billed like any other. Your organization needs this turned on by DeviceCloud first.

```ts
// e2e.config.ts
import type { E2EConfig } from 'e2e';
import { mobile } from '@e2e-dev/mobile';
import { deviceCloud } from '@devicecloud.dev/dcd/e2e';

const engine = mobile({ platform: 'android', device: deviceCloud() });

export default {
targets: [{ name: 'android', engine, app: { bundleId: 'com.example.app', appPath: './build/app.apk' } }],
// The first screen read after a launch can take a few seconds.
assertionTimeout: 20_000,
} satisfies E2EConfig;
```

Run `npx e2e run` with `DEVICE_CLOUD_API_KEY` set. The provider uploads `appPath` once per run and each session installs it, so e2e installs nothing itself. To use a build you already uploaded, pass `deviceCloud({ appBinaryId })`. It also takes `model`, `os` and `maxDurationMin`. Each session's console link is printed as the run starts, and the session is stopped when e2e is done with it.


## Development

Expand Down
9 changes: 9 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,15 @@
"testing"
],
"types": "dist/index.d.ts",
"exports": {
".": "./dist/index.js",
"./e2e": {
"types": "./dist/e2e/index.d.ts",
"default": "./dist/e2e/index.js"
},
"./package.json": "./package.json",
"./dist/*": "./dist/*"
},
"packageManager": "pnpm@10.17.1",
"pnpm": {
"overrides": {
Expand Down
58 changes: 58 additions & 0 deletions src/e2e/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
/**
* `@devicecloud.dev/dcd/e2e`: run e2e (https://github.com/e2e-inc/e2e) tests
* on DeviceCloud devices.
*
* import { mobile } from '@e2e-dev/mobile';
* import { deviceCloud } from '@devicecloud.dev/dcd/e2e';
*
* const engine = mobile({ platform: 'android', device: deviceCloud() });
*
* Each e2e worker gets its own DeviceCloud device session, which shows in the
* console, is recorded, and is billed like any other. Reads
* `DEVICE_CLOUD_API_KEY` from the run's environment. Early access: the
* organization needs it turned on by DeviceCloud.
*
* Importing this module has no side effects; it does not start the CLI.
*/
import { uploadLocalApp } from '../utils/app-upload.js';
import { getCliVersion } from '../utils/cli.js';

import {
createProvider,
type DeviceCloudOptions,
type DeviceCloudProvider,
} from './provider.js';

export type {
DeviceCloudOptions,
DeviceCloudProvider,
E2eDeviceLease,
E2eDeviceRequest,
E2eReleaseContext,
} from './provider.js';

/** A DeviceCloud device provider, for `mobile({ device })` in an e2e config. */
export function deviceCloud(
options: DeviceCloudOptions = {},
): DeviceCloudProvider {
return createProvider(options, {
fetch: (input, init) => fetch(input, init),
pollMs: 3000,
startTimeoutMs: 20 * 60_000,
upload: ({ apiKey, apiUrl, filePath, log }) =>
uploadLocalApp({
apiUrl,
auth: {
headers: {
'x-app-api-key': apiKey,
'x-dcd-cli-version': getCliVersion(),
},
mode: 'apiKey',
},
filePath,
log,
showProgress: false,
}),
version: getCliVersion(),
});
}
Loading
Loading