question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Getting "TypeError: Path must be a string. Received undefined" preventing me from upgrading to Jest v24 in some repos

See original GitHub issue

🐛 Bug Report

I have a number of repos in our enterprise setup that are running into the following error:

  ● Test suite failed to run

    TypeError: Path must be a string. Received undefined

      at buffer.reduce (node_modules/jest-util/build/getConsoleOutput.js:54:52)
          at Array.reduce (<anonymous>)

As far as I can tell, the trend seems to be related to when something in the test needs to output via the console, but a mock may be involved that either spies something related to a console log, or spies the console itself. This doesn’t happen with all tests, only a few. And when running the tests one off, I get the same error, but with a stack trace that is more defined than the above.

An example of one of the failing tests

  test('should exit if config assertion fails', () => {
    const message = 'dummy error';
    assertConfig.mockImplementation(() => {
      throw new Error(message);
    });
    // no-op exit spy to stop the actual process exit.
    jest.spyOn(process, 'exit').mockImplementation(() => {});
    jest.spyOn(console, 'log');

    config.loadConfig();

    expect(process.exit).toBeCalled();
    expect(process.exit).not.toBeCalledWith(0);
    // eslint-disable-next-line no-console
    expect(console.log).toBeCalledWith(message);

    process.exit.mockRestore();
    // eslint-disable-next-line no-console
    console.log.mockRestore();
  });

It’s possible this is fixed by https://github.com/facebook/jest/pull/7844/files, @SimenB maybe you can let me know? If so, I can wait till the next minor to validate.

EDIT: Doing some more digging it seems the config context is getting lost. When I run console.log on this line in my node_modules https://github.com/facebook/jest/blob/b49075ede2ec0b26bc626e25c5d383df31770413/packages/jest-runner/src/index.js#L82

I get cwd is undefined. When I run jest --showConfig, I don’t see that cwd is defined.

To Reproduce

Steps to reproduce the behavior:

  1. Upgrade all jest and jest related modules to v24 or later
  2. Run tests

Expected behavior

All tests should pass

Link to repl or repo (highly encouraged)

I can’t do this because the repl uses v22 of Jest

Please provide either a repl.it demo or a minimal repository on GitHub.

Issues without a reproduction link are likely to stall.

Run npx envinfo --preset jest

Paste the results here:

  System:
    OS: macOS 10.14.3
    CPU: (8) x64 Intel(R) Core(TM) i7-4980HQ CPU @ 2.80GHz
  Binaries:
    Node: 8.12.0 - ~/.nvm/versions/node/v8.12.0/bin/node
    Yarn: 1.13.0 - ~/git/repo/node_modules/.bin/yarn
    npm: 6.5.0 - ~/git/repo/node_modules/.bin/npm
  npmPackages:
    jest: 24.1.0 => 24.1.0

Issue Analytics

  • State:closed
  • Created 5 years ago
  • Reactions:4
  • Comments:17 (8 by maintainers)

github_iconTop GitHub Comments

1reaction
jeysalcommented, Feb 19, 2019

IMO it just makes things confusing if cwd becomes anything other than what the OS considers the cwd of the process. For all purposes that require setting the the base directory manually, we have rootDir.

0reactions
github-actions[bot]commented, May 12, 2021

This issue has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs. Please note this issue tracker is not a help forum. We recommend using StackOverflow or our discord channel for questions.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Jest TypeError: Path must be a string. Received undefined
I solved this issue using: npm uninstall -g jest; npm install -g jest; npm cache clean; npm install.
Read more >
npm err! code err_invalid_arg_type ...
yml Press Ctrl-C to stop this script TypeError [ERRINVALIDARG_TYPE]: The "path" argument must be of type string or an instance of Buffer or...
Read more >
TypeError: Path must be a string. Received undefined - ionic-v3
I upgraded my ionic version and an error appears when I run it in Windows cmd TypeError: Path must be a string.
Read more >
Webpack Error In Path Must Be A String. Received Undefined
To get started, install jscodeshift globally from npm. does not exist” message or “TypeError: path must be a string or Buffer” if the...
Read more >
Changelog
Fixed a regression introduced in Cypress 12 where cy.get() would ignore a ... Fixed an issue with the Specs list search that prevented...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found