Skip to content

process.env.profile is the string "undefined" when no --profile is specified #3339

Closed
@dantman

Description

@dantman

What are you trying to achieve?

I wanted to control what browser is run using --profile and fallback to chrome if --profile was not provided.

What do you get instead?

I got errors like "Error: Cannot find the browser. "undefined:headless" is neither a known browser alias, nor a path to an executable file.".

I tried debugging by putting console.log(process.env.profile, typeof process.env.profile); in my codecept.conf.js and got "undefined string".

Details

  • CodeceptJS version: 3.3.3
  • NodeJS Version: v16.15.1
  • Operating System:
  • puppeteer || webdriverio || testcafe version (if related): [email protected]
  • Configuration file:
require('ts-node/register');
const {
  setHeadlessWhen,
  setBrowser,
  setTestHost,
} = require('@codeceptjs/configure');

console.log(process.env.profile, typeof process.env.profile);
setHeadlessWhen(process.env.CI);
setBrowser(process.env.profile || 'chrome');
setTestHost(process.env.TEST_HOST);

exports.config = {
  tests: './tests/e2e/codecept/features/*.ts',
  output: './tests/e2e/codecept/output',
  helpers: {
    TestCafe: {
      url: process.env.BASE_URL || 'http://localhost:3000',
    },
  },
  include: {
    // I: './tests/e2e/codecept/custom-steps.ts',
  },
  bootstrap: null,
  mocha: {},
  name: 'seymour-portal',
};

Investigation

I did a bit of debugging and it looks like the issue is the way that the run command (and other commands) set the profile.

// registering options globally to use in config
// Backward compatibility for --profile
process.profile = options.profile;
process.env.profile = options.profile;

It appears that when you assign to process.env.profile Node stringifies the value. So if options.profile is undefined then it gets stringified to "undefined" instead of resulting in the env not being set.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions