Skip to content

userDataDir must be specified in args outside launch, or else browser crashes #583

Open
@alisha

Description

@alisha

🐛 Bug Report

At first I thought this was a bug where I couldn't specify the userDataDir parameter, as my browser would always crash and my tests would never run. I found out how to specify this parameter correctly and have the tests run, but it's unintuitive. I think this should either be documented, or be fixed to be more intiutive.

If your config file looks like this:

// jest-puppeteer.config.cjs

/** @type {import('jest-environment-puppeteer').JestPuppeteerConfig} */
module.exports = {
    launch: {
      headless: false,
      userDataDir: "./user_data_dir",
    },
};

Or like this:

// jest-puppeteer.config.cjs

/** @type {import('jest-environment-puppeteer').JestPuppeteerConfig} */
module.exports = {
    launch: {
      headless: false,
        args: [
            '--user-data-dir=./user_data_dir',
        ]
    },
};

The browser will launch, immediately crash, and the tests are never run. I also get this error message:

Error: Jest: Got error running globalSetup - jest-bug-repro/node_modules/jest-environment-puppeteer/setup.js, reason: Failed to launch the browser process!


TROUBLESHOOTING: https://pptr.dev/troubleshooting

    at ChildProcess.onClose (jest-bug-repro/node_modules/@puppeteer/browsers/lib/cjs/launch.js:310:24)
    at ChildProcess.emit (node:events:539:35)
    at Process.ChildProcess._handle.onexit (node:internal/child_process:291:12)

However, if you have the following config file (where args is outside of launch):

// jest-puppeteer.config.cjs

/** @type {import('jest-environment-puppeteer').JestPuppeteerConfig} */
module.exports = {
    launch: {
      headless: false,
    },
    args: [
        '--user-data-dir=./user_data_dir',
    ]
};

It will work as expected. Note that if you want to specify other args for puppeteer, you must have another args array inside launch (like the second config file I showed).

To Reproduce

Use either of these config files:

// jest-puppeteer.config.cjs

/** @type {import('jest-environment-puppeteer').JestPuppeteerConfig} */
module.exports = {
    launch: {
      headless: false,
      userDataDir: "./user_data_dir",
    },
};

Or

// jest-puppeteer.config.cjs

/** @type {import('jest-environment-puppeteer').JestPuppeteerConfig} */
module.exports = {
    launch: {
      headless: false,
        args: [
            '--user-data-dir=./user_data_dir',
        ]
    },
};

Expected behavior

The browser exits only after tests are run. I would also expect the second config file showed (where launch has args, which in turn has --user-data-dir=...) to work.

Link to repl or repo (highly encouraged)

https://github.com/alisha/jest-bug-repro

The jest-puppeteer.config.cjs file contains 4 versions of a config file, 3 of which are commented out so you can run it. The first 2 versions reproduce the issue, while the last two versions work.

Run npx envinfo --system --binaries --npmPackages expect-puppeteer,jest-dev-server,jest-environment-puppeteer,jest-puppeteer,spawnd --markdown --clipboard

Paste the results here:

## System:
 - OS: macOS 13.5.2
 - CPU: (10) arm64 Apple M1 Max
 - Memory: 2.58 GB / 64.00 GB
 - Shell: 3.2.57 - /bin/bash
## Binaries:
 - Node: 17.9.1 - ~/.nvm/versions/node/v17.9.1/bin/node
 - npm: 8.11.0 - ~/.nvm/versions/node/v17.9.1/bin/npm
## npmPackages:
 - jest-puppeteer: ^10.0.1 => 10.0.1

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