Skip to content

Remove development debug code from production builds (#10521) #10522

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

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 4 additions & 1 deletion src/core/components/debug.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,10 @@ export default class Debug extends React.Component {

let { getState, getComponent } = this.props

window.props = this.props
// Only expose props to window in development mode
if (process.env.NODE_ENV === "development") {
window.props = this.props
}

const Collapse = getComponent("Collapse")

Expand Down
10 changes: 3 additions & 7 deletions src/core/components/examples-select.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -19,13 +19,9 @@ export default class ExamplesSelect extends React.PureComponent {

static defaultProps = {
examples: Map({}),
onSelect: (...args) =>
// eslint-disable-next-line no-console
console.log(
// FIXME: remove before merging to master...
`DEBUG: ExamplesSelect was not given an onSelect callback`,
...args
),
onSelect: () => {
// No-op default callback
},
currentExampleKey: null,
showLabels: true,
}
Expand Down
7 changes: 6 additions & 1 deletion src/core/config/sources/query.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,13 @@ const optionsFromQuery = () => (options) => {
const urlSearchParams = options.queryConfigEnabled ? parseSearch() : {}

return Object.entries(urlSearchParams).reduce((acc, [key, value]) => {
// TODO(oliwia.rogala@smartbear.com): drop support for `config` in the next major release
// Legacy support for 'config' parameter (deprecated, will be removed in next major release)
if (key === "config") {
if (process.env.NODE_ENV === "development") {
console.warn(
"The 'config' query parameter is deprecated and will be removed in the next major release. Use 'configUrl' instead."
)
}
acc["configUrl"] = value
} else if (key === "urls.primaryName") {
acc[key] = value
Expand Down
15 changes: 11 additions & 4 deletions src/core/plugins/spec/actions.js
Original file line number Diff line number Diff line change
Expand Up @@ -66,13 +66,20 @@ export const parseToJson = (str) => ({specActions, specSelectors, errActions}) =
errActions.clear({ source: "parser" })
json = YAML.load(str, { schema: JSON_SCHEMA })
} catch(e) {
// TODO: push error to state
console.error(e)
// Handle parsing errors by creating proper error state
const errorMessage = e.reason || e.message || "Failed to parse specification"
const errorLine = e.mark && e.mark.line ? e.mark.line + 1 : undefined

// Only log to console in development
if (process.env.NODE_ENV === "development") {
console.error("Spec parsing error:", e)
}

return errActions.newSpecErr({
source: "parser",
level: "error",
message: e.reason,
line: e.mark && e.mark.line ? e.mark.line + 1 : undefined
message: errorMessage,
line: errorLine
})
}
if(json && typeof json === "object") {
Expand Down