Hello, I'm following the pact-workshop-js on Windo...
# pact-js
p
Hello, I'm following the pact-workshop-js on Windows 10. I forked the project into my own repo, ran
npm install
, and was able to complete step 1. I'm trying step2, I did "git checkout step2" and step 2 seems to have loaded fine. However, when running "npm test --prefix consumer", I get this error:
> CI=true react-scripts test
'CI' is not recognized as an internal or external command,
operable program or batch file.
npm ERR! Test failed.  See above for more details.
m
ah, that’s because the script is prefixed with
CI=true
to set the env var inline
Did you want to see if https://www.npmjs.com/package/cross-env helps?
if it does, I’d accept a PR to use that so that it’s more portable?
I think you could then replace it with
cross-env CI=true react-scripts ….
type thing
u
You can also run the commands using Bash
☝️ 1
m
does windows 10 come with WSL?
u
👍 1
WSL will need to be enabled and Ubuntu image installed
👍 1
p
Thanks guys, just now saw your replies. Sorry it's taken so long. I'll review all of your replies and let you know how it goes. I did find that I needed some React updates, so I've applied those. I probably won't get back till tomorrow some time. Thanks!
👍 1
@uglyog Yes, I've been doing this in Git Bash, I always run my VSCode with that as the terminal.
🤔 1
u
Ah! Damn, it means the npm steps are not using bash
p
Really?
It runs fine when I do "npm start....", etc.
Also, I've run the tests on the individual consumer and provider samples at the Git root (not the work shop ones). Those tests worked fine, after a couple of tweaks.
Yeah, so the other Consumer example does have "cross-env CI=true react-scripts test", and that works in that example (no WSL, etc.).
But if I paste that into the Consumer sample embedded in the js workshop, it does not work - I get "cross-env" is not recognized as an internal command, etc.
I've also done npm install, just hoping it missed something, it updates, but no change to the behavior.
doing npm install again actually breaks a lot of stuff.
m
did you add
cross-env
to the project’s dependencies?
p
Nope, not there. I'm going to nuke my local and recheck-out, try again.
But now dinner's ready!
m
haha
ok
My point above was you could try adding the package and using it - it’s not currently part of the project
👍 1
i.e. you’d need to
npm i --save-dev cross-env
and then modify the scripts accordingly
if you’re manually cd’ing into consumer/provider, don’t run
npm i
run
npm ci
if you’re running the commands from the project root,
npm i
should work. But as a general rule, use
npm ci
👍 1
p
FYI, sorry, having to be on customer site yesterday, I'll try these out today at some time, I hope.
Okay, I was able to make the changes to the package.json file, added "cross-env" to the "test" value, and the dependency, etc. I was also able to download/install "cross-env", though it worked by being at the workshop root (i.e., not cd'd into the consumer path). I was able to complete step 2. I'm going to experiment a bit, and maybe try that WSL option as well, though I wanted it to work as expected on straight windows, etc.
Thanks for the guidance!
I wonder if the workshop could be updated to include some instructions for this case?
☝️ 1
@Matt (pactflow.io / pact-js / pact-go) Just a note - on my Windows 10 laptop at least, running "ci" does not work, only "i". I've tried it a number of times/ways, and ci is not doing it. Thanks!
m
as in
npm ci
doesn’t work on Windows? what’s the problem?
ci
says “install exactly the versions of the dependencies in the lock file” where as
i
says: “install the latest version of every package in the package.json using the semver specified dependency rules”
I wonder if the workshop could be updated to include some instructions for this case?
Agreed! If you have cross-env working already, we’d appreciate a PR that adds it in and I’ll get it in so others can benefit?
p
I've never done a pull request. Should I do that at the pact-foundation level, or on my fork?
So, I made the change only to Step 2, and pushed to my fork. Now, I can see "This branch is 1 step ahead of pact-foundation:step 2". And under "Contribute", I see the option to "Open pull request".
Just looking for the steps to take from that point....
Also, just to clarify - the four files updated were the root "package.json" and "package-lock.json" and the "consumer/package.json" and "consumer/package-lock.json". They are all dependency references, etc.
Let me know if you want me to proceed. And if so, is there a way to do this all at once for each of the Step branches, etc.? Or would I have to do that for each of them?
I did a test pull request for Step 3, had to add cross-env to two locations in package. I'll hold off on any more till I hear back from you.
Yeah, and so with Step 4, I tried the "npm ci...." 2x, did not add cross-env. Did it with "npm c...." and it loaded fine. Odd.
For Step 4, when running test on the Provider, I'm getting this error:
"E:/Training/Pact.io/Pacit.io Demos/pact-workshop-js/provider/node_modules/@pact-foundation/pact-node/standalone/win32-1.88.63/pact/lib/vendor/ruby/2.2.0/gems/pact-provider-verifier-1.35.1/lib/pact/provider_verifier/app.rb3in `require': cannot load such file -- pact/provider_verifier/provider_states/add_provider_states_header (LoadError)"
Implementing the expanded path length in Windows did not work, but I was able to move to a shallower path, and that is working.
I did notice your comment from May 24, 2021, that the v3 branch would resolve this. Is that available yet, or merged into master, etc.?
Actually, is there a way to undo my pull request? I'd like to submit it a different way. I've read something about reverting from an already committed branch, or rebasing, etc. That's one reason I wanted someone from Pact to do the update, I'm still too new at this. Thanks!
m
I'll review tomorrow and come back to you. The main thing was to get you the commit/contribution credit, but all good if you'd like us to address it!
(the change committed to one step won't automatically work in another step, you'll need to merge the code into all steps. Again, we can do if easier)
The current workshop is designed for the main/stable release. If you want to use the V3 release you can, it’s back under active development after being blocked by some upstream issues.
https://github.com/pact-foundation/pact-js#pact-js-v3 The workshop will be helpful in understanding the concepts, but there will be some minor differences in APIs.
Let me know if you want me to proceed. And if so, is there a way to do this all at once for each of the Step branches, etc.? Or would I have to do that for each of them?
Ah, yes. We’ll need them in all steps. It’s a bit of a pain in the butt. I tend to get a single branch working first, and then cherry-pick each commit into separate branches (see e.g. https://github.com/pact-foundation/pact-workshop-js/blob/master/consumer/scripts/update-branches.sh to do so)
p
I'm thinking the best thing is to reject the Step 3 pull request, and I should have just updated the ReadMe file (near the beginning) on the main page, just instructions for anyone that has that error. Should not have updated the code.