Add dynamic require for driver plugins#1919
Conversation
detox/src/Detox.js
Outdated
| await this._client.connect(); | ||
|
|
||
| const DeviceDriverClass = DEVICE_CLASSES[this._deviceConfig.type]; | ||
| const DeviceDriverClass = DEVICE_CLASSES[this._deviceConfig.type] || require(this._deviceConfig.type); |
There was a problem hiding this comment.
One thing I don't like about this direct fallback to require is you get a weird error about module resolution if you have a typo for one of the built-in drivers. In other words, the if on the line below is sort of useless...
@rotemmiz, what are your thoughts about requiring third party drivers to be prefixed in the configuration?
Something like:
"ios.sim.release": {
"binaryPath": "...",
"build": "...",
"type": "plugin:my-custom-driver-package-name",
"device": {
// can be pretty flexible (according to the device driver), add whatever device specification needed
}
},
let DeviceDriverClass = DEVICE_CLASSES[this._deviceConfig.type];
if (!DeviceDriverClass) {
if (this._deviceConfig.type.startsWith('plugin:')) {
DeviceDriverClass = require(this._deviceConfig.type);
}
throw new Error(`'${this._deviceConfig.type}' is not supported`);
}|
One other thing that would be great to resolve as part of this PR is the Essentially, I want a way to avoid this line which is currently mandatory but doesn't make sense in the context of a website which doesn't have a binaryPath. (Currently I'm using binary path to specify the base web url but have to add a leading Detox/detox/src/devices/Device.js Line 18 in 475d10e |
|
Re binaryPath, let's make sure it is only used where needed (push it into the drivers maybe). |
|
@rotemmiz thanks for the direction. I just pushed a commit that pushes absolute path logic into the driver layer (removing from device). I wasn't sure exactly how you wanted me to handle Did you want to totally remove Or add a new In the grand scheme of things, it's currently not a huge issue to keep the Let me know how you'd like to proceed! |
|
Hey @awinograd, seems like a few unit tests failed, and coverage is missing as well. |
…rtions also fix code coverage
|
@rotemmiz, tests + coverage fixed |
|
Hey @awinograd, sorry for the delay here, I was trying to think and consult on how to proceed here.
WDYT? |
|
@rotemmiz no need to apologize! I appreciate your guidance through the PR process.
|
|
Although it makes little sense to add the project to one of the platform specific test project CI builds, I believe it will be the fastest and easiest, and you'll be able to do it independently. Try adding your new project to the list here, and see |
|
@rotemmiz, sorry for the delay in getting back to this. I just pushed an example project (🤞 that the CI passes!) Still need to work on the Doc, but wanted you to take a look at f014adc as I'm not happy with what i've done there. It's related to our discussion above (#1919 (comment)) about |
|
Just put up a first pass at a new Guide around Third party drivers. I'm curious to know what areas you think may be interesting to include that i've left off. As of now, it's a pretty high level summary. |
8b3c27b to
cb1266a
Compare
|
The CI is failing due to
I see two potential solutions:
Let me know which direction you prefer. If it's (1), I'll need help |
|
I went ahead an chose path (2) since it seemed like simplest way to test the actual integration without worrying about the internal plugin details. If you'd like to go down path (1) and restore |
|
Most recent test failure seems unrelated to my changes |
|
Good call going with 2, we wouldn't want detox CI to be more complex than what it already is, this demo you added is there only to showcase the API and make sure we don't break it unintentionally |
|
Though the first error is probably not related (couldn't found the cause scrolling with my phone), the second (in demo projects build) looks related to your work |
|
I see a new coveralls ci process has been added to the PR and has failed. https://coveralls.io/builds/29961248 Should I be paying attention to it? |
|
@awinograd, thanks for telling. I'll look into it. |
rotemmiz
left a comment
There was a problem hiding this comment.
Perfect documentation writing (Expect for a small terminology note), Kudos.
I added a few notes, and we're checking why CI fails, bare with us, we will merge this ASAP.
detox/src/devices/Device.test.js
Outdated
| const device = schemeDevice(configurationsMock.pathsTests, configuration); | ||
|
|
||
| await device.prepare(); | ||
| await device.prepare({ checkBinaryPath: true }); |
There was a problem hiding this comment.
Seems to me like checkBinaryPath doesn't really belong in here, is there any function call without checkBinaryPath:true ?
If this is to separate the web driver from iOS/Android drivers, then maybe this logic should reside in the drivers themselves.
There was a problem hiding this comment.
I'm not ecstatic about how I had to get the tests passing. If I remember correctly, I was fighting against code coverage, but perhaps the real solution is to add a separate test for getAbsoluteBinaryPath
There was a problem hiding this comment.
So does this mean you can get rid of checkBinaryPath: true?
There was a problem hiding this comment.
sorry I missed this reference. yes we can get rid of it
| await device.installApp('newAppPath'); | ||
|
|
||
| expect(driverMock.driver.installApp).toHaveBeenCalledWith(device._deviceId, 'newAppPath', undefined); | ||
| expect(driverMock.driver.installApp).toHaveBeenCalledWith(device._deviceId, 'newAppPath', device._deviceConfig.testBinaryPath); |
There was a problem hiding this comment.
Why did this change from undefined to testBinaryPath ?
There was a problem hiding this comment.
Previously this expectation was relying on implementation details of the Device class. Specifically, it knew that testBinaryPath was not passed along to newAppPath if prepare has not yet been called. That's because previously, the binary path instance properties were set on the instance during prepare after doing the absolute path logic I have pushed down into the driver layer.
That seemed a bit odd to me, since in all real uses of Device (as far as I'm aware) prepare will always be called before using the other methods. This method expects the testBinaryPath as the last argument, it just previously happened to not be defined yet
| @@ -0,0 +1,62 @@ | |||
| # Third Party Drivers | |||
|
|
|||
| Detox comes with built-in support for running on Android and iOS by choosing a driver type in your detox configurations. For example, the following configuration uses the "ios.simulator" driver. | |||
There was a problem hiding this comment.
"as of v16.(3?)"
We need to remember to add it
|
@rotemmiz thanks for the review! I've done a first pass at addressing your comments |
|
Can't yet understand why all builds failed, I will try figuring it out tomorrow morning. |
4c8c9ba to
88ea1dc
Compare
|
@rotemmiz just updated the PR to remove the remaining reference to thanks for taking a look at the remaining failures. |
|
@awinograd, the issue with Coveralls was finally solved - could you please merge |
|
@noomorph . Sure thing. Just merged master |
|
Coveralls ran but failed here. Jenkins CI is green again! |
|
@awinograd, thanks for reporting. I have found why the coverage was below 70ish% and pushed the fix. Could you please merge |
|
merged! |
|
|
||
| // This will post which device has assigned to run a suite, which can be useful in a multiple-worker tests run. | ||
| // This is strictly optional. | ||
| jasmine.getEnv().addReporter(assignReporter); |
There was a problem hiding this comment.
@noomorph another thing to keep up to date with respect to jasmine deprecation
|
Anything else I can do here? |
|
🥳 |
|
Amazing! Thanks for all of your help getting this change developed & merged! Excited to see it released officially 🎊 |
|
Thank you for having such persistency in having this PR perfected. |
|
W00t! Don't forget to bump a minor version for the next release :) |
|
Amazing stuff @awinograd this is super stuff 😍thanks so much for driving this! |
|
@awinograd @justinwyer please be advised that we're about to introduce a minor yet breaking change to the plugged-in drivers in #2214. The change it subtle and we will report the details in the release itself, but it will not be release as a major version. |
Description:
This PR adds support for external drivers as discussed in #1882 (comment).