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

feat: export the adb utilities to be used in third party nodejs scripts #2116

Merged
merged 35 commits into from
Jan 27, 2021
Merged
Show file tree
Hide file tree
Changes from 20 commits
Commits
Show all changes
35 commits
Select commit Hold shift + click to select a range
525fd59
initial attempt to export adb utils
ankushduacodes Jan 11, 2021
b94db98
revert accidental changes to imports
ankushduacodes Jan 11, 2021
d11cf88
revert accidental changes to imports
ankushduacodes Jan 11, 2021
712d5c6
add deviceId param
ankushduacodes Jan 11, 2021
914847f
add deviceId param
ankushduacodes Jan 11, 2021
744f97d
added lazy loading to adb function imports
ankushduacodes Jan 14, 2021
72f31a3
added type annotation to getter
ankushduacodes Jan 14, 2021
2d8e5a9
added tests to test out new adb util export
ankushduacodes Jan 14, 2021
d3f799e
refactored test-import and test-require to reduce code duplication
ankushduacodes Jan 15, 2021
1f061a1
fixed paths for newly refactored import tests
ankushduacodes Jan 15, 2021
e612848
fixed test-require imports
ankushduacodes Jan 15, 2021
ea76ae3
trying to fix webext-as-library imports
ankushduacodes Jan 15, 2021
3354d88
trying to fix webext-as-library exports
ankushduacodes Jan 15, 2021
20a52cd
trying to fix webext-as-library exports
ankushduacodes Jan 15, 2021
90cf955
trying to fix webext-as-library exports
ankushduacodes Jan 15, 2021
a00f2ae
trying to fix webext-as-library exports
ankushduacodes Jan 15, 2021
5e4760b
trying to fix webext-as-library exports
ankushduacodes Jan 15, 2021
2c3f3da
trying to fix webext-as-library exports
ankushduacodes Jan 15, 2021
8c659db
trying to fix webext-as-library exports
ankushduacodes Jan 15, 2021
116d49f
more trying to fix webext-as-library exports
ankushduacodes Jan 15, 2021
2ea9470
addressing minor changes
ankushduacodes Jan 19, 2021
610e85e
testing
ankushduacodes Jan 19, 2021
40c626f
testing windows inports/exports
ankushduacodes Jan 20, 2021
56bb049
trying to distingush between win32 path and posix path
ankushduacodes Jan 21, 2021
cc3f3e9
removing log statemet
ankushduacodes Jan 21, 2021
49f1e71
testing new exposed adb functions
ankushduacodes Jan 21, 2021
bad409f
added some documentation for new ADB functions and on how to run an e…
ankushduacodes Jan 21, 2021
5ebea01
updated adbPathString to use path lib
ankushduacodes Jan 21, 2021
9616682
docs update
ankushduacodes Jan 21, 2021
c74a4e2
Addressing minor nits
ankushduacodes Jan 22, 2021
24c4483
Update README.md
ankushduacodes Jan 22, 2021
22edc26
Update README.md
ankushduacodes Jan 22, 2021
4794f81
wording change
ankushduacodes Jan 26, 2021
3c3bd4a
more wording change
ankushduacodes Jan 26, 2021
315c0f7
addressing final few nits and polish requests
ankushduacodes Jan 27, 2021
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
10 changes: 8 additions & 2 deletions src/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,14 @@ import {main} from './program';
import cmd from './cmd';
import * as logger from './util/logger';

// This only exposes util/logger so far.
// This only exposes util/logger and a couple of functions from util/adb so far.
ankushduacodes marked this conversation as resolved.
Show resolved Hide resolved
// Do we need anything else?
const util = {logger};
const util = {
logger,
get adb(): Object {
ankushduacodes marked this conversation as resolved.
Show resolved Hide resolved
const {listADBDevices, listADBFirefoxAPKs} = require('./util/adb.js');
ankushduacodes marked this conversation as resolved.
Show resolved Hide resolved
return {listADBDevices, listADBFirefoxAPKs};
},
};

export default {main, cmd, util};
13 changes: 13 additions & 0 deletions src/util/adb.js
Original file line number Diff line number Diff line change
Expand Up @@ -418,3 +418,16 @@ export default class ADBUtils {
});
}
}

export async function listADBDevices(adbBin?: string): Promise<Array<string>> {
const adbClient = new ADBUtils({adbBin});
return adbClient.discoverDevices();
}

export async function listADBFirefoxAPKs(
deviceId: string,
adbBin?: string
): Promise<Array<string>> {
const adbClient = new ADBUtils({adbBin});
return adbClient.discoverInstalledFirefoxAPKs(deviceId);
}
ankushduacodes marked this conversation as resolved.
Show resolved Hide resolved
ankushduacodes marked this conversation as resolved.
Show resolved Hide resolved
7 changes: 0 additions & 7 deletions tests/fixtures/import-as-esm/test-import.mjs

This file was deleted.

6 changes: 0 additions & 6 deletions tests/fixtures/require-as-cjs/test-require.js

This file was deleted.

15 changes: 15 additions & 0 deletions tests/fixtures/webext-as-library/helpers.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
const assert = require('assert');

function testWebExtModuleImports(webExt) {
ankushduacodes marked this conversation as resolved.
Show resolved Hide resolved
assert.deepEqual(Object.keys(webExt).sort(), ['cmd', 'main', 'util'].sort());
assert.deepEqual(Object.keys(webExt.util).sort(), ['logger', 'adb'].sort());
assert.deepEqual(
Object.keys(webExt.util.adb).sort(),
['listADBDevices', 'listADBFirefoxAPKs'].sort(),
);
assert.equal(typeof webExt.cmd.run, 'function');
ankushduacodes marked this conversation as resolved.
Show resolved Hide resolved
}

module.exports = {
testWebExtModuleImports,
};
ankushduacodes marked this conversation as resolved.
Show resolved Hide resolved
7 changes: 7 additions & 0 deletions tests/fixtures/webext-as-library/test-import.mjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
// eslint-disable-next-line import/no-unresolved
import webExt from 'web-ext';

// eslint-disable-next-line import/extensions
import _ from './helpers.js';
ankushduacodes marked this conversation as resolved.
Show resolved Hide resolved

_.testWebExtModuleImports(webExt);
ankushduacodes marked this conversation as resolved.
Show resolved Hide resolved
5 changes: 5 additions & 0 deletions tests/fixtures/webext-as-library/test-require.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
const webExt = require('web-ext');

const _ = require('./helpers.js');

_.testWebExtModuleImports(webExt);
ankushduacodes marked this conversation as resolved.
Show resolved Hide resolved
4 changes: 2 additions & 2 deletions tests/functional/common.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,9 +21,9 @@ export const fixturesDir: string =
export const minimalAddonPath: string =
path.join(fixturesDir, 'minimal-web-ext');
export const fixtureEsmImport: string =
path.join(fixturesDir, 'import-as-esm');
path.join(fixturesDir, 'webext-as-library');
export const fixtureCjsRequire: string =
path.join(fixturesDir, 'require-as-cjs');
path.join(fixturesDir, 'webext-as-library');
ankushduacodes marked this conversation as resolved.
Show resolved Hide resolved
export const fakeFirefoxPath: string = path.join(
functionalTestsDir,
process.platform === 'win32' ?
Expand Down
9 changes: 9 additions & 0 deletions tests/unit/test.web-ext.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import sinon from 'sinon';
import webExt from '../../src/main';
import {main} from '../../src/program';
import {consoleStream} from '../../src/util/logger';
import {listADBDevices, listADBFirefoxAPKs} from '../../src/util/adb';


describe('webExt', () => {
Expand All @@ -17,6 +18,14 @@ describe('webExt', () => {
assert.equal(webExt.util.logger.consoleStream, consoleStream);
});

it('gives access to listADBDevices', () => {
assert.equal(webExt.util.adb.listADBDevices, listADBDevices);
});

it('gives access to listADBFirefoxAPKs', () => {
assert.equal(webExt.util.adb.listADBFirefoxAPKs, listADBFirefoxAPKs);
});

ankushduacodes marked this conversation as resolved.
Show resolved Hide resolved
describe('exposes commands', () => {
let stub: any;
afterEach(() => {
Expand Down