From 3351b6262b004f681dba6eb10835d770f8b098d6 Mon Sep 17 00:00:00 2001 From: Popov Aleksey Date: Wed, 2 Nov 2022 14:58:28 +0400 Subject: [PATCH] feat: added the possibility to disable a cross-domain emulation (#7350) [closes #7022] ## Purpose Add `--disable-cross-domain` option ## Approach 1. Add handling CLI option `--disable-cross-domain` 2. Add switching cross-domain ## References https://github.com/DevExpress/testcafe/issues/7022 https://github.com/DevExpress/testcafe-hammerhead/pull/2806 ## Pre-Merge TODO - [ ] Write tests for your proposed changes - [ ] Make sure that existing tests do not fail Co-authored-by: Andrey Belym Co-authored-by: Andrey Belym --- package.json | 2 +- src/cli/argument-parser/index.ts | 1 + src/cli/cli.js | 2 ++ src/configuration/default-values.ts | 1 + src/configuration/option-names.ts | 1 + src/configuration/testcafe-configuration.ts | 17 +++++++++++------ test/server/cli-argument-parser-test.js | 6 ++++-- 7 files changed, 21 insertions(+), 9 deletions(-) diff --git a/package.json b/package.json index 57d1ccd9982..35ad16b7337 100644 --- a/package.json +++ b/package.json @@ -139,7 +139,7 @@ "source-map-support": "^0.5.16", "strip-bom": "^2.0.0", "testcafe-browser-tools": "2.0.23", - "testcafe-hammerhead": "28.0.0", + "testcafe-hammerhead": "28.1.0", "testcafe-legacy-api": "5.1.6", "testcafe-reporter-dashboard": "^0.2.7-rc.1", "testcafe-reporter-json": "^2.1.0", diff --git a/src/cli/argument-parser/index.ts b/src/cli/argument-parser/index.ts index 97a003722b3..fbbe3b1d257 100644 --- a/src/cli/argument-parser/index.ts +++ b/src/cli/argument-parser/index.ts @@ -211,6 +211,7 @@ export default class CLIArgumentParser { // NOTE: temporary hide experimental options from --help command .addOption(new Option('--proxyless', 'experimental').hideHelp()) .addOption(new Option('--experimental-debug', 'enable experimental debug mode').hideHelp()) + .addOption(new Option('--disable-cross-domain', 'experimental').hideHelp()) .action((opts: CommandLineOptions) => { this.opts = opts; }); diff --git a/src/cli/cli.js b/src/cli/cli.js index dccf6a287b8..0ebb0611081 100644 --- a/src/cli/cli.js +++ b/src/cli/cli.js @@ -86,6 +86,7 @@ async function runTests (argParser) { disableHttp2, v8Flags, proxyless, + disableCrossDomain, } = opts; const testCafe = await createTestCafe({ @@ -103,6 +104,7 @@ async function runTests (argParser) { disableHttp2, v8Flags, proxyless, + disableCrossDomain, }); const correctedBrowsersAndSources = await correctBrowsersAndSources(argParser, testCafe.configuration); diff --git a/src/configuration/default-values.ts b/src/configuration/default-values.ts index 1039e5868b7..b64b11baaec 100644 --- a/src/configuration/default-values.ts +++ b/src/configuration/default-values.ts @@ -21,6 +21,7 @@ export const DEFAULT_DISABLE_HTTP2 = false; export const DEFAULT_PROXYLESS = false; export const DEFAULT_SCREENSHOT_THUMBNAILS = true; export const DEFAULT_FILTER_FN = null; +export const DEFAULT_DISABLE_CROSS_DOMAIN = false; export const DEFAULT_TYPESCRIPT_COMPILER_OPTIONS: Dictionary = { experimentalDecorators: true, diff --git a/src/configuration/option-names.ts b/src/configuration/option-names.ts index b69e7fbe6b3..4233e5e4206 100644 --- a/src/configuration/option-names.ts +++ b/src/configuration/option-names.ts @@ -55,6 +55,7 @@ enum OptionNames { hooks = 'hooks', dashboard = 'dashboard', baseUrl = 'baseUrl', + disableCrossDomain = 'disableCrossDomain', } export default OptionNames; diff --git a/src/configuration/testcafe-configuration.ts b/src/configuration/testcafe-configuration.ts index 7183f58580b..4ae7639ca09 100644 --- a/src/configuration/testcafe-configuration.ts +++ b/src/configuration/testcafe-configuration.ts @@ -13,6 +13,7 @@ import { DEFAULT_APP_INIT_DELAY, DEFAULT_CONCURRENCY_VALUE, DEFAULT_DEVELOPMENT_MODE, + DEFAULT_DISABLE_CROSS_DOMAIN, DEFAULT_DISABLE_HTTP2, DEFAULT_FILTER_FN, DEFAULT_PROXYLESS, @@ -65,6 +66,7 @@ const OPTION_INIT_FLAG_NAMES = [ OPTION_NAMES.cache, OPTION_NAMES.disableHttp2, OPTION_NAMES.proxyless, + OPTION_NAMES.disableCrossDomain, ]; interface TestCafeAdditionalStartOptions { @@ -74,6 +76,7 @@ interface TestCafeAdditionalStartOptions { cache: boolean; disableHttp2: boolean; proxyless: boolean; + disableCrossDomain: boolean; } interface TestCafeStartOptions { @@ -155,12 +158,13 @@ export default class TestCafeConfiguration extends Configuration { port2: this.getOption(OPTION_NAMES.port2) as number, options: { - ssl: this.getOption(OPTION_NAMES.ssl) as string, - developmentMode: this.getOption(OPTION_NAMES.developmentMode) as boolean, - retryTestPages: this.getOption(OPTION_NAMES.retryTestPages) as boolean, - cache: this.getOption(OPTION_NAMES.cache) as boolean, - disableHttp2: this.getOption(OPTION_NAMES.disableHttp2) as boolean, - proxyless: this.getOption(OPTION_NAMES.proxyless) as boolean, + ssl: this.getOption(OPTION_NAMES.ssl) as string, + developmentMode: this.getOption(OPTION_NAMES.developmentMode) as boolean, + retryTestPages: this.getOption(OPTION_NAMES.retryTestPages) as boolean, + cache: this.getOption(OPTION_NAMES.cache) as boolean, + disableHttp2: this.getOption(OPTION_NAMES.disableHttp2) as boolean, + proxyless: this.getOption(OPTION_NAMES.proxyless) as boolean, + disableCrossDomain: this.getOption(OPTION_NAMES.disableCrossDomain) as boolean, }, }; @@ -266,6 +270,7 @@ export default class TestCafeConfiguration extends Configuration { this._ensureOptionWithValue(OPTION_NAMES.retryTestPages, DEFAULT_RETRY_TEST_PAGES, OptionSource.Configuration); this._ensureOptionWithValue(OPTION_NAMES.disableHttp2, DEFAULT_DISABLE_HTTP2, OptionSource.Configuration); this._ensureOptionWithValue(OPTION_NAMES.proxyless, DEFAULT_PROXYLESS, OptionSource.Configuration); + this._ensureOptionWithValue(OPTION_NAMES.disableCrossDomain, DEFAULT_DISABLE_CROSS_DOMAIN, OptionSource.Configuration); this._ensureScreenshotOptions(); this._ensureSkipJsOptions(); diff --git a/test/server/cli-argument-parser-test.js b/test/server/cli-argument-parser-test.js index ea4d022de8f..ece1f42a927 100644 --- a/test/server/cli-argument-parser-test.js +++ b/test/server/cli-argument-parser-test.js @@ -753,7 +753,7 @@ describe('CLI argument parser', function () { }); it('Should parse command line arguments', function () { - return parse('-r list -S -q -e message=/testMessage/i,stack=testStack,pageUrl=testPageUrl --hostname myhost --base-url localhost:3000 --proxy localhost:1234 --proxy-bypass localhost:5678 --qr-code --app run-app --speed 0.5 --debug-on-fail --disable-page-reloads --retry-test-pages --dev --sf --disable-page-caching --disable-http2 --proxyless ie test/server/data/file-list/file-1.js') + return parse('-r list -S -q -e message=/testMessage/i,stack=testStack,pageUrl=testPageUrl --hostname myhost --base-url localhost:3000 --proxy localhost:1234 --proxy-bypass localhost:5678 --qr-code --app run-app --speed 0.5 --debug-on-fail --disable-page-reloads --retry-test-pages --dev --sf --disable-page-caching --disable-http2 --proxyless --disable-cross-domain ie test/server/data/file-list/file-1.js') .then(parser => { expect(parser.opts.browsers).eql(['ie']); expect(parser.opts.src).eql(['test/server/data/file-list/file-1.js']); @@ -779,6 +779,7 @@ describe('CLI argument parser', function () { expect(parser.opts.disablePageReloads).to.be.ok; expect(parser.opts.retryTestPages).to.be.ok; expect(parser.opts.disableHttp2).to.be.ok; + expect(parser.opts.disableCrossDomain).to.be.ok; expect(parser.opts.proxyless).to.be.ok; expect(parser.opts.baseUrl).eql('localhost:3000'); }); @@ -857,6 +858,7 @@ describe('CLI argument parser', function () { { long: '--disable-http2' }, { long: '--proxyless' }, { long: '--base-url' }, + { long: '--disable-cross-domain' }, ]; const parser = new CliArgumentParser(''); @@ -873,7 +875,7 @@ describe('CLI argument parser', function () { } const expectedRunOptionsCount = 22; - const expectedOtherOptionsCount = 36; + const expectedOtherOptionsCount = 37; const otherOptionsCount = options.length - expectedRunOptionsCount; expect(runOptionNames.length).eql(expectedRunOptionsCount, ADD_TO_RUN_OPTIONS_WARNING);