Skip to content

Commit

Permalink
wip: more typescript gardening and simplification
Browse files Browse the repository at this point in the history
  • Loading branch information
mefellows committed Oct 9, 2018
1 parent 56843a1 commit 8421853
Show file tree
Hide file tree
Showing 31 changed files with 118 additions and 111 deletions.
2 changes: 2 additions & 0 deletions .eslintrc.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,3 +4,5 @@ env:
mocha: true
extends:
- plugin:prettier/recommended"
rules:
comma-dangle: "always-multiline"
2 changes: 1 addition & 1 deletion .prettierrc.yml
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
trailingComma: "all"
trailingComma: "es5"
semi: false
2 changes: 1 addition & 1 deletion examples/e2e/consumer.js
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ const suggestion = mate => {

return availableAnimals().then(available => {
const eligible = available.filter(
a => !predicates.map(p => p(a, mate)).includes(false),
a => !predicates.map(p => p(a, mate)).includes(false)
)

return {
Expand Down
2 changes: 1 addition & 1 deletion examples/e2e/provider.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ server.use(bodyParser.json())
server.use(
bodyParser.urlencoded({
extended: true,
}),
})
)
server.use((req, res, next) => {
res.header("Content-Type", "application/json; charset=utf-8")
Expand Down
10 changes: 5 additions & 5 deletions examples/e2e/test/consumer.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -124,15 +124,15 @@ describe("Pact", () => {
},
body: animalListExpectation,
},
}),
})
)

it("returns a list of animals", done => {
const suggestedMates = suggestion(suitor)

expect(suggestedMates).to.eventually.have.deep.property(
"suggestions[0].score",
94,
94
)
expect(suggestedMates)
.to.eventually.have.property("suggestions")
Expand All @@ -159,7 +159,7 @@ describe("Pact", () => {
},
body: animalBodyExpectation,
},
}),
})
)

it("returns the animal", done => {
Expand All @@ -183,7 +183,7 @@ describe("Pact", () => {
willRespondWith: {
status: 404,
},
}),
})
)

it("returns a 404", done => {
Expand Down Expand Up @@ -217,7 +217,7 @@ describe("Pact", () => {
},
body: like(suitor),
},
}),
})
)

it("should create a new mate", done => {
Expand Down
2 changes: 1 addition & 1 deletion examples/e2e/test/publish.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ const opts = {
pactFilesOrDirs: [
path.resolve(
__dirname,
"../pacts/matching_service-animal_profile_service.json",
"../pacts/matching_service-animal_profile_service.json"
),
],
pactBroker: "https://test.pact.dius.com.au",
Expand Down
8 changes: 6 additions & 2 deletions examples/graphql/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,9 @@
"build": "tsc",
"clean": "rimraf pacts",
"test": "npm run clean && npm run test:consumer && npm run test:publish && npm run test:provider",
"test:consumer": "nyc --check-coverage --reporter=html --reporter=text-summary mocha consumer.spec.ts",
"test:consumer": "nyc --reporter=text-summary mocha consumer.spec.ts",
"test:publish": "node publish.js",
"test:provider": "nyc --check-coverage --reporter=html --reporter=text-summary mocha -t 10000 provider.spec.ts"
"test:provider": "nyc --reporter=text-summary mocha -t 10000 provider.spec.ts"
},
"keywords": [
"graphql",
Expand All @@ -31,6 +31,10 @@
"graphql-tag": "^2.9.1",
"graphql-tools": "^2.24.0",
"node-fetch": "^2.2.0",
"nyc": "^11.6.0",
"rimraf": "^2.6.2"
},
"dependencies": {
"mocha": "^5.1.1"
}
}
2 changes: 1 addition & 1 deletion examples/graphql/provider.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ app.use(
graphiql: true,
rootValue: root,
schema,
}),
})
)

export function start(): any {
Expand Down
2 changes: 1 addition & 1 deletion examples/messages/publish.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ const opts = {
pactFilesOrDirs: [
path.resolve(
__dirname,
"pacts/myjsmessageconsumer-myjsmessageprovider.json",
"pacts/myjsmessageconsumer-myjsmessageprovider.json"
),
],
pactBroker: "https://test.pact.dius.com.au",
Expand Down
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,7 @@
"cli-color": "^1.1.0",
"es6-object-assign": "^1.1.0",
"es6-promise": "^4.1.1",
"eslint": "^5.6.1",
"eslint-plugin-prettier": "^3.0.0",
"express": "^4.16.3",
"graphql": "^0.13.2",
Expand Down
2 changes: 1 addition & 1 deletion src/common/logger.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ export class Logger extends bunyan {
duration: time,
type: "TIMER",
},
`TIMER: ${action} completed in ${time} milliseconds`,
`TIMER: ${action} completed in ${time} milliseconds`
)
}

Expand Down
2 changes: 1 addition & 1 deletion src/common/net.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ describe("Net", () => {
},
(e: any) => {
done()
},
}
)
})
})
Expand Down
2 changes: 1 addition & 1 deletion src/common/net.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ const isPortAvailable = (port: number, host: string): Promise<void> => {
(e: any) =>
e.code === "EADDRINUSE"
? reject(new Error(`Port ${port} is unavailable`))
: reject(e),
: reject(e)
)
.on("listening", () => server.once("close", () => resolve()).close())
})
Expand Down
2 changes: 1 addition & 1 deletion src/common/request.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ export class Request {
public send(
method: HTTPMethod | methods,
url: string,
body?: string,
body?: string
): Promise<string> {
const opts = {
body,
Expand Down
2 changes: 1 addition & 1 deletion src/dsl/graphql.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ describe("GraphQLInteraction", () => {
describe("when given an invalid query", () => {
it("should fail with an error", () => {
expect(() =>
interaction.withQuery("{ not properly terminated"),
interaction.withQuery("{ not properly terminated")
).to.throw(Error)
})
})
Expand Down
6 changes: 3 additions & 3 deletions src/dsl/graphql.ts
Original file line number Diff line number Diff line change
Expand Up @@ -37,8 +37,8 @@ export class GraphQLInteraction extends Interaction {
) {
throw new Error(
`You must provide a valid HTTP method: ${keys(GraphQLOperations).join(
", ",
)}.`,
", "
)}.`
)
}

Expand Down Expand Up @@ -114,7 +114,7 @@ export class GraphQLInteraction extends Interaction {
headers: { "content-type": "application/json" },
method: "POST",
},
this.state.request,
this.state.request
)

return this.state
Expand Down
18 changes: 9 additions & 9 deletions src/dsl/interaction.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ describe("Interaction", () => {
it("throws error when no description provided", () => {
expect(interaction.uponReceiving).to.throw(
Error,
"You must provide a description for the interaction.",
"You must provide a description for the interaction."
)
})

Expand All @@ -58,29 +58,29 @@ describe("Interaction", () => {
it("throws error when method is not provided", () => {
expect(interaction.withRequest.bind(interaction, {})).to.throw(
Error,
"You must provide an HTTP method.",
"You must provide an HTTP method."
)
})

it("throws error when an invalid method is provided", () => {
expect(
interaction.withRequest.bind(interaction, { method: "FOO" }),
interaction.withRequest.bind(interaction, { method: "FOO" })
).to.throw(
Error,
"You must provide a valid HTTP method: GET, POST, PUT, PATCH, DELETE, HEAD, OPTIONS.",
"You must provide a valid HTTP method: GET, POST, PUT, PATCH, DELETE, HEAD, OPTIONS."
)
})

it("throws error when method is not provided", () => {
expect(interaction.withRequest.bind(interaction, { ath: "/" })).to.throw(
Error,
"You must provide an HTTP method.",
"You must provide an HTTP method."
)
})

it("throws error when path is not provided", () => {
expect(
interaction.withRequest.bind(interaction, { method: HTTPMethod.GET }),
interaction.withRequest.bind(interaction, { method: HTTPMethod.GET })
).to.throw(Error, "You must provide a path.")
})

Expand Down Expand Up @@ -119,7 +119,7 @@ describe("Interaction", () => {
"path",
"query",
"headers",
"body",
"body"
)
})
})
Expand Down Expand Up @@ -157,13 +157,13 @@ describe("Interaction", () => {
it("throws error when status is not provided", () => {
expect(interaction.willRespondWith.bind(interaction, {})).to.throw(
Error,
"You must provide a status code.",
"You must provide a status code."
)
})

it("throws error when status is blank", () => {
expect(
interaction.willRespondWith.bind(interaction, { status: "" }),
interaction.willRespondWith.bind(interaction, { status: "" })
).to.throw(Error, "You must provide a status code.")
})

Expand Down
4 changes: 2 additions & 2 deletions src/dsl/interaction.ts
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ export class Interaction {

if (keys(HTTPMethod).indexOf(requestOpts.method.toString()) < 0) {
throw new Error(
`You must provide a valid HTTP method: ${keys(HTTPMethod).join(", ")}.`,
`You must provide a valid HTTP method: ${keys(HTTPMethod).join(", ")}.`
)
}

Expand Down Expand Up @@ -118,7 +118,7 @@ export class Interaction {
headers: responseOpts.headers || undefined,
status: responseOpts.status,
},
isNil,
isNil
) as ResponseOptions
return this
}
Expand Down
30 changes: 15 additions & 15 deletions src/dsl/matchers.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,14 +28,14 @@ describe("Matcher", () => {
describe("and a matching example", () => {
it("should return true", () => {
expect(validateExample("2010-01-01", ISO8601_DATE_FORMAT)).to.eql(
true,
true
)
})
})
describe("and a failing example", () => {
it("should return false", () => {
expect(validateExample("not a date", ISO8601_DATE_FORMAT)).to.eql(
false,
false
)
})
})
Expand Down Expand Up @@ -220,7 +220,7 @@ describe("Matcher", () => {

const match = eachLike({ id: somethingLike(10) }, { min: 1 })
expect(JSON.stringify(match)).to.deep.include(
JSON.stringify(expected),
JSON.stringify(expected)
)
})
})
Expand Down Expand Up @@ -252,11 +252,11 @@ describe("Matcher", () => {
matcher: "red|green",
}),
},
{ min: 1 },
{ min: 1 }
)

expect(JSON.stringify(match)).to.deep.include(
JSON.stringify(expected),
JSON.stringify(expected)
)
})
})
Expand All @@ -275,7 +275,7 @@ describe("Matcher", () => {

const match = eachLike(eachLike("blue", { min: 1 }), { min: 1 })
expect(JSON.stringify(match)).to.deep.include(
JSON.stringify(expected),
JSON.stringify(expected)
)
})
})
Expand Down Expand Up @@ -329,16 +329,16 @@ describe("Matcher", () => {
size: somethingLike(10),
tag: eachLike(
[somethingLike("jumper"), somethingLike("shirt")],
{ min: 2 },
{ min: 2 }
),
},
{ min: 1 },
{ min: 1 }
),
{ min: 1 },
{ min: 1 }
)

expect(JSON.stringify(match)).to.deep.include(
JSON.stringify(expected),
JSON.stringify(expected)
)
})
})
Expand Down Expand Up @@ -408,7 +408,7 @@ describe("Matcher", () => {
it("should not fail", () => {
expect(ipv6Address("::1")).to.be.an("object")
expect(ipv6Address("2001:0db8:85a3:0000:0000:8a2e:0370:7334")).to.be.an(
"object",
"object"
)
expect(ipv6Address()).to.be.an("object")
})
Expand Down Expand Up @@ -469,7 +469,7 @@ describe("Matcher", () => {
describe("when given a valid rfc3339Timestamp", () => {
it("should not fail", () => {
expect(rfc3339Timestamp("Mon, 31 Oct 2016 15:21:41 -0400")).to.be.an(
"object",
"object"
)
expect(rfc3339Timestamp()).to.be.an("object")
})
Expand Down Expand Up @@ -519,7 +519,7 @@ describe("Matcher", () => {
describe("when given a valid iso8601DateTime", () => {
it("should not fail", () => {
expect(iso8601DateTime("2015-08-06T16:53:10+01:00")).to.be.an(
"object",
"object"
)
expect(iso8601DateTime()).to.be.an("object")
})
Expand All @@ -537,7 +537,7 @@ describe("Matcher", () => {
describe("when given a valid iso8601DateTimeWithMillis", () => {
it("should not fail", () => {
expect(
iso8601DateTimeWithMillis("2015-08-06T16:53:10.123+01:00"),
iso8601DateTimeWithMillis("2015-08-06T16:53:10.123+01:00")
).to.be.an("object")
expect(iso8601DateTimeWithMillis()).to.be.an("object")
})
Expand Down Expand Up @@ -586,7 +586,7 @@ describe("Matcher", () => {
foo: "bar",
baz: somethingLike("bat"),
},
{ min: 3 },
{ min: 3 }
),
},
})
Expand Down
Loading

0 comments on commit 8421853

Please sign in to comment.