Skip to content

Commit

Permalink
refactor: pass all options down to server
Browse files Browse the repository at this point in the history
Options which are added to the server will now be automatically passed
down without a need for modifications in this library, other than
exposing the new options in the types, if that is desirable.

This allows consumers to pass down the monkeypatch option when creating
the server, but that option is intentionally excluded from the
PactOptions type, as this option is advanced and its use is discouraged.
  • Loading branch information
kevinkir committed Jan 11, 2022
1 parent 4b9486d commit b40eee9
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 14 deletions.
2 changes: 2 additions & 0 deletions src/httpPact.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ describe("Pact", () => {
spec: 2,
cors: false,
pactfileWriteMode: "overwrite",
monkeypatch: "/path/to/monkeypatch.rb",
} as PactOptionsComplete

before(() => {
Expand Down Expand Up @@ -140,6 +141,7 @@ describe("Pact", () => {
spec: 2,
cors: false,
pactfileWriteMode: "overwrite",
monkeypatch: "/path/to/monkeypatch.rb",
})
})
})
Expand Down
18 changes: 4 additions & 14 deletions src/httpPact.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import { isPortAvailable } from "./common/net"
import logger, { traceHttpInteractions, setLogLevel } from "./common/logger"
import { MockService } from "./dsl/mockService"
import { LogLevel, PactOptions, PactOptionsComplete } from "./dsl/options"
import { Server } from "@pact-foundation/pact-node/src/server"
import { Server, ServerOptions } from "@pact-foundation/pact-node/src/server"
import VerificationError from "./errors/verificationError"
import ConfigurationError from "./errors/configurationError"

Expand Down Expand Up @@ -278,19 +278,9 @@ export class Pact {

private createServer(config: PactOptions) {
this.server = serviceFactory.createServer({
consumer: this.opts.consumer,
cors: this.opts.cors,
dir: this.opts.dir,
host: this.opts.host,
log: this.opts.log,
pactFileWriteMode: this.opts.pactfileWriteMode,
timeout: 30000,
...this.opts,
port: config.port, // allow to be undefined
provider: this.opts.provider,
spec: this.opts.spec,
ssl: this.opts.ssl,
sslcert: this.opts.sslcert,
sslkey: this.opts.sslkey,
timeout: this.opts.timeout || 30000,
})
} as ServerOptions)
}
}

0 comments on commit b40eee9

Please sign in to comment.