Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix #152 - modify browserstack config file path to work #222

Open
wants to merge 3 commits into
base: master
Choose a base branch
from

Conversation

patrickathompson
Copy link

@patrickathompson patrickathompson commented Aug 5, 2024

This change will modify the provided config file path to match the relative path of the file needed by the plugin to resolve it correctly.

@patrickathompson patrickathompson marked this pull request as draft August 5, 2024 23:05
@patrickathompson
Copy link
Author

needs a test for configuration file + environment variables

@patrickathompson patrickathompson marked this pull request as ready for review August 6, 2024 00:46
@patrickathompson
Copy link
Author

patrickathompson commented Aug 6, 2024

I realized that the _getAdditionalCapabilities logic was calling both functions _getCapabilitiesFromEnvironment and _getCapabilitiesFromConfig regardless of which configuration was used. Individual functions need to be modified with this in mind. This also necessitates an additional test scenario where the mixed configuration is used.

@PavelMor25
Copy link
Contributor

Hello @patrickathompson,

Thank you for your pull request. We will review it and merge it if everything looks good.

Copy link
Contributor

@PavelMor25 PavelMor25 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you for your contribution. Please take a look at my suggestions.

Comment on lines +144 to +146
const configPath = path.resolve(process.env.BROWSERSTACK_CAPABILITIES_CONFIG_PATH);

relativeConfigPath = path.relative(__dirname, configPath);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Since path.resolve already returns an absolute path, converting it to a relative path is unnecessary.

Comment on lines +68 to +79
process.env['BROWSERSTACK_BUILD_ID'] = 'build-1';
process.env['BROWSERSTACK_PROJECT_NAME'] = 'project-1';
process.env['BROWSERSTACK_DISPLAY_RESOLUTION'] = '1024x768';
process.env['BROWSERSTACK_TEST_RUN_NAME'] = 'Testcafe test run 1';
process.env['BROWSERSTACK_DEBUG'] = 'false'; //env var should take precedence
process.env['BROWSERSTACK_CONSOLE'] = 'errors';
process.env['BROWSERSTACK_NETWORK_LOGS'] = 'true';
process.env['BROWSERSTACK_VIDEO'] = 'true';
process.env['BROWSERSTACK_TIMEZONE'] = 'Asia/Taipei';
process.env['BROWSERSTACK_GEO_LOCATION'] = 'ZA';
process.env['BROWSERSTACK_CUSTOM_NETWORK'] = '"1000", "1000", "100", "1"';
process.env['BROWSERSTACK_NETWORK_PROFILE'] = '4g-lte-lossy';
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Since the test uses a configuration file and environment variables, it is not necessary to duplicate all variables present in the configuration file. It is sufficient to set just one variable that differs from the one in the configuration.

Comment on lines +81 to +83
process.env.BROWSERSTACK_CAPABILITIES_CONFIG_PATH = require.resolve('./data/capabilities-config.json');

const capabilities = browserStackProvider._getAdditionalCapabilities();
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The current implementation sets an absolute path, but we need to test the functionality of _getCapabilitiesFromConfig with a relative path.

When a relative path is passed to path.resolve() in _getCapabilitiesFromConfig, it returns an absolute path based on the working directory. Therefore, I suggest you save the current working directory, set __dirname before retrieving the capabilities, and then restore the original working directory afterwards.

Suggested change
process.env.BROWSERSTACK_CAPABILITIES_CONFIG_PATH = require.resolve('./data/capabilities-config.json');
const capabilities = browserStackProvider._getAdditionalCapabilities();
process.env.BROWSERSTACK_CAPABILITIES_CONFIG_PATH = './data/capabilities-config.json';
const originWorkDir = process.cwd();
process.chdir(__dirname)
const capabilities = browserStackProvider._getAdditionalCapabilities();
process.chdir(originWorkDir)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants