-
Notifications
You must be signed in to change notification settings - Fork 26
Modifying pact-consumer-js-dsl to work with both Nodejs and Web projects #27
Changes from all commits
b4b062a
be089e9
65c5632
a4fc3fb
b3e4251
cc1a2ea
933b3e0
1714620
a18d954
3ca2d25
dd23677
2a3689f
9f8ad2c
62015d7
473df4e
b85108f
074ea22
ea7ece9
95b25be
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
This file was deleted.
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1,2 @@ | ||
source 'https://rubygems.org' | ||
gem 'pact-mock_service', '~> 0.2.3.pre.rc1' | ||
gem 'pact-mock_service', '~> 0.2.4' |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -12,11 +12,15 @@ This DSL relies on the Ruby [pact-mock_service][pact-mock-service] gem to provid | |
* Google users group: https://groups.google.com/forum/#!forum/pact-support | ||
* Twitter: [@pact_up](https://twitter.com/pact_up) | ||
|
||
### Getting Started (with Karma, Jasmine and the pact-mock_service gem) | ||
### Installing pact-mock-service | ||
|
||
1. Install the [pact-mock_service](https://github.com/bethesque/pact-mock_service) ruby gem | ||
* If on Windows, please refer to the [Installing pact-mock-service on Windows](https://github.com/bethesque/pact-mock_service/wiki/Installing-the-pact-mock_service-gem-on-Windows) * | ||
|
||
The easiest way is to add `gem 'pact-mock_service', '~> 0.2.3.pre.rc1'` to your `Gemfile` and run `bundle install` | ||
1. You must install [Ruby](https://www.ruby-lang.org/en/downloads/) and [RubyGems](https://rubygems.org/pages/download) first. | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. If you have multiple versions of the gem installed, and you omit the Gemfile and bundle exec, then you may not get the gem version you expect. It is not good Ruby practise to use a gem without a Gemfile. Can you put that back in please? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @bethesque I added the Gemfile back in, but I'm leaving the README how it is. It might be good Ruby practice, but this isn't for people that write Ruby. As of yet, I haven't had the need of more than one version of pact-mock-service. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. That's like me claiming that I don't need to follow good node practice because I'm not a node developer :P |
||
|
||
1. After these binaries as available in the console, you can install the mock service easily using this command: `gem i pact-mock_service -v 0.2.4` * Windows users must run this command after following Wiki instructions * | ||
|
||
### Getting Started (with Karma, Jasmine and pact-mock-service) | ||
|
||
1. Install and configure Karma with Jasmine | ||
|
||
|
@@ -25,18 +29,19 @@ This DSL relies on the Ruby [pact-mock_service][pact-mock-service] gem to provid | |
1. Install Karma using their [installation instructions](http://karma-runner.github.io/0.12/intro/installation.html) | ||
|
||
This basically consists of running, | ||
|
||
* `npm install karma --save-dev` | ||
* `npm install karma-jasmine karma-chrome-launcher --save-dev` | ||
* `npm install -g karma-cli` | ||
|
||
``` | ||
npm install karma karma-jasmine karma-chrome-launcher --save-dev | ||
npm install -g karma-cli | ||
``` | ||
|
||
1. Initialise and configure Karma | ||
|
||
Run `karma init`. Answer **jasmine** for *testing framework* and **no** for *use require.js*. | ||
|
||
1. Add `pact-consumer-js-dsl` to your project by running `npm install DiUS/pact-consumer-js-dsl#X.Y.Z --save-dev`, where `X.Y.Z` is the latest stable version, according to the [releases][releases] page. | ||
1. Add `pact-consumer-js-dsl` to your project by running `bower install pact-consumer-js-dsl --save-dev`. | ||
|
||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. What about people who are using npm without bower? I would have thought npm was a more consistent common denominator? (Not being a javascript person, I can't really comment though). There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @bethesque If you're using Karma, it would need to use the web version, and not the node version . For web libraries, you use Bower, for Node libraries you use npm. It's not a hard rule, but either way, with the new UMD wrapping, they both work. |
||
1. Tell Karma about `pact-consumer-js-dsl.js` in `karma.conf.js`. In the `files: []` section add a new entry for `node_modules/pact-consumer-js-dsl/dist/pact-consumer-js-dsl.js`. | ||
1. Tell Karma about `pact-consumer-js-dsl.js` in `karma.conf.js`. In the `files: []` section add a new entry for `bower_components/pact-consumer-js-dsl/dist/web/pact-consumer-js-dsl.js`. | ||
|
||
1. Allow tests to load resources from `pact` mock server. One way to do this is in the `karma.conf.js`, change `browsers: ['Chrome'],` or `browsers: ['PhantomJS'],` to, | ||
|
||
|
@@ -104,19 +109,32 @@ This DSL relies on the Ruby [pact-mock_service][pact-mock-service] gem to provid | |
|
||
1. Let's run that bad boy! | ||
|
||
* start the pact mock server with `bundle exec pact-mock-service -p 1234 -l log/pact.logs --pact-dir tmp/pacts` | ||
* start the pact mock server with `pact-mock-service -p 1234 -l log/pact.logs --pact-dir tmp/pacts` | ||
* run `karma start` (in another terminal window) | ||
* inspect the pact file that has been written to "hello_consumer-hello_provider.json" | ||
|
||
### Example | ||
#### Web Example | ||
|
||
Have a look at the [example](/example) folder. Ensure you have Google Chrome installed. | ||
Have a look at the [example](/example/web) folder. Ensure you have Google Chrome installed. | ||
|
||
$ cd example | ||
$ bundle install | ||
$ npm install | ||
$ npm test | ||
|
||
|
||
#### Nodejs Example | ||
|
||
This is only an example on how to use the pact-consumer-js-dsl within Node. This is not best practice, but is a good starting point without creating a lengthy example using Grunt or Gulp with Protractor or Karma. | ||
|
||
1. Start pact-mock-service with `pact-mock-service -p 1234 -l tmp/pact.log --pact-dir tmp/pacts` | ||
|
||
1. Run nodejs command to setup pact consumer `node example/nodejs/setup.js` | ||
|
||
1. Run your tests here with whatever you want, like Protractor for e2e testing | ||
|
||
1. Run nodejs command to verify interactions and write pact files `node example/nodejs/teardown.js` | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This assumes that there is only one big setup and one big tear down, and one big verify - is that what is happening? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @bethesque that's the way the example does it, but it's not a requirement. I will need to expand more on this in the example. I just wanted to show something quick and dirty for using it in Node. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Righto. If it works for you, that's great, but it's not the example I'd like to show people, because people will just unthinkingly copy stuff without critical thought. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I doubt people would simply copy paste, plus, I was trying to go for the simplest example without having to setup a massive protractor project in the first place. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Understandable. Maybe we can put in a comment to that effect? |
||
|
||
# Contributing | ||
|
||
Please read [CONTRIBUTING.md](/CONTRIBUTING.md) | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,13 +1,28 @@ | ||
{ | ||
"name": "pact-consumer-js-dsl", | ||
"version": "0.1.0", | ||
"version": "0.1.1", | ||
"ignore": [ | ||
".gitignore", | ||
".jshintrc", | ||
".ruby-gemset", | ||
".travis.yml", | ||
"checkstyle.xml", | ||
"gulpfile.js", | ||
"node.prefix", | ||
"node.suffix", | ||
"package.json", | ||
"src", | ||
"spec" | ||
], | ||
"authors": [ | ||
"Fu Ying <fu.ying.er@rea-group.com>", | ||
"Malinda Kapuruge <mkapuruge@dius.com.au>" | ||
"Malinda Kapuruge <mkapuruge@dius.com.au>", | ||
"Tarcio Saraiva <tsaraiva@dius.com.au>", | ||
"Beth Skurrie <bskurrie@dius.com.au>", | ||
"Michel Boudreau <michelboudreau@gmail.com>", | ||
"Ben Sayers <bpsayers@gmail.com>" | ||
], | ||
"main": ["dist/pact-consumer-js-dsl.js"], | ||
"dependencies": { | ||
"jquery": "~1.8.3" | ||
}, | ||
"dependencies": {}, | ||
"devDependencies": {} | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I would think that installing gulp, bower and karma as global or local is the user's choice, is it not? There's nothing in the pact dsl that requires them to be global is there?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It is, just makes it easier to run things. I guess I can change that.