Skip to content

Commit

Permalink
feat: added the possibility to disable a cross-domain emulation (#7350)
Browse files Browse the repository at this point in the history
<!--
Thank you for your contribution.

Before making a PR, please read our contributing guidelines at

https://github.com/DevExpress/testcafe/blob/master/CONTRIBUTING.md#code-contribution

We recommend creating a *draft* PR, so that you can mark it as 'ready
for review' when you are done.
-->
[closes #7022]

## Purpose
Add `--disable-cross-domain` option

## Approach
1. Add handling CLI option `--disable-cross-domain`
2. Add switching cross-domain

## References
#7022
DevExpress/testcafe-hammerhead#2806

## Pre-Merge TODO
- [ ] Write tests for your proposed changes
- [ ] Make sure that existing tests do not fail

Co-authored-by: Andrey Belym <belym.a.2105@gmail.com>
Co-authored-by: Andrey Belym <andrey.belym@devexpress.com>
  • Loading branch information
3 people committed Nov 2, 2022
1 parent 89eecab commit 3351b62
Show file tree
Hide file tree
Showing 7 changed files with 21 additions and 9 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
1 change: 1 addition & 0 deletions src/cli/argument-parser/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
});
Expand Down
2 changes: 2 additions & 0 deletions src/cli/cli.js
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,7 @@ async function runTests (argParser) {
disableHttp2,
v8Flags,
proxyless,
disableCrossDomain,
} = opts;

const testCafe = await createTestCafe({
Expand All @@ -103,6 +104,7 @@ async function runTests (argParser) {
disableHttp2,
v8Flags,
proxyless,
disableCrossDomain,
});

const correctedBrowsersAndSources = await correctBrowsersAndSources(argParser, testCafe.configuration);
Expand Down
1 change: 1 addition & 0 deletions src/configuration/default-values.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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<boolean | number> = {
experimentalDecorators: true,
Expand Down
1 change: 1 addition & 0 deletions src/configuration/option-names.ts
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,7 @@ enum OptionNames {
hooks = 'hooks',
dashboard = 'dashboard',
baseUrl = 'baseUrl',
disableCrossDomain = 'disableCrossDomain',
}

export default OptionNames;
17 changes: 11 additions & 6 deletions src/configuration/testcafe-configuration.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -65,6 +66,7 @@ const OPTION_INIT_FLAG_NAMES = [
OPTION_NAMES.cache,
OPTION_NAMES.disableHttp2,
OPTION_NAMES.proxyless,
OPTION_NAMES.disableCrossDomain,
];

interface TestCafeAdditionalStartOptions {
Expand All @@ -74,6 +76,7 @@ interface TestCafeAdditionalStartOptions {
cache: boolean;
disableHttp2: boolean;
proxyless: boolean;
disableCrossDomain: boolean;
}

interface TestCafeStartOptions {
Expand Down Expand Up @@ -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,
},
};

Expand Down Expand Up @@ -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();
Expand Down
6 changes: 4 additions & 2 deletions test/server/cli-argument-parser-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -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']);
Expand All @@ -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');
});
Expand Down Expand Up @@ -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('');
Expand All @@ -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);
Expand Down

0 comments on commit 3351b62

Please sign in to comment.