Skip to content

Commit

Permalink
Set the job name before a suite is run (#7672)
Browse files Browse the repository at this point in the history
Co-authored-by: Christian Bromann <github@christian-bromann.com>
  • Loading branch information
gabriel-kohen-by and christian-bromann committed Nov 15, 2021
1 parent f8d20cc commit a1d33f7
Show file tree
Hide file tree
Showing 2 changed files with 36 additions and 7 deletions.
13 changes: 10 additions & 3 deletions packages/wdio-sauce-service/src/service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,14 @@ export default class SauceService implements Services.ServiceInstance {

beforeSuite (suite: Frameworks.Suite) {
this._suiteTitle = suite.title

/**
* Make sure we account for the cases where there is a long running `before` function for a
* suite or one that can fail so we set the default job name at the suite level
**/
if (this._browser && !this._isUP && !this._isJobNameSet) {
this._browser.execute('sauce:job-name=' + this._suiteTitle)
}
}

beforeTest (test: Frameworks.Test) {
Expand All @@ -94,16 +102,15 @@ export default class SauceService implements Services.ServiceInstance {
}

if (this._browser && !this._isJobNameSet) {
let jobName = this._suiteTitle
if (this._options.setJobName) {
jobName = this._options.setJobName(
let jobName = this._options.setJobName(
this._config,
this._capabilities,
this._suiteTitle!
)
this._browser.execute(`sauce:job-name=${jobName}`)
}

this._browser.execute(`sauce:job-name=${jobName}`)
this._isJobNameSet = true
}

Expand Down
30 changes: 26 additions & 4 deletions packages/wdio-sauce-service/tests/service.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,31 @@ test('beforeSession should set to unknown creds if no sauce user and key are fou
expect(config.key).toBe('unknown_key')
})

test('beforeTest should set job-name', () => {
test('beforeSuite should send request to set the job name as suite name', () => {
const service = new SauceService({}, {}, {} as any)
service['_browser'] = browser
expect(service['_suiteTitle']).toBeUndefined()
service.beforeSuite({ title: 'foobar' } as any)
expect(service['_suiteTitle']).toBe('foobar')
expect(browser.execute).toBeCalledWith('sauce:job-name=foobar')
})

test('beforeTest should send the job-name as suite name by default', () => {
const service = new SauceService({}, {}, { user: 'foobar', key: '123', capabilities: {} })
service['_browser'] = browser
service['_suiteTitle'] = 'Suite Title'
expect(service['_isJobNameSet']).toBe(false)
service.beforeSuite({ title: 'foobar suite' } as any)
service.beforeTest({
fullName: 'my test can do something',
description: 'foobar'
} as any)
expect(browser.execute).toBeCalledTimes(2)
expect(browser.execute).toBeCalledWith('sauce:job-name=foobar suite')
expect(browser.execute).toBeCalledWith('sauce:context=my test can do something')
})

test('beforeTest should mark job-name as set', () => {
const service = new SauceService({}, {}, { user: 'foobar', key: '123', capabilities: {} })
service['_browser'] = browser
service['_suiteTitle'] = 'Suite Title'
Expand All @@ -84,7 +108,6 @@ test('beforeTest should set job-name', () => {
description: 'foobar'
} as any)
expect(service['_isJobNameSet']).toBe(true)
expect(browser.execute).toBeCalledWith('sauce:job-name=Suite Title')
})

test('beforeTest should set job-name via custom setJobName method', () => {
Expand Down Expand Up @@ -165,8 +188,7 @@ test('beforeTest should not set context for UP test', () => {
upService.beforeTest({
title: 'update up job name'
} as any)
expect(browser.execute).toBeCalledTimes(1)
expect(browser.execute).not.toBeCalledWith('sauce:job-name==update up job name')
expect(browser.execute).toBeCalledTimes(0)
})

test('beforeTest should not set context if user does not use sauce', () => {
Expand Down

0 comments on commit a1d33f7

Please sign in to comment.