Skip to content

Commit c4a9d63

Browse files
Ankit098francisf
authored andcommitted
fix: maintain backward compatibility
1 parent db135a3 commit c4a9d63

File tree

2 files changed

+18
-14
lines changed

2 files changed

+18
-14
lines changed

src/launcher.ts

Lines changed: 14 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -18,10 +18,12 @@ export default class BrowserstackLauncherService implements Services.ServiceInst
1818
browserstackLocal?: BrowserstackLocal
1919

2020
constructor (
21-
private _options: BrowserstackConfig,
21+
private _options: BrowserstackConfig | any,
2222
capabilities: Capabilities.RemoteCapability,
23-
private _config: Options.Testrunner
24-
) {}
23+
private _config: Options.Testrunner | any
24+
) {
25+
this._config || (this._config = _options)
26+
}
2527

2628
onPrepare (config?: Options.Testrunner, capabilities?: Capabilities.RemoteCapabilities) {
2729
if (!this._options.browserstackLocal) {
@@ -30,26 +32,27 @@ export default class BrowserstackLauncherService implements Services.ServiceInst
3032

3133
const opts = {
3234
key: this._config.key,
33-
forcelocal: true,
34-
onlyAutomate: true,
35+
forcelocal: this._config.services[0][1] ? this._config.services[0][1].forcelocal : false,
3536
...this._options.opts
3637
}
3738

3839
this.browserstackLocal = new BrowserstackLocalLauncher.Local()
3940

4041
if (Array.isArray(capabilities)) {
4142
capabilities.forEach((capability: Capabilities.DesiredCapabilities) => {
42-
if (!capability['bstack:options']) {
43-
capability['bstack:options'] = {}
43+
if (capability['bstack:options']) {
44+
capability['bstack:options'].local = true
45+
} else {
46+
capability['browserstack.local'] = true
4447
}
45-
capability['bstack:options'].local = true
4648
})
4749
} else if (typeof capabilities === 'object') {
4850
Object.entries(capabilities as Capabilities.MultiRemoteCapabilities).forEach(([, caps]) => {
49-
if (!(caps.capabilities as Capabilities.Capabilities)['bstack:options']) {
50-
(caps.capabilities as Capabilities.Capabilities)['bstack:options'] = {}
51+
if ((caps.capabilities as Capabilities.Capabilities)['bstack:options']) {
52+
(caps.capabilities as Capabilities.Capabilities)['bstack:options']!.local = true
53+
} else {
54+
(caps.capabilities as Capabilities.Capabilities)['browserstack.local'] = true
5155
}
52-
(caps.capabilities as Capabilities.Capabilities)['bstack:options']!.local = true
5356
})
5457
} else {
5558
throw TypeError('Capabilities should be an object or Array!')

src/service.ts

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -17,10 +17,11 @@ export default class BrowserstackService implements Services.ServiceInstance {
1717
private _fullTitle?: string
1818

1919
constructor (
20-
private _options: BrowserstackConfig,
20+
private _options: BrowserstackConfig | any,
2121
private _caps: Capabilities.RemoteCapability,
22-
private _config: Options.Testrunner
22+
private _config: Options.Testrunner | any
2323
) {
24+
this._config || (this._config = _options);
2425
// Cucumber specific
2526
const strict = Boolean(this._config.cucumberOpts && this._config.cucumberOpts.strict)
2627
// See https://github.com/cucumber/cucumber-js/blob/master/src/runtime/index.ts#L136
@@ -57,7 +58,7 @@ export default class BrowserstackService implements Services.ServiceInstance {
5758
}
5859

5960
before(caps: Capabilities.RemoteCapability, specs: string[], browser: Browser<'async'> | MultiRemoteBrowser<'async'>) {
60-
this._browser = browser
61+
this._browser = browser ? browser : (global as any).browser;
6162

6263
// Ensure capabilities are not null in case of multiremote
6364

0 commit comments

Comments
 (0)