Skip to content

Commit

Permalink
enforce curly brackets
Browse files Browse the repository at this point in the history
  • Loading branch information
christian-bromann committed Dec 28, 2022
1 parent f7d4b2e commit e233109
Show file tree
Hide file tree
Showing 13 changed files with 66 additions and 41 deletions.
1 change: 1 addition & 0 deletions .eslintrc.js
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ module.exports = {
}],
'no-var': 'error',
'unicode-bom': ['error', 'never'],
'curly': ['error', 'all'],
'object-curly-spacing': ['error', 'always'],
'keyword-spacing':['error'],
'require-atomic-updates': 0,
Expand Down
8 changes: 4 additions & 4 deletions packages/wdio-allure-reporter/src/compoundError.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,10 @@ export default class CompoundError extends Error {

constructor(...innerErrors: Error[]) {
const message = ['CompoundError: One or more errors occurred. ---\n'].
concat(innerErrors.map(x => {
if (x.stack) return `${indentAll(x.stack)}\n--- End of stack trace ---\n`
return ` ${x.message}\n--- End of error message ---\n`
})).join('\n')
concat(innerErrors.map(x => x.stack
? `${indentAll(x.stack)}\n--- End of stack trace ---\n`
: ` ${x.message}\n--- End of error message ---\n`
)).join('\n')

super(message)
this.innerErrors = innerErrors
Expand Down
47 changes: 24 additions & 23 deletions packages/wdio-allure-reporter/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -389,11 +389,9 @@ class AllureReporter extends WDIOReporter {

// set beforeEach / afterEach hook (step) status
if (this._options.disableMochaHooks && isMochaEachHooks(hook.title)) {
if (hook.error) {
this._allure.endStep('failed')
} else {
this._allure.endStep('passed')
}
hook.error
? this._allure.endStep('failed')
: this._allure.endStep('passed')
return
}

Expand All @@ -404,26 +402,29 @@ class AllureReporter extends WDIOReporter {
this.attachScreenshot()
}
this.onTestFail(hook)
} else if (this._options.disableMochaHooks || this._options.useCucumberStepReporter) {
if (!isMochaAllHooks(hook.title)) {
this.onTestPass()

// remove hook from suite if it has no steps
if (this._allure.getCurrentTest().steps.length === 0 && !this._options.useCucumberStepReporter) {
this._allure.getCurrentSuite().testcases.pop()
} else if (this._options.useCucumberStepReporter) {
// remove hook when it's registered as a step and if it's passed
const step = this._allure.getCurrentTest().steps.pop()

// if it had any attachments, reattach them to current test
if (step && step.attachments.length >= 1) {
step.attachments.forEach((attachment: any) => {
this._allure.getCurrentTest().addAttachment(attachment)
})
}
} else if (
(this._options.disableMochaHooks || this._options.useCucumberStepReporter) &&
!isMochaAllHooks(hook.title)
) {
this.onTestPass()

// remove hook from suite if it has no steps
if (this._allure.getCurrentTest().steps.length === 0 && !this._options.useCucumberStepReporter) {
this._allure.getCurrentSuite().testcases.pop()
} else if (this._options.useCucumberStepReporter) {
// remove hook when it's registered as a step and if it's passed
const step = this._allure.getCurrentTest().steps.pop()

// if it had any attachments, reattach them to current test
if (step && step.attachments.length >= 1) {
step.attachments.forEach((attachment: any) => {
this._allure.getCurrentTest().addAttachment(attachment)
})
}
}
} else if (!this._options.disableMochaHooks) this.onTestPass()
} else if (!this._options.disableMochaHooks) {
this.onTestPass()
}
}

addLabel({
Expand Down
8 changes: 6 additions & 2 deletions packages/wdio-browserstack-service/src/launcher.ts
Original file line number Diff line number Diff line change
Expand Up @@ -179,8 +179,12 @@ export default class BrowserstackLauncherService implements Services.ServiceInst
log.info(`uploading app ${app.app} ${app.customId? `and custom_id: ${app.customId}` : ''} to browserstack`)

const form = new FormData()
if (app.app) form.append('file', fs.createReadStream(app.app))
if (app.customId) form.append('custom_id', app.customId)
if (app.app) {
form.append('file', fs.createReadStream(app.app))
}
if (app.customId) {
form.append('custom_id', app.customId)
}

const res = await got.post('https://api-cloud.browserstack.com/app-automate/upload', {
body: form,
Expand Down
4 changes: 3 additions & 1 deletion packages/wdio-cucumber-framework/src/reporter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -271,7 +271,9 @@ export default class CucumberReporter {
getTitle (featureOrScenario: Feature | Pickle) {
const name = featureOrScenario.name
const tags = featureOrScenario.tags
if (!this._tagsInTitle || !tags || !tags.length) return name
if (!this._tagsInTitle || !tags || !tags.length) {
return name
}
return `${tags.map((tag: PickleTag | Tag) => tag.name).join(', ')}: ${name}`
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,9 @@ export default function collectMetaElements () {
return metas.map(meta => {
const getAttribute = (name: string) => {
const attr = meta.attributes.getNamedItem(name)
if (!attr) return
if (!attr) {
return
}
return attr.value
}

Expand Down
4 changes: 3 additions & 1 deletion packages/wdio-junit-reporter/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -212,7 +212,9 @@ class JunitReporter extends WDIOReporter {
}

const output = this._getStandardOutput(test)
if (output) testCase.standardOutput(`\n${output}\n`)
if (output) {
testCase.standardOutput(`\n${output}\n`)
}
}
return builder
}
Expand Down
6 changes: 4 additions & 2 deletions packages/wdio-junit-reporter/src/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,9 @@ const STRINGLIMIT = 1000
const STRINGTRUNCATE = 200

export const limit = function (rawVal?: any) {
if (!rawVal) return rawVal
if (!rawVal) {
return rawVal
}

// Ensure we're working with a copy
let val = JSON.parse(stringify(rawVal))
Expand Down Expand Up @@ -47,4 +49,4 @@ export const limit = function (rawVal?: any) {
return val
}
return val
}
}
4 changes: 3 additions & 1 deletion packages/wdio-mocha-framework/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -169,7 +169,9 @@ class MochaAdapter {
* For some reason, Mocha fires a second 'suite:end' event for the root suite,
* with no matching 'suite:start', so this can be ignored.
*/
if (payload.root) return
if (payload.root) {
return
}

const message = formatMessage({ type: event, payload, err })

Expand Down
8 changes: 6 additions & 2 deletions packages/wdio-reporter/src/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -61,8 +61,12 @@ export function sanitizeCaps (caps?: Capabilities.DesiredCapabilities) {
* @param {*} e An event emitted by a framework adapter
*/
export function getErrorsFromEvent(e: { errors?: any; error?: any }) {
if (e.errors) return e.errors
if (e.error) return [e.error]
if (e.errors) {
return e.errors
}
if (e.error) {
return [e.error]
}
return []
}

Expand Down
4 changes: 3 additions & 1 deletion packages/wdio-sauce-service/src/service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -433,7 +433,9 @@ export default class SauceService implements Services.ServiceInstance {
}

private async _setJobName(suiteTitle: string | undefined) {
if (!suiteTitle) return
if (!suiteTitle) {
return
}
let jobName = suiteTitle
if (this._options.setJobName) {
jobName = this._options.setJobName(
Expand Down
6 changes: 4 additions & 2 deletions packages/webdriverio/src/scripts/isElementDisplayed.ts
Original file line number Diff line number Diff line change
Expand Up @@ -58,10 +58,11 @@ export default function isElementDisplayed (element: Element): boolean {
let node: ParentNode = targetNode;
node && node !== (targetNode as Node).ownerDocument;
node = (node as HTMLElement).parentNode as ParentNode
)
) {
if (predicate(node)) {
return node
}
}

return null
}
Expand All @@ -71,10 +72,11 @@ export default function isElementDisplayed (element: Element): boolean {
let element: HTMLElement | ParentNode = targetElement;
element && element !== targetElement.ownerDocument;
element = parentElementForElement(element as HTMLElement) as HTMLElement
)
) {
if (predicate(element)) {
return element
}
}

return null
}
Expand Down
3 changes: 2 additions & 1 deletion packages/webdriverio/src/utils/findStrategy.ts
Original file line number Diff line number Diff line change
Expand Up @@ -34,8 +34,9 @@ const defineStrategy = function (selector: SelectorStrategy) {
// an error like "selector.match is not a function"
// Use '-android datamatcher' or '-android viewmatcher' strategy if selector is a plain object (Android only)
if (typeof selector === 'object') {
if (JSON.stringify(selector).indexOf('test.espresso.matcher.ViewMatchers') < 0)
if (JSON.stringify(selector).indexOf('test.espresso.matcher.ViewMatchers') < 0) {
return '-android datamatcher'
}
return '-android viewmatcher'
}

Expand Down

0 comments on commit e233109

Please sign in to comment.