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

Error when running "detox test" for windows using detox 8 due to findstr not supporting /s in regex #886

Closed
dat00ste opened this issue Aug 15, 2018 · 7 comments

Comments

@dat00ste
Copy link

Description

When running detox test with detox 8 I get the following error:

detox[7016] INFO: [DetoxServer.js] server listening on localhost:56121...
detox[7016] ERROR: [exec.js/EXEC_FAIL, #1] "C:\Users\stina.emrikstrand\AppData\Local\Android\sdk\platform-tools\adb -s emulator-5554 shell dumpsys power | findstr /R /C:"^\sm[UW].="" failed with code = 1, stdout and stderr:

detox[7016] ERROR: [exec.js/EXEC_FAIL, #1]
detox[7016] ERROR: [exec.js/EXEC_FAIL, #1]
detox[7016] ERROR: [index.js/DETOX_INIT_ERROR]
{ ChildProcessError: Command failed: C:\Users\stina.emrikstrand\AppData\Local\Android\sdk\platform-tools\adb -s emulator-5554 shell dumpsys power | findstr /R /C:"^\sm[UW].="
C:\Users\stina.emrikstrand\AppData\Local\Android\sdk\platform-tools\adb -s emulator-5554 shell dumpsys power | findstr /R /C:"^\s*m[UW].*=" (exited with error code 1)
at callback (C:\Users\stina.emrikstrand\code\App\powerup\node_modules\child-process-promise\lib\index.js:33:27)
at ChildProcess.exithandler (child_process.js:295:5)
at ChildProcess.emit (events.js:182:13)
at maybeClose (internal/child_process.js:962:16)
at Process.ChildProcess._handle.onexit (internal/child_process.js:249:5)

I have located the problem to that windows findstr does not support /s in regex. If I replace the line:

const stdout = await this.shell(deviceId, dumpsys power | ${grep('^\\s*m[UW].*=')});

with

const stdout = await this.shell(deviceId, dumpsys power | ${grep('^ *m[UW].*=')});

in detox/src/devices/android/ADB.js, it seems to work, for windows at least. I'm not sure about other OS, and since I'm not a developer I'm not sure this is the best way of solving it either :)

Detox, Node, Device, Xcode and macOS Versions

  • Detox: 8.1.6
  • React Native: 0.55.3
  • Node: 10.8.0
@noomorph
Copy link
Collaborator

Hmmm.... looks fair, though weird a bit - I'm almost sure I tested that, but maybe I forgot something. What Windows version, you say?

@dat00ste
Copy link
Author

Sorry for the missing information. I'm using windows 10.
As I understand from the documentation, findstr is very limited regarding the regex metacharacters: https://docs.microsoft.com/en-us/windows-server/administration/windows-commands/findstr :(

@noomorph
Copy link
Collaborator

@dat00ste, no worries. 👍 I just did not want to enforce Windows users of Detox to install grep. Sad that findstr is so weak, but anyway your suggestion with a less stricter regexp should work just fine.

I've submitted a pull request with a bugfix already.

I hope that a hotfix version will appear in the next few days, maybe today if we are very lucky.

P.S. And extra thanks for investigating the issue before submitting it. 🥇

noomorph added a commit that referenced this issue Aug 15, 2018
@dat00ste
Copy link
Author

Great, thanks!
Im not sure but maybe it needs to be replaced in this line as well?:
const bundleIdRegex = pipeCommands.escape.inQuotedRegexp(bundleId) + '\s*$';

@noomorph
Copy link
Collaborator

@dat00ste, it is a good question. I clearly remember it worked just fine on Windows... hmm.

@noomorph
Copy link
Collaborator

@dat00ste, right you are! apparently, it was looking for s* not [ ]*. Thanks much!

@dat00ste
Copy link
Author

No problem, happy to help :).

noomorph added a commit that referenced this issue Aug 15, 2018
@lock lock bot locked as resolved and limited conversation to collaborators Aug 18, 2018
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

3 participants