0

I'm using detox for end-to-end testing my react-native app. When I try to run yarn detox build -c android.emu.release it does not run the script well cd android ; ./gradlew assembleRelease app:assembleAndroidTest -DtestBuildType=release ; cd -. This script was generated automatically by detox init.

Here is my package.json file:

{
  "detox": {
    /*...*/
    "android.emu.release": {
        "binaryPath": "android/app/build/outputs/apk/release/app-release.apk",
        "build": "cd android  ./gradlew assembleRelease app:assembleAndroidTest -DtestBuildType=release ; cd -", //<<<<<<<<<<<
        "type": "android.emulator",
        "device": {
          "avdName": "NexusOneAPI29"
        }
      }
    /*...*/
  },
  /*...*/
}

I am struggling to run yarn detox build -c android.emu.release for instance. If

Which symbol/char do I need to use to concat commands instead of ; on detox?

The main error I believe is: The system cannot find the path specified. extracted from below.

$ yarn detox-build                                                  
yarn run v1.21.1
detox[7600] INFO:  [build.js] cd android ; gradlew assembleRelease app:assembleAndroidTest -DtestBuildType=release ; cd -
The system cannot find the path specified.
detox[7600] ERROR: [cli.js] Error: Command failed: cd android ; gradlew assembleRelease app:assembleAndroidTest -DtestBuildType=releas
error Command failed with exit code 1.
info Visit https://yarnpkg.com/en/docs/cli/run for documentation about this command.
ofundefined
  • 2,692
  • 2
  • 18
  • 35
  • are you trying to have shell script inside ? – Aziz.G Jan 23 '20 at 21:25
  • 1
    https://stackoverflow.com/questions/34937724/running-bash-scripts-with-npm – Aziz.G Jan 23 '20 at 21:29
  • I know you are targeting Android, but what envrioment are you running the npm scripts from? Have you tried using `&&` instead of `;`? – Brian H. Jan 23 '20 at 21:34
  • I did try `&&` but it does not work on Powershell on Windows :'( – ofundefined Jan 23 '20 at 21:35
  • @G.aziz, that's a nice point, but I'd rather find the way to write it on one line :D – ofundefined Jan 23 '20 at 21:36
  • When you run `npm config get script-shell` via Powershell, presumably it returns the path to `cmd.exe` (as that's the default shell that npm utilizes on Windows) - in which case the `&&` operator should work OK. However perhaps when you run `npm config get script-shell` via Powershell it returns path to `pwsh` - which may be the reason the `&&` operator doesn't work. You can set the `script-shell` to `cmd.exe` by **1)** Running: `which cmd.exe` **2)** Running `npm config set script-shell ` - whereby the _``_ part should be replaced with the path returned from step 1. – RobC Jan 24 '20 at 12:55
  • Thanks RobC. Unfortunatelly `which cmd.exe` does not work. It does not recognize `which` as the name of a cmdlet. Anyways I appreciate your comment. I also updated my question as it is not a problem with `npm scripts` but with `detox scripts` – ofundefined Jan 24 '20 at 13:54
  • 1
    @AlexandreLage - Yes, you're right, I forgot that I [created an alias for the which command](https://stackoverflow.com/questions/63805/equivalent-of-nix-which-command-in-powershell) in _Powershell_ some time ago. You'd need to run `get-command cmd.exe` instead. However, it's not relevant now as your issue is very different from the original question. – RobC Jan 24 '20 at 14:18

1 Answers1

1

You should use && to run multiple commands on any platform and any shell from npm scripts. You would expect it does not work on powershell but it does actually.

[npm] doesn't have the exact same semantics for && (it executes the second command regardless of the success of the first), but it does work to string together multiple commands on a line.

https://github.com/npm/npm/issues/4040#issuecomment-209034612

fredericrous
  • 2,833
  • 1
  • 25
  • 26
  • Thanks. You are right. I updated my question as I realized the problem is not using `&&` with npm scripts but with detox script. Voted you up – ofundefined Jan 24 '20 at 13:50