diff --git a/packages/browserstack-service/tests/launcher.test.ts b/packages/browserstack-service/tests/launcher.test.ts index 9bbb24a..d97a02a 100644 --- a/packages/browserstack-service/tests/launcher.test.ts +++ b/packages/browserstack-service/tests/launcher.test.ts @@ -1559,6 +1559,39 @@ describe('_handleBuildIdentifier', () => { expect(caps[0]['bstack:options']?.buildIdentifier).toEqual('run-${NOT_SET_ANYWHERE}') }) + it('should still resolve buildIdentifier when buildName is in caps and BROWSERSTACK_BUILD_NAME is set', async() => { + process.env.BROWSERSTACK_BUILD_NAME = 'browserstack wdio build' + const caps: any = [{ + 'bstack:options': { + buildName: 'browserstack wdio build', + buildIdentifier: '#${BUILD_NUMBER}' + } + }] + const service = new BrowserstackLauncher(options as any, caps, config) + + vi.spyOn(utils, 'getCiInfo').mockReturnValueOnce(null) + vi.spyOn(service, '_getLocalBuildNumber').mockReturnValueOnce('3') + vi.spyOn(service, '_updateLocalBuildCache').mockImplementation(() => {}) + service._handleBuildIdentifier(caps) + + expect(caps[0]['bstack:options']?.buildIdentifier).toEqual('#3') + delete process.env.BROWSERSTACK_BUILD_NAME + }) + + it('should not retain an unresolved buildIdentifier template when the identifier is skipped', async() => { + const caps: any = [{ + 'bstack:options': { + buildIdentifier: '#${BUILD_NUMBER}' + } + }] + const service = new BrowserstackLauncher(options as any, caps, config) + + service._handleBuildIdentifier(caps) + + // onPrepare forwards this to TestHub as build_identifier; the raw template must not leak + expect(service._buildIdentifier).toBeUndefined() + }) + it('should not evaluate buildIdentifier if buildIdentifier is not present in the caps', async() => { const caps: any = [{}] const updatedcaps: any = [{ 'browserstack.wdioService': pkg.version }]