fix(basedriver): ensure "opts" is defined at time of construction
MODIFY
packages/base-driver/lib/basedriver/driver.js
packages/base-driver/lib/basedriver/driver.js
@@ -27,12 +27,12 @@ const ON_UNEXPECTED_SHUTDOWN_EVENT = 'onUnexpectedShutdown';
/**
* @implements {SessionHandler<C>}
* @template {Constraints} C
- * @template {StringRecord} [A=StringRecord]
+ * @template {StringRecord} [CArgs=StringRecord]
* @extends {DriverCore<C>}
*/
export class BaseDriverCore extends DriverCore {
/**
- * @type {A & ServerArgs}
+ * @type {CArgs & ServerArgs}
*/
cliArgs;
@@ -56,6 +56,23 @@ export class BaseDriverCore extends DriverCore {
*/
opts;
+ static BASE_DESIRED_CAP_CONSTRAINTS = BASE_DESIRED_CAP_CONSTRAINTS;
+
+ /**
+ *
+ * @param {DriverOpts<C>} opts
+ * @param {boolean} shouldValidateCaps
+ */
+ constructor(opts = /** @type {DriverOpts<C>} */ ({}), shouldValidateCaps = true) {
+ super(opts, shouldValidateCaps);
+
+ /**
+ * This must be assigned here because the declaration of {@linkcode BaseDriverCore.opts} above
+ * blows away {@linkcode DriverCore.opts}.
+ */
+ this.opts = opts;
+ }
+
/**
* Contains the base constraints plus whatever the subclass wants to add.
*
@@ -69,8 +86,6 @@ export class BaseDriverCore extends DriverCore {
return Object.freeze(_.merge({}, BASE_DESIRED_CAP_CONSTRAINTS, this.desiredCapConstraints));
}
- static BASE_DESIRED_CAP_CONSTRAINTS = BASE_DESIRED_CAP_CONSTRAINTS;
-
// This is the main command handler for the driver. It wraps command
// execution with timeout logic, checking that we have a valid session,
// and ensuring that we execute commands one at a time. This method is called

MODIFY
packages/base-driver/test/unit/basedriver/driver.spec.js
packages/base-driver/test/unit/basedriver/driver.spec.js
import BaseDriver from '../../../lib';
import {driverUnitTestSuite} from '@appium/driver-test-support';
+const {expect} = chai;
+
driverUnitTestSuite(BaseDriver, {
platformName: 'iOS',
'appium:deviceName': 'Delorean',
});
+
+describe('BaseDriver', function () {
+ describe('constructor', function () {
+ it('should initialize "opts"', function () {
+ const driver = new BaseDriver();
+ expect(driver.opts).to.exist;
+ });
+ });
+});

fix(basedriver): ensure "opts" is defined at time of construction