diff --git a/package-lock.json b/package-lock.json index 38765b020ed..36a3454b958 100644 --- a/package-lock.json +++ b/package-lock.json @@ -235,7 +235,6 @@ "resolved": "https://registry.npmjs.org/@babel/core/-/core-7.28.3.tgz", "integrity": "sha512-yDBHV9kQNcr2/sUr9jghVyz9C3Y5G2zUM2H2lo+9mKv4sFgbA8s8Z9t8D1jiTkGoO/NoIfKMyKWr4s6CN23ZwQ==", "license": "MIT", - "peer": true, "dependencies": { "@ampproject/remapping": "^2.2.0", "@babel/code-frame": "^7.27.1", @@ -3226,7 +3225,6 @@ "integrity": "sha512-VlJEV0fOQ7BExOsHYAGrgbEiZoi8D+Bl2+f6V2RrXerRSylnp+ZBHmPvaIa8cz0Ajx7WO7Z5RqfgYg7ED1nRhA==", "dev": true, "license": "BSD-2-Clause", - "peer": true, "dependencies": { "@typescript-eslint/scope-manager": "5.62.0", "@typescript-eslint/types": "5.62.0", @@ -3622,7 +3620,6 @@ "integrity": "sha512-nQyp0o1/mNdbTO1PO6kHkwSrmgZ0MT/jCCpNiwbUjGoRN4dlBhqJtoQuCnEOKzgTVwg0ZWiCoQy6SxMebQVh8A==", "dev": true, "license": "MIT", - "peer": true, "bin": { "acorn": "bin/acorn" }, @@ -4823,7 +4820,6 @@ } ], "license": "MIT", - "peer": true, "dependencies": { "caniuse-lite": "^1.0.30001733", "electron-to-chromium": "^1.5.199", @@ -5132,7 +5128,6 @@ "resolved": "https://registry.npmjs.org/chai/-/chai-4.3.4.tgz", "integrity": "sha512-yS5H68VYOCtN1cjfwumDSuzn/9c+yza4f3reKXlE5rUg7SFcCEy90gJvydNgOYtblyf4Zi6jIWRnXOgErta0KA==", "license": "MIT", - "peer": true, "dependencies": { "assertion-error": "^1.1.0", "check-error": "^1.0.2", @@ -6764,7 +6759,6 @@ "deprecated": "This version is no longer supported. Please see https://eslint.org/version-support for other options.", "dev": true, "license": "MIT", - "peer": true, "dependencies": { "@babel/code-frame": "7.12.11", "@eslint/eslintrc": "^0.4.3", @@ -15392,7 +15386,6 @@ "integrity": "sha512-fS6iqSPZDs3dr/y7Od6y5nha8dW1YnbgtsyotCVvoFGKbERG++CVRFv1meyGDE1SNItQA8BrnCw7ScdAhRJ3XQ==", "dev": true, "license": "MIT", - "peer": true, "bin": { "rollup": "dist/bin/rollup" }, @@ -17643,7 +17636,6 @@ "resolved": "https://registry.npmjs.org/typescript/-/typescript-4.7.4.tgz", "integrity": "sha512-C0WQT0gezHuw6AdY1M2jxUO83Rjf0HP7Sk1DtXj6j1EwkQNZrHAg2XPWlq62oqEhYvONq5pkC2Y9oPljWToLmQ==", "license": "Apache-2.0", - "peer": true, "bin": { "tsc": "bin/tsc", "tsserver": "bin/tsserver" diff --git a/src/configuration/testcafe-configuration.ts b/src/configuration/testcafe-configuration.ts index 3c8fbdf7688..83b942ee970 100644 --- a/src/configuration/testcafe-configuration.ts +++ b/src/configuration/testcafe-configuration.ts @@ -330,10 +330,12 @@ export default class TestCafeConfiguration extends Configuration { this.mergeOptions({ hostname }); } - public async calculateHostname ({ nativeAutomation } = { nativeAutomation: false }): Promise { + public async calculateHostname ({ nativeAutomation, allBrowsersLocal } = { nativeAutomation: false, allBrowsersLocal: false }): Promise { await this.ensureHostname(async hostname => { if (nativeAutomation) hostname = LOCALHOST_NAMES.LOCALHOST; + else if (!hostname && allBrowsersLocal) + hostname = LOCALHOST_NAMES.LOCALHOST; else hostname = await getValidHostname(hostname); diff --git a/src/runner/bootstrapper.ts b/src/runner/bootstrapper.ts index 9291b9a445e..484f13ac557 100644 --- a/src/runner/bootstrapper.ts +++ b/src/runner/bootstrapper.ts @@ -171,11 +171,16 @@ export default class Bootstrapper { }; } - private async _setupProxy (): Promise { + private async _setupProxy (browserInfo: BrowserInfoSource[]): Promise { if (this.browserConnectionGateway.status === BrowserConnectionGatewayStatus.initialized) return; - await this.configuration.calculateHostname({ nativeAutomation: !this.configuration.getOption(OPTION_NAMES.disableNativeAutomation) }); + const allBrowsersLocal = await this._isAllBrowsersLocal(browserInfo); + + await this.configuration.calculateHostname({ + nativeAutomation: !this.configuration.getOption(OPTION_NAMES.disableNativeAutomation), + allBrowsersLocal, + }); this.browserConnectionGateway.initialize(this.configuration.startOptions); } @@ -209,7 +214,7 @@ export default class Bootstrapper { this._validateUserProfileOptionInNativeAutomation(automated); - await this._setupProxy(); + await this._setupProxy(browserInfo); let browserConnections = this._createAutomatedConnections(automated); @@ -349,13 +354,17 @@ export default class Bootstrapper { return testedApp; } - private async _canUseParallelBootstrapping (browserInfo: BrowserInfoSource[]): Promise { + private async _isAllBrowsersLocal (browserInfo: BrowserInfoSource[]): Promise { const isLocalPromises = browserInfo.map(browser => browser.provider.isLocalBrowser(void 0, Bootstrapper._getBrowserName(browser))); const isLocalBrowsers = await Promise.all(isLocalPromises); return isLocalBrowsers.every(result => result); } + private async _canUseParallelBootstrapping (browserInfo: BrowserInfoSource[]): Promise { + return this._isAllBrowsersLocal(browserInfo); + } + private async _bootstrapSequence (browserInfo: BrowserInfoSource[], id: string): Promise { const tests = await this._getTests(id); const testedApp = await this._startTestedApp(); diff --git a/test/functional/fixtures/regression/gh-8391/pages/index.html b/test/functional/fixtures/regression/gh-8391/pages/index.html new file mode 100644 index 00000000000..acade237284 --- /dev/null +++ b/test/functional/fixtures/regression/gh-8391/pages/index.html @@ -0,0 +1,10 @@ + + + + + GH-8391 + + +
ok
+ + diff --git a/test/functional/fixtures/regression/gh-8391/test.js b/test/functional/fixtures/regression/gh-8391/test.js new file mode 100644 index 00000000000..90d664633e6 --- /dev/null +++ b/test/functional/fixtures/regression/gh-8391/test.js @@ -0,0 +1,5 @@ +describe('[Regression](GH-8391)', function () { + it('Should not fail Firefox proxy-mode initialization', function () { + return runTests('testcafe-fixtures/index.js', 'Should run a simple assertion in Firefox proxy mode', { only: 'firefox' }); + }); +}); diff --git a/test/functional/fixtures/regression/gh-8391/testcafe-fixtures/index.js b/test/functional/fixtures/regression/gh-8391/testcafe-fixtures/index.js new file mode 100644 index 00000000000..8a38cb40371 --- /dev/null +++ b/test/functional/fixtures/regression/gh-8391/testcafe-fixtures/index.js @@ -0,0 +1,8 @@ +import { Selector } from 'testcafe'; + +fixture('GH-8391 - Firefox proxy mode should initialize scripts') + .page`http://localhost:3000/fixtures/regression/gh-8391/pages/index.html`; + +test('Should run a simple assertion in Firefox proxy mode', async t => { + await t.expect(Selector('#status').innerText).eql('ok'); +}); diff --git a/test/server/bootstrapper-test.js b/test/server/bootstrapper-test.js index 81e2ea5b38b..0634667e6d5 100644 --- a/test/server/bootstrapper-test.js +++ b/test/server/bootstrapper-test.js @@ -189,5 +189,39 @@ describe('Bootstrapper', () => { 'the "userProfile" suffix from the following browser aliases: "chrome, edge".'); } }); + + it('Should use localhost hostname strategy for local browsers in proxy mode', async () => { + let calculateHostnameOptions = null; + + const originalGetOption = bootstrapper.configuration.getOption; + const originalCalculateHostname = bootstrapper.configuration.calculateHostname; + + try { + bootstrapper.configuration.getOption = optionName => { + if (optionName === 'disableNativeAutomation') + return true; + + return originalGetOption(optionName); + }; + + bootstrapper.configuration.calculateHostname = options => { + calculateHostnameOptions = options; + }; + + await bootstrapper._setupProxy([{ + browserName: 'firefox', + provider: createBrowserProviderMock({ local: true }), + }]); + + expect(calculateHostnameOptions).eql({ + nativeAutomation: false, + allBrowsersLocal: true, + }); + } + finally { + bootstrapper.configuration.getOption = originalGetOption; + bootstrapper.configuration.calculateHostname = originalCalculateHostname; + } + }); }); }); diff --git a/test/server/configuration-test.js b/test/server/configuration-test.js index 6f41c35b30e..76a415a9b84 100644 --- a/test/server/configuration-test.js +++ b/test/server/configuration-test.js @@ -505,6 +505,20 @@ describe('TestCafeConfiguration', function () { expect(configuration.getOption('hostname')).eql('123.456.789'); }); + + it('Native automation is disabled/all browsers are local/hostname is unset', async () => { + await configuration.init(); + await configuration.calculateHostname({ nativeAutomation: false, allBrowsersLocal: true }); + + expect(configuration.getOption('hostname')).eql('localhost'); + }); + + it('Native automation is disabled/all browsers are local/hostname is set', async () => { + await configuration.init({ hostname: '123.456.789' }); + await configuration.calculateHostname({ nativeAutomation: false, allBrowsersLocal: true }); + + expect(configuration.getOption('hostname')).eql('123.456.789'); + }); }); });