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

feat: support browser args #278

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
42 changes: 33 additions & 9 deletions packages/remote/src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ const {
} = require('./cp');
require('@faltest/utils/src/require-before-webdriverio');
const { remote } = require('webdriverio');
const path = require('path');
const psList = require('ps-list');
const fkill = require('fkill');
const getPort = require('get-port');
Expand All @@ -19,6 +20,9 @@ const { defaults } = require('@faltest/utils');
// We aren't using `@wdio/cli` (wdio testrunner)
process.env.SUPPRESS_NO_CONFIG_WARNING = 'true';

let configDir = process.env.FALTEST_CONFIG_DIR || process.cwd();

Copy link
Author

Choose a reason for hiding this comment

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

if interested, I could do another PR for adding prettier

Copy link
Collaborator

Choose a reason for hiding this comment

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

I wouldn't want this project to have a custom solution. I'd want everything to be in it's own package like https://github.com/CrowdStrike/eslint-config-crowdstrike, then appllied here and in other repos.


let port;

const webDriverRegex = /^(chromedriver(?:\.exe)?|geckodriver)$/;
Expand Down Expand Up @@ -163,7 +167,7 @@ async function spawnWebDriver(name, args) {
if (process.platform === 'win32') {
let { emit } = webDriver;

webDriver.emit = function(eventName, exitCode) {
webDriver.emit = function (eventName, exitCode) {
if (eventName === 'exit' && exitCode === 1) {
return true;
}
Expand All @@ -179,6 +183,18 @@ async function spawnWebDriver(name, args) {
return webDriver;
}

function loadConfig() {
try {
return require(path.resolve(configDir, '.faltestrc.js'));
} catch (err) {
if (err.code !== 'MODULE_NOT_FOUND') {
throw err;
}

return {};
}
}

function startWebDriver(options = {}) {
return log(async () => {
if (!yn(process.env.WEBDRIVER_DISABLE_CLEANUP)) {
Expand Down Expand Up @@ -232,12 +248,20 @@ function stopWebDriver(webDriver) {
});
}

async function getCapabilities({
customizeCapabilities = (browserName, capabilities) => capabilities,
overrides: {
browser: _browser = getDefaults().browser,
} = {},
}) {
async function getCapabilities(options) {
NullVoxPopuli marked this conversation as resolved.
Show resolved Hide resolved
let {
browserArgs = [],
NullVoxPopuli marked this conversation as resolved.
Show resolved Hide resolved
customizeCapabilities = (browserName, capabilities) => capabilities,
overrides: {
browser: _browser = getDefaults().browser,
} = {},
} = options;

let faltestConfig = loadConfig();

let argsFromConfig = (((faltestConfig.options || {}).browsers || {})[_browser] || {}).args || [];
Copy link
Author

Choose a reason for hiding this comment

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

this is what my .faltestrc.js looks like

'use strict';

module.exports = {
  options: {
    targets: {
      default: 'default',
      list: ['default', 'local', 'ember', 'pull-request'],
    },
    browsers: {
      firefox: {
        args: [
           // TODO
        ],
      },
      chrome: {

        args: [
          '--window-size=1280,720', // 720p
          '--ignore-certificate-errors'
        ].filter(Boolean)
      }
    }
  },
  globs: ['tests/**/*-test.js'],
};



let capabilities = {
browserName: _browser,
};
Expand All @@ -248,7 +272,7 @@ async function getCapabilities({

switch (_browser) {
case 'chrome': {
let args = [];
let args = [...browserArgs, ...argsFromConfig];
if (headless) {
args.push('--headless');
}
Expand All @@ -259,7 +283,7 @@ async function getCapabilities({
break;
}
case 'firefox': {
let args = [];
let args = [...browserArgs, ...argsFromConfig];
if (headless) {
args.push('-headless');
}
Expand Down