Skip to content

Commit

Permalink
feat: add listTarget api & revert original bin file location (#1320)
Browse files Browse the repository at this point in the history
* feat: add listTarget api & revert original bin file location
* test: write Platform API target list specs
  • Loading branch information
erisu committed May 8, 2023
1 parent 1a5cd45 commit c000a1b
Show file tree
Hide file tree
Showing 7 changed files with 56 additions and 3 deletions.
5 changes: 5 additions & 0 deletions lib/Api.js
Expand Up @@ -665,6 +665,11 @@ class Api {
.then(() => require('./run').run.call(this, runOptions));
}

listTargets (options) {
return check_reqs.run()
.then(() => require('./run').runListDevices.call(this, options));
}

/**
* Cleans out the build artifacts from platform's directory.
*
Expand Down
15 changes: 15 additions & 0 deletions lib/run.js
Expand Up @@ -228,3 +228,18 @@ function listEmulators () {
});
});
}

module.exports.runListDevices = async function (options = {}) {
const { options: cliArgs = {} } = options;

if (cliArgs?.device) {
await module.exports.listDevices.call(this);
} else if (cliArgs?.emulator) {
await module.exports.listEmulators.call(this);
} else {
await module.exports.listDevices.call(this);
await module.exports.listEmulators.call(this);
}

return true;
};
2 changes: 1 addition & 1 deletion package.json
Expand Up @@ -25,7 +25,7 @@
"xcodebuild": "xcodebuild -quiet test -workspace tests/cordova-ios.xcworkspace -destination \"platform=iOS Simulator,name=iPhone 8\" CONFIGURATION_BUILD_DIR=\"`mktemp -d 2>/dev/null || mktemp -d -t 'cordova-ios'`\"",
"preobjc-tests": "killall Simulator || true",
"unit-tests": "jasmine --config=tests/spec/unit.json",
"lint": "eslint . \"lib/**/!(*.*)\""
"lint": "eslint . \"templates/cordova/lib/!(*.*)\""
},
"author": "Apache Software Foundation",
"license": "Apache-2.0",
Expand Down
2 changes: 1 addition & 1 deletion lib/list-devices → templates/cordova/lib/list-devices
Expand Up @@ -19,7 +19,7 @@
under the License.
*/

const { run } = require('./listDevices');
const { run } = require('cordova-ios/lib/listDevices');

run().then(devices => {
devices.forEach(device => {
Expand Down
Expand Up @@ -19,7 +19,7 @@
under the License.
*/

const { run } = require('./listEmulatorImages');
const { run } = require('cordova-ios/lib/listEmulatorImages');

run().then(names => {
names.forEach(name => {
Expand Down
12 changes: 12 additions & 0 deletions tests/spec/unit/Api.spec.js
Expand Up @@ -92,6 +92,18 @@ describe('Platform Api', () => {
});
});
});

describe('listTargets', () => {
beforeEach(() => {
spyOn(check_reqs, 'run').and.returnValue(Promise.resolve());
});
it('should call into lib/run module', () => {
spyOn(run_mod, 'runListDevices');
return api.listTargets().then(() => {
expect(run_mod.runListDevices).toHaveBeenCalled();
});
});
});
}

describe('addPlugin', () => {
Expand Down
21 changes: 21 additions & 0 deletions tests/spec/unit/lib/run.spec.js
Expand Up @@ -48,6 +48,27 @@ if (process.platform === 'darwin') {
expect(run.listEmulators).toHaveBeenCalled();
});
});

it('should delegate to "listDevices" when the "runListDevices" method options param contains "options.device".', () => {
return run.runListDevices({ options: { device: true } }).then(() => {
expect(run.listDevices).toHaveBeenCalled();
expect(run.listEmulators).not.toHaveBeenCalled();
});
});

it('should delegate to "listDevices" when the "runListDevices" method options param contains "options.emulator".', () => {
return run.runListDevices({ options: { emulator: true } }).then(() => {
expect(run.listDevices).not.toHaveBeenCalled();
expect(run.listEmulators).toHaveBeenCalled();
});
});

it('should delegate to both "listEmulators" and "listDevices" when the "runListDevices" method does not contain "options.device" or "options.emulator".', () => {
return run.runListDevices({ options: {} }).then(() => {
expect(run.listDevices).toHaveBeenCalled();
expect(run.listEmulators).toHaveBeenCalled();
});
});
});
});
}

0 comments on commit c000a1b

Please sign in to comment.