Skip to content

Commit

Permalink
wip: gardening 🌳
Browse files Browse the repository at this point in the history
- Enforce prettier to simplify formatting
- Make standard, eslint, tslint and prettier all work together
- standard + eslint + prettier = JS
- standard + tslint + prettier = Typescript
- Formatted code
- Updated a bunch dependencies in `npm run audit`
- Brought karma up to 3.0.0 and corresponding examples
  • Loading branch information
mefellows committed Oct 9, 2018
1 parent 1a56178 commit 98aef59
Show file tree
Hide file tree
Showing 56 changed files with 1,933 additions and 1,517 deletions.
3 changes: 2 additions & 1 deletion examples/e2e/.eslintrc.yml → .eslintrc.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,5 @@ env:
es6: true
node: true
mocha: true
extends: 'eslint:recommended'
extends:
- "plugin:prettier/recommended"
20 changes: 13 additions & 7 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,9 @@ There may also be an answer to your question on [stackoverflow].

Please provide the following information with your issue to enable us to respond as quickly as possible.

* The relevant versions of the packages you are using.
* The steps to recreate your issue.
* An executable code example where possible. You can fork this repository and use one of the [examples] to quickly recreate your issue.
- The relevant versions of the packages you are using.
- The steps to recreate your issue.
- An executable code example where possible. You can fork this repository and use one of the [examples] to quickly recreate your issue.

### Commit messages

Expand All @@ -27,12 +27,18 @@ npm i -g cz-conventional-changelog

`git cz` to commit and commitizen will guide you.

## Code style and formatting

We use [Prettier](https://prettier.io/) for formatting, and for linting we use [TSLint](https://palantir.github.io/tslint/) (for TypeScript) and [Standard](https://standardjs.com) (for JS).

Please update your editor to enable Prettier, and things should be easy 👌. If not, our lint step will catch it.

## Pull requests

* Write tests for any changes
* Follow existing code style and conventions
* Separate unrelated changes into multiple pull requests
* For bigger changes, make sure you start a discussion first by creating an issue and explaining the intended change
- Write tests for any changes
- Follow existing code style and conventions
- Separate unrelated changes into multiple pull requests
- For bigger changes, make sure you start a discussion first by creating an issue and explaining the intended change

[stackoverflow]: https://stackoverflow.com/questions/tagged/pact
[examples]: https://github.com/pact-foundation/pact-js/tree/master/examples
3 changes: 1 addition & 2 deletions LICENSE
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
The MIT License (MIT)

Original work Copyright (c) 2014 ThoughtWorks
Modified work Copyright (c) 2014 DiUS
Original work Copyright (c) 2014 DiUS

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
Expand Down
36 changes: 18 additions & 18 deletions examples/ava/index.js
Original file line number Diff line number Diff line change
@@ -1,31 +1,31 @@
'use strict'
"use strict";

const axios = require('axios')
const axios = require("axios");

exports.getMeDogs = (endpoint) => {
const url = endpoint.url
const port = endpoint.port
exports.getMeDogs = endpoint => {
const url = endpoint.url;
const port = endpoint.port;

return axios.request({
method: 'GET',
method: "GET",
baseURL: `${url}:${port}`,
url: '/dogs',
url: "/dogs",
headers: {
'Accept': 'application/json'
Accept: "application/json"
}
})
}
});
};

exports.getMeDog = (endpoint) => {
const url = endpoint.url
const port = endpoint.port
exports.getMeDog = endpoint => {
const url = endpoint.url;
const port = endpoint.port;

return axios.request({
method: 'GET',
method: "GET",
baseURL: `${url}:${port}`,
url: '/dogs/1',
url: "/dogs/1",
headers: {
'Accept': 'application/json'
Accept: "application/json"
}
})
}
});
};
94 changes: 49 additions & 45 deletions examples/ava/test/get-dog_1.spec.js
Original file line number Diff line number Diff line change
@@ -1,79 +1,83 @@
'use strict'
"use strict";

const path = require('path')
const test = require('ava')
const pact = require('../../../dist/pact')
const path = require("path");
const test = require("ava");
const pact = require("../../../dist/pact");
const Pact = pact.Pact;
const getMeDog = require('../index').getMeDog
const getMeDog = require("../index").getMeDog;

const url = 'http://localhost'
const port = 8990
const url = "http://localhost";
const port = 8990;

const provider = new Pact({
port: port,
log: path.resolve(process.cwd(), 'logs', 'mockserver-integration.log'),
dir: path.resolve(process.cwd(), 'pacts'),
log: path.resolve(process.cwd(), "logs", "mockserver-integration.log"),
dir: path.resolve(process.cwd(), "pacts"),
spec: 2,
consumer: 'MyConsumer',
provider: 'MyProvider',
pactfileWriteMode: 'merge'
})
consumer: "MyConsumer",
provider: "MyProvider",
pactfileWriteMode: "merge"
});

test.before('setting up Dog API expectations', async() => {
await provider.setup()
})
test.before("setting up Dog API expectations", async () => {
await provider.setup();
});

test('Dog API GET /dogs/1', async t => {
t.plan(1)
test("Dog API GET /dogs/1", async t => {
t.plan(1);

// BEGIN -
// Setup interactions for expected API response from provider
// This is done due to similar reasons of tear-up/down of database
// data in tests.
const interaction = {
state: 'dog 1 exists',
uponReceiving: 'a request for dog 1',
state: "dog 1 exists",
uponReceiving: "a request for dog 1",
withRequest: {
method: 'GET',
path: '/dogs/1',
method: "GET",
path: "/dogs/1",
headers: {
'Accept': 'application/json'
Accept: "application/json"
}
},
willRespondWith: {
status: 200,
headers: {
'Content-Type': 'application/json'
"Content-Type": "application/json"
},
body: [{
dog: pact.Matchers.somethingLike(1),
name: pact.Matchers.term({
matcher: '\(\\S+\)',
generate: 'rocky'
})
}]
body: [
{
dog: pact.Matchers.somethingLike(1),
name: pact.Matchers.term({
matcher: "(\\S+)",
generate: "rocky"
})
}
]
}
}
};

await provider.addInteraction(interaction)
await provider.addInteraction(interaction);
// END

const urlAndPort = {
url: url,
port: port
}
const response = await getMeDog(urlAndPort)
t.deepEqual(response.data, [{
dog: 1,
name: "rocky"
}])
})
};
const response = await getMeDog(urlAndPort);
t.deepEqual(response.data, [
{
dog: 1,
name: "rocky"
}
]);
});

test.afterEach(async t => {
// verify with Pact, and reset expectations
await t.notThrows(provider.verify())
})
await t.notThrows(provider.verify());
});

test.always.after('pact.js mock server graceful shutdown', async() => {
await provider.finalize()
})
test.always.after("pact.js mock server graceful shutdown", async () => {
await provider.finalize();
});
94 changes: 49 additions & 45 deletions examples/ava/test/get-dogs.spec.js
Original file line number Diff line number Diff line change
@@ -1,79 +1,83 @@
'use strict'
"use strict";

const path = require('path')
const test = require('ava')
const pact = require('../../../dist/pact')
const path = require("path");
const test = require("ava");
const pact = require("../../../dist/pact");
const Pact = pact.Pact;
const getMeDogs = require('../index').getMeDogs
const getMeDogs = require("../index").getMeDogs;

const url = 'http://localhost'
const port = 8989
const url = "http://localhost";
const port = 8989;

const provider = new Pact({
port: port,
log: path.resolve(process.cwd(), 'logs', 'mockserver-integration.log'),
dir: path.resolve(process.cwd(), 'pacts'),
log: path.resolve(process.cwd(), "logs", "mockserver-integration.log"),
dir: path.resolve(process.cwd(), "pacts"),
spec: 2,
consumer: 'MyConsumer',
provider: 'MyProvider',
pactfileWriteMode: 'merge'
})
consumer: "MyConsumer",
provider: "MyProvider",
pactfileWriteMode: "merge"
});

test.before('setting up Dog API expectations', async() => {
await provider.setup()
})
test.before("setting up Dog API expectations", async () => {
await provider.setup();
});

test('Dog API GET /dogs', async t => {
t.plan(1)
test("Dog API GET /dogs", async t => {
t.plan(1);

// BEGIN -
// Setup interactions for expected API response from provider
// This is done due to similar reasons of tear-up/down of database
// data in tests.
const interaction = {
state: 'i have a list of dogs',
uponReceiving: 'a request for all dogs',
state: "i have a list of dogs",
uponReceiving: "a request for all dogs",
withRequest: {
method: 'GET',
path: '/dogs',
method: "GET",
path: "/dogs",
headers: {
'Accept': 'application/json'
Accept: "application/json"
}
},
willRespondWith: {
status: 200,
headers: {
'Content-Type': 'application/json'
"Content-Type": "application/json"
},
body: [{
dog: pact.Matchers.somethingLike(1),
name: pact.Matchers.term({
matcher: '\(\\S+\)',
generate: 'rocky'
})
}]
body: [
{
dog: pact.Matchers.somethingLike(1),
name: pact.Matchers.term({
matcher: "(\\S+)",
generate: "rocky"
})
}
]
}
}
};

await provider.addInteraction(interaction)
await provider.addInteraction(interaction);
// END

const urlAndPort = {
url: url,
port: port
}
const response = await getMeDogs(urlAndPort)
t.deepEqual(response.data, [{
dog: 1,
name: "rocky"
}])
})
};
const response = await getMeDogs(urlAndPort);
t.deepEqual(response.data, [
{
dog: 1,
name: "rocky"
}
]);
});

test.afterEach(async t => {
// verify with Pact, and reset expectations
await t.notThrows(provider.verify())
})
await t.notThrows(provider.verify());
});

test.always.after('pact.js mock server graceful shutdown', async() => {
await provider.finalize()
})
test.always.after("pact.js mock server graceful shutdown", async () => {
await provider.finalize();
});
Loading

0 comments on commit 98aef59

Please sign in to comment.