Skip to content

Commit

Permalink
refactor!: Remove obsolete methods and properties (#700)
Browse files Browse the repository at this point in the history
BREAKING CHANGE: The obsolete emPort property has been removed. Use emulatorPort instead
BREAKING CHANGE: The following coverage-related methods were removed as obsolete: endAndroidCoverage, instrument, androidCoverage
BREAKING CHANGE: The obsolete jars property has been removed.
BREAKING CHANGE: The obsolete instrumentProc property has been removed.
  • Loading branch information
mykola-mokhnach committed Oct 18, 2023
1 parent b40d1db commit 2673b96
Show file tree
Hide file tree
Showing 5 changed files with 0 additions and 112 deletions.
3 changes: 0 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -103,9 +103,6 @@ console.log(await adb.getPIDsByName('com.android.phone'));
- `killProcessByPID`
- `broadcastProcessEnd`
- `broadcast`
- `endAndroidCoverage`
- `instrument`
- `androidCoverage`
- `packageAndLaunchActivityFromManifest`
- `compileManifest`
- `insertManifest`
Expand Down
1 change: 0 additions & 1 deletion lib/adb.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@ export const DEFAULT_OPTS = {
executable: {path: 'adb', defaultArgs: []},
tmpDir: os.tmpdir(),
binaries: {},
jars: {},
adbPort: DEFAULT_ADB_PORT,
adbExecTimeout: DEFAULT_ADB_EXEC_TIMEOUT,
remoteAppsCacheLimit: 10,
Expand Down
3 changes: 0 additions & 3 deletions lib/options.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,7 @@ export interface ADBOptions {
emulatorPort?: number;
logcat?: Logcat;
binaries?: StringRecord;
instrumentProc?: SubProcess;
suppressKillServer?: boolean;
jars?: StringRecord;
adbPort?: number;
adbHost?: string;
adbExecTimeout?: number;
Expand All @@ -30,7 +28,6 @@ export interface ADBOptions {
remoteAdbHost?: string;
remoteAdbPort?: number;
clearDeviceLogsOnStart?: boolean;
emPort?: number;
}

export interface ADBExecutable {
Expand Down
73 changes: 0 additions & 73 deletions lib/tools/adb-commands.js
Original file line number Diff line number Diff line change
Expand Up @@ -1477,79 +1477,6 @@ methods.broadcast = async function broadcast (intent) {
await this.shell(['am', 'broadcast', '-a', intent]);
};

/**
* Kill Android instruments if they are currently running.
* @this {import('../adb.js').ADB}
*/
methods.endAndroidCoverage = async function endAndroidCoverage () {
if (this.instrumentProc && this.instrumentProc.isRunning) {
await this.instrumentProc.stop();
}
};

/**
* Instrument the particular activity.
*
* @this {import('../adb.js').ADB}
* @param {string} pkg - The name of the package to be instrumented.
* @param {string} activity - The name of the main activity in this package.
* @param {string} instrumentWith - The name of the package to instrument
* the activity with.
* @throws {error} If any exception is reported by adb shell.
*/
methods.instrument = async function instrument (pkg, activity, instrumentWith) {
if (activity[0] !== '.') {
pkg = '';
}
let pkgActivity = (pkg + activity).replace(/\.+/g, '.'); // Fix pkg..activity error
let stdout = await this.shell([
'am', 'instrument',
'-e', 'main_activity',
pkgActivity,
instrumentWith,
]);
if (stdout.indexOf('Exception') !== -1) {
throw new Error(`Unknown exception during instrumentation. Original error ${stdout.split('\n')[0]}`);
}
};

/**
* Collect Android coverage by instrumenting the particular activity.
*
* @this {import('../adb.js').ADB}
* @param {string} instrumentClass - The name of the instrumentation class.
* @param {string} waitPkg - The name of the package to be instrumented.
* @param {string} waitActivity - The name of the main activity in this package.
*
* @return {Promise<void>} The promise is successfully resolved if the instrumentation starts
* without errors.
*/
methods.androidCoverage = async function androidCoverage (instrumentClass, waitPkg, waitActivity) {
if (!this.isValidClass(instrumentClass)) {
throw new Error(`Invalid class ${instrumentClass}`);
}
return await new B(async (resolve, reject) => {
let args = this.executable.defaultArgs
.concat(['shell', 'am', 'instrument', '-e', 'coverage', 'true', '-w'])
.concat([instrumentClass]);
log.debug(`Collecting coverage data with: ${[this.executable.path].concat(args).join(' ')}`);
try {
// am instrument runs for the life of the app process.
this.instrumentProc = new SubProcess(this.executable.path, args);
await this.instrumentProc.start(0);
this.instrumentProc.on('output', (stdout, stderr) => {
if (stderr) {
reject(new Error(`Failed to run instrumentation. Original error: ${stderr}`));
}
});
await this.waitForActivity(waitPkg, waitActivity);
resolve();
} catch (e) {
reject(new Error(`Android coverage failed. Original error: ${(/**@type {Error} */ (e)).message}`));
}
});
};

/**
* Get the particular property of the device under test.
*
Expand Down
32 changes: 0 additions & 32 deletions test/unit/adb-commands-specs.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ import chaiAsPromised from 'chai-as-promised';
// eslint-disable-next-line import/no-unresolved
import {ADB} from '../../lib/adb';
import net from 'net';
import events from 'events';
import Logcat from '../../lib/logcat.js';
import * as teen_process from 'teen_process';
import { withMocks } from '@appium/test-support';
Expand Down Expand Up @@ -872,37 +871,6 @@ describe('adb commands', withMocks({adb, logcat, teen_process, net}, function (m
await adb.broadcast(intent);
});
});
describe('instrument', function () {
it('should call shell with correct arguments', async function () {
let intent = 'intent';
mocks.adb.expects('shell')
.once().withExactArgs(['am', 'broadcast', '-a', intent])
.returns('');
await adb.broadcast(intent);
});
});
describe('androidCoverage', function () {
it('should call shell with correct arguments', async function () {
adb.executable.defaultArgs = [];
adb.executable.path = 'dummy_adb_path';
let conn = new events.EventEmitter();
conn.start = () => { }; // do nothing
const instrumentClass = 'instrumentClass',
waitPkg = 'waitPkg',
waitActivity = 'waitActivity';
let args = adb.executable.defaultArgs
.concat(['shell', 'am', 'instrument', '-e', 'coverage', 'true', '-w'])
.concat([instrumentClass]);
mocks.teen_process.expects('SubProcess')
.withArgs('dummy_adb_path', args)
.onFirstCall()
.returns(conn);
mocks.adb.expects('waitForActivity')
.once().withExactArgs(waitPkg, waitActivity)
.returns('');
await adb.androidCoverage(instrumentClass, waitPkg, waitActivity);
});
});
});
describe('device info', function () {
it('should get device model', async function () {
Expand Down

0 comments on commit 2673b96

Please sign in to comment.