-
-
Notifications
You must be signed in to change notification settings - Fork 349
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- 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
Showing
56 changed files
with
1,933 additions
and
1,517 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2,4 +2,5 @@ env: | |
es6: true | ||
node: true | ||
mocha: true | ||
extends: 'eslint:recommended' | ||
extends: | ||
- "plugin:prettier/recommended" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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" | ||
} | ||
}) | ||
} | ||
}); | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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(); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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(); | ||
}); |
Oops, something went wrong.