-
Notifications
You must be signed in to change notification settings - Fork 64
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
feat: generate "X-Request-ID" header #801
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,7 +1,6 @@ | ||
"use strict"; | ||
|
||
const _ = require("lodash"); | ||
|
||
const { Config } = require("src/config"); | ||
const defaults = require("src/config/defaults"); | ||
const { WEBDRIVER_PROTOCOL, DEVTOOLS_PROTOCOL, SAVE_HISTORY_MODE } = require("src/constants/config"); | ||
|
@@ -1626,34 +1625,75 @@ describe("config browser-options", () => { | |
}); | ||
}); | ||
|
||
["agent", "headers"].forEach(option => { | ||
describe(option, () => { | ||
it(`should throw error if "${option}" is not an object`, () => { | ||
const readConfig = _.set({}, "browsers.b1", mkBrowser_({ [option]: "string" })); | ||
describe("agent", () => { | ||
it(`should throw error if "agent" is not an object`, () => { | ||
const readConfig = _.set({}, "browsers.b1", mkBrowser_({ agent: "string" })); | ||
|
||
Config.read.returns(readConfig); | ||
Config.read.returns(readConfig); | ||
|
||
assert.throws(() => createConfig(), Error, `"${option}" must be an object`); | ||
}); | ||
assert.throws(() => createConfig(), Error, `"agent" must be an object`); | ||
}); | ||
|
||
it("should set a default value if it is not set in config", () => { | ||
it("should set a default value if it is not set in config", () => { | ||
const readConfig = _.set({}, "browsers.b1", mkBrowser_()); | ||
Config.read.returns(readConfig); | ||
|
||
const config = createConfig(); | ||
|
||
assert.equal(config.agent, defaults.option); | ||
}); | ||
|
||
it("should set provided value", () => { | ||
const readConfig = _.set({}, "browsers.b1", mkBrowser_({ agent: { k1: "v1", k2: "v2" } })); | ||
Config.read.returns(readConfig); | ||
|
||
const config = createConfig(); | ||
|
||
assert.deepEqual(config.browsers.b1.agent, { k1: "v1", k2: "v2" }); | ||
}); | ||
}); | ||
|
||
describe("headers", () => { | ||
it("should throw error if option is not an object", () => { | ||
const readConfig = _.set({}, "browsers.b1", mkBrowser_({ headers: null })); | ||
|
||
Config.read.returns(readConfig); | ||
|
||
assert.throws(() => createConfig(), Error, `"headers" must be an object`); | ||
}); | ||
|
||
describe("should generate 'X-Request-ID'", () => { | ||
it("if value is not set in config", () => { | ||
const readConfig = _.set({}, "browsers.b1", mkBrowser_()); | ||
Config.read.returns(readConfig); | ||
|
||
const config = createConfig(); | ||
|
||
assert.equal(config[option], defaults[option]); | ||
assert.typeOf(config.browsers.b1.headers["X-Request-ID"], "string"); | ||
assert.isAbove(config.browsers.b1.headers["X-Request-ID"].length, 20); | ||
}); | ||
|
||
it("should set provided value", () => { | ||
const readConfig = _.set({}, "browsers.b1", mkBrowser_({ [option]: { k1: "v1", k2: "v2" } })); | ||
it("if it is not specified in value", () => { | ||
const readConfig = _.set({}, "browsers.b1", mkBrowser_({ headers: { k1: "v1" } })); | ||
Config.read.returns(readConfig); | ||
|
||
const config = createConfig(); | ||
|
||
assert.deepEqual(config.browsers.b1[option], { k1: "v1", k2: "v2" }); | ||
assert.typeOf(config.browsers.b1.headers["X-Request-ID"], "string"); | ||
assert.isAbove(config.browsers.b1.headers["X-Request-ID"].length, 20); | ||
assert.equal(config.browsers.b1.headers.k1, "v1"); | ||
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. Тут используя sinon@4 невозможно застабать Пробовал застабать и через |
||
}); | ||
}); | ||
|
||
it("should not generate 'X-Request-ID' if it is specified by user", () => { | ||
const headers = { "X-Request-ID": "my-req-id" }; | ||
const readConfig = _.set({}, "browsers.b1", mkBrowser_({ headers })); | ||
Config.read.returns(readConfig); | ||
|
||
const config = createConfig(); | ||
|
||
assert.deepEqual(config.browsers.b1.headers, headers); | ||
}); | ||
}); | ||
|
||
["transformRequest", "transformResponse"].forEach(option => { | ||
|
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.
Теперь только
object
.null
юзать нельзя