bitrise-steplib / steps-npm

Bitrise step for running npm commands
MIT License
0 stars 10 forks source link

Running multiple commands sequentially (&&) in a script , files/folders created by the 1st command are not available to the 2nd one #50

Closed davidesalerno closed 3 years ago

davidesalerno commented 3 years ago

Troubleshooting

Issue description

Running multiple commands sequentially in a script is not working as expected because the 2nd command executed it is not able to find a folder created by the first one

Bitrise info

 [2021-09-14 10:29:57.260 +0000] INFO (2692 on vm-osx-xcode-12.5.x-elite-cb91ecfc-1a97-4582-acea-e2273199daac.local): pact-node@10.13.7: Publishing Pacts to Broker
/Users/vagrant/git/node_modules/@pact-foundation/pact-node/src/publisher.js:36
throw new Error("Path '" + v + "' given in pactFilesOrDirs does not exists.");
^

Error: Path '/Users/vagrant/git/pacts' given in pactFilesOrDirs does not exists.
at /Users/vagrant/git/node_modules/@pact-foundation/pact-node/src/publisher.js:36:27
at Array.map ()
at new Publisher (/Users/vagrant/git/node_modules/@pact-foundation/pact-node/src/publisher.js:33:63)
at Object.default (/Users/vagrant/git/node_modules/@pact-foundation/pact-node/src/publisher.js:86:48)
at Pact.publishPacts (/Users/vagrant/git/node_modules/@pact-foundation/pact-node/src/pact.js:110:35)
at Object. (/Users/vagrant/git/pact.publish.js:12:4)
at Module._compile (internal/modules/cjs/loader.js:999:30)
at Object.Module._extensions..js (internal/modules/cjs/loader.js:1027:10)
at Module.load (internal/modules/cjs/loader.js:863:32)
at Function.Module._load (internal/modules/cjs/loader.js:708:14)
at Function.executeUserEntryPoint [as runMain] (internal/modules/run_main.js:60:12)
at internal/main/run_main_module.js:17:47
  

Steps to reproduce

  1. We have got a Single Page Application (SPA) using AngularJS and Capacitor that contains in the tests PactJS for contract testing.
  2. We are running the pact tests with all the other unit test of our SPA using Jest
  3. After tests are successfully executed we would like to upload the contacts produced by PactJS to our Pact Broker using a node script like suggested here: https://github.com/pact-foundation/pact-js#publish-in-a-custom-script
  4. The test execution and the upload on the pact broker are executed in the same npm (test:ci) script and the 2 commands are executed sequentially with the && ("test:ci": "npm run test && node pact.publish"`)
  5. If we run the "test:ci" script locally everything works fine and the /pacts/ folder is being created with the contracts tests JSON file. On BitRise when the node script it is executed it seems not to be able to find the /pacts/ folder
davidesalerno commented 3 years ago

The root cause of the issue it is related to the fact that we weren't able to detect when jest-pact mock server had started and so sometimes consumer driver contact test were fired even if the jest-pact mock server wasn't up and running causing the tests and this test to fail even if the file in the ./pacts folder was created.