Skip to content

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

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

Closed
dantman opened this issue Jun 18, 2022 · 0 comments · Fixed by #3443
Closed

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

dantman opened this issue Jun 18, 2022 · 0 comments · Fixed by #3443

Comments

@dantman
Copy link

dantman commented Jun 18, 2022

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.

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 a pull request may close this issue.

1 participant